diff --git a/hy/compiler.py b/hy/compiler.py index d94e94b..0dc28b7 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -423,6 +423,8 @@ class HyASTCompiler(object): # pass in `atom_type`. atom_compiler = _compile_table[atom_type] arity = hy.inspect.get_arity(atom_compiler) + # Compliation methods may mutate the atom, so copy it first. + atom = copy.copy(atom) ret = (atom_compiler(self, atom, atom_type) if arity == 3 else atom_compiler(self, atom)) diff --git a/hy/macros.py b/hy/macros.py index 110c37d..72dc8bd 100644 --- a/hy/macros.py +++ b/hy/macros.py @@ -181,8 +181,6 @@ def macroexpand_1(tree, compiler): fn = tree[0] if fn in ("quote", "quasiquote"): return tree - ntree = HyExpression(tree[:]) - ntree.replace(tree) opts = {} @@ -197,14 +195,14 @@ def macroexpand_1(tree, compiler): try: m_copy = make_empty_fn_copy(m) - m_copy(compiler.module_name, *ntree[1:], **opts) + m_copy(compiler.module_name, *tree[1:], **opts) except TypeError as e: msg = "expanding `" + str(tree[0]) + "': " msg += str(e).replace("()", "", 1).strip() raise HyMacroExpansionError(tree, msg) try: - obj = m(compiler.module_name, *ntree[1:], **opts) + obj = m(compiler.module_name, *tree[1:], **opts) except HyTypeError as e: if e.expression is None: e.expression = tree @@ -214,7 +212,6 @@ def macroexpand_1(tree, compiler): raise HyMacroExpansionError(tree, msg) replace_hy_obj(obj, tree) return obj - return ntree return tree