From 5a010e7ec292507dc0e28640644742edb64c1c00 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Tue, 15 Oct 2024 23:40:27 +0200 Subject: [PATCH] rpython: prevent defmacro! from mutating its argument --- impls/rpython/step8_macros.py | 6 ++++-- impls/rpython/step9_try.py | 6 ++++-- impls/rpython/stepA_mal.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/impls/rpython/step8_macros.py b/impls/rpython/step8_macros.py index eaecd35ec9..c7219c4ab3 100644 --- a/impls/rpython/step8_macros.py +++ b/impls/rpython/step8_macros.py @@ -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=fn.env, + params=fn.params, EvalFunc=fn.EvalFunc, + ismacro=True)) elif u"do" == a0sym: if len(ast) == 0: return nil diff --git a/impls/rpython/step9_try.py b/impls/rpython/step9_try.py index f98074dfbb..b641376de3 100644 --- a/impls/rpython/step9_try.py +++ b/impls/rpython/step9_try.py @@ -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=fn.env, + params=fn.params, EvalFunc=fn.EvalFunc, + ismacro=True)) elif u"try*" == a0sym: if len(ast) < 3: return EVAL(ast[1], env); diff --git a/impls/rpython/stepA_mal.py b/impls/rpython/stepA_mal.py index 624a9b0e7b..9c76749c7e 100644 --- a/impls/rpython/stepA_mal.py +++ b/impls/rpython/stepA_mal.py @@ -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=fn.env, + params=fn.params, EvalFunc=fn.EvalFunc, + ismacro=True)) elif u"try*" == a0sym: if len(ast) < 3: return EVAL(ast[1], env);