Merge branch 'master' into pr/294

This commit is contained in:
Paul Tagliamonte 2013-10-10 17:25:13 -04:00
commit e053157ff1
14 changed files with 68 additions and 72 deletions

View File

@ -17,3 +17,4 @@
* Bob Tolbert <bob@tolbert.org> * Bob Tolbert <bob@tolbert.org>
* Ralph Möritz <ralph.moeritz@outlook.com> * Ralph Möritz <ralph.moeritz@outlook.com>
* Josh McLaughlin <josh@phear.cc> * Josh McLaughlin <josh@phear.cc>
* Berker Peksag <berker.peksag@gmail.com>

View File

@ -2,6 +2,8 @@
Hacking on hy Hacking on hy
=============== ===============
.. highlight:: bash
Join our hyve! Join our hyve!
============== ==============
@ -21,24 +23,39 @@ Hack!
Do this: Do this:
1. create a `Python virtual environment 1. create a `virtual environment
<https://pypi.python.org/pypi/virtualenv>`_ <https://pypi.python.org/pypi/virtualenv>`_::
2. (optional) go to https://github.com/paultag/hy and fork it
3. get the source code::
$ git clone git://github.com/paultag/hy.git $ virtualenv venv
(or use your fork) and activate it::
4. install for hacking::
$ python setup.py develop $ . venv/bin/activate
5. install other develop-y requirements:: or use `virtualenvwrapper <http://virtualenvwrapper.readthedocs.org/en/latest/#introduction>`_
to create and manage your virtual environment::
$ mkvirtualenv hy
$ workon hy
2. get the source code::
$ git clone https://github.com/hylang/hy.git
or use your fork::
$ git clone git@github.com:<YOUR_USERNAME>/hy.git
3. install for hacking::
$ cd hy/
$ pip install -e .
4. install other develop-y requirements::
$ pip install -r requirements-dev.txt $ pip install -r requirements-dev.txt
6. do awesome things; make someone shriek in delight/disgust at what 5. do awesome things; make someone shriek in delight/disgust at what
you have wrought you have wrought.
Test! Test!
@ -60,7 +77,7 @@ Document!
Documentation is located in ``docs/``. We use `Sphinx Documentation is located in ``docs/``. We use `Sphinx
<http://sphinx-doc.org/>`_. <http://sphinx-doc.org/>`_.
To build the docs in html:: To build the docs in HTML::
$ cd docs $ cd docs
$ make html $ make html

View File

@ -24,8 +24,8 @@ languages.
* UTF-8 entities will be encoded using * UTF-8 entities will be encoded using
`punycode <http://en.wikipedia.org/wiki/Punycode>`_ and prefixed with `punycode <http://en.wikipedia.org/wiki/Punycode>`_ and prefixed with
`hy_`. For instance, `⚘` will become `hy_w7h`, and `♥` will become `hy_`. For instance, `⚘` will become `hy_w7h`, `♥` will become `hy_g6h`,
`hy_g6h`. and `i♥u` will become `hy_iu_t0x`.
* Symbols that contain dashes will have them replaced with underscores. For * Symbols that contain dashes will have them replaced with underscores. For
example, `render-template` will become `render_template`. example, `render-template` will become `render_template`.

View File

@ -19,10 +19,20 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
try:
import __builtin__ as builtins
except ImportError:
import builtins # NOQA
import sys import sys
PY3 = sys.version_info[0] >= 3
if sys.version_info[0] >= 3: if PY3:
str_type = str str_type = str
else: else:
str_type = unicode # NOQA str_type = unicode # NOQA
if PY3:
long_type = int
else:
long_type = long # NOQA

View File

@ -41,11 +41,7 @@ from hy.models.expression import HyExpression
from hy.models.string import HyString from hy.models.string import HyString
from hy.models.symbol import HySymbol from hy.models.symbol import HySymbol
from hy._compat import builtins
try:
import __builtin__ as builtins
except ImportError:
import builtins
class HyQuitter(object): class HyQuitter(object):

View File

