Now have quote. Everything still seems to work. Unit tests still pass.

This commit is contained in:
Simon Brooke 2017-01-20 12:27:09 +00:00
parent 03dfe37045
commit 770767c11e
3 changed files with 22 additions and 0 deletions

View file

@ -36,6 +36,11 @@ int main (int argc, char *argv[]) {
fprintf( stderr, "Post scarcity software environment version %s\n", VERSION);
initialise_cons_pages();
/* privileged variables (keywords) */
deep_bind( intern( c_string_to_lisp_string( "nil"), oblist), NIL);
deep_bind( intern( c_string_to_lisp_string( "t"), oblist), TRUE);
/* primitive function operations */
bind_function( "assoc", &lisp_assoc);
bind_function( "car", &lisp_car);
bind_function( "cdr", &lisp_cdr);
@ -45,8 +50,10 @@ int main (int argc, char *argv[]) {
bind_function( "read", &lisp_read);
bind_function( "print", &lisp_print);
/* primitive special forms */
bind_special( "apply", &lisp_apply);
bind_special( "eval", &lisp_eval);
bind_special( "quote", &lisp_quote);
fprintf( stderr, "\n:: ");
struct cons_pointer input = read( stdin);

View file

@ -117,6 +117,7 @@ struct cons_pointer lisp_eval( struct cons_pointer s_expr, struct cons_pointer e
struct cons_space_object special = pointer2cell( fn_pointer);
result = (*special.payload.special.executable)( args, env, previous);
} else if ( functionp( fn_pointer)) {
/* actually, this is apply */
struct cons_space_object function = pointer2cell( fn_pointer);
struct stack_frame* frame = make_stack_frame( my_frame, args, env);
@ -147,6 +148,18 @@ struct cons_pointer lisp_eval( struct cons_pointer s_expr, struct cons_pointer e
return result;
}
/**
* (quote a)
*
* Special form
* Returns its argument (strictly first argument - only one is expected but
* this isn't at this stage checked) unevaluated.
*/
struct cons_pointer lisp_quote( struct cons_pointer args, struct cons_pointer env,
struct stack_frame* frame) {
return c_car( args);
}
/**
* (cons a b)
*

View file

@ -24,6 +24,8 @@ struct cons_pointer lisp_eval( struct cons_pointer args, struct cons_pointer env
struct stack_frame* frame);
struct cons_pointer lisp_apply( struct cons_pointer args, struct cons_pointer env,
struct stack_frame* frame);
struct cons_pointer lisp_quote( struct cons_pointer args, struct cons_pointer env,
struct stack_frame* frame);
/* functions */
struct cons_pointer lisp_cons( struct stack_frame* frame, struct cons_pointer env);