Class: Java::OrgJrubyAst::FCallNode

Inherits:
Object
  • Object
show all
Defined in:
lib/duby/old/compiler_old.rb,
lib/duby/old/typer_old.rb,
lib/duby/old/mapper.rb

Instance Method Summary collapse

Instance Method Details

#compile(builder) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/duby/old/compiler_old.rb', line 470

def compile(builder)
  case name
  when "puts"
    compile_puts(builder)
  when "import"
    compile_import(builder)
  else
    if (builder.static)
      arg_types = []
      args_node.child_nodes.each do |node|
        node.compile(builder)
        arg_types << node.type(builder)
      end

      builder.invokestatic builder.this, name, builder.static_signature(name, arg_types)
    else
      builder.aload 0
      arg_types = []
      args_node.child_nodes.each do |node|
        node.compile(builder)
        arg_types << node.type(builder)
      end

      builder.invokevirtual builder.this, name, builder.instance_signature(name, arg_types)
    end
  end
end

#compile_import(builder) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
# File 'lib/duby/old/compiler_old.rb', line 512

def compile_import(builder)
  log "Compiling import at #{position.start_line}"
  args_node.child_nodes.each do |node|
    case node
    when StrNode
      builder.import(node.value)
    else
      raise CompileError.new(position, "Imports only allow strings right now")
    end
  end
end

#compile_puts(builder) ⇒ Object



498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/duby/old/compiler_old.rb', line 498

def compile_puts(builder)
  log "Compiling special #{name} at #{position.start_line}"
  builder.getstatic System, "out", [PrintStream]

  arg_types = []
  args_node.child_nodes.each do |node|
    node.compile(builder)
    arg_types << node.type(builder)
  end

  builder.invokevirtual PrintStream, "println", special_signature(PrintStream, builder)
  builder.aconst_null
end

#mapped_name(builder) ⇒ Object



45
46
47
48
49
# File 'lib/duby/old/mapper.rb', line 45

def mapped_name(builder)
  if name == "puts"
    "println"
  end
end

#special_signature(recv_type, builder) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/duby/old/typer_old.rb', line 62

def special_signature(recv_type, builder)
  arg_types = []
  args_node.child_nodes.each do |node|
    arg_types << node.type(builder)
  end if args_node
  recv_java_class = recv_type
  declared_method = recv_java_class.declared_method_smart(mapped_name(builder), *arg_types)
  return_type = declared_method.return_type
  if (return_type)
    return_class = return_type
  else
    return_class = Void
  end
  
  return [
    return_class,
    *declared_method.parameter_types
  ]
end

#type(builder) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/duby/old/typer_old.rb', line 82

def type(builder)
  @type ||= begin
    arg_types = []
    args_node.child_nodes.each do |node|
      arg_types << node.type(builder)
    end if args_node
    if builder.static
      signature = builder.static_signature(name, arg_types)
    else
      signature = builder.instance_signature(name, arg_types)
    end
    raise CompileError.new(position, "Signature not found for call #{name}") unless signature

    signature[0]
  end
end