Fixed bug where sexpr with a single function will try to delete an expression twice and added an exit functionality
This commit is contained in:
parent
a52490de8b
commit
6c0fd3df86
2 changed files with 9 additions and 2 deletions
|
@ -57,6 +57,7 @@ lval* lval_take(lval* v, int i) {
|
||||||
lval* lval_eval_sexpr(lenv* e, lval* v) {
|
lval* lval_eval_sexpr(lenv* e, lval* v) {
|
||||||
// No argument functions
|
// No argument functions
|
||||||
if (v->count == 1 && v->cell[0]->type == LVAL_SYM) {
|
if (v->count == 1 && v->cell[0]->type == LVAL_SYM) {
|
||||||
|
if (strcmp(v->cell[0]->sym, "exit") == 0) { return v; }
|
||||||
lval* x = lenv_get(e, v->cell[0]);
|
lval* x = lenv_get(e, v->cell[0]);
|
||||||
if (x->type == LVAL_FUN) {
|
if (x->type == LVAL_FUN) {
|
||||||
lval_del(x);
|
lval_del(x);
|
||||||
|
@ -64,8 +65,10 @@ lval* lval_eval_sexpr(lenv* e, lval* v) {
|
||||||
lval_del(v);
|
lval_del(v);
|
||||||
return builtin_ls(e, lval_sexpr());
|
return builtin_ls(e, lval_sexpr());
|
||||||
}
|
}
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
if (x->type == LVAL_ERR) { lval_del(v); return x; }
|
||||||
|
lval_del(x);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
// Evaluate children
|
// Evaluate children
|
||||||
|
|
6
prompt.c
6
prompt.c
|
@ -83,9 +83,13 @@ int main (int argc, char** argv) {
|
||||||
// lval result = eval(r.output);
|
// lval result = eval(r.output);
|
||||||
lval* result = lval_eval(e, lval_read(r.output));
|
lval* result = lval_eval(e, lval_read(r.output));
|
||||||
lval_println(result);
|
lval_println(result);
|
||||||
lval_del(result);
|
|
||||||
// mpc_ast_print(r.output);
|
// mpc_ast_print(r.output);
|
||||||
mpc_ast_delete(r.output);
|
mpc_ast_delete(r.output);
|
||||||
|
if ((result->type == LVAL_SEXPR && result->count > 0 && strcmp(result->cell[0]->sym, "exit") == 0) ||
|
||||||
|
(result->type == LVAL_SYM && strcmp(result->sym, "exit") == 0))
|
||||||
|
{ lval_del(result); free(input); break; }
|
||||||
|
lval_del(result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Otherwise print the error
|
// Otherwise print the error
|
||||||
mpc_err_print(r.error);
|
mpc_err_print(r.error);
|
||||||
|
|
Reference in a new issue