Class: Twostroke::Compiler::Javascript
- Inherits:
-
Object
- Object
- Twostroke::Compiler::Javascript
- Defined in:
- lib/twostroke/compiler/javascript.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#src ⇒ Object
Returns the value of attribute src.
Instance Method Summary collapse
- #compile(node = nil) ⇒ Object
-
#initialize(ast) ⇒ Javascript
constructor
A new instance of Javascript.
Constructor Details
#initialize(ast) ⇒ Javascript
Returns a new instance of Javascript.
4 5 6 7 |
# File 'lib/twostroke/compiler/javascript.rb', line 4 def initialize(ast) @methods = Hash[self.class.private_instance_methods(false).map { |name| [name, true] }] @ast = ast end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
2 3 4 |
# File 'lib/twostroke/compiler/javascript.rb', line 2 def ast @ast end |
#src ⇒ Object
Returns the value of attribute src.
2 3 4 |
# File 'lib/twostroke/compiler/javascript.rb', line 2 def src @src end |
Instance Method Details
#compile(node = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/twostroke/compiler/javascript.rb', line 9 def compile(node = nil) if node if node.respond_to? :each # hoist named functions to top node.select { |n| n.is_a?(Twostroke::AST::Function) && n.name }.each { |n| compile n } node.reject { |n| n.is_a?(Twostroke::AST::Function) && n.name }.each { |n| compile n } else if @methods[type(node)] send type(node), node if node else error! "#{type node} not implemented" end end else @indent = 0 @src = "" prologue ast.each { |node| compile node } end end |