Commit Graph

49 Commits

Author SHA1 Message Date
Kodi Arfer d3fa375052 Migrate from Nose to pytest 2017-04-26 14:00:11 -07:00
Kodi Arfer ec0902b649 Set __file__ of bytecode imports 2017-04-25 09:30:13 -07:00
Kodi Arfer a27d737e1c Drop support for Pythons 3 older than 3.3 2017-04-24 14:22:13 -07:00
Kodi Arfer a87b23b4e8 Check the magic number of bytecode files 2017-04-14 13:38:38 -07:00
Kodi Arfer 36324e9499 Work around a Nose import bug on PyPy 2017-04-14 13:38:38 -07:00
Kodi Arfer 2b11b9be20 Automatically read and write bytecode
Importing or executing a Hy file now loads the byte-compiled version if it exists and is up to date, and if not, the source is byte-compiled after it's parsed.

This change can speed up Hy a lot. Here are some examples comparing run times of the current master (491b474e) to this commit, on my laptop with Python 3.6:

- `nosetests --exclude='test_bin'` goes from 3.8 s to 0.7 s (a 5-fold speedup)
- `hy -c '(print "hello world")` goes from 0.47 s to 0.20 s (a 2-fold speedup)
- Rogue TV's startup goes from 3.6 s to 0.4 s (a 9-fold speedup)

Accompanying changes include:

- `setup.py` now creates and installs bytecode for `hy.core`, `hy.contrib`, and `hy.extra`.
- The `hyc` command under Python 3 now creates bytecode in `__pycache__`, as usual for Python 3, instead of putting the `.pyc` right next to the source file like Python 2 does.

