mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-04-05 03:37:43 +00:00
Improve tail recursion by inlining cond in eval_expr
This commit is contained in:
parent
2a21428a54
commit
52d4c08f36
@ -35,7 +35,7 @@ end
|
||||
|
||||
predef eval_expr(expr)
|
||||
|
||||
var sym_quote, sym_lambda
|
||||
var sym_quote, sym_lambda, sym_cond
|
||||
res[t_elem] pred_true = 0, 0, BOOL_TRUE
|
||||
res[t_elem] pred_false = 0, 0, BOOL_FALSE
|
||||
|
||||
@ -527,6 +527,15 @@ export def eval_expr(expr)#1
|
||||
break
|
||||
elsif expr_car=>lambda // DEFINEd lambda S-expression
|
||||
expr = enter_lambda(expr_car=>lambda, expr=>cdr)
|
||||
elsif expr_car == sym_cond
|
||||
expr = expr=>cdr
|
||||
while expr
|
||||
if eval_expr(expr=>car=>car) == @pred_true
|
||||
expr = expr=>car=>cdr=>car
|
||||
break
|
||||
fin
|
||||
expr = expr=>cdr
|
||||
loop
|
||||
else // Symbol associated with lambda
|
||||
expr = enter_lambda(assoc(expr_car)=>cdr, expr=>cdr)
|
||||
fin
|
||||
@ -779,6 +788,7 @@ new_assoc(new_sym("T"), @pred_true)
|
||||
new_assoc(new_sym("F"), @pred_false)
|
||||
sym_lambda = new_sym("LAMBDA")
|
||||
sym_quote = new_sym("QUOTE")
|
||||
sym_cond = new_sym("COND")
|
||||
sym_quote=>natv = @natv_quote
|
||||
new_sym("CAR")=>natv = @natv_car
|
||||
new_sym("CDR")=>natv = @natv_cdr
|
||||
@ -788,7 +798,6 @@ new_sym("EQ")=>natv = @natv_eq
|
||||
new_sym("NOT")=>natv = @natv_not
|
||||
new_sym("AND")=>natv = @natv_and
|
||||
new_sym("OR")=>natv = @natv_or
|
||||
new_sym("COND")=>natv = @natv_cond
|
||||
new_sym("SET")=>natv = @natv_set
|
||||
new_sym("SETQ")=>natv = @natv_setq
|
||||
new_sym("NULL")=>natv = @natv_null
|
||||
|
Loading…
x
Reference in New Issue
Block a user