Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Hy builtins as actual builtins #1979

Merged
merged 10 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Removals
* `#doc` has been removed. Instead of `#doc @`, say `(doc "#@")`.
* `__tags__` has been removed. Tag macros are now tracked in
`__macros__`.
* `eval` has been removed from core.
Use the fully qualified name `hy.eval` instead.

Breaking Changes
------------------------------
Expand Down Expand Up @@ -56,6 +58,9 @@ Bug Fixes
* Fixed compiler crash on `.` form with empty attributes.
* Attempts to assign to constants are now more reliably detected.
* Fixed bugs with `require` of names that need mangling.
* Fixed namespace pollution caused by automatic imports of Hy builtins and macros.
* Fixed Hy model objects sometimes not being in scope.
* Fixed `doc` sometimes failing to find builtin macros.

0.20.0 (released 2021-01-25)
==============================
Expand Down
8 changes: 4 additions & 4 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
API
===

.. hy:autofunction:: hy.eval

.. _special-forms:

Special Forms
Expand Down Expand Up @@ -684,7 +686,7 @@ Special Forms
(print "A result from Python:" (py "'hello' + 'world'"))

The code must be given as a single string literal, but you can still use
macros, :hy:func:`eval <hy.core.language.eval>`, and related tools to construct the ``py`` form. If
macros, :hy:func:`hy.eval <hy.eval>`, and related tools to construct the ``py`` form. If
having to backslash-escape internal double quotes is getting you down, try a
:ref:`bracket string <syntax-bracket-strings>`. If you want to evaluate some
Python code that's only defined at run-time, try the standard Python function
Expand Down Expand Up @@ -741,7 +743,7 @@ Special Forms
HyExpression([
HySymbol('print'),
HyString('Hello World')])
=> (eval x)
=> (hy.eval x)
Hello World


Expand Down Expand Up @@ -1198,8 +1200,6 @@ Core

.. hy:autofunction:: hy.core.language.calling-module

.. hy:autofunction:: hy.core.language.eval

.. hy:autofunction:: hy.core.language.mangle

.. hy:autofunction:: hy.core.language.unmangle
Expand Down
2 changes: 1 addition & 1 deletion docs/cheatsheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"hy.core.language.calling-module-name",
"hy.core.language.parse-args",
"hy.core.language.disassemble",
"hy.core.language.eval",
"hy.eval",
"hy.core.language.gensym",
"hy.core.language.keyword",
"hy.core.language.macroexpand",
Expand Down
2 changes: 1 addition & 1 deletion docs/language/interop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ two separate steps. First, use the ``read_str`` function (or ``read`` for a
>>> import hy
>>> expr = hy.read_str("(- (/ (+ 1 3 88) 2) 8)")

Then, use the ``eval`` function to evaluate it:
Then, use the ``hy.eval`` function to evaluate it:

.. code-block:: python

Expand Down
2 changes: 1 addition & 1 deletion docs/whyhy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ benefit of error messages, and models can represent syntactic features that the
corresponding primitive type can't, such as the order in which elements appear
in a set literal. However, models can be concatenated and indexed just like
plain lists, and you can return ordinary Python types from a macro or give them
to ``eval`` and Hy will automatically promote them to models.
to ``hy.eval`` and Hy will automatically promote them to models.

Hy takes much of its semantics from Python. For example, Hy is a Lisp-1 because
Python functions use the same namespace as objects that aren't functions. In
Expand Down
1 change: 1 addition & 0 deletions hy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def _initialize_env_var(env_var, default_val):


import hy.importer # NOQA
hy.importer._inject_builtins()
# we import for side-effects.


Expand Down
10 changes: 8 additions & 2 deletions hy/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ def __call__(self, source, filename="<input>", symbol="single"):
exec_ast, eval_ast = hy_compile(hy_ast, self.module, root=root_ast,
get_expr=True,
compiler=self.hy_compiler,
filename=filename, source=source)
filename=filename, source=source,
import_stdlib=False)

if self.ast_callback:
self.ast_callback(exec_ast, eval_ast)
Expand Down Expand Up @@ -297,13 +298,18 @@ def __init__(self, spy=False, output_fn=None, locals=None,
# Allow access to the running REPL instance
self.locals['_hy_repl'] = self

# Compile an empty statement to load the standard prelude
exec_ast = hy_compile(hy_parse(''), self.module, compiler=self.hy_compiler, import_stdlib=True)
if self.ast_callback:
self.ast_callback(exec_ast, None)

def ast_callback(self, exec_ast, eval_ast):
if self.spy:
try:
# Mush the two AST chunks into a single module for
# conversion into Python.
new_ast = ast.Module(
exec_ast.body + [ast.Expr(eval_ast.body)],
exec_ast.body + ([] if eval_ast is None else [ast.Expr(eval_ast.body)]),
type_ignores=[])
print(astor.to_source(new_ast))
except Exception:
Expand Down
Loading