Class: Peruby::Compiler
- Inherits:
-
Object
- Object
- Peruby::Compiler
- Defined in:
- lib/peruby/compiler.rb
Overview
Converts immutable syntax nodes into executable operation trees.
Instance Method Summary collapse
- #compile(node) ⇒ Object
-
#initialize(predeclared: nil) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(predeclared: nil) ⇒ Compiler
Returns a new instance of Compiler.
19 20 21 |
# File 'lib/peruby/compiler.rb', line 19 def initialize(predeclared: nil) @predeclared = predeclared end |
Instance Method Details
#compile(node) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/peruby/compiler.rb', line 23 def compile(node) name = node.class.name.split('::').last.gsub(/([A-Z]+)([A-Z][a-z])/, '\\1_\\2') .gsub(/([a-z\d])([A-Z])/, '\\1_\\2').downcase method = "compile_#{name}" raise CompileError, "Unsupported syntax node #{node.class}" unless respond_to?(method, true) send(method, node) end |