Class: Ascode::Interpreter::Environment
- Inherits:
-
Object
- Object
- Ascode::Interpreter::Environment
- Defined in:
- lib/ascode/interpreter/environment.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#register ⇒ Object
Returns the value of attribute register.
-
#stack ⇒ Object
Returns the value of attribute stack.
Instance Method Summary collapse
- #duplicate ⇒ Object
-
#initialize(ast = "") ⇒ Environment
constructor
A new instance of Environment.
- #pop(ask = true) ⇒ Object
- #push(what) ⇒ Object
- #reg_copy ⇒ Object
- #reg_paste ⇒ Object
- #swap ⇒ Object
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
#ast ⇒ Object
Returns the value of attribute ast.
6 7 8 |
# File 'lib/ascode/interpreter/environment.rb', line 6 def ast @ast end |
#register ⇒ Object
Returns the value of attribute register.
6 7 8 |
# File 'lib/ascode/interpreter/environment.rb', line 6 def register @register end |
#stack ⇒ Object
Returns the value of attribute stack.
6 7 8 |
# File 'lib/ascode/interpreter/environment.rb', line 6 def stack @stack end |
Instance Method Details
#duplicate ⇒ Object
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_copy ⇒ Object
18 19 20 |
# File 'lib/ascode/interpreter/environment.rb', line 18 def reg_copy @register = pop end |
#reg_paste ⇒ Object
22 23 24 |
# File 'lib/ascode/interpreter/environment.rb', line 22 def reg_paste push @register end |
#swap ⇒ Object
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 |