From 13a84ba0aaac25543e8e851505bb9e02306a5ce2 Mon Sep 17 00:00:00 2001 From: Nicolas Boulenguez Date: Mon, 30 Aug 2021 23:38:46 +0200 Subject: [PATCH] d: prevent defmacro from mutating functions --- impls/d/step8_macros.d | 1 + impls/d/step9_try.d | 1 + impls/d/stepA_mal.d | 1 + 3 files changed, 3 insertions(+) diff --git a/impls/d/step8_macros.d b/impls/d/step8_macros.d index 7671d6f8..a186e795 100644 --- a/impls/d/step8_macros.d +++ b/impls/d/step8_macros.d @@ -165,6 +165,7 @@ MalType EVAL(MalType ast, Env env) case "defmacro!": auto a1 = verify_cast!MalSymbol(aste[1]); auto mac = verify_cast!MalFunc(EVAL(aste[2], env)); + mac = new MalFunc(mac.arg_names, mac.func_body, mac.def_env); mac.is_macro = true; return env.set(a1, mac); diff --git a/impls/d/step9_try.d b/impls/d/step9_try.d index cd44bf27..77da44b4 100644 --- a/impls/d/step9_try.d +++ b/impls/d/step9_try.d @@ -165,6 +165,7 @@ MalType EVAL(MalType ast, Env env) case "defmacro!": auto a1 = verify_cast!MalSymbol(aste[1]); auto mac = verify_cast!MalFunc(EVAL(aste[2], env)); + mac = new MalFunc(mac.arg_names, mac.func_body, mac.def_env); mac.is_macro = true; return env.set(a1, mac); diff --git a/impls/d/stepA_mal.d b/impls/d/stepA_mal.d index 9fdd0f5d..1b6e4908 100644 --- a/impls/d/stepA_mal.d +++ b/impls/d/stepA_mal.d @@ -166,6 +166,7 @@ MalType EVAL(MalType ast, Env env) case "defmacro!": auto a1 = verify_cast!MalSymbol(aste[1]); auto mac = verify_cast!MalFunc(EVAL(aste[2], env)); + mac = new MalFunc(mac.arg_names, mac.func_body, mac.def_env); mac.is_macro = true; return env.set(a1, mac);