Class: Lignite::Condition
- Inherits:
-
Object
- Object
- Lignite::Condition
- Defined in:
- lib/lignite/condition.rb
Overview
Compile a conditional jump forward or backward
Instance Method Summary collapse
-
#cond_jump(_compiler, _offset) ⇒ Object
Call that instruction of the compiler that jumps by offset according to the condition that we implement.
- #jump_back(compiler, body_size, self_size = nil) ⇒ Object
- #jump_forward(compiler, body_size) ⇒ Object
-
#not ⇒ Object
Negation of this condition.
Instance Method Details
#cond_jump(_compiler, _offset) ⇒ Object
Call that instruction of the compiler that jumps by offset according to the condition that we implement
6 7 8 |
# File 'lib/lignite/condition.rb', line 6 def cond_jump(_compiler, _offset) raise ScriptError, "subclasses must override this" end |
#jump_back(compiler, body_size, self_size = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/lignite/condition.rb', line 20 def jump_back(compiler, body_size, self_size = nil) if self_size.nil? fake = compiler.clone_context jump_back(fake, body_size, 0) self_size = fake.bytes.bytesize end cond_jump(compiler, - (body_size + self_size)) end |
#jump_forward(compiler, body_size) ⇒ Object
16 17 18 |
# File 'lib/lignite/condition.rb', line 16 def jump_forward(compiler, body_size) cond_jump(compiler, body_size) end |
#not ⇒ Object
Negation of this condition. An ‘if(cond){ body }` becomes roughly `cond.not.jump_forward(body.size); body`
12 13 14 |
# File 'lib/lignite/condition.rb', line 12 def not raise ScriptError, "subclasses must override this" end |