diff --git a/bltin.c b/bltin.c index 0ae2104..9fc3542 100644 --- a/bltin.c +++ b/bltin.c @@ -19,11 +19,11 @@ extern Object* fnlambda(Object *, Object *); extern Object* fndefine(Object *, Object *); extern Object* fnsetq(Object *, Object *); extern Object* fnundef(Object *, Object *); +extern Object* fnquote(Object *, Object *); +extern Object* fncar(Object *, Object *); +extern Object* fncdr(Object *, Object *); +extern Object* fncons(Object *, Object *); /*extern Object* fnminus(Object *, Object *);*/ -/*extern Object* fncons(Object *, Object *);*/ -/*extern Object* fnquote(Object *, Object *);*/ -/*extern Object* fncar(Object *, Object *);*/ -/*extern Object* fncdr(Object *, Object *);*/ Bltinfn bltinlookup(Object *obj) @@ -37,11 +37,11 @@ bltinlookup(Object *obj) {&Plus , fnplus}, {&Define ,fndefine}, {&Setq ,fnsetq}, + {&Quote ,fnquote}, + {&Car ,fncar}, + {&Cdr ,fncdr}, + {&Cons ,fncons}, {&Minus ,0}, - {&Cons ,0}, - {&Quote ,0}, - {&Car ,0}, - {&Cdr ,0}, {0}, }; diff --git a/eval.c b/eval.c index a47c0d8..874242e 100644 --- a/eval.c +++ b/eval.c @@ -83,6 +83,42 @@ fndefine(Object *env, Object *list) return env->vars; } +Object* +fnquote(Object *env, Object *list) +{ + if(exprlen(list)!=1) + error("Malformed quote"); + return list->car; +} + +Object* +fncar(Object *env, Object *list) +{ + list = evallist(env, list); + if(list->car->type != OCELL || list->cdr != &Nil) + error("Malformed Car"); + return list->car->car; +} + +Object* +fncdr(Object *env, Object *list) +{ + list = evallist(env, list); + if(list->car->type != OCELL || list->cdr != &Nil) + error("Malformed Car"); + return list->car->cdr; +} + +Object* +fncons(Object *env, Object *list) +{ + if(exprlen(list) != 2) + error("Malformoed cons"); + list = evallist(env, list); + list->cdr = list->cdr->car; + return list; +} + Object* fnplus(Object *env, Object *list) { diff --git a/parser.c b/parser.c index bc09b53..d3b543d 100644 --- a/parser.c +++ b/parser.c @@ -6,7 +6,7 @@ #define SYMBOL_LEN 64 -const char symbolchars[] = "*-=+<>"; +const char symbolchars[] = "*-=+<>'"; static Object* lparlist(void); static Object* list(void);