Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

LispContinuation Class Reference

#include <lcont.hpp>

Inheritance diagram for LispContinuation:

Inheritance graph
[legend]
Collaboration diagram for LispContinuation:

Collaboration graph
[legend]
List of all members.

Detailed Description

Lisp-specific continuation-based virtual machine.

This class determines the Lisp computation model providing the method JustEvaluate() and overriding the method CustomCommand() so that it handles to instruction codes missing in the base class. The specific context handling is also provided.

Definition at line 111 of file lcont.hpp.

Public Types

enum  CustomInstructions { take_result_as_form = max_command - 1, duplicate_last_result = max_command - 2 }
 additional instructions More...
enum  Instructions {
  just_evaluate = -1, evaluate_prepared = -2, evaluate_progn = -3, quote_parameter = -4,
  drop_result = -5, return_unspecified = -6, end_of_clauses = -7, cond_clause = -8,
  bail_on_false = -9, set_context = -10, assign_to = -11, assign_location = -12,
  generic_iteration = -13, iteration_callback = -14, max_command = -14
}
 The instruction set of the machine. More...

Public Member Functions

 LispContinuation ()
 The default constructor.
 LispContinuation (const LispContinuation &other, bool b)
 The CALL/CC-related constructor.
 ~LispContinuation ()
 The destructor.
LContextRef GetContext () const
 Get the current lexical context.
void SetContext (const LContextRef &context)
 Set the current lexical context.
bool Step ()
 Perform a single step of the evaluation.
int GetMark () const
 Mark the todo stack before starting an evaluation.
bool Ready (int mark=0) const
 Is the evaluation complete?
SReference Get ()
 Get the result of the evaluation.
void ReplaceContinuation (const IntelibContinuation &other)
 Replace the entire state of the continuation.
void PushTodo (int opcode, const SReference &param)
 Add an instruction to the todo stack.
void PushTodo (int opcode)
 Add a parameterless instruction to the todo stack.
bool PopTodo (int &opcode, SReference &param)
 Get (and remove) the top of the todo stack.
void PushResult (const SReference &param)
 Put item into the result stack.
bool PopResult (SReference &param)
 Get (and remove) the item from top of the result stack.
void RegularReturn (const SReference &ref)
 Return a value from a Lisp function.
void ReferenceReturn (SReference &ref, const SReference &superstruct)
 Return an assignable reference from a Lisp function.
void AgentReturn (const SReference &val, const SExpressionSetfAgent *ag)
 Return a Setf Agent from a Lisp function.
void TailReturn (const SReference &ref)
 Return a tail (to be evaluated) from a Lisp function.
void ReturnUnspecified ()
 Return the 'unspecified' value from a Lisp function.
void SetContext (const SReference &cont)
 Set current lexical context.

Static Public Member Functions

static void InterruptEvaluator ()
 Interrupt the evaluation.
static void RemoveInterruption ()
 Cances the interruption of the evaluation.
static void SuspendInterruptions ()
 Temporaryly disallow interruptions.
static void ResumeInterruptions ()
 Allow interruptions again.

Protected Member Functions

void PlaceFormToStack (const SExpressionCons *form, int len)
 Place a prepared form to the stack.

Protected Attributes

SReferencePTheFalseValue


Member Enumeration Documentation

enum LispContinuation::CustomInstructions
 

additional instructions

Enumeration values:
take_result_as_form  pop a result and evaluate it as a form
duplicate_last_result  pop a result and then push it twice

Definition at line 126 of file lcont.hpp.

enum IntelibContinuation::Instructions [inherited]
 

The instruction set of the machine.

Zero and positive opcodes stand for "call a function with that many args", in which case the function object and the args are taken from the result stack. The numbers from -1 downto max_command are the special operation codes. The numbers below max_command are for the operations added by subclasses (e.g., Scheme-specific and Lisp-specific instructions).

Enumeration values:
just_evaluate  Just evaluate the param.
evaluate_prepared  Evaluate a form in which all params are already computed.
evaluate_progn  Evaluate a list of forms, one by one.
quote_parameter  Just put the parameter into the result stack.
drop_result  Remove one item from the result stack thus dropping it.
return_unspecified  Return the value which stands for 'unspecified result'.
end_of_clauses  No-op, used as a label for cond_clause and bail_on_false.
cond_clause  A conditional clause.

