Class: Ascode::Interpreter::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/ascode/interpreter/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast = "") ⇒ Environment

Returns a new instance of Environment.



8
9
10
11
12
# File 'lib/ascode/interpreter/environment.rb', line 8

def initialize(ast = "")
  @ast = ast
  @stack = []
  @register = nil
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



6
7
8
# File 'lib/ascode/interpreter/environment.rb', line 6

def ast
  @ast
end

#registerObject

Returns the value of attribute register.



6
7
8
# File 'lib/ascode/interpreter/environment.rb', line 6

def register
  @register
end

#stackObject

Returns the value of attribute stack.



6
7
8
# File 'lib/ascode/interpreter/environment.rb', line 6

def stack
  @stack
end

Instance Method Details

#duplicateObject



43
44
45
46
47
# File 'lib/ascode/interpreter/environment.rb', line 43

def duplicate
  a = pop
  push a
  push a
end

#pop(ask = true) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/ascode/interpreter/environment.rb', line 26

def pop(ask = true)
  value = @stack.pop
  if value
    value
  elsif ask
    IO.input itself
    @stack.pop
  end
end

#push(what) ⇒ Object



14
15
16
# File 'lib/ascode/interpreter/environment.rb', line 14

def push(what)
  @stack.push what
end

#reg_copyObject



18
19
20
# File 'lib/ascode/interpreter/environment.rb', line 18

def reg_copy
  @register = pop
end

#reg_pasteObject



22
23
24
# File 'lib/ascode/interpreter/environment.rb', line 22

def reg_paste
  push @register
end

#swapObject



36
37
38
39
40
41
# File 'lib/ascode/interpreter/environment.rb', line 36

def swap
  a = pop false
  b = pop false
  push a
  push b
end