@ -37,7 +37,7 @@ from hy.models.list import HyList
from hy.models.dict import HyDict from hy.models.dict import HyDict
from hy.macros import require, process from hy.macros import require, process
from hy.util import str_type from hy._compat import str_type
import hy.importer import hy.importer
import traceback import traceback
@ -610,7 +610,7 @@ class HyASTCompiler(object):
level) level)
imports.update(f_imports) imports.update(f_imports)
if splice: if splice:
to_add = f_contents to_add = HyExpression([HySymbol("list"), f_contents])
else: else:
to_add = HyList([f_contents]) to_add = HyList([f_contents])
@ -966,31 +966,6 @@ class HyASTCompiler(object):
col_offset=expression.start_column) col_offset=expression.start_column)
return ret return ret
@builds("print")
def compile_print_expression(self, expr):
call = expr.pop(0) # print
values, ret = self._compile_collect(expr)
if sys.version_info[0] >= 3:
call = self.compile(call)
ret += call
ret += ast.Call(func=call.expr,
args=values,
keywords=[],
starargs=None,
kwargs=None,
lineno=expr.start_line,
col_offset=expr.start_column)
else:
ret += ast.Print(
lineno=expr.start_line,
col_offset=expr.start_column,
dest=None,
values=values,
nl=True)
return ret
@builds("break") @builds("break")
def compile_break_expression(self, expr): def compile_break_expression(self, expr):
ret = ast.Break(lineno=expr.start_line, ret = ast.Break(lineno=expr.start_line,

View File

@ -43,15 +43,11 @@ except ImportError:
import hy.macros import hy.macros
import hy.compiler import hy.compiler
try: from hy._compat import builtins
import __builtin__
except ImportError:
import builtins as __builtin__ # NOQA
PATH = [hy.compiler._compile_table, PATH = [hy.compiler._compile_table,
hy.macros._hy_macros, hy.macros._hy_macros,
__builtin__.__dict__] builtins.__dict__]
class Completer(object): class Completer(object):

View File

@ -32,17 +32,15 @@ import ast
import os import os
import __future__ import __future__
if sys.version_info[0] >= 3: from hy._compat import builtins, long_type
long_type = int
else:
import __builtin__
long_type = long # NOQA
def ast_compile(ast, filename, mode): def ast_compile(ast, filename, mode):
"""Compile AST. """Compile AST.
Like Python's compile, but with some special flags.""" Like Python's compile, but with some special flags."""
return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION) flags = (__future__.CO_FUTURE_DIVISION |
__future__.CO_FUTURE_PRINT_FUNCTION)
return compile(ast, filename, mode, flags)
def import_buffer_to_hst(buf): def import_buffer_to_hst(buf):
@ -127,10 +125,7 @@ def write_hy_as_pyc(fname):
code = ast_compile(_ast, fname, "exec") code = ast_compile(_ast, fname, "exec")
cfile = "%s.pyc" % fname[:-len(".hy")] cfile = "%s.pyc" % fname[:-len(".hy")]
if sys.version_info[0] >= 3: open_ = builtins.open
open_ = open
else:
open_ = __builtin__.open
with open_(cfile, 'wb') as fc: with open_(cfile, 'wb') as fc:
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:

View File

@ -26,7 +26,7 @@ from hy.models.integer import HyInteger
from hy.models.float import HyFloat from hy.models.float import HyFloat
from hy.models.complex import HyComplex from hy.models.complex import HyComplex
from hy.models.dict import HyDict from hy.models.dict import HyDict
from hy.util import str_type from hy._compat import str_type
from collections import defaultdict from collections import defaultdict

View File

@ -24,7 +24,6 @@ class HyObject(object):
Generic Hy Object model. This is helpful to inject things into all the Generic Hy Object model. This is helpful to inject things into all the
Hy lexing Objects at once. Hy lexing Objects at once.
""" """
pass
def replace(self, other): def replace(self, other):
if isinstance(other, HyObject): if isinstance(other, HyObject):

View File

@ -20,7 +20,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from hy.models import HyObject from hy.models import HyObject
from hy.util import str_type from hy._compat import str_type
class HyKeyword(HyObject, str_type): class HyKeyword(HyObject, str_type):

View File

@ -19,7 +19,7 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
from hy.models import HyObject from hy.models import HyObject
from hy.util import str_type from hy._compat import str_type
class HyString(HyObject, str_type): class HyString(HyObject, str_type):

View File

@ -26,7 +26,6 @@ from hy.compiler import hy_compile, HyCompileError, HyTypeError
from hy.lex import tokenize from hy.lex import tokenize
import ast import ast
import sys
def _ast_spotcheck(arg, root, secondary): def _ast_spotcheck(arg, root, secondary):
@ -369,10 +368,7 @@ def test_ast_lambda_lists():
def test_ast_print(): def test_ast_print():
code = can_compile("(print \"foo\")").body[0] code = can_compile("(print \"foo\")").body[0]
if sys.version_info[0] >= 3: assert type(code.value) == ast.Call
assert type(code.value) == ast.Call
return
assert type(code) == ast.Print
def test_ast_tuple(): def test_ast_tuple():

View File

@ -82,3 +82,14 @@
(setv opt (quote &optional)) (setv opt (quote &optional))
(assert (isinstance opt hy.HyLambdaListKeyword)) (assert (isinstance opt hy.HyLambdaListKeyword))
(assert (= (str opt) "&optional"))) (assert (= (str opt) "&optional")))
(defmacro doodle [&rest body]
`(do ~@body))
(defn test-unquote-splice []
"NATIVE: test unquote-splice does what's intended"
(assert (=
(doodle
[1 2 3]
[4 5 6])
[4 5 6])))