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, tipath, type_insn_path
#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.
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
# File 'lib/bitescript/builder.rb', line 473
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.
471
472
473
|
# File 'lib/bitescript/builder.rb', line 471
def class_builder
@class_builder
end
|
#method_visitor ⇒ Object
Returns the value of attribute method_visitor.
466
467
468
|
# File 'lib/bitescript/builder.rb', line 466
def method_visitor
@method_visitor
end
|
#name ⇒ Object
Returns the value of attribute name.
470
471
472
|
# File 'lib/bitescript/builder.rb', line 470
def name
@name
end
|
#signature ⇒ Object
Returns the value of attribute signature.
469
470
471
|
# File 'lib/bitescript/builder.rb', line 469
def signature
@signature
end
|
#static ⇒ Object
Also known as:
static?
Returns the value of attribute static.
467
468
469
|
# File 'lib/bitescript/builder.rb', line 467
def static
@static
end
|
Class Method Details
.build(class_builder, modifiers, name, signature, &block) ⇒ Object
502
503
504
505
506
507
508
509
510
511
|
# File 'lib/bitescript/builder.rb', line 502
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
513
514
515
516
517
518
|
# File 'lib/bitescript/builder.rb', line 513
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
498
499
500
|
# File 'lib/bitescript/builder.rb', line 498
def declaring_class
@class_builder
end
|
#generate(&block) ⇒ Object
520
521
522
523
524
|
# File 'lib/bitescript/builder.rb', line 520
def generate(&block)
start
block.call(self)
stop
end
|
#local(name, type = nil) ⇒ Object
530
531
532
533
534
535
536
537
538
539
540
541
|
# File 'lib/bitescript/builder.rb', line 530
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
565
566
567
568
569
570
571
572
573
|
# File 'lib/bitescript/builder.rb', line 565
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
490
491
492
|
# File 'lib/bitescript/builder.rb', line 490
def parameter_types
signature[1..-1]
end
|
#pop_local(name) ⇒ Object
575
576
577
578
579
|
# File 'lib/bitescript/builder.rb', line 575
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
|
# File 'lib/bitescript/builder.rb', line 543
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
494
495
496
|
# File 'lib/bitescript/builder.rb', line 494
def return_type
signature[0]
end
|
#this ⇒ Object
526
527
528
|
# File 'lib/bitescript/builder.rb', line 526
def this
@class_builder
end
|
#visit_annotation(*args) ⇒ Object
581
582
583
|
# File 'lib/bitescript/builder.rb', line 581
def visit_annotation(*args)
@method_visitor.visit_annotation(*args)
end
|