Take the value on top of the result stack. If it is true, then remove all the stuff from the todo stack until the end_of_clauses mark, and then add the param as progn to todo. Otherwise (that is, the condition value was false), just do nothing.

bail_on_false  Check and jump on false.

Take the value on top of the result stack. If it is false, then remove all the stuff from the todo stack until the end_of_clauses mark, and then return the false value back to stack. Otherwise, just do nothing

set_context  Set the current context to the param.

Note:
PushTodo() never adds another set_context if the top of the todo stack contains set_context
assign_to  Assign to the given location.

Warning:
param MUST be SExpressionLocation
assign_location  Assign to a location taken from result stack.

The top of the result stack should contain either a SExpressionLocation or a SExpressionSetfAgent

generic_iteration  Generic iteration.

See SExpressionGenericIteration

iteration_callback  Generic iteration implementation subcommand.
max_command  -max_command is the count of defined commands

Definition at line 201 of file conteval.hpp.


Constructor & Destructor Documentation

LispContinuation::LispContinuation  ) 
 

The default constructor.

Definition at line 114 of file lcont.hpp.

References PTheLispBooleanFalse.

LispContinuation::LispContinuation const LispContinuation other,
bool  b
 

The CALL/CC-related constructor.

Definition at line 118 of file lcont.hpp.

References PTheLispBooleanFalse.

LispContinuation::~LispContinuation  ) 
 

The destructor.

Definition at line 123 of file lcont.hpp.


Member Function Documentation

LContextRef LispContinuation::GetContext  )  const
 

Get the current lexical context.

Reimplemented from IntelibContinuation.

Definition at line 134 of file lcont.hpp.

References IntelibContinuation::GetContext().

void LispContinuation::SetContext const LContextRef context  ) 
 

Set the current lexical context.

Definition at line 138 of file lcont.hpp.

References IntelibContinuation::SetContext().

bool IntelibContinuation::Step  )  [inherited]
 

Perform a single step of the evaluation.

Returns false in case the todo stack is empty

Note:
This function must never be reentered, otherwise CALL/CC won't work for obvious reasons. Should you decide to work your own evaluation-based machine, make sure you never call evaluator from within itself.

Definition at line 105 of file conteval.cpp.

References IntelibContinuation::assign_location, IntelibContinuation::assign_to, IntelibContinuation::bail_on_false, IntelibContinuation::cond_clause, IntelibContinuation::CustomCommand(), IntelibContinuation::drop_result, IntelibContinuation::end_of_clauses, IntelibContinuation::evaluate_prepared, IntelibContinuation::evaluate_progn, IntelibContinuation::generic_iteration, SReference::GetPtr(), IntelibContinuation::iteration_callback, IntelibContinuation::just_evaluate, IntelibContinuation::JustEvaluate(), IntelibContinuation::PopResult(), IntelibContinuation::PopTodo(), PTheEmptyList, IntelibContinuation::PushResult(), IntelibContinuation::quote_parameter, IntelibContinuation::return_unspecified, IntelibContinuation::ReturnUnspecified(), and IntelibContinuation::set_context.

int IntelibContinuation::GetMark  )  const [inherited]
 

Mark the todo stack before starting an evaluation.

Definition at line 168 of file conteval.hpp.

bool IntelibContinuation::Ready int  mark = 0  )  const [inherited]
 

Is the evaluation complete?

Parameters:
mark is the optional mark returned by the GetMark() method. This is to be used when you wish to evaluate an expression within the existing machine

Definition at line 175 of file conteval.hpp.

SReference IntelibContinuation::Get  )  [inherited]
 

Get the result of the evaluation.

Definition at line 96 of file conteval.cpp.

void IntelibContinuation::ReplaceContinuation const IntelibContinuation other  )  [inherited]
 

Replace the entire state of the continuation.

This is how the CALL/CC feature works.

Parameters:
other should be an object made with the 2-ary constructor.

Definition at line 70 of file conteval.cpp.

void IntelibContinuation::PushTodo int  opcode,
const SReference param
[inherited]
 

Add an instruction to the todo stack.

Parameters:
opcode is the instruction code, see the Instructions enum for explanation
param is the instruction parameter

