PROGN working
This commit is contained in:
parent
45d129facb
commit
b989b5e041
6 changed files with 100 additions and 9 deletions
|
|
@ -78,23 +78,24 @@ int main( int argc, char *argv[] ) {
|
|||
/*
|
||||
* primitive function operations
|
||||
*/
|
||||
bind_function( "add", &lisp_add );
|
||||
bind_function( "apply", &lisp_apply );
|
||||
bind_function( "assoc", &lisp_assoc );
|
||||
bind_function( "car", &lisp_car );
|
||||
bind_function( "cdr", &lisp_cdr );
|
||||
bind_function( "cons", &lisp_cons );
|
||||
bind_function( "eq", &lisp_eq );
|
||||
bind_function( "equal", &lisp_equal );
|
||||
bind_function( "multiply", &lisp_multiply );
|
||||
bind_function( "read", &lisp_read );
|
||||
bind_function( "print", &lisp_print );
|
||||
bind_function( "progn", &lisp_progn );
|
||||
bind_function( "subtract", &lisp_subtract );
|
||||
bind_function( "type", &lisp_type );
|
||||
|
||||
bind_function( "add", &lisp_add );
|
||||
bind_function( "+", &lisp_add );
|
||||
bind_function( "multiply", &lisp_multiply );
|
||||
bind_function( "*", &lisp_multiply );
|
||||
bind_function( "subtract", &lisp_subtract );
|
||||
bind_function( "-", &lisp_subtract );
|
||||
bind_function( "apply", &lisp_apply );
|
||||
|
||||
/*
|
||||
* primitive special forms
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ lisp_print( struct stack_frame *frame, struct cons_pointer env ) {
|
|||
|
||||
|
||||
/**
|
||||
* Get the Lisp type of the single argument.
|
||||
* Function: Get the Lisp type of the single argument.
|
||||
* @param frame My stack frame.
|
||||
* @param env My environment (ignored).
|
||||
* @return As a Lisp string, the tag of the object which is the argument.
|
||||
|
|
@ -384,6 +384,35 @@ lisp_type( struct stack_frame *frame, struct cons_pointer env ) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function; evaluate the forms which are listed in my single argument
|
||||
* sequentially and return the value of the last. This function is called 'do'
|
||||
* in some dialects of Lisp.
|
||||
*
|
||||
* @param frame My stack frame.
|
||||
* @param env My environment (ignored).
|
||||
* @return the value of the last form on the sequence which is my single
|
||||
* argument.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_progn( struct stack_frame *frame, struct cons_pointer env ) {
|
||||
struct cons_pointer remaining = frame->arg[0];
|
||||
struct cons_pointer result = NIL;
|
||||
|
||||
while ( consp(remaining)) {
|
||||
struct cons_space_object cell = pointer2cell( remaining );
|
||||
struct stack_frame * next = make_empty_frame(frame, env);
|
||||
next->arg[0] = cell.payload.cons.car;
|
||||
inc_ref( next->arg[0] );
|
||||
result = lisp_eval(next, env);
|
||||
free_stack_frame( next);
|
||||
|
||||
remaining = cell.payload.cons.cdr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO: make this do something sensible somehow.
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ struct cons_pointer lisp_read( struct stack_frame *frame,
|
|||
struct cons_pointer lisp_print( struct stack_frame *frame,
|
||||
struct cons_pointer env );
|
||||
/**
|
||||
* Get the Lisp type of the single argument.
|
||||
* Function: Get the Lisp type of the single argument.
|
||||
* @param frame My stack frame.
|
||||
* @param env My environment (ignored).
|
||||
* @return As a Lisp string, the tag of the object which is the argument.
|
||||
|
|
@ -57,6 +57,20 @@ struct cons_pointer lisp_print( struct stack_frame *frame,
|
|||
struct cons_pointer
|
||||
lisp_type( struct stack_frame *frame, struct cons_pointer env );
|
||||
|
||||
|
||||
/**
|
||||
* Function; evaluate the forms which are listed in my single argument
|
||||
* sequentially and return the value of the last. This function is called 'do'
|
||||
* in some dialects of Lisp.
|
||||
*
|
||||
* @param frame My stack frame.
|
||||
* @param env My environment (ignored).
|
||||
* @return the value of the last form on the sequence which is my single
|
||||
* argument.
|
||||
*/
|
||||
struct cons_pointer
|
||||
lisp_progn( struct stack_frame *frame, struct cons_pointer env );
|
||||
|
||||
/*
|
||||
* neither, at this stage, really
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue