Rewrite the stack
This commit is contained in:
+12
-7
@@ -19,8 +19,10 @@ static void construct_manual_symbols(void) {
|
||||
lisp_gc_register_static_object(Qt);
|
||||
Qunbound = Fmake_symbol(LISP_LITSTR("unbound"));
|
||||
((LispSymbol *) Qunbound)->value = Qunbound;
|
||||
((LispSymbol *) Qunbound)->value = Qunbound;
|
||||
lisp_gc_register_static_object(Qunbound);
|
||||
Qlexical_environment = Fmake_symbol(LISP_LITSTR("lexical-environment"));
|
||||
((LispSymbol *) Qlexical_environment)->value = Qnil;
|
||||
lisp_gc_register_static_object(Qlexical_environment);
|
||||
|
||||
Qhash_string = Fmake_symbol(LISP_LITSTR("hash-string"));
|
||||
lisp_gc_register_static_object(Qhash_string);
|
||||
@@ -41,6 +43,7 @@ static void register_manual_symbols(void) {
|
||||
|
||||
void lisp_init(void) {
|
||||
construct_manual_symbols();
|
||||
Vlexical_environment = Qnil;
|
||||
obarray = Fmake_hash_table(Qhash_string, Qstrings_equal);
|
||||
lisp_gc_register_static_object(obarray);
|
||||
|
||||
@@ -63,8 +66,8 @@ void lisp_init(void) {
|
||||
}
|
||||
|
||||
void lisp_shutdown(void) {
|
||||
lisp_gc_teardown();
|
||||
lisp_teardown_stack();
|
||||
lisp_gc_teardown();
|
||||
}
|
||||
|
||||
static inline LispVal *lookup_variable(LispSymbol *name, LispVal *lexenv) {
|
||||
@@ -120,7 +123,7 @@ DEFUN(eval, "eval", (LispVal * form, LispVal *lexenv),
|
||||
DEFSPECIAL(progn, "progn", (LispVal * forms), "(&rest forms)", "") {
|
||||
LispVal *rval = Qnil;
|
||||
DOLIST(form, forms) {
|
||||
rval = Feval(form, TOP_LEXENV());
|
||||
rval = Feval(form, Vlexical_environment);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
@@ -128,18 +131,20 @@ DEFSPECIAL(progn, "progn", (LispVal * forms), "(&rest forms)", "") {
|
||||
DEFSPECIAL(let, "let", (LispVal * bindings, LispVal *body),
|
||||
"(bindings &rest body)", "") {
|
||||
CHECK_LISTP(bindings);
|
||||
copy_parent_lexenv();
|
||||
LispVal *lexenv = Vlexical_environment;
|
||||
DOLIST(binding, bindings) {
|
||||
if (SYMBOLP(binding)) {
|
||||
new_lexical_variable(binding, Qnil);
|
||||
lexenv = CONS(binding, CONS(Qnil, lexenv));
|
||||
} else if (CONSP(binding) && list_length_eq(binding, 2)) {
|
||||
new_lexical_variable(FIRST(binding),
|
||||
Feval(SECOND(binding), TOP_LEXENV()));
|
||||
lexenv = CONS(
|
||||
FIRST(binding),
|
||||
CONS(Feval(SECOND(binding), Vlexical_environment), lexenv));
|
||||
} else {
|
||||
// TODO better error
|
||||
abort();
|
||||
}
|
||||
}
|
||||
push_dynamic_binding(Qlexical_environment, lexenv);
|
||||
return Fprogn(body);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user