Definition at line 199 of file conteval.cpp.

References IntelibContinuation::set_context.

Referenced by IntelibContinuation::PlaceFormToStack(), IntelibContinuation::PushTodo(), and IntelibContinuation::TailReturn().

void IntelibContinuation::PushTodo int  opcode  )  [inherited]
 

Add a parameterless instruction to the todo stack.

Parameters:
opcode is the instruction code, see the Instructions enum for explanation

Definition at line 229 of file conteval.cpp.

References IntelibContinuation::PushTodo().

bool IntelibContinuation::PopTodo int &  opcode,
SReference param
[inherited]
 

Get (and remove) the top of the todo stack.

Warning:
you shouldn't ever want to use this method

Definition at line 235 of file conteval.cpp.

Referenced by IntelibContinuation::Step().

void IntelibContinuation::PushResult const SReference param  )  [inherited]
 

Put item into the result stack.

Definition at line 249 of file conteval.cpp.

Referenced by IntelibContinuation::AgentReturn(), IntelibContinuation::ReferenceReturn(), IntelibContinuation::RegularReturn(), and IntelibContinuation::Step().

bool IntelibContinuation::PopResult SReference param  )  [inherited]
 

Get (and remove) the item from top of the result stack.

Definition at line 264 of file conteval.cpp.

Referenced by IntelibContinuation::Step().

void IntelibContinuation::RegularReturn const SReference ref  )  [inherited]
 

Return a value from a Lisp function.

Definition at line 273 of file conteval.cpp.

References IntelibContinuation::PushResult().

Referenced by IntelibContinuation::ReturnUnspecified().

void IntelibContinuation::ReferenceReturn SReference ref,
const SReference superstruct
[inherited]
 

Return an assignable reference from a Lisp function.

Definition at line 290 of file conteval.cpp.

References IntelibContinuation::PushResult().

void IntelibContinuation::AgentReturn const SReference val,
const SExpressionSetfAgent ag
[inherited]
 

Return a Setf Agent from a Lisp function.

Definition at line 300 of file conteval.cpp.

References IntelibContinuation::PushResult().

void IntelibContinuation::TailReturn const SReference ref  )  [inherited]
 

Return a tail (to be evaluated) from a Lisp function.

Definition at line 310 of file conteval.cpp.

References IntelibContinuation::just_evaluate, and IntelibContinuation::PushTodo().

void IntelibContinuation::ReturnUnspecified  )  [inherited]
 

Return the 'unspecified' value from a Lisp function.

Definition at line 315 of file conteval.cpp.

References IntelibContinuation::RegularReturn().

Referenced by IntelibContinuation::Step().

void IntelibContinuation::SetContext const SReference cont  )  [inherited]
 

Set current lexical context.

Definition at line 288 of file conteval.hpp.

Referenced by SchemeContinuation::SetContext(), and SetContext().

static void IntelibContinuation::InterruptEvaluator  )  [static, inherited]
 

Interrupt the evaluation.

Definition at line 296 of file conteval.hpp.

static void IntelibContinuation::RemoveInterruption  )  [static, inherited]
 

Cances the interruption of the evaluation.

Definition at line 298 of file conteval.hpp.

static void IntelibContinuation::SuspendInterruptions  )  [static, inherited]
 

Temporaryly disallow interruptions.

Definition at line 300 of file conteval.hpp.

static void IntelibContinuation::ResumeInterruptions  )  [static, inherited]
 

Allow interruptions again.

Definition at line 302 of file conteval.hpp.

void IntelibContinuation::PlaceFormToStack const SExpressionCons form,
int  len
[protected, inherited]
 

Place a prepared form to the stack.

Parameters:
form is the list
len is the count of already-pushed elements e.g. if you have already passed the function and form is only the list of parameters, use 1. If the list contains the function as well, use 0

Definition at line 452 of file conteval.cpp.

References IntelibContinuation::just_evaluate, and IntelibContinuation::PushTodo().


Member Data Documentation

SReference* IntelibContinuation::PTheFalseValue [protected, inherited]
 

Definition at line 134 of file conteval.hpp.


The documentation for this class was generated from the following files:
Generated on Tue Dec 18 00:42:26 2007 for InteLib by  doxygen 1.4.1