Commit Graph

1162 Commits

Author SHA1 Message Date
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