Class: AmberVM::Interpreter::Block

Inherits:
Element show all
Defined in:
lib/amber/interpreter.rb

Overview

A block localizes variables, do not mix this up with the AmberVM::Classes::Block class!

Blocks are mostly used to handle tasks as not interfeeing With outer code.

Direct Known Subclasses

SimpleBlock

Instance Attribute Summary collapse

Attributes inherited from Element

#pos

Instance Method Summary collapse

Constructor Details

#initialize(content, pos = nil) ⇒ Block

Returns a new instance of Block.



231
232
233
234
# File 'lib/amber/interpreter.rb', line 231

def initialize content, pos = nil
  super(pos)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



230
231
232
# File 'lib/amber/interpreter.rb', line 230

def content
  @content
end

Instance Method Details

#execute(env) ⇒ Object

When executed a temporary environment is created with the passed Enviroement as a parent to it. This new environment is discaded after the execution.



246
247
248
249
# File 'lib/amber/interpreter.rb', line 246

def execute env
  tenv = Environment.new({}, env) 
  @content.execute tenv
end

#optimize(variables = {}) ⇒ Object



251
252
253
254
# File 'lib/amber/interpreter.rb', line 251

def optimize variables = {}
  content = @content.optimize variables
  Block.new(content, @pos)
end

#pretty_print(q) ⇒ Object



236
237
238
239
240
241
# File 'lib/amber/interpreter.rb', line 236

def pretty_print(q)
  first = true 
  q.group 1, "{", "}" do
    q.pp @content
  end
end