Merge branch 'master' into feature/site-corrections
This commit is contained in:
commit
96711cb270
1
AUTHORS
1
AUTHORS
@ -7,3 +7,4 @@
|
|||||||
* Julien Danjou <julien@danjou.info>
|
* Julien Danjou <julien@danjou.info>
|
||||||
* Nicolas Dandrimont <nicolas.dandrimont@crans.org>
|
* Nicolas Dandrimont <nicolas.dandrimont@crans.org>
|
||||||
* Gergely Nagy <algernon@madhouse-project.org>
|
* Gergely Nagy <algernon@madhouse-project.org>
|
||||||
|
* Konrad Hinsen <konrad.hinsen@fastmail.net>
|
||||||
|
7
bin/hy
7
bin/hy
@ -48,7 +48,12 @@ class HyREPL(code.InteractiveConsole):
|
|||||||
_machine = Machine(Idle, 1, 0)
|
_machine = Machine(Idle, 1, 0)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
tokens = process(_machine.nodes)
|
try:
|
||||||
|
tokens = process(_machine.nodes)
|
||||||
|
except Exception:
|
||||||
|
_machine = Machine(Idle, 1, 0)
|
||||||
|
self.showtraceback()
|
||||||
|
return False
|
||||||
|
|
||||||
_machine = Machine(Idle, 1, 0)
|
_machine = Machine(Idle, 1, 0)
|
||||||
try:
|
try:
|
||||||
|
@ -25,3 +25,10 @@ __version__ = "0.9.5"
|
|||||||
|
|
||||||
import hy.importer # NOQA
|
import hy.importer # NOQA
|
||||||
# we import for side-effects.
|
# 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
|
||||||
|
@ -83,8 +83,7 @@ def builds(_type):
|
|||||||
|
|
||||||
|
|
||||||
def _raise_wrong_args_number(expression, error):
|
def _raise_wrong_args_number(expression, error):
|
||||||
err = TypeError(error % (expression.pop(0),
|
err = TypeError(error % (expression.pop(0), len(expression)))
|
||||||
len(expression)))
|
|
||||||
err.start_line = expression.start_line
|
err.start_line = expression.start_line
|
||||||
err.start_column = expression.start_column
|
err.start_column = expression.start_column
|
||||||
raise err
|
raise err
|
||||||
@ -94,9 +93,8 @@ def checkargs(exact=None, min=None, max=None):
|
|||||||
def _dec(fn):
|
def _dec(fn):
|
||||||
def checker(self, expression):
|
def checker(self, expression):
|
||||||
if exact is not None and (len(expression) - 1) != exact:
|
if exact is not None and (len(expression) - 1) != exact:
|
||||||
_raise_wrong_args_number(expression,
|
_raise_wrong_args_number(
|
||||||
"`%%s' needs %d arguments, got %%d" %
|
expression, "`%%s' needs %d arguments, got %%d" % exact)
|
||||||
exact)
|
|
||||||
|
|
||||||
if min is not None and (len(expression) - 1) < min:
|
if min is not None and (len(expression) - 1) < min:
|
||||||
_raise_wrong_args_number(
|
_raise_wrong_args_number(
|
||||||
@ -140,8 +138,7 @@ class HyASTCompiler(object):
|
|||||||
def _mangle_branch(self, tree, start_line, start_column):
|
def _mangle_branch(self, tree, start_line, start_column):
|
||||||
# If tree is empty, just return a pass statement
|
# If tree is empty, just return a pass statement
|
||||||
if tree == []:
|
if tree == []:
|
||||||
return [ast.Pass(lineno=start_line,
|
return [ast.Pass(lineno=start_line, col_offset=start_column)]
|
||||||
col_offset=start_column)]
|
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
tree = list(flatten_literal_list(tree))
|
tree = list(flatten_literal_list(tree))
|
||||||
@ -166,9 +163,10 @@ class HyASTCompiler(object):
|
|||||||
ret.append(el)
|
ret.append(el)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ret.append(ast.Expr(value=el,
|
ret.append(ast.Expr(
|
||||||
lineno=el.lineno,
|
value=el,
|
||||||
col_offset=el.col_offset))
|
lineno=el.lineno,
|
||||||
|
col_offset=el.col_offset))
|
||||||
|
|
||||||
ret.reverse()
|
ret.reverse()
|
||||||
return ret
|
return ret
|
||||||
@ -177,6 +175,22 @@ class HyASTCompiler(object):
|
|||||||
def compile_raw_list(self, entries):
|
def compile_raw_list(self, entries):
|
||||||
return [self.compile(x) for x in 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("do")
|
||||||
@builds("progn")
|
@builds("progn")
|
||||||
def compile_do_expression(self, expr):
|
def compile_do_expression(self, expr):
|
||||||
|
@ -34,3 +34,5 @@ class HyObject(object):
|
|||||||
setattr(self, attr, getattr(other, attr))
|
setattr(self, attr, getattr(other, attr))
|
||||||
else:
|
else:
|
||||||
raise TypeError("Can't replace a non Hy object with a Hy object")
|
raise TypeError("Can't replace a non Hy object with a Hy object")
|
||||||
|
|
||||||
|
return self
|
||||||
|
@ -31,6 +31,7 @@ class HyList(HyObject, list):
|
|||||||
x.replace(other)
|
x.replace(other)
|
||||||
|
|
||||||
HyObject.replace(self, other)
|
HyObject.replace(self, other)
|
||||||
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "[%s]" % (" ".join([str(x) for x in self]))
|
return "[%s]" % (" ".join([str(x) for x in self]))
|
||||||
|
0
tests/compilers/native/__init__.hy
Normal file
0
tests/compilers/native/__init__.hy
Normal file
10
tests/compilers/native/quoting.hy
Normal file
10
tests/compilers/native/quoting.hy
Normal 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)))
|
1
tests/compilers/test_quoting.py
Normal file
1
tests/compilers/test_quoting.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .native.quoting import * # NOQA
|
Loading…
Reference in New Issue
Block a user