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
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.
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
# File 'lib/bitescript/builder.rb', line 424
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.
422
423
424
|
# File 'lib/bitescript/builder.rb', line 422
def class_builder
@class_builder
end
|
#method_visitor ⇒ Object
Returns the value of attribute method_visitor.
417
418
419
|
# File 'lib/bitescript/builder.rb', line 417
def method_visitor
@method_visitor
end
|
#name ⇒ Object
Returns the value of attribute name.
421
422
423
|
# File 'lib/bitescript/builder.rb', line 421
def name
@name
end
|
#signature ⇒ Object
Returns the value of attribute signature.
420
421
422
|
# File 'lib/bitescript/builder.rb', line 420
def signature
@signature
end
|
#static ⇒ Object
Also known as:
static?
Returns the value of attribute static.
418
419
420
|
# File 'lib/bitescript/builder.rb', line 418
def static
@static
end
|
Class Method Details
.build(class_builder, modifiers, name, signature, &block) ⇒ Object
453
454
455
456
457
458
459
460
461
462
|
# File 'lib/bitescript/builder.rb', line 453
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
464
465
466
467
468
469
|
# File 'lib/bitescript/builder.rb', line 464
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
449
450
451
|
# File 'lib/bitescript/builder.rb', line 449
def declaring_class
@class_builder
end
|
#generate(&block) ⇒ Object
471
472
473
474
475
|
# File 'lib/bitescript/builder.rb', line 471
def generate(&block)
start
block.call(self)
stop
end
|
#local(name, type = nil) ⇒ Object
481
482
483
484
485
486
487
488
489
490
491
492
|
# File 'lib/bitescript/builder.rb', line 481
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
516
517
518
519
520
521
522
523
524
|
# File 'lib/bitescript/builder.rb', line 516
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
441
442
443
|
# File 'lib/bitescript/builder.rb', line 441
def parameter_types
signature[1..-1]
end
|
#pop_local(name) ⇒ Object
526
527
528
529
530
|
# File 'lib/bitescript/builder.rb', line 526
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
# File 'lib/bitescript/builder.rb', line 494
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
445
446
447
|
# File 'lib/bitescript/builder.rb', line 445
def return_type
signature[0]
end
|
#this ⇒ Object
477
478
479
|
# File 'lib/bitescript/builder.rb', line 477
def this
@class_builder
end
|
#visit_annotation(*args) ⇒ Object
532
533
534
|
# File 'lib/bitescript/builder.rb', line 532
def visit_annotation(*args)
@method_visitor.visit_annotation(*args)
end
|