Class: Pyper::PostfixMachine::ArgumentSource
- Defined in:
- lib/pyper/postfix_machine/argument_source.rb
Overview
Compile-time argument source stack. To explain, the default source of arguments in compiled Pyper methods is ‘args’ local variable, containing all the arguments supplied to the method (as in method(*args) call). However, this default argument source can be changed to something else. For this purpose, compil-time argument source stack is maintained, showing where the next argument will come from. It is implemented as a struct with two arrays: source and grab_method. The source shows where the argument comes from, and grab method shows how is it obtained. There are 3 possible ways to obtain an argument from a source:
-
:ref – by reference (ie. by simply taking it)
-
:dup – by duplication (calling #dup method on the source)
-
:shift – by shifting (calling #shift method on the source)
As for the sources, there may be the following ones in a compiled method:
-
:args – whole argument array
-
:args_counted – args referenced with compile time counter – default
-
:alpha – primary pipeline
-
:beta – secondary pipeline
-
:delta – in-block pipeline
-
:epsilon – block argument 0
-
:zeta – block argument 1
-
:psi – penultimate element in the args array; penultimate argument
-
:omega – last element in the args array; last argument
We can se that :args_counted source comes as if with its own special grabbing method. At compile time, PostfixMachine maintains @args_count attribute, an index to the args array, and increments it each time an argument is taken. Other argument sources do not have counters and if they contain arrays, they can only be grabbed by the standard three methods.
Instance Attribute Summary collapse
-
#grab_method ⇒ Object
Returns the value of attribute grab_method.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
-
.new ⇒ Object
Initially, argument stack has a single layer with
:args_countedas the source, and:refas grab method.
Instance Method Summary collapse
-
#alpha ⇒ Object
Pushes
:alphasource and:refgrab method on the stack. -
#alpha! ⇒ Object
Modifies the topmost source on the stack to
:alpha, leaving the grab method unchanged. -
#args ⇒ Object
Pushes
:argssource and:shiftgrab method on the stack. -
#args! ⇒ Object
Modifies the topmost source on the stack to
:args, and grab method to:shift. -
#args_counted ⇒ Object
Pushes
:args_countedsource and:refgrab method on the stack. -
#args_counted! ⇒ Object
Modifies the topmost source on the stack to
:args_counted, leaving grab method unchanged. -
#beta ⇒ Object
Pushes
:betasource and:refgrab method on the stack. -
#beta! ⇒ Object
Modifies the topmost source on the stack to
:beta, leaving the grab method unchanged. -
#delta ⇒ Object
Pushes
:deltasource and:refgrab method on the stack. -
#delta! ⇒ Object
Modifies the topmost source on the stack to
:delta, leaving the grab method unchanged. -
#dup! ⇒ Object
Modifies the topmost grab method on the stack to
:dup. -
#epsilon ⇒ Object
Pushes
:epsilonsource and:refgrab method on the stack. -
#epsilon! ⇒ Object
Modifies the topmost source on the stack to
:epsilon, leaving the grab method unchanged. -
#omega ⇒ Object
Pushes
:omegasource and:refgrab method on the stack. -
#omega! ⇒ Object
Modifies the topmost source on the stack to
:omega, leaving the grab method unchanged. -
#psi ⇒ Object
Pushes
:psisource and:refgrab method on the stack. -
#psi! ⇒ Object
Modifies the topmost source on the stack to
:psi, leaving the grab method unchanged. -
#ref! ⇒ Object
Modifies the topmost grab method on the stack to
:ref. -
#shift! ⇒ Object
Modifies the topmost grab method on the stack to
:shift. -
#std! ⇒ Object
Resets the stack back to the initial condition.
-
#var(variable) ⇒ Object
Pushes on the stack a given variable name as the source, and
:refas the grab method. -
#var!(variable) ⇒ Object
Modifies the topmost source on the stack to the given variable name, leaving the grab method unchanged.
-
#zeta ⇒ Object
Pushes
:zetasource and:refgrab method on the stack. -
#zeta! ⇒ Object
Modifies the topmost source on the stack to
:zeta, leaving the grab method unchanged.
Instance Attribute Details
#grab_method ⇒ Object
Returns the value of attribute grab_method
35 36 37 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 35 def grab_method @grab_method end |
#source ⇒ Object
Returns the value of attribute source
35 36 37 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 35 def source @source end |
Class Method Details
.new ⇒ Object
Initially, argument stack has a single layer with :args_counted as the source, and :ref as grab method.
40 41 42 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 40 def new self[ [:args_counted], [:ref] ] end |
Instance Method Details
#alpha ⇒ Object
Pushes :alpha source and :ref grab method on the stack.
116 117 118 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 116 def alpha var :alpha end |
#alpha! ⇒ Object
Modifies the topmost source on the stack to :alpha, leaving the grab method unchanged.
123 124 125 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 123 def alpha! var! :alpha end |
#args ⇒ Object
Pushes :args source and :shift grab method on the stack.
86 87 88 89 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 86 def args source.push :args grab_method.push :shift end |
#args! ⇒ Object
Modifies the topmost source on the stack to :args, and grab method to :shift.
94 95 96 97 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 94 def args! source[-1] = :args shift! end |
#args_counted ⇒ Object
Pushes :args_counted source and :ref grab method on the stack.
72 73 74 75 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 72 def args_counted source.push :args_counted grab_method.push :ref end |
#args_counted! ⇒ Object
Modifies the topmost source on the stack to :args_counted, leaving grab method unchanged.
80 81 82 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 80 def args_counted! source[-1] = :args_counted end |
#beta ⇒ Object
Pushes :beta source and :ref grab method on the stack.
129 130 131 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 129 def beta var :beta end |
#beta! ⇒ Object
Modifies the topmost source on the stack to :beta, leaving the grab method unchanged.
136 137 138 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 136 def beta! var! :beta end |
#delta ⇒ Object
Pushes :delta source and :ref grab method on the stack.
142 143 144 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 142 def delta var :delta end |
#delta! ⇒ Object
Modifies the topmost source on the stack to :delta, leaving the grab method unchanged.
149 150 151 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 149 def delta! var! :delta end |
#dup! ⇒ Object
Modifies the topmost grab method on the stack to :dup.
66 67 68 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 66 def dup! grab_method[-1] = :dup end |
#epsilon ⇒ Object
Pushes :epsilon source and :ref grab method on the stack.
155 156 157 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 155 def epsilon var :epsilon end |
#epsilon! ⇒ Object
Modifies the topmost source on the stack to :epsilon, leaving the grab method unchanged.
162 163 164 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 162 def epsilon! var! :epsilon end |
#omega ⇒ Object
Pushes :omega source and :ref grab method on the stack.
194 195 196 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 194 def omega var :omega end |
#omega! ⇒ Object
Modifies the topmost source on the stack to :omega, leaving the grab method unchanged.
201 202 203 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 201 def omega! var! :omega end |
#psi ⇒ Object
Pushes :psi source and :ref grab method on the stack.
181 182 183 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 181 def psi var :psi end |
#psi! ⇒ Object
Modifies the topmost source on the stack to :psi, leaving the grab method unchanged.
188 189 190 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 188 def psi! var! :psi end |
#ref! ⇒ Object
Modifies the topmost grab method on the stack to :ref.
60 61 62 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 60 def ref! grab_method[-1] = :ref end |
#shift! ⇒ Object
Modifies the topmost grab method on the stack to :shift.
54 55 56 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 54 def shift! grab_method[-1] = :shift end |
#std! ⇒ Object
Resets the stack back to the initial condition.
47 48 49 50 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 47 def std! self.source = [:args_counted] self.grab_method = [:ref] end |
#var(variable) ⇒ Object
Pushes on the stack a given variable name as the source, and :ref as the grab method.
102 103 104 105 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 102 def var variable source.push variable grab_method.push :ref end |
#var!(variable) ⇒ Object
Modifies the topmost source on the stack to the given variable name, leaving the grab method unchanged.
110 111 112 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 110 def var! variable source[-1] = variable end |
#zeta ⇒ Object
Pushes :zeta source and :ref grab method on the stack.
168 169 170 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 168 def zeta var :zeta end |
#zeta! ⇒ Object
Modifies the topmost source on the stack to :zeta, leaving the grab method unchanged.
175 176 177 |
# File 'lib/pyper/postfix_machine/argument_source.rb', line 175 def zeta! var! :zeta end |