Class: Lignite::BodyCompiler
- Inherits:
-
Object
- Object
- Lignite::BodyCompiler
- Includes:
- VariableDeclarer
- Defined in:
- lib/lignite/body_compiler.rb
Overview
Extends OpCompiler by
-
variable declarations: VariableDeclarer
-
high level flow control: #loop
Defined Under Namespace
Modules: VariableDeclarer
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
-
#initialize(locals) ⇒ BodyCompiler
constructor
A new instance of BodyCompiler.
- #loop(&body) ⇒ Object
- #method_missing(name, *args) ⇒ Object
Methods included from VariableDeclarer
Constructor Details
#initialize(locals) ⇒ BodyCompiler
Returns a new instance of BodyCompiler.
22 23 24 25 26 |
# File 'lib/lignite/body_compiler.rb', line 22 def initialize(locals) @bytes = "" @locals = locals @op_compiler = OpCompiler.new(nil, @locals) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
36 37 38 39 40 |
# File 'lib/lignite/body_compiler.rb', line 36 def method_missing(name, *args) super unless @op_compiler.respond_to?(name) @bytes += @op_compiler.send(name, *args) end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
19 20 21 |
# File 'lib/lignite/body_compiler.rb', line 19 def bytes @bytes end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
20 21 22 |
# File 'lib/lignite/body_compiler.rb', line 20 def locals @locals end |
Instance Method Details
#loop(&body) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/lignite/body_compiler.rb', line 28 def loop(&body) subc = BodyCompiler.new(@locals) subc.instance_exec(&body) @bytes << subc.bytes # the jump takes up 4 bytes: JR, LC2, LO, HI jr(Complex(- (subc.bytes.bytesize + 4), 2)) end |