plan-kernel 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. plan_kernel-0.1.1/PKG-INFO +219 -0
  2. plan_kernel-0.1.1/README.md +194 -0
  3. plan_kernel-0.1.1/plan_kernel/__init__.py +3 -0
  4. plan_kernel-0.1.1/plan_kernel/__main__.py +14 -0
  5. plan_kernel-0.1.1/plan_kernel/evaluator.py +305 -0
  6. plan_kernel-0.1.1/plan_kernel/expander.py +23 -0
  7. plan_kernel-0.1.1/plan_kernel/kernel.py +219 -0
  8. plan_kernel-0.1.1/plan_kernel/magics.py +72 -0
  9. plan_kernel-0.1.1/plan_kernel/parser.py +11 -0
  10. plan_kernel-0.1.1/plan_kernel/prelude.py +77 -0
  11. plan_kernel-0.1.1/plan_kernel/render.py +161 -0
  12. plan_kernel-0.1.1/plan_kernel/runtime/__init__.py +1 -0
  13. plan_kernel-0.1.1/plan_kernel/runtime/bplan.py +20 -0
  14. plan_kernel-0.1.1/plan_kernel/runtime/bplan_deps.py +115 -0
  15. plan_kernel-0.1.1/plan_kernel/runtime/plan.py +133 -0
  16. plan_kernel-0.1.1/plan_kernel.egg-info/PKG-INFO +219 -0
  17. plan_kernel-0.1.1/plan_kernel.egg-info/SOURCES.txt +30 -0
  18. plan_kernel-0.1.1/plan_kernel.egg-info/dependency_links.txt +1 -0
  19. plan_kernel-0.1.1/plan_kernel.egg-info/requires.txt +5 -0
  20. plan_kernel-0.1.1/plan_kernel.egg-info/top_level.txt +1 -0
  21. plan_kernel-0.1.1/pyproject.toml +46 -0
  22. plan_kernel-0.1.1/setup.cfg +4 -0
  23. plan_kernel-0.1.1/tests/test_evaluator.py +236 -0
  24. plan_kernel-0.1.1/tests/test_expander.py +292 -0
  25. plan_kernel-0.1.1/tests/test_fixtures.py +36 -0
  26. plan_kernel-0.1.1/tests/test_kernel_smoke.py +141 -0
  27. plan_kernel-0.1.1/tests/test_magics.py +265 -0
  28. plan_kernel-0.1.1/tests/test_parser.py +300 -0
  29. plan_kernel-0.1.1/tests/test_prelude.py +190 -0
  30. plan_kernel-0.1.1/tests/test_render.py +207 -0
  31. plan_kernel-0.1.1/tests/test_runtime_smoke.py +61 -0
  32. plan_kernel-0.1.1/tests/test_tutorials.py +107 -0
