Class: Duby::JVM::Types::IterableType

Inherits:
Type show all
Defined in:
lib/duby/jvm/types/intrinsics.rb

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 Type

#add_enumerable_macros, #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, #get_method, #init_value, #initialize, #inner_class?, #inner_class_getter, #inspect, #interface?, #interfaces, #intrinsics, #is_parent, #iterable?, #java_method, #jvm_type, #load, #log, #meta, #meta?, #newarray, #prefix, #primitive?, #return, #store, #superclass, #to_source, #unmeta, #void?, #wide?

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

#==, #block?, #compatible?, #component_type, #eql?, #error?, #hash, #initialize, #is_parent, #iterable?, #meta?, #narrow, #null?, #primitive?, #to_s, #unmeta, #unreachable?

Methods included from AST::Named

#to_s

Methods inherited from AST::Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #expr?, #initialize, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

This class inherits a constructor from Duby::JVM::Types::Type

Instance Method Details

#add_intrinsicsObject



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/duby/jvm/types/intrinsics.rb', line 217

def add_intrinsics
  super
  add_enumerable_macros
  add_macro('each', Duby::AST.block_type) do |transformer, call|
    Duby::AST::Loop.new(call.parent,
                        call.position, true, false) do |forloop|
      it = transformer.tmp

      assignment = transformer.eval("#{it} = foo.iterator")
      assignment.value.target = call.target
      call.target.parent = assignment.value
      forloop.init << assignment

      var = call.block.args.args[0]
      if var
        forloop.pre << transformer.eval(
            "#{var.name} = #{it}.next", '', forloop, it)
      end
      call.block.body.parent = forloop if call.block.body
      [
        Duby::AST::Condition.new(forloop, call.position) do |c|
          [transformer.eval("#{it}.hasNext", '', forloop, it)]
        end,
        call.block.body
      ]
    end
  end
end