Class: Mirah::JVM::Types::FloatType

Inherits:
Number show all
Defined in:
lib/mirah/jvm/types/floats.rb

Direct Known Subclasses

DoubleType

Constant Summary

Constants inherited from AST::TypeReference

AST::TypeReference::BlockType, AST::TypeReference::ErrorType, AST::TypeReference::NoType, AST::TypeReference::NullType, AST::TypeReference::UnreachableType

Instance Attribute Summary

Attributes inherited from Type

#inner_class

Attributes inherited from AST::TypeReference

#array, #meta

Attributes included from AST::Named

#name

Attributes inherited from AST::Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods inherited from Number

#add_delegates, #add_intrinsics, #boolean_operator, #box, #compile_boolean_operator, #delegate_intrinsic, #invert_op, #jump_if, #math_operator, #unary_operator

Methods inherited from PrimitiveType

#add_intrinsics, #convertible_to?, #initialize, #interfaces, #newarray, #primitive?, #primitive_type, #superclass

Methods inherited from Type

#add_compiled_macro, #add_enumerable_macros, #add_intrinsics, #add_macro, #add_method, #aload, #array?, #array_type, #assignable_from?, #astore, #basic_type, #compatible?, #component_type, #constructor, #declared_class_methods, #declared_constructors, #declared_instance_methods, #declared_intrinsics, #dynamic?, #expand_each, #field_getter, #field_setter, #full_name, #get_method, #include, #initialize, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #is_parent, #iterable?, #java_method, #jvm_type, #load, #load_extensions, #log, #meta, #meta?, #newarray, #pop, #primitive?, #return, #store, #superclass, #to_source, #unmeta, #void?, #wide?, #wrap_with_scoped_body

Methods included from MethodLookup

#each_is_exact, #each_is_exact_or_subtype_or_convertible, #field_lookup, #find_jls, #find_method, #inner_class, #is_more_specific?, #log, #phase1, #phase2, #phase3, #primitive_convertible?

Methods inherited from AST::TypeReference

#==, #_dump, _load, #basic_type, #block?, #compatible?, #component_type, #eql?, #error?, #full_name, #hash, #initialize, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #type_reference, #unmeta, #unreachable?, #void?

Methods included from AST::Named

#string_value, #to_s, #validate_name

Methods inherited from AST::Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #expr?, #inferred_type!, #initialize, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

This class inherits a constructor from Mirah::JVM::Types::PrimitiveType

Instance Method Details

#box_typeObject



26
27
28
# File 'lib/mirah/jvm/types/floats.rb', line 26

def box_type
  java.lang.Float
end

#init_value(builder) ⇒ Object



34
35
36
# File 'lib/mirah/jvm/types/floats.rb', line 34

def init_value(builder)
  builder.fconst_0
end

#literal(builder, value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mirah/jvm/types/floats.rb', line 38

def literal(builder, value)
  case value
  when 0.0
    builder.fconst_0
  when 1.0
    builder.fconst_1
  when 2.0
    builder.fconst_2
  else
    builder.ldc_float(value)
  end
end

#math_typeObject



22
23
24
# File 'lib/mirah/jvm/types/floats.rb', line 22

def math_type
  Float
end

#prefixObject



18
19
20
# File 'lib/mirah/jvm/types/floats.rb', line 18

def prefix
  'f'
end

#suffixObject



30
31
32
# File 'lib/mirah/jvm/types/floats.rb', line 30

def suffix
  'g'
end

#widen(builder, type) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/mirah/jvm/types/floats.rb', line 51

def widen(builder, type)
  case type
  when Float
    # Do nothing
  when Double
    builder.f2d
  else
    raise ArgumentError, "Invalid widening conversion from float to #{type}"
  end
end