Class: BiteScript::MethodBuilder
Constant Summary
Constants included
from Bytecode
Bytecode::JDobule, Bytecode::JFloat, Bytecode::JInteger, Bytecode::JLong, Bytecode::JObject, Bytecode::JPrintStream, Bytecode::JSystem, Bytecode::JVoid, Bytecode::OpcodeInstructions, Bytecode::OpcodeStackDeltas
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Bytecode
#aprintln, #label, #labels, #line, #println, #push_int, #start, #stop, #swap2, #sym_to_label, #trycatch
Methods included from Signature
ci, class_id, classname, path, sig, signature
#annotate, #find_retention
Methods included from QuickTypes
#boolean, #byte, #char, #double, #float, #int, #long, #null, #object, #short, #string, #void
Constructor Details
#initialize(class_builder, modifiers, name, exceptions, signature) ⇒ MethodBuilder
Returns a new instance of MethodBuilder.
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
# File 'lib/bitescript/builder.rb', line 439
def initialize(class_builder, modifiers, name, exceptions, signature)
@class_builder = class_builder
@modifiers = modifiers
@name = name
@signature = signature
@method_visitor = class_builder.new_method(modifiers, name, signature, exceptions)
@locals = {}
@next_local = 0
@static = (modifiers & Opcodes::ACC_STATIC) != 0
@start_label = labels[:start] = self.label
@end_label = labels[:end] = self.label
@exceptions = exceptions || []
end
|
Instance Attribute Details
#class_builder ⇒ Object
Returns the value of attribute class_builder.
437
438
439
|
# File 'lib/bitescript/builder.rb', line 437
def class_builder
@class_builder
end
|
#method_visitor ⇒ Object
Returns the value of attribute method_visitor.
432
433
434
|
# File 'lib/bitescript/builder.rb', line 432
def method_visitor
@method_visitor
end
|
#name ⇒ Object
Returns the value of attribute name.
436
437
438
|
# File 'lib/bitescript/builder.rb', line 436
def name
@name
end
|
#signature ⇒ Object
Returns the value of attribute signature.
435
436
437
|
# File 'lib/bitescript/builder.rb', line 435
def signature
@signature
end
|
#static ⇒ Object
Also known as:
static?
Returns the value of attribute static.
433
434
435
|
# File 'lib/bitescript/builder.rb', line 433
def static
@static
end
|
Class Method Details
.build(class_builder, modifiers, name, signature, &block) ⇒ Object
468
469
470
471
472
473
474
475
476
477
|
# File 'lib/bitescript/builder.rb', line 468
def self.build(class_builder, modifiers, name, signature, &block)
mb = MethodBuilder.new(class_builder, modifiers, name, signature)
mb.start
if block.arity == 1
block.call(mb)
else
mb.instance_eval(&block)
end
mb.stop
end
|
.build2(class_builder, modifiers, name, signature, &block) ⇒ Object
479
480
481
482
483
484
|
# File 'lib/bitescript/builder.rb', line 479
def self.build2(class_builder, modifiers, name, signature, &block)
mb = MethodBuilder.new(class_builder, modifiers, name, signature)
mb.start
block.call(mb)
mb.stop
end
|
Instance Method Details
#declaring_class ⇒ Object
464
465
466
|
# File 'lib/bitescript/builder.rb', line 464
def declaring_class
@class_builder
end
|
#generate(&block) ⇒ Object
486
487
488
489
490
|
# File 'lib/bitescript/builder.rb', line 486
def generate(&block)
start
block.call(self)
stop
end
|
#local(name, type = nil) ⇒ Object
496
497
498
499
500
501
502
503
504
505
506
507
|
# File 'lib/bitescript/builder.rb', line 496
def local(name, type=nil)
if name == "this" && @static
raise "'this' attempted to load from static method"
end
if @locals[name]
return @locals[name][-1][0]
else
raise ArgumentError, 'Local type required' unless type
return push_local(name, type, @start_label)
end
end
|
#local_debug_info(name, local, end_label = nil) ⇒ Object
531
532
533
534
535
536
537
538
539
|
# File 'lib/bitescript/builder.rb', line 531
def local_debug_info(name, local, end_label=nil)
return unless local
index, big, type, start = local
end_label ||= self.label.set!
method_visitor.visit_local_variable(name, type, nil,
start.label,
end_label.label,
index)
end
|
#parameter_types ⇒ Object
456
457
458
|
# File 'lib/bitescript/builder.rb', line 456
def parameter_types
signature[1..-1]
end
|
#pop_local(name) ⇒ Object
541
542
543
544
545
|
# File 'lib/bitescript/builder.rb', line 541
def pop_local(name)
here = self.label.set!
local_debug_info(name, @locals[name].pop, here)
@locals[name][-1][-1] = here if @locals[name].size > 0
end
|
#push_local(name, type, start = nil) ⇒ Object
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
|
# File 'lib/bitescript/builder.rb', line 509
def push_local(name, type, start=nil)
start ||= self.label.set!
type = ci(type)
big = "JD".include? type
match = @locals[name].find {|local| !big || local[1]} if @locals[name]
if match
index = match[0]
else
index = @next_local
@next_local += 1
@next_local += 1 if big
end
if @locals[name] && @locals[name].size > 0
local_debug_info(name, @locals[name][-1])
else
@locals[name] = []
end
@locals[name] << [index, big, type, start]
index
end
|
#return_type ⇒ Object
460
461
462
|
# File 'lib/bitescript/builder.rb', line 460
def return_type
signature[0]
end
|
#this ⇒ Object
492
493
494
|
# File 'lib/bitescript/builder.rb', line 492
def this
@class_builder
end
|
#visit_annotation(*args) ⇒ Object
547
548
549
|
# File 'lib/bitescript/builder.rb', line 547
def visit_annotation(*args)
@method_visitor.visit_annotation(*args)
end
|