Class: Schemurai::VM::Compiler
- Inherits:
-
Object
- Object
- Schemurai::VM::Compiler
- Defined in:
- lib/schemurai/vm/compiler.rb
Instance Method Summary collapse
- #compile(node) ⇒ Object
- #compile_all ⇒ Object
-
#initialize(graph) ⇒ Compiler
constructor
A new instance of Compiler.
- #resolve(program, reference) ⇒ Object
Constructor Details
#initialize(graph) ⇒ Compiler
Returns a new instance of Compiler.
162 163 164 165 |
# File 'lib/schemurai/vm/compiler.rb', line 162 def initialize(graph) @graph = graph @programs = {}.compare_by_identity end |
Instance Method Details
#compile(node) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/schemurai/vm/compiler.rb', line 167 def compile(node) program = @programs[node] return program if program program = Program.new(node) @programs[node] = program program.finish(compile_code(node, program)) end |
#compile_all ⇒ Object
176 177 178 179 |
# File 'lib/schemurai/vm/compiler.rb', line 176 def compile_all @graph.nodes.each { |node| compile(node) } self end |
#resolve(program, reference) ⇒ Object
181 182 183 |
# File 'lib/schemurai/vm/compiler.rb', line 181 def resolve(program, reference) compile(@graph.resolve(program.node, reference)) end |