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.
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
# File 'lib/bitescript/builder.rb', line 497
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.
495
496
497
|
# File 'lib/bitescript/builder.rb', line 495
def class_builder
@class_builder
end
|
#method_visitor ⇒ Object
Returns the value of attribute method_visitor.
490
491
492
|
# File 'lib/bitescript/builder.rb', line 490
def method_visitor
@method_visitor
end
|
#name ⇒ Object
Returns the value of attribute name.
494
495
496
|
# File 'lib/bitescript/builder.rb', line 494
def name
@name
end
|
#signature ⇒ Object
Returns the value of attribute signature.
493
494
495
|
# File 'lib/bitescript/builder.rb', line 493
def signature
@signature
end
|
#static ⇒ Object
Also known as:
static?
Returns the value of attribute static.
491
492
493
|
# File 'lib/bitescript/builder.rb', line 491
def static
@static
end
|
Class Method Details
.build(class_builder, modifiers, name, signature, &block) ⇒ Object
526
527
528
529
530
531
532
533
534
535
|
# File 'lib/bitescript/builder.rb', line 526
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
537
538
539
540
541
542
|
# File 'lib/bitescript/builder.rb', line 537
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
522
523
524
|
# File 'lib/bitescript/builder.rb', line 522
def declaring_class
@class_builder
end
|
#generate(&block) ⇒ Object
544
545
546
547
548
|
# File 'lib/bitescript/builder.rb', line 544
def generate(&block)
start
block.call(self)
stop
end
|
#local(name, type = nil) ⇒ Object
554
555
556
557
558
559
560
561
562
563
564
565
|
# File 'lib/bitescript/builder.rb', line 554
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
589
590
591
592
593
594
595
596
597
|
# File 'lib/bitescript/builder.rb', line 589
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
514
515
516
|
# File 'lib/bitescript/builder.rb', line 514
def parameter_types
signature[1..-1]
end
|
#pop_local(name) ⇒ Object
599
600
601
602
603
|
# File 'lib/bitescript/builder.rb', line 599
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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
# File 'lib/bitescript/builder.rb', line 567
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
518
519
520
|
# File 'lib/bitescript/builder.rb', line 518
def return_type
signature[0]
end
|
#this ⇒ Object
550
551
552
|
# File 'lib/bitescript/builder.rb', line 550
def this
@class_builder
end
|
#visit_annotation(*args) ⇒ Object
605
606
607
|
# File 'lib/bitescript/builder.rb', line 605
def visit_annotation(*args)
@method_visitor.visit_annotation(*args)
end
|