Class: Verneuil::Compiler
- Inherits:
-
Object
- Object
- Verneuil::Compiler
- Defined in:
- lib/verneuil/compiler.rb
Overview
Compiles verneuil code into a program.
Defined Under Namespace
Classes: Visitor
Class Method Summary collapse
Instance Method Summary collapse
-
#compile(code) ⇒ Object
Compiles a piece of code within the current program.
-
#initialize ⇒ Compiler
constructor
A new instance of Compiler.
- #program ⇒ Object
Constructor Details
Class Method Details
.compile(*args) ⇒ Object
15 16 17 18 |
# File 'lib/verneuil/compiler.rb', line 15 def self.compile(*args) new. tap { |compiler| compiler.compile(*args) } end |
Instance Method Details
#compile(code) ⇒ Object
Compiles a piece of code within the current program. This means that any method definitions that have already been encountered will be used to resolve method calls. Returns the program which can also be accessed using #program on the compiler instance.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/verneuil/compiler.rb', line 25 def compile(code) parser = RubyParser.new sexp = parser.parse(code) # pp sexp visitor = Visitor.new(@generator, self) visitor.visit(sexp) @generator.program end |
#program ⇒ Object
11 12 13 |
# File 'lib/verneuil/compiler.rb', line 11 def program @generator.program end |