@@ -0,0 +1,219 @@
1
+ Metadata-Version: 2.4
2
+ Name: plan-kernel
3
+ Version: 0.1.1
4
+ Summary: Jupyter kernel for interactive PLAN evaluation.
5
+ Author-email: Neal Davis <davisneale@gmail.com>
6
+ Project-URL: Homepage, https://github.com/sigilante/marduk
7
+ Project-URL: Repository, https://github.com/sigilante/marduk
8
+ Keywords: plan,jupyter,kernel,ipykernel,gallowglass
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Framework :: IPython
12
+ Classifier: Framework :: Jupyter
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Topic :: Education
18
+ Classifier: Topic :: Software Development :: Interpreters
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: ipykernel>=6.0
22
+ Requires-Dist: marduk-plan>=0.2.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+
26
+ # plan-kernel
27
+
28
+ ![](https://upload.wikimedia.org/wikipedia/commons/c/c3/Chaos_Monster_and_Sun_God.png)
29
+
30
+ A Jupyter kernel for the [PLAN virtual machine](https://github.com/xocore-tech/PLAN).
31
+ Type Plan Asm in a cell, see the reduced PLAN value back.
32
+
33
+ plan-kernel is intended for tutorial use: learning what PLAN's three opcodes
34
+ (Pin / Law / Elim) do, exercising BPLAN's named primitives, and walking
35
+ through small programs (Church booleans, factorial, Y-combinator) one
36
+ reduction at a time.
37
+
38
+ ## Status
39
+
40
+ Alpha. All nine phases of [`PLAN.md`](PLAN.md) are complete: vendored
41
+ runtime, Plan Asm parser, macro expander, cell-level evaluator,
42
+ structural renderer, cell magics, BPLAN op prelude, Jupyter kernel +
43
+ CLI, and a starter set of teaching fixtures + tour notebook. A fresh
44
+ notebook can evaluate `(Add 2 3)` in cell 1.
45
+
46
+ PyPI publication is the next step.
47
+
48
+ ## Install
49
+
50
+ ### From PyPI (once published)
51
+
52
+ ```bash
53
+ pip install plan-kernel
54
+ python -m plan_kernel install # registers the kernelspec with Jupyter
55
+ jupyter notebook # "PLAN" appears in the kernel picker
56
+ ```
57
+
58
+ `plan-kernel` is the PyPI package; `plan_kernel` is the import name. The same
59
+ package supplies both the Python library and the Jupyter kernel — there is
60
+ no separate `plan-kernel-kernel` distribution.
61
+
62
+ ### From a clone (local development)
63
+
64
+ If you've cloned this repo (the typical case while plan-kernel is pre-1.0), do an
65
+ editable install so changes to the source tree take effect without
66
+ re-installing:
67
+
68
+ ```bash
69
+ git clone git@github.com:sigilante/marduk.git
70
+ cd marduk/packages/plan-kernel
71
+ python -m venv .venv && source .venv/bin/activate # optional but recommended
72
+ pip install -e '.[dev]' # installs ipykernel + pytest
73
+ pytest # confirm the runtime smoke test passes
74
+ ```
75
+
76
+ To register the kernel with Jupyter so it appears in the notebook kernel
77
+ picker:
78
+
79
+ ```bash
80
+ python -m plan_kernel install # user-level install (writes to ~/.local/share/jupyter/kernels/plan-kernel/)
81
+ # or
82
+ python -m plan_kernel install --prefix .venv # install only inside the active virtualenv
83
+ ```
84
+
85
+ Verify the registration:
86
+
87
+ ```bash
88
+ jupyter kernelspec list # "plan-kernel" should appear
89
+ ```
90
+
91
+ Launch:
92
+
93
+ ```bash
94
+ jupyter notebook # or: jupyter lab
95
+ ```
96
+
97
+ In a new notebook, choose **"PLAN"** from the kernel picker. A
98
+ fresh notebook has the BPLAN op prelude pre-bound, so `(Add 2 3)` evaluates
99
+ to `5` in cell 1.
100
+
101
+ ### Uninstall
102
+
103
+ ```bash
104
+ jupyter kernelspec remove plan-kernel # remove kernelspec only
105
+ pip uninstall plan-kernel # remove the package
106
+ ```
107
+
108
+ ## Quickstart
109
+
110
+ A cell is a sequence of Plan Asm forms. The result of the last non-bind
111
+ form displays; bind-only cells render `bind <name>` summary lines.
112
+
113
+ ```text
114
+ (Add 2 3)
115
+ ```
116
+
117
+ ```text
118
+ 5
119
+ ```
120
+
121
+ Define a law and apply it:
122
+
123
+ ```text
124
+ (#bind id
125
+ (#pin
126
+ (#law "id" (id x)
127
+ x)))
128
+
129
+ (id 42)
130
+ ```
131
+
132
+ ```text
133
+ 42
134
+ ```
135
+
136
+ The K combinator and a use:
137
+
138
+ ```text
139
+ (#bind k
140
+ (#pin
141
+ (#law "k" (k a b)
142
+ a)))
143
+
144
+ (k 7 99)
145
+ ```
146
+
147
+ ```text
148
+ 7
149
+ ```
150
+
151
+ The fixtures in [`tests/fixtures/`](tests/fixtures/) cover identity,
152
+ K, S, arithmetic, `Elim` on a nat, and Church booleans — copy any of
153
+ them into a cell to see them run.
154
+
155
+ ## What's a cell?
156
+
157
+ A cell is a sequence of Plan Asm forms — the same syntax accepted by the
158
+ canonical Reaver parser
159
+ ([`vendor/reaver/src/hs/PlanAssembler.hs`](https://github.com/xocore-tech/PLAN)),
160
+ minus `#macro`, `#export`, and `@include` (those need module-loading semantics
161
+ that don't make sense in a notebook).
162
+
163
+ Supported macros: `#pin`, `#law`, `#app`, `#bind`. The BPLAN op prelude
164
+ auto-loads on kernel start, so `(Add 2 3)` works in cell 1.
165
+
166
+ ## Magic reference
167
+
168
+ Magics live on lines that start with `%`, at the very top of the cell.
169
+ Comments and blank lines above them stop magic parsing — magics must
170
+ lead the cell body.
171
+
172
+ | Magic | Scope | Effect |
173
+ |---------------------------|--------------|-------------------------------------------------------------------------|
174
+ | `%backend evaluate` | this cell | Use the formal Python evaluator (default). |
175
+ | `%backend bevaluate` | this cell | Use the jet-aware evaluator. Faster for arithmetic-heavy programs. |
176
+ | `%reset` | persistent | Drop all user bindings. The BPLAN op prelude is reloaded. |
177
+ | `%env` | read-only | Display user bindings (sorted, comma-separated). Prelude names are filtered out. |
178
+
179
+ `%backend` reverts at end-of-cell. `%reset` is permanent until the next
180
+ `%reset`. `%env`'s output prepends to the cell's value text when the
181
+ cell also has a body.
182
+
183
+ ## Troubleshooting
184
+
185
+ **`No module named 'plan_kernel'` when launching the kernel.** The kernel.json's
186
+ `argv` uses the Python interpreter that ran `plan-kernel install`. Reinstall
187
+ from the active venv: `pip install -e '.[dev]'` and `python -m plan_kernel install`.
188
+
189
+ **plan-kernel not in the kernel picker.** Confirm the install:
190
+ `jupyter kernelspec list` should show a `plan-kernel` row. If `--prefix .venv`
191
+ was used, only that venv's Jupyter sees it; install without `--prefix`
192
+ for a user-wide registration.
193
+
194
+ **`unbound: <name>` for a name that's clearly defined.** Macro expansion
195
+ runs before the body's evaluation, so a bind form `(#bind name expr)`
196
+ must appear *before* any reference to `name` in cell-execution order.
197
+ Within a cell, this is the form order; across cells, the binding from
198
+ cell N is in scope for cell N+1.
199
+
200
+ **Recursive laws hit `RecursionError`.** plan-kernel bumps Python's recursion
201
+ limit to 200K during evaluation — past that, the BPLAN harness's own
202
+ depth guard fires. Most tutorial-scale recursion is fine; deep
203
+ factorials or Y-combinator-driven loops may exhaust it.
204
+
205
+ **`%env` shows nothing.** It filters the BPLAN op prelude. Pass
206
+ `prelude=False` when constructing `PlanKernelEvaluator` programmatically to
207
+ see *all* names, or just rely on the filtered view in the kernel.
208
+
209
+ ## Naming
210
+
211
+ This package was originally called *Marduk*. As the runtime portion grew
212
+ into a generally useful artifact in its own right, it took the name; the
213
+ kernel was renamed `plan-kernel` and the runtime now lives at
214
+ [`packages/marduk/`](../marduk/) in this monorepo. See
215
+ [`PLAN_KERNEL.md`](PLAN_KERNEL.md) for design notes.
216
+
217
+ ## License
218
+
219
+ MIT.
@@ -0,0 +1,194 @@
1
+ # plan-kernel
2
+
3
+ ![](https://upload.wikimedia.org/wikipedia/commons/c/c3/Chaos_Monster_and_Sun_God.png)
4
+
5
+ A Jupyter kernel for the [PLAN virtual machine](https://github.com/xocore-tech/PLAN).
6
+ Type Plan Asm in a cell, see the reduced PLAN value back.
7
+
8
+ plan-kernel is intended for tutorial use: learning what PLAN's three opcodes
9
+ (Pin / Law / Elim) do, exercising BPLAN's named primitives, and walking
10
+ through small programs (Church booleans, factorial, Y-combinator) one
11
+ reduction at a time.
12
+
13
+ ## Status
14
+
15
+ Alpha. All nine phases of [`PLAN.md`](PLAN.md) are complete: vendored
16
+ runtime, Plan Asm parser, macro expander, cell-level evaluator,
17
+ structural renderer, cell magics, BPLAN op prelude, Jupyter kernel +
18
+ CLI, and a starter set of teaching fixtures + tour notebook. A fresh
19
+ notebook can evaluate `(Add 2 3)` in cell 1.
20
+
21
+ PyPI publication is the next step.
22
+
23
+ ## Install
24
+
25
+ ### From PyPI (once published)
26
+
27
+ ```bash
28
+ pip install plan-kernel
29
+ python -m plan_kernel install # registers the kernelspec with Jupyter
30
+ jupyter notebook # "PLAN" appears in the kernel picker
31
+ ```
32
+
33
+ `plan-kernel` is the PyPI package; `plan_kernel` is the import name. The same
34
+ package supplies both the Python library and the Jupyter kernel — there is
35
+ no separate `plan-kernel-kernel` distribution.
36
+
37
+ ### From a clone (local development)
38
+
39
+ If you've cloned this repo (the typical case while plan-kernel is pre-1.0), do an
40
+ editable install so changes to the source tree take effect without
41
+ re-installing:
42
+
43
+ ```bash
44
+ git clone git@github.com:sigilante/marduk.git
45
+ cd marduk/packages/plan-kernel
46
+ python -m venv .venv && source .venv/bin/activate # optional but recommended
47
+ pip install -e '.[dev]' # installs ipykernel + pytest
48
+ pytest # confirm the runtime smoke test passes
49
+ ```
50
+
51
+ To register the kernel with Jupyter so it appears in the notebook kernel
52
+ picker:
53
+
54
+ ```bash
55
+ python -m plan_kernel install # user-level install (writes to ~/.local/share/jupyter/kernels/plan-kernel/)
56
+ # or
57
+ python -m plan_kernel install --prefix .venv # install only inside the active virtualenv
58
+ ```
59
+
60
+ Verify the registration:
61
+
62
+ ```bash
63
+ jupyter kernelspec list # "plan-kernel" should appear
64
+ ```
65
+
66
+ Launch:
67
+
68
+ ```bash
69
+ jupyter notebook # or: jupyter lab
70
+ ```
71
+
72
+ In a new notebook, choose **"PLAN"** from the kernel picker. A
73
+ fresh notebook has the BPLAN op prelude pre-bound, so `(Add 2 3)` evaluates
74
+ to `5` in cell 1.
75
+
76
+ ### Uninstall
77
+
78
+ ```bash
79
+ jupyter kernelspec remove plan-kernel # remove kernelspec only
80
+ pip uninstall plan-kernel # remove the package
81
+ ```
82
+
83
+ ## Quickstart
84
+
85
+ A cell is a sequence of Plan Asm forms. The result of the last non-bind
86
+ form displays; bind-only cells render `bind <name>` summary lines.
87
+
88
+ ```text
89
+ (Add 2 3)
90
+ ```
91
+
92
+ ```text
93
+ 5
94
+ ```
95
+
96
+ Define a law and apply it:
97
+
98
+ ```text
99
+ (#bind id
100
+ (#pin
101
+ (#law "id" (id x)
102
+ x)))
103
+
104
+ (id 42)
105
+ ```
106
+
107
+ ```text
108
+ 42
109
+ ```
110
+
111
+ The K combinator and a use:
112
+
113
+ ```text
114
+ (#bind k
115
+ (#pin
116
+ (#law "k" (k a b)
117
+ a)))
118
+
119
+ (k 7 99)
120
+ ```
121
+
122
+ ```text
123
+ 7
124
+ ```
125
+
126
+ The fixtures in [`tests/fixtures/`](tests/fixtures/) cover identity,
127
+ K, S, arithmetic, `Elim` on a nat, and Church booleans — copy any of
128
+ them into a cell to see them run.
129
+
130
+ ## What's a cell?
131
+
132
+ A cell is a sequence of Plan Asm forms — the same syntax accepted by the
133
+ canonical Reaver parser
134
+ ([`vendor/reaver/src/hs/PlanAssembler.hs`](https://github.com/xocore-tech/PLAN)),
135
+ minus `#macro`, `#export`, and `@include` (those need module-loading semantics
136
+ that don't make sense in a notebook).
137
+
138
+ Supported macros: `#pin`, `#law`, `#app`, `#bind`. The BPLAN op prelude
139
+ auto-loads on kernel start, so `(Add 2 3)` works in cell 1.
140
+
141
+ ## Magic reference
142
+
143
+ Magics live on lines that start with `%`, at the very top of the cell.
144
+ Comments and blank lines above them stop magic parsing — magics must
145
+ lead the cell body.
146
+
147
+ | Magic | Scope | Effect |
148
+ |---------------------------|--------------|-------------------------------------------------------------------------|
149
+ | `%backend evaluate` | this cell | Use the formal Python evaluator (default). |
150
+ | `%backend bevaluate` | this cell | Use the jet-aware evaluator. Faster for arithmetic-heavy programs. |
151
+ | `%reset` | persistent | Drop all user bindings. The BPLAN op prelude is reloaded. |
152
+ | `%env` | read-only | Display user bindings (sorted, comma-separated). Prelude names are filtered out. |
153
+
154
+ `%backend` reverts at end-of-cell. `%reset` is permanent until the next
155
+ `%reset`. `%env`'s output prepends to the cell's value text when the
156
+ cell also has a body.
157
+
158
+ ## Troubleshooting
159
+
160
+ **`No module named 'plan_kernel'` when launching the kernel.** The kernel.json's
161
+ `argv` uses the Python interpreter that ran `plan-kernel install`. Reinstall
162
+ from the active venv: `pip install -e '.[dev]'` and `python -m plan_kernel install`.
163
+
164
+ **plan-kernel not in the kernel picker.** Confirm the install:
165
+ `jupyter kernelspec list` should show a `plan-kernel` row. If `--prefix .venv`
166
+ was used, only that venv's Jupyter sees it; install without `--prefix`
167
+ for a user-wide registration.
168
+
169
+ **`unbound: <name>` for a name that's clearly defined.** Macro expansion
170
+ runs before the body's evaluation, so a bind form `(#bind name expr)`
171
+ must appear *before* any reference to `name` in cell-execution order.
172
+ Within a cell, this is the form order; across cells, the binding from
173
+ cell N is in scope for cell N+1.
174
+
175
+ **Recursive laws hit `RecursionError`.** plan-kernel bumps Python's recursion
176
+ limit to 200K during evaluation — past that, the BPLAN harness's own
177
+ depth guard fires. Most tutorial-scale recursion is fine; deep
178
+ factorials or Y-combinator-driven loops may exhaust it.
179
+
180
+ **`%env` shows nothing.** It filters the BPLAN op prelude. Pass
181
+ `prelude=False` when constructing `PlanKernelEvaluator` programmatically to
182
+ see *all* names, or just rely on the filtered view in the kernel.
183
+
184
+ ## Naming
185
+
186
+ This package was originally called *Marduk*. As the runtime portion grew
187
+ into a generally useful artifact in its own right, it took the name; the
188
+ kernel was renamed `plan-kernel` and the runtime now lives at
189
+ [`packages/marduk/`](../marduk/) in this monorepo. See
190
+ [`PLAN_KERNEL.md`](PLAN_KERNEL.md) for design notes.
191
+
192
+ ## License
193
+
194
+ MIT.
@@ -0,0 +1,3 @@
1
+ """plan-kernel — a Jupyter kernel for the PLAN virtual machine."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,14 @@
1
+ """``python -m plan_kernel`` entry point.
2
+
3
+ With no args (or with ``-f <connection_file>`` supplied by Jupyter) this
4
+ launches the kernel. With the ``install`` subcommand it registers the
5
+ kernelspec.
6
+ """
7
+
8
+ import sys
9
+
10
+ from .kernel import _cli_main
11
+
12
+
13
+ if __name__ == "__main__":
14
+ sys.exit(_cli_main(sys.argv))