can read external .lisp file

This commit is contained in:
yoyo 2024-09-08 17:06:08 +09:00
parent 3ae8c663e7
commit cf54be4c78
3 changed files with 21 additions and 4 deletions

10
macro.lisp Normal file
View File

@ -0,0 +1,10 @@
(defn list (x . y) (cons x y))
(macro cond (expr. rest)
(if rest (list 'if (car expr) (car (cdr expr)) (cons 'cond rest))
expr))
(macro and (expr . rest)
(if rest (list 'if expr (cons 'and rest)) expr))
;(cond ((== 1 0) 0) ((== 1 1) -1) (+ 100000000))

11
main.c
View File

@ -72,15 +72,12 @@ loop(Object *env, FILE *f)
skipline(f);
}
while(1){
printf(">> ");
Object *res = nextexpr(f);
printexpr(res);
res = eval(env, res);
printgc("status", gc);
printf("=============res===========\n");
printexpr(res);
printf("=============env===========\n");
printexpr(env);
printf("===========================\n");
}
}
@ -89,5 +86,11 @@ main(int argc, char *argv[])
{
gc = newgc(&argc, 400);
Object *env = newenv(gc, &Nil, &Nil, &Nil);
for(int i = 1; i < argc; ++i){
FILE *f = fopen(argv[i], "r");
if(f == 0)
panic("can't open %s", argv[i]);
loop(env, f);
}
loop(env, stdin);
}

View File

@ -145,8 +145,12 @@ lparlist(FILE *f)
static Object*
list(FILE *f)
{
redo:
char c = slookup(f);
switch(c){
case ';':
skipline(f);
goto redo;
case '\'':
get(f);
return quote(f);