Class: Malady::AST::LetNode

Inherits:
FnNode show all
Defined in:
lib/malady/ast.rb

Instance Attribute Summary collapse

Attributes inherited from FnNode

#arguments, #body

Attributes inherited from Node

#filename, #line

Instance Method Summary collapse

Methods inherited from FnNode

#new_block_generator

Methods inherited from Node

#pos

Constructor Details

#initialize(filename, line, bindings, body) ⇒ LetNode

Returns a new instance of LetNode.



257
258
259
260
261
262
# File 'lib/malady/ast.rb', line 257

def initialize(filename, line, bindings, body)
  @bindings = bindings
  @identifiers = @bindings.map(&:first)
  @values = @bindings.map(&:last)
  super(filename, line, identifiers, body)
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



255
256
257
# File 'lib/malady/ast.rb', line 255

def bindings
  @bindings
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



255
256
257
# File 'lib/malady/ast.rb', line 255

def identifiers
  @identifiers
end

#valuesObject (readonly)

Returns the value of attribute values.



255
256
257
# File 'lib/malady/ast.rb', line 255

def values
  @values
end

Instance Method Details

#bytecode(g) ⇒ Object

A LetNode is basically a closure with its arguments applied to the bindings



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/malady/ast.rb', line 265

def bytecode(g)
  super(g)

  # compile bindings' values
  @values.each do |val|
    val.bytecode(g)
  end

  # send :call to the block
  g.send :call, @bindings.count
end