Class: Java::OrgJrubyAst::DefsNode

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

Instance Method Summary collapse

Instance Method Details

#compile(builder) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/duby/old/compiler_old.rb', line 418

def compile(builder)
  first_real_node = body_node
  first_real_node = body_node.child_nodes[0] if BlockNode === body_node
  while NewlineNode === first_real_node
    first_real_node = first_real_node.next_node
  end
  
  # determine signature from declaration line
  signature = first_real_node.signature(builder) if HashNode === first_real_node
  
  signature ||= [Void]
  
  log "Compiling static method for #{name} as #{signature.join(',')}"
  builder.static_method(name, *signature) do |method|
    # Run through any type declarations first
    first_real_node.declare_types(method) if HashNode === first_real_node

    # declare args that may not have been declared already
    args_node.compile(method)
    
    body_node.compile(method) if body_node
    
    # Expectation is that last element leaves the right type on stack
    if signature[0].primitive?
      case signature[0]
      when Void
        method.returnvoid
      when Jboolean, Jbyte
        method.breturn
      when Jchar
        method.creturn
      when Jshort
        method.sreturn
      when Jint
        method.ireturn
      when Jlong
        method.lreturn
      when Jfloat
        method.freturn
      when Jdouble
        method.dreturn
      else
        raise CompileError.new(position, "Unknown return type: #{signature[0]}")
      end
    else
      method.areturn
    end
  end
end