From f27378e57a378ee745fbe9729c00351bc1c667f9 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Mon, 8 Apr 2013 20:18:15 -0400 Subject: [PATCH] Adding in some prototype bits for quoted forms. --- hy/compiler.py | 16 ++++++++++++++++ hy/models/__init__.py | 2 ++ hy/models/list.py | 1 + 3 files changed, 19 insertions(+) diff --git a/hy/compiler.py b/hy/compiler.py index 76b266a..249a0cc 100644 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -160,6 +160,22 @@ class HyASTCompiler(object): def compile_raw_list(self, entries): return [self.compile(x) for x in entries] + def _render_quoted_form(self, form): + name = form.__class__.__name__ + if isinstance(form, HyList): + return HyExpression( + [HySymbol(name), + HyList([self._render_quoted_form(x) for x in form])] + ).replace(form) + elif isinstance(form, HySymbol): + return HyExpression([HySymbol(name), HyString(form)]).replace(form) + return HyExpression([HySymbol(name), form]).replace(form) + + @builds("quote") + @checkargs(min=1, max=2) + def compile_quote(self, entries): + return self.compile(self._render_quoted_form(entries[1])) + @builds("do") @builds("progn") def compile_do_expression(self, expr): diff --git a/hy/models/__init__.py b/hy/models/__init__.py index 408c917..775862a 100644 --- a/hy/models/__init__.py +++ b/hy/models/__init__.py @@ -34,3 +34,5 @@ class HyObject(object): setattr(self, attr, getattr(other, attr)) else: raise TypeError("Can't replace a non Hy object with a Hy object") + + return self diff --git a/hy/models/list.py b/hy/models/list.py index f92bff9..183ec42 100644 --- a/hy/models/list.py +++ b/hy/models/list.py @@ -31,6 +31,7 @@ class HyList(HyObject, list): x.replace(other) HyObject.replace(self, other) + return self def __repr__(self): return "[%s]" % (" ".join([str(x) for x in self]))