| Class | Ruva::VM::Stack::Stack |
| In: |
lib/ruva/stack.rb
|
| Parent: | Object |
These are direct-access - they don‘t translate cat2s and following nils, or even check that cat2s aren‘t split up. They‘re mainly for use by the stack manipulation instructions.
both [] and []= need to support most of the stuff Array#[] and Array#[]= support (range support isn‘t required).
# File lib/ruva/stack.rb, line 50
50: def [](*args)
51: @data[*args]
52: end
# File lib/ruva/stack.rb, line 54
54: def []=(*args)
55: last = args.pop
56: @data[*args] = last
57: end
# File lib/ruva/stack.rb, line 40
40: def peek
41: n1 = @data[-1] or ((n2 = @data[-2]).is_a?(VM::Types::Cat2Value) ? n2 : n1)
42: end
# File lib/ruva/stack.rb, line 23
23: def pop
24: raise Ruva::VM::StackUnderflowError, "System stack underflow" if @data.empty?
25: ((v = @data.pop).nil? && @data[-1].is_a?(VM::Types::Cat2Value)) ? @data.pop : v
26: end
Pop method args. This doesn‘t filter out nils following cat2s, so the return from this method can be directly assigned to the locals of the new frame.
# File lib/ruva/stack.rb, line 31
31: def pop_args(count)
32: raise(VM::StackUnderflowError, "System stack underflow") unless length >= count
33: if self[-(count+1)].is_a?(VM::Types::Cat2Value)
34: raise(VM::StackStateError, "Cannot split Cat2 value")
35: end
36:
37: @data.slice!(-count, count)
38: end