Class: Lignite::BodyCompiler
Overview
Constant Summary
ParameterDeclarer::IN, ParameterDeclarer::OUT, ParameterDeclarer::PAR16, ParameterDeclarer::PAR32, ParameterDeclarer::PAR8, ParameterDeclarer::PARF, ParameterDeclarer::PARS
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#call(name, *args) ⇒ Object
-
#clone_context ⇒ Object
-
#if(flag8, &body) ⇒ Object
-
#initialize(globals, locals, declared_objects) ⇒ BodyCompiler
constructor
A new instance of BodyCompiler.
-
#loop(&body) ⇒ Object
-
#loop_while(a, b) ⇒ Object
-
#loop_while_post(condition, &body) ⇒ Object
-
#loop_while_postcond(flag8, &body) ⇒ Object
-
#method_missing(name, *args) ⇒ Object
Delegate the ops to the OpCompiler, but also aggregate the result in @bytes.
-
#param_decl_header ⇒ Object
-
#parameters ⇒ Object
-
#respond_to_missing?(name, _include_private) ⇒ Boolean
-
#variables ⇒ Object
#in16, #in32, #in8, #inf, #ins, #io16, #io32, #io8, #iof, #ios, #out16, #out32, #out8, #outf, #outs
#array8, #data16, #data32, #data8, #dataf, #datas
Constructor Details
#initialize(globals, locals, declared_objects) ⇒ BodyCompiler
Returns a new instance of BodyCompiler.
53
54
55
56
57
58
59
|
# File 'lib/lignite/body_compiler.rb', line 53
def initialize(globals, locals, declared_objects)
@bytes = ""
@globals = globals
@locals = locals
@declared_objects = declared_objects
@op_compiler = OpCompiler.new(@globals, @locals)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Delegate the ops to the OpCompiler, but also aggregate the result in @bytes.
115
116
117
118
119
|
# File 'lib/lignite/body_compiler.rb', line 115
def method_missing(name, *args)
super unless @op_compiler.respond_to?(name)
@bytes += @op_compiler.send(name, *args)
end
|
Instance Attribute Details
33
34
35
|
# File 'lib/lignite/body_compiler.rb', line 33
def bytes
@bytes
end
|
#declared_objects ⇒ Object
Returns the value of attribute declared_objects.
37
38
39
|
# File 'lib/lignite/body_compiler.rb', line 37
def declared_objects
@declared_objects
end
|
35
36
37
|
# File 'lib/lignite/body_compiler.rb', line 35
def locals
@locals
end
|
Instance Method Details
#call(name, *args) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/lignite/body_compiler.rb', line 105
def call(name, *args)
obj_id = declared_objects.index_of(name)
raise "Name #{name} not found" if obj_id.nil?
super(obj_id, *args) end
|
#clone_context ⇒ Object
61
62
63
|
# File 'lib/lignite/body_compiler.rb', line 61
def clone_context
BodyCompiler.new(@globals, @locals, @declared_objects)
end
|
#if(flag8, &body) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/lignite/body_compiler.rb', line 65
def if(flag8, &body)
subc = BodyCompiler.new(@globals, @locals, @declared_objects)
subc.instance_exec(&body)
jr_false(flag8, Complex(subc.bytes.bytesize, 2))
@bytes << subc.bytes
end
|
#loop(&body) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/lignite/body_compiler.rb', line 73
def loop(&body)
subc = BodyCompiler.new(@globals, @locals, @declared_objects)
subc.instance_exec(&body)
@bytes << subc.bytes
jr(Complex(- (subc.bytes.bytesize + 4), 2))
end
|
#loop_while(a, b) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/lignite/body_compiler.rb', line 89
def loop_while(a, b)
if a.respond_to? :call
loop_while_post(b, &a)
else
loop_while_pre(a, &b)
end
end
|
#loop_while_post(condition, &body) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/lignite/body_compiler.rb', line 97
def loop_while_post(condition, &body)
subc = BodyCompiler.new(@globals, @locals, @declared_objects)
subc.instance_exec(&body)
@bytes << subc.bytes
body_size = subc.bytes.bytesize
condition.jump_back(self, body_size)
end
|
#loop_while_postcond(flag8, &body) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/lignite/body_compiler.rb', line 81
def loop_while_postcond(flag8, &body)
subc = BodyCompiler.new(@globals, @locals, @declared_objects)
subc.instance_exec(&body)
@bytes << subc.bytes
jr_true(flag8, Complex(- (subc.bytes.bytesize + 5), 2))
end
|
49
50
51
|
# File 'lib/lignite/body_compiler.rb', line 49
def
parameters.
end
|
#parameters ⇒ Object
44
45
46
|
# File 'lib/lignite/body_compiler.rb', line 44
def parameters
locals
end
|
#respond_to_missing?(name, _include_private) ⇒ Boolean
121
122
123
|
# File 'lib/lignite/body_compiler.rb', line 121
def respond_to_missing?(name, _include_private)
@op_compiler.respond_to?(name) || super
end
|
#variables ⇒ Object
39
40
41
|
# File 'lib/lignite/body_compiler.rb', line 39
def variables
locals
end
|