Browse Source

&body

master
Gabriel Pariat 3 years ago
parent
commit
d6665034a2
  1. 10
      implementations/c/src/evaluator.c
  2. 1
      implementations/c/src/lisp.c
  3. 1
      implementations/c/src/lisp.h
  4. 2
      implementations/c/src/symbol.c

10
implementations/c/src/evaluator.c

@ -11,9 +11,13 @@ static Pointer run_fn(Func fn, Pointer params) {
env = cons(tbl, env); env = cons(tbl, env);
while(args != NIL && params != NIL) { while(args != NIL && params != NIL) {
table_set(tbl, CAR(args), CAR(params)); if (CAR(args) == BODY && CAR(CDR(args)) != NIL) {
args = CDR(args); table_set(tbl, CAR(CDR(args)), params);
params = CDR(params); break;
}
table_set(tbl, CAR(args), CAR(params));
args = CDR(args);
params = CDR(params);
} }
REDUCE(body, eval(CAR(body), env), value); REDUCE(body, eval(CAR(body), env), value);

1
implementations/c/src/lisp.c

@ -325,6 +325,7 @@ void init(void) {
/* /*
(set-reader-macro \' (fn (s c) (list quote (read s)))) (set-reader-macro \' (fn (s c) (list quote (read s))))
(defmacro defn (name args &body body) (list def name (cons fn (cons args body))))
*/ */
void repl(void) { void repl(void) {

1
implementations/c/src/lisp.h

@ -113,6 +113,7 @@ extern Pointer UNDEFINED;
extern Pointer T; extern Pointer T;
extern Pointer STANDARD_INPUT; extern Pointer STANDARD_INPUT;
extern Pointer STANDARD_OUTPUT; extern Pointer STANDARD_OUTPUT;
extern Pointer BODY;
/** UTILS **/ /** UTILS **/
void init(void); void init(void);

2
implementations/c/src/symbol.c

@ -6,6 +6,7 @@ Pointer T;
Pointer STANDARD_INPUT; Pointer STANDARD_INPUT;
Pointer STANDARD_OUTPUT; Pointer STANDARD_OUTPUT;
Pointer UNDEFINED; Pointer UNDEFINED;
Pointer BODY;
static Pointer SYMBOLS; static Pointer SYMBOLS;
@ -53,5 +54,6 @@ void symbol_init(void) {
STANDARD_INPUT = symbol1("*standard-input*"); STANDARD_INPUT = symbol1("*standard-input*");
STANDARD_OUTPUT = symbol1("*standard-output*"); STANDARD_OUTPUT = symbol1("*standard-output*");
UNDEFINED = symbol1("undefined"); UNDEFINED = symbol1("undefined");
BODY = symbol1("&body");
} }

Loading…
Cancel
Save