Merge branch 'master' into feature/site-corrections

This commit is contained in:
Paul R. Tagliamonte 2013-04-10 19:47:33 -04:00
commit 96711cb270
9 changed files with 52 additions and 11 deletions

View File

@ -7,3 +7,4 @@
* Julien Danjou <julien@danjou.info>
* Nicolas Dandrimont <nicolas.dandrimont@crans.org>
* Gergely Nagy <algernon@madhouse-project.org>
* Konrad Hinsen <konrad.hinsen@fastmail.net>

5
bin/hy
View File

@ -48,7 +48,12 @@ class HyREPL(code.InteractiveConsole):
_machine = Machine(Idle, 1, 0)
return True
try:
tokens = process(_machine.nodes)
except Exception:
_machine = Machine(Idle, 1, 0)
self.showtraceback()
return False
_machine = Machine(Idle, 1, 0)
try:

View File

@ -25,3 +25,10 @@ __version__ = "0.9.5"
import hy.importer # NOQA
# we import for side-effects.
from hy.models.expression import HyExpression # NOQA
from hy.models.integer import HyInteger # NOQA
from hy.models.string import HyString # NOQA
from hy.models.symbol import HySymbol # NOQA
from hy.models.dict import HyDict # NOQA
from hy.models.list import HyList # NOQA

View File

@ -83,8 +83,7 @@ def builds(_type):
def _raise_wrong_args_number(expression, error):
err = TypeError(error % (expression.pop(0),
len(expression)))
err = TypeError(error % (expression.pop(0), len(expression)))
err.start_line = expression.start_line
err.start_column = expression.start_column
raise err
@ -94,9 +93,8 @@ def checkargs(exact=None, min=None, max=None):
def _dec(fn):
def checker(self, expression):
if exact is not None and (len(expression) - 1) != exact:
_raise_wrong_args_number(expression,
"`%%s' needs %d arguments, got %%d" %
exact)
_raise_wrong_args_number(
expression, "`%%s' needs %d arguments, got %%d" % exact)
if min is not None and (len(expression) - 1) < min:
_raise_wrong_args_number(
@ -140,8 +138,7 @@ class HyASTCompiler(object):
def _mangle_branch(self, tree, start_line, start_column):
# If tree is empty, just return a pass statement
if tree == []:
return [ast.Pass(lineno=start_line,
col_offset=start_column)]
return [ast.Pass(lineno=start_line, col_offset=start_column)]
ret = []
tree = list(flatten_literal_list(tree))
@ -166,7 +163,8 @@ class HyASTCompiler(object):
ret.append(el)
continue
ret.append(ast.Expr(value=el,
ret.append(ast.Expr(
value=el,
lineno=el.lineno,
col_offset=el.col_offset))
@ -177,6 +175,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(exact=1)
def compile_quote(self, entries):
return self.compile(self._render_quoted_form(entries[1]))
@builds("do")
@builds("progn")
def compile_do_expression(self, expr):

View File

@ -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

View File

@ -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]))

View File

View File

@ -0,0 +1,10 @@
;;;
;;;
(import-from hy HyExpression HySymbol HyString)
(defn test-basic-quoting []
(assert (= (type (quote (foo bar))) HyExpression))
(assert (= (type (quote foo)) HySymbol))
(assert (= (type (quote "string")) HyString)))

View File

@ -0,0 +1 @@
from .native.quoting import * # NOQA