Skip to content

Commit

Permalink
rpython: prevent defmacro! from mutating its argument
Browse files Browse the repository at this point in the history
  • Loading branch information
asarhaddon authored and kanaka committed Oct 15, 2024
1 parent 1590fda commit b463373
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions impls/rpython/step8_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def EVAL(ast, env):
ast = quasiquote(ast[1]) # Continue loop (TCO)
elif u"defmacro!" == a0sym:
func = EVAL(ast[2], env)
func.ismacro = True
return env.set(ast[1], func)
return env.set(ast[1],
MalFunc(func.fn, ast=func.ast, env=func.env,
params=func.params, EvalFunc=func.EvalFunc,
ismacro=True))
elif u"do" == a0sym:
if len(ast) == 0:
return nil
Expand Down
6 changes: 4 additions & 2 deletions impls/rpython/step9_try.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ def EVAL(ast, env):
ast = quasiquote(ast[1]) # Continue loop (TCO)
elif u"defmacro!" == a0sym:
func = EVAL(ast[2], env)
func.ismacro = True
return env.set(ast[1], func)
return env.set(ast[1],
MalFunc(func.fn, ast=func.ast, env=func.env,
params=func.params, EvalFunc=func.EvalFunc,
ismacro=True))
elif u"try*" == a0sym:
if len(ast) < 3:
return EVAL(ast[1], env);
Expand Down
6 changes: 4 additions & 2 deletions impls/rpython/stepA_mal.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def EVAL(ast, env):
ast = quasiquote(ast[1]) # Continue loop (TCO)
elif u"defmacro!" == a0sym:
func = EVAL(ast[2], env)
func.ismacro = True
return env.set(ast[1], func)
return env.set(ast[1],
MalFunc(func.fn, ast=func.ast, env=func.env,
params=func.params, EvalFunc=func.EvalFunc,
ismacro=True))
elif u"try*" == a0sym:
if len(ast) < 3:
return EVAL(ast[1], env);
Expand Down

0 comments on commit b463373

Please sign in to comment.