Class: Schemurai::VM::Program
- Inherits:
-
Object
- Object
- Schemurai::VM::Program
- Defined in:
- lib/schemurai/vm/compiler.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#dynamic_anchor ⇒ Object
readonly
Returns the value of attribute dynamic_anchor.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #emit(code, opcode, operand) ⇒ Object
- #finish(code) ⇒ Object
-
#initialize(node) ⇒ Program
constructor
A new instance of Program.
- #recursive_anchor? ⇒ Boolean
- #track_dynamic_scope! ⇒ Object
- #track_evaluation! ⇒ Object
- #tracks_dynamic_scope? ⇒ Boolean
- #tracks_evaluation? ⇒ Boolean
Constructor Details
#initialize(node) ⇒ Program
Returns a new instance of Program.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/schemurai/vm/compiler.rb', line 113 def initialize(node) @node = node @tracks_evaluation = false @tracks_dynamic_scope = false schema = node.schema if schema.instance_of?(Hash) @recursive_anchor = schema["$recursiveAnchor"] == true dynamic_anchor = schema["$dynamicAnchor"] @dynamic_anchor = -dynamic_anchor if dynamic_anchor.instance_of?(String) else @recursive_anchor = false end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
111 112 113 |
# File 'lib/schemurai/vm/compiler.rb', line 111 def code @code end |
#dynamic_anchor ⇒ Object (readonly)
Returns the value of attribute dynamic_anchor.
111 112 113 |
# File 'lib/schemurai/vm/compiler.rb', line 111 def dynamic_anchor @dynamic_anchor end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
111 112 113 |
# File 'lib/schemurai/vm/compiler.rb', line 111 def node @node end |
Instance Method Details
#emit(code, opcode, operand) ⇒ Object
127 128 129 |
# File 'lib/schemurai/vm/compiler.rb', line 127 def emit(code, opcode, operand) code.push(opcode, operand) end |
#finish(code) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/schemurai/vm/compiler.rb', line 139 def finish(code) flags = 0 flags |= TRACKS_EVALUATION if @tracks_evaluation flags |= TRACKS_DYNAMIC_SCOPE if @tracks_dynamic_scope code[0] = flags @code = code.freeze freeze end |
#recursive_anchor? ⇒ Boolean
152 153 154 |
# File 'lib/schemurai/vm/compiler.rb', line 152 def recursive_anchor? @recursive_anchor end |
#track_dynamic_scope! ⇒ Object
135 136 137 |
# File 'lib/schemurai/vm/compiler.rb', line 135 def track_dynamic_scope! @tracks_dynamic_scope = true end |
#track_evaluation! ⇒ Object
131 132 133 |
# File 'lib/schemurai/vm/compiler.rb', line 131 def track_evaluation! @tracks_evaluation = true end |
#tracks_dynamic_scope? ⇒ Boolean
156 157 158 |
# File 'lib/schemurai/vm/compiler.rb', line 156 def tracks_dynamic_scope? @tracks_dynamic_scope end |
#tracks_evaluation? ⇒ Boolean
148 149 150 |
# File 'lib/schemurai/vm/compiler.rb', line 148 def tracks_evaluation? @tracks_evaluation end |