add 'not'

This commit is contained in:
yoyo 2024-09-09 16:25:11 +09:00
parent b1f355b248
commit 67788893b3
4 changed files with 13 additions and 1 deletions

View File

@ -14,6 +14,7 @@ Object Lt = (Object){.type=OBLTIN, .beg= "<"};
Object Gt = (Object){.type=OBLTIN, .beg= ">"}; Object Gt = (Object){.type=OBLTIN, .beg= ">"};
Object Ne = (Object){.type=OBLTIN, .beg= "!="}; Object Ne = (Object){.type=OBLTIN, .beg= "!="};
Object Eq = (Object){.type=OBLTIN, .beg= "=="}; Object Eq = (Object){.type=OBLTIN, .beg= "=="};
Object Not = (Object){.type=OBLTIN, .beg= "not"};
Object Comma= (Object){.type=OBLTIN, .beg=","}; Object Comma= (Object){.type=OBLTIN, .beg=","};
Object Bquote= (Object){.type=OBLTIN, .beg="`"}; Object Bquote= (Object){.type=OBLTIN, .beg="`"};
@ -44,6 +45,7 @@ extern Object* fncar(Object *, Object *);
extern Object* fncdr(Object *, Object *); extern Object* fncdr(Object *, Object *);
extern Object* fncons(Object *, Object *); extern Object* fncons(Object *, Object *);
extern Object* fneq(Object *, Object *); extern Object* fneq(Object *, Object *);
extern Object* fnnot(Object *, Object *);
extern Object* fnif(Object *, Object *); extern Object* fnif(Object *, Object *);
extern Object* fnge(Object *env, Object *list); extern Object* fnge(Object *env, Object *list);
extern Object* fngt(Object *env, Object *list); extern Object* fngt(Object *env, Object *list);
@ -75,6 +77,7 @@ bltinlookup(Object *obj)
{&Cdr ,fncdr}, {&Cdr ,fncdr},
{&Cons ,fncons}, {&Cons ,fncons},
{&Eq, fneq}, {&Eq, fneq},
{&Not, fnnot},
{&Ne, fnne}, {&Ne, fnne},
{&If, fnif}, {&If, fnif},
{&Ge, fnge}, {&Ge, fnge},

1
dat.h
View File

@ -69,6 +69,7 @@ extern Object Progn;
extern Object Macro; extern Object Macro;
extern Object Setq; extern Object Setq;
extern Object Eq; extern Object Eq;
extern Object Not;
extern Object Ne; extern Object Ne;
extern Object If; extern Object If;
extern Object Ge; extern Object Ge;

8
eval.c
View File

@ -267,6 +267,14 @@ _newint(int n)
return newint(gc, 1); return newint(gc, 1);
} }
Object*
fnnot(Object *env, Object *list)
{
if(list->type != OCELL || exprlen(list)!= 1)
error("Malformed not");
return _newint(list->car == &Nil);
}
Object* Object*
fneq(Object *env, Object *list) fneq(Object *env, Object *list)
{ {

2
obj.c
View File

@ -63,7 +63,7 @@ newsymbol(GC *gc, char *str, int len)
&Nil, &Minus, &Plus, &Mul, &Mod, &Div, &Ge, &Le, &Nil, &Minus, &Plus, &Mul, &Mod, &Div, &Ge, &Le,
&Lt, &Gt, &Ne, &Lambda, &Car, &Cdr, &Quote, &Cons, &Lt, &Gt, &Ne, &Lambda, &Car, &Cdr, &Quote, &Cons,
&Define, &Setq, &Eq, &If, &Macro, &Progn, &Bquote, &Define, &Setq, &Eq, &If, &Macro, &Progn, &Bquote,
&Comma, &Comma, &Not,
}; };
for(int i = 0; i < sizeof(syms)/sizeof(syms[0]); ++i){ for(int i = 0; i < sizeof(syms)/sizeof(syms[0]); ++i){
Object *c = syms[i]; Object *c = syms[i];