Class Ruva::VM::Stack::Stack
In: lib/ruva/stack.rb
Parent: Object

Methods

==   []   []=   empty?   eql?   hash   inspect   length   map   new   peek   pop   pop_args   push   to_ary  

Public Class methods

[Source]

    # File lib/ruva/stack.rb, line 11
11:         def initialize(maxsize) 
12:           @data = Array.new()       
13:         end

Public Instance methods

[Source]

    # File lib/ruva/stack.rb, line 76
76:         def ==(other)
77:           to_ary == other
78:         end

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).

[Source]

    # File lib/ruva/stack.rb, line 50
50:         def [](*args)
51:           @data[*args]
52:         end

[Source]

    # File lib/ruva/stack.rb, line 54
54:         def []=(*args)
55:           last = args.pop
56:           @data[*args] = last
57:         end

[Source]

    # File lib/ruva/stack.rb, line 63
63:         def empty?
64:           @data.empty?       
65:         end

[Source]

    # File lib/ruva/stack.rb, line 80
80:         def eql?(other)
81:           to_ary.eql?(other)
82:         end

[Source]

    # File lib/ruva/stack.rb, line 84
84:         def hash
85:           to_ary.hash
86:         end

[Source]

    # File lib/ruva/stack.rb, line 88
88:         def inspect
89:           "#<Stack: #{to_ary.inspect}>"
90:         end

[Source]

    # File lib/ruva/stack.rb, line 59
59:         def length
60:           @data.length
61:         end

Based off of to_ary

[Source]

    # File lib/ruva/stack.rb, line 72
72:         def map(*args, &blk)
73:           to_ary.map(*args, &blk)
74:         end

[Source]

    # 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

[Source]

    # 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.

[Source]

    # 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

[Source]

    # File lib/ruva/stack.rb, line 15
15:         def push(value)
16:           if value.is_a?(VM::Types::Cat2Value)
17:             @data.push(*[value, nil])
18:           else
19:             @data.push(value)
20:           end
21:         end

[Source]

    # File lib/ruva/stack.rb, line 67
67:         def to_ary
68:           @data.dup
69:         end

[Validate]