Brandon T. Willard
5d325a5156
Add a test for module docstrings
2018-08-27 01:02:29 -05:00
Brandon T. Willard
2ea1e8e017
Make Hy a Python-source module type
2018-08-26 13:20:49 -05:00
Brandon T. Willard
cbaba4a10a
Use Python cmdline file-relative sys.path
...
Closes hylang/hy#1457 .
2018-08-26 00:27:21 -05:00
Brandon T. Willard
c022abc831
Add Python cmdline bytecode option and set sys.executable
...
Closes hylang/hy#459 .
2018-08-26 00:17:12 -05:00
Brandon T. Willard
87a5b117a1
Implement new importer using PEP-302 semantics
...
Python 3.x is patched in a way that integrates `.hy` source files into
Pythons default `importlib` machinery. In Python 2.7, a PEP-302 "importer"
and "loader" is implemented according to the standard `import` logic (via
`pkgutil` and later pure-Python `imp` package code).
In both cases, the entry-point for the loaders is through `sys.path_hooks` only.
As well, the import semantics have been updated all throughout to utilize
`importlib` and follow aspects of PEP-420. This, along with some light
patches, should allow for basic use of `runpy`, `py_compile` and `reload`.
In all cases, if a `.hy` file is shadowed by a `.py`, Hy will silently use
`.hy`.
2018-08-25 22:50:38 -05:00
Kodi Arfer
734cdcd2fd
Delay importing the lexer and parser
...
This speeds up runs of Hy that never need to parse or compile Hy code (e.g., running a Hy program that's already byte-compiled).
2018-08-18 18:05:40 -04:00
Kodi Arfer
7ba2105a2b
Fix date and time hy-reprs on Windows
2018-08-08 09:26:20 -04:00
gilch
109c0b0f5b
Merge pull request #1664 from brandonwillard/require-in-macroexpand-all
...
Expand `require`d macros in `macroexpand-all`
2018-08-02 23:57:32 -06:00
Brandon T. Willard
33f2b4a91a
Compile `require`s in the body of a macro
...
This change enables further macro expansion for cases in which a macro
`require`s other macros within its body.
2018-07-25 17:20:19 -05:00
Kodi Arfer
081a710b0f
Fix handling of unpacking in method calls and attribute lookups
2018-07-24 09:45:00 -07:00
Kodi Arfer
0f85331c81
Rename variables in @builds_model(HyExpression)
2018-07-24 09:41:57 -07:00
Kodi Arfer
1d2c73165d
Make HyKeyword callable
...
Co-authored-by: Simon Gomizelj <simon@vodik.xyz>
2018-07-24 09:19:37 -07:00
Kodi Arfer
03aafad657
Make empty expressions illegal at the top level
2018-07-24 08:59:52 -07:00
gilch
0de8557fb5
Merge pull request #1647 from gilch/let-rebind
...
Fix let rebind bug.
2018-07-08 21:52:32 -06:00
Kodi Arfer
af8907b151
Minor cleanup in compile_unary_operator
2018-06-30 11:04:57 -07:00
Kodi Arfer
88f33453dc
Minor cleanup for `raise` and `try`
2018-06-30 11:04:11 -07:00
Kodi Arfer
bd675a5db6
Unmangle in compile_expression before build_method
...
This ensures that e.g. the symbols "~" and "hyx_XtildeX" in the root position will both appear as "~" to the build method.
2018-06-30 11:04:11 -07:00
Kodi Arfer
fca2eb93b0
Remove dead code from HyASTCompiler.compile
2018-06-30 11:04:11 -07:00
Kodi Arfer
00150c088c
Remove an unused helper method in the compiler
2018-06-30 11:04:11 -07:00
Kodi Arfer
e2b98effda
Replace an unused variable with `_`
2018-06-30 11:04:11 -07:00
Kodi Arfer
217fc2a487
Clean up _render_quoted_form
2018-06-30 11:04:11 -07:00
Kodi Arfer
8a70d5c90f
Fold _branch into the compiler
2018-06-30 11:04:11 -07:00
Kodi Arfer
45ec57ab56
Simplify Result.force_expr
2018-06-30 11:04:11 -07:00
Kodi Arfer
21f7ef0713
Fold load_stdlib into the compiler
2018-06-30 11:04:11 -07:00
Kodi Arfer
d501b073d8
Fold compile_time_ns into the compiler
2018-06-30 11:04:11 -07:00
Kodi Arfer
3d3d1fe6ae
Remove unused compiler subroutines
2018-06-30 11:04:11 -07:00
Kodi Arfer
9c6714c176
Remove unused imports
2018-06-30 11:04:11 -07:00
gilch
8c79015b40
Fix let rebind bug.
2018-06-27 23:41:49 -06:00
gilch
4b0e318997
Remove outdated comment in walk.
2018-06-27 23:39:44 -06:00
Kodi Arfer
7abd8ffc2a
Make importing a dotted name a syntax error, per Python
2018-06-27 10:24:22 -07:00
Oskar Kvist
edbe8e3b7f
Make defmacro! work with optional args
2018-06-25 11:45:23 -07:00
Kodi Arfer
76b80bad81
Remove support for the old comprehension forms
2018-06-13 17:31:08 -07:00
Kodi Arfer
cf0dafef9b
Update uses of the old comprehension forms
2018-06-13 17:31:08 -07:00
Kodi Arfer
4754b152a9
Allow comprehensions with no looping parts
2018-06-13 17:31:08 -07:00
Kodi Arfer
e1972c535f
Remove `for/a`, `for*`, and `for/a*`
2018-06-13 17:31:08 -07:00
Kodi Arfer
3256932b13
Add a version of `for` parallel to `lfor` etc.
2018-06-13 17:31:08 -07:00
Kodi Arfer
ba1dc55e96
Implement `lfor`, `sfor`, `gfor`, `dfor`
2018-06-13 17:31:08 -07:00
Kodi Arfer
7a40561db8
Add tagged model patterns
2018-06-13 17:31:08 -07:00
Kodi Arfer
5ffbb4b0eb
Add Result.lineno and Result.col_offset
2018-06-13 17:31:08 -07:00
Kodi Arfer
844256b99b
Make Asty use static rather than instance methods
...
This ensures `asty.Pass is asty.Pass`.
2018-06-13 17:31:08 -07:00
Kodi Arfer
c3d4c7aa82
Clean up `else` compilation in `while`
2018-06-11 21:05:29 -07:00
Kodi Arfer
ea899471af
Remove an unused compiler function
2018-06-11 21:05:29 -07:00
Kodi Arfer
16ec46a473
Update docstring handling for Python 3.7
...
See https://github.com/python/cpython/pull/7121 .
2018-06-05 17:35:48 -07:00
Kodi Arfer
3204a9e8a3
Streamline auto-promotion and position spoofing
...
Auto-promotion now occurs in only two cases: when we start the compiler and when we expand a macro. It's fully recursive so even a non-model nested in a model will be promoted.
This change fixes some regressions induced by the stricter type checks of the pattern-matching compiler.
2018-06-05 09:23:21 -07:00
Kodi Arfer
a38c948ed2
Fix a regression with mangling module names
2018-06-03 15:38:49 -07:00
Ryan Gonzalez
e66743c976
Merge pull request #1615 from Kodiologist/no-parser-cache
...
Disable the parser cache
2018-05-27 16:28:00 -05:00
Kodi Arfer
e344ac1fd6
Fix the management of _stdlib
...
_stdlib is a global variable, so core modules could use it, contrary to our intention, so long as they happened to be compiled after a non-core module. I've added a compiler attribute to track whether we can use _stdlib.
This fix exposed some cases where hy.core.shadow tried to use a core function, so I fixed those.
I've also added an `if not _stdlib` to `load_stdlib` so that we only bother to actually load _stdlib once.
2018-05-24 17:51:21 -07:00
Kodi Arfer
1732ddec4d
Disable the parser cache
...
I wasn't able to observe a meaningful performance improvement from it, and it requires some file I/O. Here are the times, in seconds, I observed on my ThinkPad T450s with Python 3.6 and Ubuntu 18.04:
test 1 test 2
master 8.96 2.59
this change 8.88 2.62
Test 1 is the total time from:
$ time dash -c 'git clean -dfx && pip install -e . && pytest --ignore tests/test_bin.py'
Test 2 is pytest's reported total time from a subsequent:
$ pytest --ignore tests/test_bin.py
2018-05-21 09:22:49 -07:00
Kodi Arfer
0a5bc21fcf
Simplify compile_numeric_literal for new astor
2018-05-20 14:11:35 -07:00
Kodi Arfer
38fdcc2114
Don't let HySymbol inherit from HyString
2018-05-20 14:11:35 -07:00
Kodi Arfer
210086c7ca
Clean up the decorators used in the compiler
2018-05-20 14:11:35 -07:00
Kodi Arfer
98fbdcfc50
Move @builds(HyExpression) next to other @builds
2018-05-20 14:11:35 -07:00
Kodi Arfer
a933646bdd
Use model patterns for the remaining special forms
2018-05-20 14:11:35 -07:00
Kodi Arfer
8b2733e921
Use model patterns for comprehensions
...
I haven't bothered to refine the patterns for these since I intend to completely overhaul the comprehension forms in the near future.
2018-05-20 14:11:35 -07:00
Kodi Arfer
41d3f26001
Use model patterns for comparison and math ops
2018-05-20 14:11:35 -07:00
Kodi Arfer
57b5fa49b1
Unify illegal special forms
2018-05-20 14:11:31 -07:00
Kodi Arfer
45e8783997
Use model patterns for `fn`
2018-05-20 14:07:44 -07:00
Kodi Arfer
3ebff987e0
Use model patterns for `defclass`
2018-05-20 14:07:44 -07:00
Kodi Arfer
9368e4bc4e
Use model patterns for `import` and `require`
...
In the process, I've banned the syntax `(import [foo])` in favor of `(import foo)`.
2018-05-20 14:07:44 -07:00
Kodi Arfer
11f1c149ef
Use model patterns for `try`
2018-05-20 14:07:44 -07:00
Kodi Arfer
79c02514b9
Introduce the use of model patterns
2018-05-20 14:07:44 -07:00
Philip Xu
8a83d0c1ea
Fixes #1605 : remove macros ap-pipe and ap-compose
...
Anaphoric macros do not work well with point-free style programming, in
which case both threading macros and `comp` are more adequate.
2018-05-20 13:52:51 -07:00
gilch
049c78f5d5
Fix bug in let's handle-dot.
2018-05-18 10:40:59 -07:00
gilch
e7ac4ec859
fix botsbuildbots for #1582
...
This is preventing Hy from installing.
Closes #1599
#1601 would make this moot, but fixing it is the more conservative change. Pick one or the other. This `botsbuildsbots` doesn't do anything important. It's just one of our Easter eggs.
2018-05-06 19:55:16 -06:00
gilch
9d1304aacd
Remove lambda list unpacking handling in `let`.
2018-05-04 10:40:22 -07:00
Kodi Arfer
a2aeca2338
Remove tuple unpacking in lambda lists
2018-05-04 10:40:22 -07:00
Simon Gomizelj
7c3477e738
Fix a bug where the compiler doesn't properly handle unquote-splice
...
Added test coverage as well
2018-04-30 09:38:57 -07:00
Kodi Arfer
c7ac4c60c4
Fix a bug that caused `try` to drop expressions
2018-04-30 09:18:01 -07:00
Kodi Arfer
ec1c92bf4e
Allow `for` with an empty body
2018-04-29 19:51:00 -07:00
Kodi Arfer
b7e5c5f17a
Allow `while` with an empty body
2018-04-29 19:51:00 -07:00
Kodi Arfer
87aced2370
Don't let HyExpression etc. inherit from HyList
...
This means the compiler no longer allows e.g. `(fn (x) ...)` in place of `(fn [x] ...)`.
2018-04-29 19:17:47 -07:00
Simon Gomizelj
032247e380
Merge pull request #1588 from Kodiologist/no-amp-key
...
Remove &key
2018-04-27 00:21:11 -04:00
Ryan Gonzalez
fbeff8d25c
Merge pull request #1587 from Kodiologist/no-empty-catchers
...
Ban `(except)`
2018-04-23 21:50:56 -05:00
Kodi Arfer
c1a487cdf7
Move logic from macroexpand_1 to macroexpand
...
By ending macro-expansion immediately when appropriate, this change fixes a bug arising from the fact that NaN != NaN.
2018-04-21 12:25:29 -07:00
Kodi Arfer
026316ebef
Refactor macroexpand_1
2018-04-21 12:25:29 -07:00
Kodi Arfer
116d7fa6ec
Copy in compile_atom instead of macroexpand_1
...
This copying is what keeps all the mutating code in the compiler methods (e.g., `expr.pop(0)`) from breaking cases in which Hy model objects are compiled more than once or inspected after compilation.
2018-04-21 12:25:29 -07:00
Kodi Arfer
4a6b633ad2
Add some missing imports
2018-04-21 12:25:29 -07:00
Kodi Arfer
1f95da2b0b
Avoid using a core function name as a variable
2018-04-21 12:25:29 -07:00
Kodi Arfer
a605936651
Remove &key
...
It's redundant with &optional.
2018-04-19 09:26:02 -07:00
Kodi Arfer
7bf2901364
Ban `(except)`
...
It's rarely useful, because it catches all exceptions, but it doesn't let you do anything other than return `None`. You can still get the same effect with `(except [])`.
2018-04-16 19:34:50 -07:00
Kodi Arfer
c93a60ede0
Remove support for cons cells
2018-04-12 16:45:17 -07:00
Simon Gomizelj
291847af15
Make HyKeyword constructor consistent
...
The colon is now only part of its string representation and no longer
accepted as part of the constructor:
:foobar == HyKeyword("foobar")
2018-04-07 22:29:20 -07:00
Simon Gomizelj
1b7dfd2839
Make HyKeyword a first class objects
...
HyKeywords are no longer an instances of string with a particular
prefix, but a completely separate object.
This means keywords no longer trip isinstance str checks, adding a
little bit of type safety to the compiler.
It also means that HyKeywords evaluate to themselves.
Closes #1352
2018-04-07 22:29:20 -07:00
Yigong Wang
564c030950
Raise LexException when codec can't decode some bytes
2018-04-07 11:47:06 -07:00
Simon Gomizelj
4d98cde663
Merge pull request #1560 from waigx/feat/results-shortcuts
...
Add recent REPL results globals *i and most recent error *e
2018-04-04 19:27:35 -04:00
Kodi Arfer
f17a21be63
Use `X` as the mangle delimiter on Python 3
2018-04-04 10:50:33 -07:00
Yigong Wang
be8537c0cf
Add recent REPL results globals *i and most recent error *e
...
This comment add *1, *2, *3 as globals for recent REPL results.
*e global is also added for the most recent error object.
2018-04-02 00:21:13 -04:00
Yigong Wang
4073c78069
Add -E support for Hy REPL
...
This commit adds -E support for Hy. Similar to Python, hy will ignore
all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME,
that might be set.
2018-03-31 15:16:40 -07:00
Simon Gomizelj
258a1f5748
Fix PY37 docstring generation
2018-03-31 03:07:26 -04:00
Simon Gomizelj
b27cdfed69
Fix `defclass` construction
...
Python Class AST expects a body which is a list of ast.Expr. Force
every entry to be stored as a statement. This means we'll preserve
print statements.
Python also doesn't construct docstrings in classes by setting a
__doc__ attribute, it does it by inspecting the first ast.Expr node of
the class. But this means we can remove the special handler for it.
2018-03-31 02:43:53 -04:00
Simon Gomizelj
84e1c65bcd
Improve checks inside `defclass`
...
We need to make sure we're looking at HyExpression when trying to
determine if we're rewriting an __init__ expression.
Fixes #1533
2018-03-31 02:43:53 -04:00
Simon Gomizelj
cf11e81c93
Remove unused imports
2018-03-31 02:43:53 -04:00
gilch
074a4bb75f
Merge pull request #1556 from waigx/chore/hy-help-msg
...
Prettify hy command helping message
2018-03-30 11:21:00 -06:00
Yigong Wang
5ae6875e88
Fix `mangle` for Pythons compiled with UCS-2
2018-03-30 07:23:32 -07:00
Yigong Wang
57064d38dd
Prettify hy command helping message
2018-03-29 23:04:22 -04:00
Tuukka Turto
af89fd68b0
Report objects when raising type error ( #1554 )
...
Give better error report when replacing non-hy objects
2018-03-28 21:45:49 -05:00
Simon Gomizelj
97cb19a8a2
Fix bytecode loading on Python 3.7
2018-03-24 12:34:43 -07:00
Kodi Arfer
03eab21fbf
Avoid a Python 3.7 deprecation warning
2018-03-24 12:34:43 -07:00
Kodi Arfer
e3058b5cf5
Handle module docstrings on Python 3.7
2018-03-24 12:34:43 -07:00
Kodi Arfer
dc30584a8a
Handle function docstrings on Python 3.7
2018-03-24 12:34:43 -07:00
gilch
e7b21cc0df
fix indent
2018-03-23 14:16:06 -07:00
Kodi Arfer
ad59fd7ff6
In -> and ->>, don't modify the arguments
2018-03-23 13:57:19 -07:00
Simon Gomizelj
c663d38e33
Add metaclass support, support PEP 3115 and PEP 487
2018-03-22 13:28:22 -07:00
Kodi Arfer
4c5dea0756
Use io.StringIO instead of the StringIO module
2018-03-13 14:57:31 -04:00
Kodi Arfer
6875ae0e3f
Replace `hyify` with `unmangle`
2018-03-13 14:56:49 -04:00
Kodi Arfer
3c97d2982c
Use `*1` instead of `_` for REPL history
...
`_`, as a variable, is now the shadow subtraction operator.
2018-03-13 14:56:47 -04:00
Kodi Arfer
85968e70dd
Add `mangle` and `unmangle` as core functions
2018-03-13 14:55:55 -04:00
Kodi Arfer
0c8c5dc830
Mangle special forms
2018-03-13 14:55:55 -04:00
Kodi Arfer
ccb3ba6092
Mangle macro names
2018-03-13 14:55:55 -04:00
Kodi Arfer
0c816f2e83
Mangle keyword arguments
2018-03-13 14:55:55 -04:00
Kodi Arfer
d252bb0e94
Mangle names that coincide with Python keywords
2018-03-13 14:55:55 -04:00
Kodi Arfer
52edad28e2
Overhaul mangling rules
2018-03-13 14:55:53 -04:00
Kodi Arfer
d501d4d806
Mangle symbols at compile-time instead of parse-time
...
This means that a HySymbol remembers its original name. That is, `a-b` and `a_b` are different symbols although `(setv a-b 1)` and `(setv a_b 1)` set the same variable (namely, `a_b`).
Most of the edits in this commit are to switch underscores to hyphens in places where mangling hasn't happened yet.
I removed some lexer tests since the lexer no longer does any mangling.
2018-03-13 14:55:15 -04:00
Kodi Arfer
7fcc7ac4b6
Make unary comparison ops evaluate their argument
2018-03-13 14:38:36 -04:00
Kodi Arfer
0574e275b5
Make hy-repr support some `collections` classes
2018-03-10 18:11:07 -08:00
Kodi Arfer
38f461890d
Make hy-repr support DateTime objects
2018-03-10 18:11:07 -08:00
Kodi Arfer
3dbe05302e
Make hy-repr support regex match objects
2018-03-10 18:11:07 -08:00
Kodi Arfer
f7ab9a6e7c
Make hy-repr support dictionary views
2018-03-10 18:11:07 -08:00
Kodi Arfer
90a09b5b44
Make hy-repr use double spaces for dictionaries
2018-03-10 18:11:07 -08:00
Kodi Arfer
83c4f63bc2
Reimplement hy-repr with registered functions
...
This removes a lot of hy-reprs that were hard-coded into the hy-repr function itself. It also allows you to add a hy-repr for an existing class without monkey-patching the class.
2018-03-10 18:11:07 -08:00
Simon Gomizelj
ef2f435647
Add a hy.introspect module to deal with getargspec deprecation
2018-02-14 16:05:31 -05:00
Simon Gomizelj
be6ddd4bb2
Fix deprecation warning triggered by PEP 479
2018-02-14 16:05:31 -05:00
Simon Gomizelj
316220b742
Fix AST generation of a naked return
2018-02-14 16:05:31 -05:00
Kodi Arfer
7cf23fabc4
Merge pull request #1503 from vodik/travis-py37
...
Add python 3.7-dev to travis, allow it to fail
2018-02-14 08:41:14 -08:00
Simon Gomizelj
a2c8f50b30
Implement changes to support PEP 552
2018-02-09 16:43:25 -05:00
Simon Gomizelj
5c40f793a1
Support PEP 328
...
Add support for proper relative imports
2018-02-06 23:41:12 -05:00
Tuukka Turto
5c720c0110
Merge pull request #1473 from Kodiologist/new-year-2018
...
Update copyright years
2018-02-05 15:11:59 +02:00
Tuukka Turto
cf87de5cc2
Merge pull request #1483 from vodik/remove-def
...
Just remove `def`
2018-01-31 08:54:59 +02:00
Simon Gomizelj
0cd4df3898
Remove def and standardize on setv
2018-01-21 00:25:33 -05:00
Tuukka Turto
a9621817f9
Merge pull request #1433 from Kodiologist/while-multistatement
...
Handle statements in the condition of `while`
2018-01-11 07:45:27 +02:00
Kodi Arfer
64cf7c7437
Merge pull request #1456 from Kodiologist/big-floats
...
Don't parse large floats as symbols
2018-01-11 00:44:50 -05:00
Kodi Arfer
6de7ddfee5
Update copyright years
2018-01-01 10:38:33 -05:00
Simon Gomizelj
f69ccd2421
Allow coroutines to be decorated
2017-12-31 09:03:39 -05:00
Kodi Arfer
b81585eaba
Reimplement _with and _for as functions
2017-12-30 19:39:15 -05:00
Simon Gomizelj
1e4ad3167b
Introduce for/a* and for/a expressions
2017-12-30 19:02:15 -05:00
Simon Gomizelj
783d53ecb7
Introduce with/a* and with/a expressions
2017-12-30 19:02:15 -05:00
Simon Gomizelj
2ffaa8e5be
Fix yield-from to prevent it from accepting no arguments
...
Closes #1472
2017-12-30 19:02:15 -05:00
Simon Gomizelj
e3e01d4405
Introduce fn/a and defn/a
...
Closes #1054
2017-12-30 19:02:15 -05:00
Jakub Wilk
8b986e87e3
Add missing space between words
2017-12-24 20:02:23 +01:00
Rob Day
eda78eb81c
Allow multiple expressions in a try
2017-12-03 09:47:41 +00:00
Jakub Wilk
e2e1b04ea3
Fix typos
2017-11-26 00:44:03 +01:00
Kodi Arfer
a26480a81b
Don't parse large floats as symbols
2017-11-11 15:14:28 -08:00
Kodi Arfer
52a0c8a870
Unify implementations of `eval-X-compile`
2017-11-02 08:43:43 -07:00
Kodi Arfer
fd64575799
Handle statements in the condition of `while`
2017-11-02 07:31:58 -07:00
Ryan Gonzalez
e0e664c030
Merge branch 'master' into letmacro
2017-11-01 09:39:18 -05:00
Kodi Arfer
a074bb9a5c
Work around an astor regression for NaN
2017-10-31 17:50:44 -07:00
gilch
6bb997dbea
update astor to 0.6
2017-10-31 14:13:41 -06:00
gilch
91bdaea535
add documentation macros
2017-10-30 21:25:25 -06:00
gilch
a4dd344ebd
protect eval-and-compile/eval-when-compile in let
2017-10-30 20:24:09 -06:00
gilch
82b4518fa6
error check defclass name
2017-10-30 20:24:09 -06:00