Skip to content

Commit

Permalink
WIP Add *local-names*
Browse files Browse the repository at this point in the history
And use earmuff naming for `ContextVar`s

TODO: Implement LOCAL_NAMES context in lambda compilation.
TODO: Test.
  • Loading branch information
gilch committed Oct 30, 2024
1 parent a18cc2e commit afa1a4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/hissp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
* from :mod:`hissp.compiler`:
* `*env*`
* `*local-names*`
* `Compiler`
* `evaluate`
* `execute`
Expand Down Expand Up @@ -67,6 +69,8 @@
`macros` available with the shorter ``hissp.._macro_`` `qualifier`.
"""
from hissp.compiler import (
ENV as QzSTAR_envQzSTAR_, # Munged form of *env*.
LOCAL_NAMES as QzSTAR_localQzH_namesQzSTAR_, # Munged form of *local-names*.
Compiler,
evaluate,
execute,
Expand Down
12 changes: 10 additions & 2 deletions src/hissp/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
_PARAM_INDENT = f"\n{len('(lambda ')*' '}"

Env: TypeAlias = dict[str, Any]
ENV: ContextVar[Env] = ContextVar("ENV")
ENV: ContextVar[Env] = ContextVar("*env*")
"""
Expansion environment.
Expansion global environment.
Sometimes a macro needs the current environment when expanding,
instead of its defining environment.
Expand All @@ -44,6 +44,14 @@
`readerless` and `macroexpand` use this automatically.
"""

LOCAL_NAMES: ContextVar[frozenset[str]] = ContextVar("*local-names*")
"""
Local variable names in expansion scope.
This does not include values (which don't exist yet) or globals.
(See `ENV` for that).
"""

MAX_PROTOCOL = pickle.HIGHEST_PROTOCOL
"""
Compiler pickle protocol limit.
Expand Down

0 comments on commit afa1a4b

Please sign in to comment.