aboutsummaryrefslogtreecommitdiff
path: root/lux-python/source/program.lux
diff options
context:
space:
mode:
Diffstat (limited to 'lux-python/source/program.lux')
-rw-r--r--lux-python/source/program.lux108
1 files changed, 83 insertions, 25 deletions
diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux
index 4fae4b331..166dee982 100644
--- a/lux-python/source/program.lux
+++ b/lux-python/source/program.lux
@@ -42,7 +42,7 @@
[analysis
[macro (#+ Expander)]]
[phase
- ["." extension (#+ Extender Handler)
+ ["." extension (#+ Bundle Extender Handler)
["#/." bundle]
["." analysis #_
["#" python]]
@@ -100,6 +100,8 @@
["#::."
(__call__ [[org/python/core/PyObject]] #try org/python/core/PyObject)])
+ (import: org/python/core/ThreadState)
+
(import: org/python/core/PyArray
["#::."
(new [(java/lang/Class java/lang/Object) java/lang/Object])
@@ -352,30 +354,86 @@
_.none)))))
(for {@.old
- (def: extender
- Extender
- ## TODO: Stop relying on coercions ASAP.
- (<| (:coerce Extender)
- (function (@self handler))
- (:coerce Handler)
- (function (@self name phase))
- (:coerce Phase)
- (function (@self archive parameters))
- (:coerce Operation)
- (function (@self state))
- (:coerce Try)
- try.assume
- (:coerce Try)
- (do try.monad
- [handler (try.from_maybe (..ensure_function handler))
- output (org/python/core/PyFunction::__call__ (|> (host.array org/python/core/PyObject 5)
- (host.array_write 0 (org/python/core/PyString::new name))
- (host.array_write 1 (..to_host phase))
- (host.array_write 2 (..to_host archive))
- (host.array_write 3 (..to_host parameters))
- (host.array_write 4 (..to_host state)))
- handler)]
- (..read output))))
+ (as_is (exception: #export (cannot_parse_phase_inputs {arity Nat})
+ (exception.report
+ ["Arity" (%.nat arity)]))
+
+ (def: (host_phase phase)
+ (All [s i o]
+ (-> (Phase [Bundle s] i o)
+ org/python/core/PyObject))
+ (host.object [] org/python/core/PyObject []
+ []
+ ## Methods
+ (org/python/core/PyObject
+ [] (__call__ self
+ {_ org/python/core/ThreadState}
+ {input/0 org/python/core/PyObject})
+ org/python/core/PyObject
+ (case [(..read input/0)]
+ [(#try.Success input/0)]
+ (host_phase (:assume ((:coerce (-> Nat Nat Nat []) phase)
+ (:coerce Nat input/0))))
+
+ _
+ (error! (exception.construct ..cannot_parse_phase_inputs [1]))))
+
+ (org/python/core/PyObject
+ [] (__call__ self
+ {_ org/python/core/ThreadState}
+ {input/0 org/python/core/PyObject}
+ {input/1 org/python/core/PyObject})
+ org/python/core/PyObject
+ (case [(..read input/0) (..read input/1)]
+ [(#try.Success input/0) (#try.Success input/1)]
+ (host_phase (:assume ((:coerce (-> Nat Nat Nat []) phase)
+ (:coerce Nat input/0)
+ (:coerce Nat input/1))))
+
+ _
+ (error! (exception.construct ..cannot_parse_phase_inputs [2]))))
+
+ (org/python/core/PyObject
+ [] (__call__ self
+ {_ org/python/core/ThreadState}
+ {input/0 org/python/core/PyObject}
+ {input/1 org/python/core/PyObject}
+ {input/2 org/python/core/PyObject})
+ org/python/core/PyObject
+ (case [(..read input/0) (..read input/1) (..read input/2)]
+ [(#try.Success input/0) (#try.Success input/1) (#try.Success input/2)]
+ (..to_host ((:coerce (-> Nat Nat Nat []) phase)
+ (:coerce Nat input/0)
+ (:coerce Nat input/1)
+ (:coerce Nat input/2)))
+
+ _
+ (error! (exception.construct ..cannot_parse_phase_inputs [3]))))))
+
+ (def: extender
+ Extender
+ ## TODO: Stop relying on coercions ASAP.
+ (<| (:coerce Extender)
+ (function (@self handler))
+ (:coerce Handler)
+ (function (@self name phase))
+ (:coerce Phase)
+ (function (@self archive parameters))
+ (:coerce Operation)
+ (function (@self state))
+ (:coerce Try)
+ try.assume
+ (:coerce Try)
+ (do try.monad
+ [handler (try.from_maybe (..ensure_function handler))
+ output (org/python/core/PyFunction::__call__ (|> (host.array org/python/core/PyObject 5)
+ (host.array_write 0 (org/python/core/PyString::new name))
+ (host.array_write 1 (..host_phase phase))
+ (host.array_write 2 (..to_host archive))
+ (host.array_write 3 (..to_host parameters))
+ (host.array_write 4 (..to_host state)))
+ handler)]
+ (..read output)))))
@.python
(def: (extender handler)