Class: Heist::Runtime::Body
Overview
Body is a subclass of Frame, used for evaluating Function bodies. Instead of providing break points between subexpressions in a single expression, it provides break points between whole expressions inside a Scheme procedure. (A ‘break point’ is a point in code execution during which Stack can inspect the last value returned and decide whether to continue the current Frame or switch to some other action.)
Instance Attribute Summary
Attributes inherited from Frame
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Returns
trueiff theBodyhas evaluated all the expressions. -
#fill!(*args) ⇒ Object
Do-nothing override of
Frame#fill!. -
#initialize(expressions, scope) ⇒ Body
constructor
A
Bodyis initialized using aConslist containing a list ofExpressions that make up the body of aFunction, and aScopein which these expressions are to be evaluated. -
#process! ⇒ Object
Processes the next remaining
Expressionfrom theFunctionbody, returning the result for inspection by theStack.
Methods inherited from Frame
Constructor Details
#initialize(expressions, scope) ⇒ Body
A Body is initialized using a Cons list containing a list of Expressions that make up the body of a Function, and a Scope in which these expressions are to be evaluated.
158 159 160 161 162 |
# File 'lib/heist/runtime/frame.rb', line 158 def initialize(expressions, scope) @expression = expressions @scope = scope @values = [] end |
Instance Method Details
#complete? ⇒ Boolean
Returns true iff the Body has evaluated all the expressions.
165 166 167 |
# File 'lib/heist/runtime/frame.rb', line 165 def complete? @expression.null? end |
#fill!(*args) ⇒ Object
Do-nothing override of Frame#fill!. Function bodies do not need to remember the return value of each expression.
189 190 |
# File 'lib/heist/runtime/frame.rb', line 189 def fill!(*args) end |
#process! ⇒ Object
Processes the next remaining Expression from the Function body, returning the result for inspection by the Stack.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/heist/runtime/frame.rb', line 171 def process! expression = @expression.car # Increment before evaluating the expression so that when a # continuation is saved we resume from the following statement @expression = @expression.cdr # Return the final expression as a +Frame+ to enable tail calls return Frame.new(expression, @scope) if complete? # For all non-tail calls, evaluate the expression and return the value stack = @scope.runtime.stack stack << Frame.new(expression, @scope) stack.value end |