I've removed a test of `hy.extra.anaphoric.a-if` that triggers #1268 when the test file is byte-compiled and then hits some weird `macroexpand` bug or something when I try to work around that—Nose crashes when trying to produce an error message, and I can't seem to replicate the bug without Nose.
2017-04-14 13:38:33 -07:00
Kodi Arfer b71962bbaa Remove unused internal fn import_file_to_globals 2017-04-14 11:15:58 -07:00
Kodi Arfer 33a696d487 Add a command-line option --repl-output-fn (especially for hy.contrib.hy-repr) 2017-03-24 09:03:12 -07:00
Kodi Arfer 397fa80380 Revert "Modernized." (#1085) (#1188)
This reverts commit 13b484ce46 and fixes #1183.
2016-12-27 09:09:58 -06:00
Elf M. Sternberg 13b484ce46 Modernized. 2016-12-20 10:54:11 +02:00
Vinh Tu 6dc12dd703 Add import_file_to_globals for use in emacs inferior lisp mode 2016-07-01 23:27:36 +01:00
Jakub Wilk ff4ba5b103 Fix typos 2016-07-01 16:44:12 +02:00
Gregor Best 856212c9d7 Tidier string type check for eval 2015-08-13 09:59:58 +02:00
Gregor Best 44416fc276 Typecheck `eval` arguments during execution instead of compilation
When checking types during compilation, things like

    (eval '(print 1) (. foo mod))

fail, even if `(. foo mod)` is a dictionary.
2015-08-12 22:01:19 +02:00
Morten Linderud 4ee308c5f2 Merge pull request #761 from larme/fix-replace-hyobject
Add 'replace_hy_obj' to safely replace Hy objects
2015-07-23 14:09:56 +02:00
Zack M. Davis 4bea6dc59e distinguish IOError when loading file from that raised by program itself
Previously, Hy scripts that raised a subclass of IOError would be caught
by code intended to deal with IOErrors raised when Hy couldn't import
the script itself, resulting in either a misleading "Can't open file"
error message, or a misleading TypeError traceback from not being able
to format the "Can't open file" message (for IOErrors for which the
errno attribute was None). This commit (a straightforward implementation
of the idea proposed by @slimetree in #714) introduces a new HyIOError
class, raises that when `import_file_to_hst` can't open the file path,
and catches it in the `cmdline_handler`.

This is believed to fix #513, #714, and #727.
2015-02-16 14:27:18 -08:00
Zhao Shenyang 2375392962 Add 'replace_hy_obj' to safely replace Hy objects
Currently '.replace' method is used to replace hy objects. This is not
safe when we are not sure if the 'obj' in 'obj.replace(other)' is an
instance of HyObject.

In these cases, we can use function 'replace_hy_obj(obj, other)'
instead. This function will try to wrap 'obj' if it's not an instance of
HyObject.

This also means that we need a wrapping function in hy.models'. Hence I
moved the '_wrap_value' function from hy.macros into hy.models. To avoid
circular importing, the wrapper functions are provided individually by
each model type's own file.
2015-01-24 08:16:38 +08:00
Bob Tolbert ffd85bcc3e Fixes a long-standing bug in import under Python 3.3 and later.
Our MetaImporter was being inserted at the end of sys.meta_path.
For Python prior to 3.3, this was fine since sys.meta_path
was empty by default. As of the completion of PEP 302 in Py3.3 and
later, there are several importers registered by default. One of
these was trying (and failing) to import simple Hy modules,
resulting in a failure to import anything inside __init__.hy.

This change simply inserts the Hy-specific importer at the front
of the list.

This was noted in issue #620 (great catch @algernon)
2014-12-07 11:02:48 -07:00
Paul Tagliamonte 575388fc13 Merge branch 'master' into pr/397
Conflicts:
	hy/importer.py
2014-01-01 16:40:16 -05:00
Bob Tolbert 5040c29946 Cleaning up some comments from berker 2013-12-31 09:56:03 -07:00
Bob Tolbert f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Berker Peksag 8120a25c08 Add py_compile.{MAGIC, wr_long} to hy._compat.
Closes #344.
2013-12-29 13:10:36 +02:00
Berker Peksag f21ddeeded Add hy._compat module.
There was a couple of duplicate imports and type checkings in the
codebase. So I added a new module to unify all Python 2 and 3
compatibility codes.

Also, this is a somewhat common pattern in Python. See Jinja2 for
example:

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/_compat.py
2013-09-29 12:10:08 +03:00
Nicolas Dandrimont f6aa7e953d Always import __future__.print_statement in hy code
This allows us to drop the print special-casing in the
compiler, and makes behavior consistent in Python2/3.
2013-09-22 15:31:15 +02:00
Morten Linderud e4ae9880f4 Don't leave cruft around in sys.modules when an import fails.
Closes: #214, #225

Squashed from a bunch of commits by @olasd
2013-07-06 20:37:44 +02:00
Konrad Hinsen 269da19d76 Make macros module-specific.
A macro is available in the module where it was defined and
in any module that does a require of the defining module.
Only macros defined in hy.core are globally available.
Fixes #181
2013-05-16 15:34:14 +02:00
Nicolas Dandrimont 387bc0d9f2 Split eval in two steps to allow eval'ing statements
We compile the evaluated operand, separating the body (statements)
from the expression. We then eval() those separately, and return
the evaluated expression.
2013-05-05 20:42:48 +02:00
Nicolas Dandrimont e9f7c47663 Do the macro processing in the compiler 2013-05-05 20:42:48 +02:00
John Jacobsen 760774afde Implement import_buffer_to_module 2013-04-24 21:58:42 -04:00
Julien Danjou 7f230fdd10 importer: remove useless import
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-20 22:14:08 +02:00
Julien Danjou 07e99dbd33 importer: doc update, MetaImport refactor
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-20 22:11:53 +02:00
Vladimir Gorbunov f30e7cd99b Fix hyc 2013-04-13 16:28:37 +04:00
Konrad Hinsen 0c56885d42 Use __future__.division for all Hy code
Fixes #106
Note: This is implemented by replacing all calls to Python's
builtin "compile" function by calls to hy.importer.compile_,
which adds the "future division" flag. Anyone using "compile"
in future work will have to remember this.
2013-04-12 05:23:25 +02:00
Paul R. Tagliamonte 8cc26ba1bf moving to locals; fixing _ast vs ast, adding tests 2013-04-09 21:40:54 -04:00
Paul R. Tagliamonte 73be6afd3a Initial cut of `eval' 2013-04-09 21:33:09 -04:00
Paul R. Tagliamonte 5a96089266 Using backslashes for now; punycode soon. 2013-04-06 21:33:52 -04:00
Paul R. Tagliamonte e0ed7cac40 Revert "Make HySymbol bytes free!"
This reverts commit 8b144a4f3d.
2013-04-06 20:02:08 -04:00
Julien Danjou 8b144a4f3d Make HySymbol bytes free!
We can know use any amount and type of bytes to build a HyString, meaning we
can use Unicode and UTF-8 for our function and variables.

Eat that, snake!

Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-06 23:37:34 +02:00
Julien Danjou 0eb795b4a5 Check the number of arguments for each function
Signed-off-by: Julien Danjou <julien@danjou.info>
2013-04-06 19:00:32 +02:00
Paul Tagliamonte 980cd493e0 futzing with a few things 2013-03-21 19:27:34 -04:00
Paul R. Tagliamonte 4cb4e7384e holy shit it's 2013 2013-03-18 10:27:14 -04:00
Paul R. Tagliamonte cdffc9d9d1 Forcing newlines 2013-03-11 20:40:38 -04:00
Paul R. Tagliamonte 3f29114fe1 Fiddling with the site. 2013-03-10 10:58:31 -04:00
Paul R. Tagliamonte 276df1b103 thinking through some manglers. 2013-03-09 16:34:35 -05:00
Paul R. Tagliamonte a19d085620 Adding in better things. 2013-03-09 15:10:49 -05:00
Paul Tagliamonte abf63fca12 fixing up the tests 2013-03-08 18:46:51 -05:00
Paul Tagliamonte 67b803b99a Breaking things to start again. 2013-03-08 18:18:43 -05:00
Paul R. Tagliamonte 9a31fc1f81 Futzin' with some things. 2013-03-04 22:35:07 -05:00
Paul R. Tagliamonte 9e16fb4ca0 Very broken. 2013-03-03 19:40:46 -05:00