Class: Malady::AST::Program

Inherits:
Node
  • Object
show all
Defined in:
lib/malady/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#filename, #line

Instance Method Summary collapse

Methods inherited from Node

#pos

Constructor Details

#initialize(filename, line, body) ⇒ Program

Returns a new instance of Program.



19
20
21
22
# File 'lib/malady/ast.rb', line 19

def initialize(filename, line, body)
  super
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



17
18
19
# File 'lib/malady/ast.rb', line 17

def body
  @body
end

Instance Method Details

#bytecode(g) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/malady/ast.rb', line 24

def bytecode(g)
  g.file = (filename || :"(malady)").to_sym
  pos(g)

  body.each_with_index do |expression, idx|
    expression.bytecode(g)
    g.pop unless idx == body.size - 1
  end

  g.finalize
end