diff options
author | Eduardo Julian | 2021-08-18 03:29:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-18 03:29:15 -0400 |
commit | e00ba096c8837abe85d366e0c1293c09dbe84d81 (patch) | |
tree | dc1f0955d4461ae30bb4945cddd74c462f1aee98 /lux-python | |
parent | 3289b9dcf9d5d1c1e5c380e3185065c8fd32535f (diff) |
Some bug fixes.
Diffstat (limited to 'lux-python')
-rw-r--r-- | lux-python/commands.md | 9 | ||||
-rw-r--r-- | lux-python/project.lux | 14 | ||||
-rw-r--r-- | lux-python/source/program.lux | 836 |
3 files changed, 448 insertions, 411 deletions
diff --git a/lux-python/commands.md b/lux-python/commands.md index 7de744436..7ea35927c 100644 --- a/lux-python/commands.md +++ b/lux-python/commands.md @@ -13,11 +13,20 @@ cd ~/lux/lux-python/ \ && lein clean \ && lein lux auto build +cd ~/lux/lux-python/ \ +&& lux clean \ +&& lux auto build + ## Build JVM-based compiler cd ~/lux/lux-python/ \ && lein clean \ && lein lux build \ && mv target/program.jar jvm_based_compiler.jar + +cd ~/lux/lux-python/ \ +&& lux clean \ +&& lux build \ +&& mv target/program.jar jvm_based_compiler.jar ``` # Try diff --git a/lux-python/project.lux b/lux-python/project.lux new file mode 100644 index 000000000..53ffe351b --- /dev/null +++ b/lux-python/project.lux @@ -0,0 +1,14 @@ +{"" + {#identity ["com.github.luxlang" "stdlib" "0.6.0-SNAPSHOT"] + + #deploy_repositories {"snapshots" "https://oss.sonatype.org/content/repositories/snapshots/" + "releases" "https://oss.sonatype.org/service/local/staging/deploy/maven2/"} + + #repositories ["https://oss.sonatype.org/content/repositories/snapshots/" + "https://oss.sonatype.org/service/local/staging/deploy/maven2/"] + + #compiler ["com.github.luxlang" "lux-jvm" "0.6.0-SNAPSHOT" "jar"] + #dependencies [["com.github.luxlang" "stdlib" "0.6.0-SNAPSHOT" "tar"] + ["org.python" "jython-standalone" "2.7.2" "jar"]] + + #program "program"}} diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 6204a721b..2949fa54e 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -67,403 +67,416 @@ ["/." cli] ["/." static]]]) -(for {@.old - (as_is (import: java/lang/String) - - (import: (java/lang/Class a)) - - (import: java/lang/Object - ["#::." - (new []) - (toString [] java/lang/String) - (getClass [] (java/lang/Class java/lang/Object))]) - - (import: org/python/core/PyNone) - (import: org/python/core/PyBoolean) - (import: org/python/core/PyInteger) - (import: org/python/core/PyLong) - (import: org/python/core/PyFloat) - (import: org/python/core/PyTuple) - (import: org/python/core/PyList) - - (import: org/python/core/PyString - ["#::." - (new [java/lang/String])]) - - (import: org/python/core/PyObject - ["#::." - (asInt [] java/lang/Integer) - (asLong [] long) - (asDouble [] double) - (asString [] java/lang/String) - (__nonzero__ [] boolean) - (__getitem__ [int] #try org/python/core/PyObject) - (__getitem__ #as __getitem__dict [org/python/core/PyObject] #try org/python/core/PyObject) - (__len__ [] int)]) - - (import: org/python/core/PyFunction - ["#::." - (__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]) - (getArray [] java/lang/Object)]) - - (import: org/python/util/PythonInterpreter - ["#::." - (new []) - (exec [java/lang/String] #try void) - (eval [java/lang/String] #try PyObject)]) - - (type: Translator - (-> org/python/core/PyObject (Try Any))) - - (def: (read_tuple read host_object) - (-> Translator Translator) - (let [size (|> host_object org/python/core/PyObject::__len__ .nat)] - (loop [idx 0 - output (:as (Array Any) (array.new size))] - (if (n.< size idx) - (case (org/python/core/PyObject::__getitem__ (.int idx) host_object) - (#try.Failure try) - (#try.Failure try) - - (#try.Success value) - (case (read value) - (#try.Failure try) - (#try.Failure try) - - (#try.Success lux_value) - (recur (inc idx) (array.write! idx lux_value output)))) - (#try.Success output))))) - - (exception: (unknown_kind_of_object {object java/lang/Object}) - (exception.report - ["Object" (java/lang/Object::toString object)])) - - (def: (read_variant read host_object) - (-> Translator Translator) - (case [(org/python/core/PyObject::__getitem__ +0 host_object) - (org/python/core/PyObject::__getitem__ +1 host_object) - (org/python/core/PyObject::__getitem__ +2 host_object)] - (^or [(#try.Failure try) _ _] [_ (#try.Failure try) _] [_ _ (#try.Failure try)]) - (#try.Failure try) - - (^multi [(#try.Success tag) (#try.Success flag) (#try.Success value)] - {(read tag) - (#try.Success tag)} - {(read value) - (#try.Success value)}) - (#try.Success [tag - (: Any - (case (ffi.check org/python/core/PyNone flag) - (#.Some _) - (ffi.null) - - #.None - synthesis.unit)) - value]) - - _ - (exception.throw ..unknown_kind_of_object host_object))) - - (def: (read host_object) - Translator - (`` (<| (~~ (template [<class> <processing>] - [(case (ffi.check <class> host_object) - (#.Some host_object) - (#try.Success (<| <processing> host_object)) - - _)] - - [org/python/core/PyNone (new> [] [])] - [org/python/core/PyBoolean org/python/core/PyObject::__nonzero__] - [org/python/core/PyInteger org/python/core/PyObject::asInt] - [org/python/core/PyLong org/python/core/PyObject::asLong] - [org/python/core/PyFloat org/python/core/PyObject::asDouble] - [org/python/core/PyString org/python/core/PyObject::asString] - [org/python/core/PyFunction (|>)] - [org/python/core/PyArray org/python/core/PyArray::getArray] - [[java/lang/Object] (|>)] - )) - (~~ (template [<class> <processing>] - [(case (ffi.check <class> host_object) - (#.Some host_object) - (<| <processing> host_object) - - _)] - - [org/python/core/PyTuple (..read_variant read)] - [org/python/core/PyList (..read_tuple read)] - )) - ... (exception.throw ..unknown_kind_of_object host_object) - (exception.return host_object)))) - - (exception: (cannot_apply_a_non_function {object java/lang/Object}) - (exception.report - ["Non-function" (java/lang/Object::toString object)])) - - (def: (ensure_macro macro) - (-> Macro (Maybe org/python/core/PyFunction)) - (ffi.check org/python/core/PyFunction (:as java/lang/Object macro))) - - (def: object_class - (java/lang/Class java/lang/Object) - (java/lang/Object::getClass (java/lang/Object::new))) - - (def: to_host - (-> Any org/python/core/PyObject) - (|>> (:as java/lang/Object) (org/python/core/PyArray::new ..object_class))) - - (def: ensure_function - (-> Any (Maybe org/python/core/PyFunction)) - (|>> (:as java/lang/Object) - (ffi.check org/python/core/PyFunction))) - ) - - @.python - (as_is)}) - -(for {@.old - (as_is (def: (call_macro inputs lux macro) - (-> (List Code) Lux org/python/core/PyFunction (Try (Try [Lux (List Code)]))) - (:expected - (do try.monad - [expansion (org/python/core/PyFunction::__call__ (|> (ffi.array org/python/core/PyObject 2) - (ffi.array_write 0 (..to_host inputs)) - (ffi.array_write 1 (..to_host lux))) - macro)] - (..read expansion)))) - - (def: (expander macro inputs lux) - Expander - (case (ensure_macro macro) - (#.Some macro) - (case (..call_macro inputs lux macro) - (#try.Success output) - (|> output - (:as org/python/core/PyObject) - ..read - (:as (Try (Try [Lux (List Code)])))) - - (#try.Failure error) - (#try.Failure error)) - - #.None - (exception.throw ..cannot_apply_a_non_function (:as java/lang/Object macro))))) - - @.python - (def: (expander macro inputs lux) - Expander - (#try.Success ((:as Macro' macro) inputs lux)))}) - -(for {@.old - (def: host - (IO (Host (_.Expression Any) (_.Statement Any))) - (io (let [interpreter (org/python/util/PythonInterpreter::new) - evaluate! (: (-> Context (_.Expression Any) (Try Any)) - (function (evaluate! context input) - (do try.monad - [output (org/python/util/PythonInterpreter::eval (_.code input) interpreter)] - (..read output)))) - execute! (: (-> (_.Statement Any) (Try Any)) - (function (execute! input) - (org/python/util/PythonInterpreter::exec (_.code input) interpreter)))] - (: (Host (_.Expression Any) (_.Statement Any)) - (implementation - (def: evaluate! evaluate!) - (def: execute! execute!) - (def: (define! context custom input) - (let [global (maybe.default (reference.artifact context) - custom) - @global (_.var global)] - (do try.monad - [#let [definition (_.set (list @global) input)] - _ (execute! definition) - value (evaluate! context @global)] - (wrap [global value definition])))) - - (def: (ingest context content) - (|> content - (\ utf8.codec decode) - try.trusted - (:as (_.Statement Any)))) - - (def: (re_learn context custom content) - (execute! content)) - - (def: (re_load context custom content) - (do try.monad - [_ (execute! content)] - (evaluate! context (_.var (reference.artifact context)))))))))) - - @.python - (as_is (import: (dict [] ffi.Dict)) - (import: (eval [ffi.String ffi.Dict] #try Any)) - - (def: host - (IO (Host (_.Expression Any) (_.Statement Any))) - (io (: (Host (_.Expression Any) (_.Statement Any)) - (let [globals (..dict []) - evaluate! (: (-> Context (_.Expression Any) (Try Any)) - (function (evaluate! context input) - (..eval [(_.code input) globals]))) - execute! (: (-> (_.Statement Any) (Try Any)) - (function (execute! input) - (ffi.try ("python exec" (_.code input) globals)))) - define! (: (-> Context (_.Expression Any) (Try [Text Any (_.Statement Any)])) - (function (define! context input) - (let [global (reference.artifact context) - @global (_.var global)] +(with_expansions [<jvm> (as_is (import: java/lang/String) + + (import: (java/lang/Class a)) + + (import: java/lang/Object + ["#::." + (new []) + (toString [] java/lang/String) + (getClass [] (java/lang/Class java/lang/Object))]) + + (import: org/python/core/PyNone) + (import: org/python/core/PyBoolean) + (import: org/python/core/PyInteger) + (import: org/python/core/PyLong) + (import: org/python/core/PyFloat) + (import: org/python/core/PyTuple) + (import: org/python/core/PyList) + + (import: org/python/core/PyString + ["#::." + (new [java/lang/String])]) + + (import: org/python/core/PyObject + ["#::." + ... (asInt [] int) + (asLong [] long) + (asDouble [] double) + (asString [] java/lang/String) + (__nonzero__ [] boolean) + (__getitem__ [int] #try org/python/core/PyObject) + (__getitem__ #as __getitem__dict [org/python/core/PyObject] #try org/python/core/PyObject) + (__len__ [] int)]) + + (import: org/python/core/PyFunction + ["#::." + (__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]) + (getArray [] java/lang/Object)]) + + (import: org/python/util/PythonInterpreter + ["#::." + (new []) + (exec [java/lang/String] #try void) + (eval [java/lang/String] #try PyObject)]) + + (type: Translator + (-> org/python/core/PyObject (Try Any))) + + (def: (read_tuple read host_object) + (-> Translator Translator) + (let [size (|> host_object org/python/core/PyObject::__len__ .nat)] + (loop [idx 0 + output (:as (Array Any) + (array.empty size))] + (if (n.< size idx) + (case (org/python/core/PyObject::__getitem__ (.int idx) host_object) + (#try.Failure try) + (#try.Failure try) + + (#try.Success value) + (case (read value) + (#try.Failure try) + (#try.Failure try) + + (#try.Success lux_value) + (recur (++ idx) (array.write! idx lux_value output)))) + (#try.Success output))))) + + (exception: (unknown_kind_of_object {object java/lang/Object}) + (exception.report + ["Object" (java/lang/Object::toString object)])) + + (def: (read_variant read host_object) + (-> Translator Translator) + (case [(org/python/core/PyObject::__getitem__ +0 host_object) + (org/python/core/PyObject::__getitem__ +1 host_object) + (org/python/core/PyObject::__getitem__ +2 host_object)] + (^or [(#try.Failure try) _ _] + [_ (#try.Failure try) _] + [_ _ (#try.Failure try)]) + (#try.Failure try) + + (^multi [(#try.Success tag) (#try.Success flag) (#try.Success value)] + {(read tag) + (#try.Success tag)} + {(read value) + (#try.Success value)}) + (#try.Success [tag + (: Any + (case (ffi.check org/python/core/PyNone + (:as java/lang/Object flag)) + (#.Some _) + (:as Any (ffi.null)) + + #.None + (:as Any synthesis.unit))) + value]) + + _ + (exception.except ..unknown_kind_of_object [(:as java/lang/Object host_object)]))) + + (def: (read host_object) + Translator + (`` (<| (~~ (template [<class> <processing>] + [(case (ffi.check <class> (:as <class> host_object)) + (#.Some host_object) + (#try.Success (`` (|> host_object (~~ (template.spliced <processing>))))) + + _)] + + [org/python/core/PyNone [(new> [] [])]] + [org/python/core/PyBoolean [org/python/core/PyObject::__nonzero__]] + ... [org/python/core/PyInteger [(ffi.:as org/python/core/PyObject) org/python/core/PyObject::asInt]] + [org/python/core/PyInteger [(ffi.:as org/python/core/PyObject) + ("jvm member invoke virtual" [] "org.python.core.PyObject" "asInt" []) + "jvm object cast" + (: (primitive "java.lang.Integer"))]] + [org/python/core/PyLong [org/python/core/PyObject::asLong]] + [org/python/core/PyFloat [org/python/core/PyObject::asDouble]] + [org/python/core/PyString [org/python/core/PyObject::asString]] + [org/python/core/PyFunction []] + [org/python/core/PyArray [org/python/core/PyArray::getArray]] + [[java/lang/Object] [(|>)]] + )) + (~~ (template [<class> <processing>] + [(case (ffi.check <class> host_object) + (#.Some host_object) + (<| <processing> (:as org/python/core/PyObject) host_object) + + _)] + + [org/python/core/PyTuple (..read_variant read)] + [org/python/core/PyList (..read_tuple read)] + )) + ... (exception.except ..unknown_kind_of_object [(:as java/lang/Object host_object)]) + (#try.Success host_object)))) + + (exception: (cannot_apply_a_non_function {object java/lang/Object}) + (exception.report + ["Non-function" (java/lang/Object::toString object)])) + + (def: (ensure_macro macro) + (-> Macro (Maybe org/python/core/PyFunction)) + (ffi.check org/python/core/PyFunction (:as java/lang/Object macro))) + + (def: object_class + (java/lang/Class java/lang/Object) + (java/lang/Object::getClass (java/lang/Object::new))) + + (def: to_host + (-> Any org/python/core/PyObject) + (|>> (:as java/lang/Object) + (org/python/core/PyArray::new ..object_class) + (:as org/python/core/PyObject))) + + (def: ensure_function + (-> Any (Maybe org/python/core/PyFunction)) + (|>> (:as java/lang/Object) + (ffi.check org/python/core/PyFunction))) + )] + (for {@.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.python (as_is)})) + +(with_expansions [<jvm> (as_is (def: (call_macro inputs lux macro) + (-> (List Code) Lux org/python/core/PyFunction (Try (Try [Lux (List Code)]))) + (:expected + (do try.monad + [expansion (org/python/core/PyFunction::__call__ (|> (ffi.array org/python/core/PyObject 2) + (ffi.write! 0 (..to_host inputs)) + (ffi.write! 1 (..to_host lux))) + macro)] + (..read expansion)))) + + (def: (expander macro inputs lux) + Expander + (case (ensure_macro macro) + (#.Some macro) + (case (..call_macro inputs lux macro) + (#try.Success output) + (|> output + (:as org/python/core/PyObject) + ..read + (:as (Try (Try [Lux (List Code)])))) + + (#try.Failure error) + (#try.Failure error)) + + #.None + (exception.except ..cannot_apply_a_non_function (:as java/lang/Object macro)))))] + (for {@.old (as_is <jvm>) + @.jvm (as_is <jvm>) + + @.python + (def: (expander macro inputs lux) + Expander + (#try.Success ((:as Macro' macro) inputs lux)))})) + +(with_expansions [<jvm> (def: host + (IO (Host (_.Expression Any) (_.Statement Any))) + (io (let [interpreter (org/python/util/PythonInterpreter::new) + evaluate! (: (-> Context (_.Expression Any) (Try Any)) + (function (evaluate! context input) + (do try.monad + [output (org/python/util/PythonInterpreter::eval (_.code input) interpreter)] + (..read output)))) + execute! (: (-> (_.Statement Any) (Try Any)) + (function (execute! input) + (org/python/util/PythonInterpreter::exec (_.code input) interpreter)))] + (: (Host (_.Expression Any) (_.Statement Any)) + (implementation + (def: evaluate! evaluate!) + (def: execute! execute!) + (def: (define! context custom input) + (let [global (maybe.else (reference.artifact context) + custom) + @global (_.var global)] + (do try.monad + [.let [definition (_.set (list @global) input)] + _ (execute! definition) + value (evaluate! context @global)] + (in [global value definition])))) + + (def: (ingest context content) + (|> content + (\ utf8.codec decode) + try.trusted + (:as (_.Statement Any)))) + + (def: (re_learn context custom content) + (execute! content)) + + (def: (re_load context custom content) + (do try.monad + [_ (execute! content)] + (evaluate! context (_.var (reference.artifact context))))))))))] + (for {@.old <jvm> + @.jvm <jvm> + + @.python + (as_is (import: (dict [] ffi.Dict)) + (import: (eval [ffi.String ffi.Dict] #try Any)) + + (def: host + (IO (Host (_.Expression Any) (_.Statement Any))) + (io (: (Host (_.Expression Any) (_.Statement Any)) + (let [globals (..dict []) + evaluate! (: (-> Context (_.Expression Any) (Try Any)) + (function (evaluate! context input) + (..eval [(_.code input) globals]))) + execute! (: (-> (_.Statement Any) (Try Any)) + (function (execute! input) + (ffi.try ("python exec" (_.code input) globals)))) + define! (: (-> Context (_.Expression Any) (Try [Text Any (_.Statement Any)])) + (function (define! context input) + (let [global (reference.artifact context) + @global (_.var global)] + (do try.monad + [.let [definition (_.set (list @global) input)] + _ (execute! definition) + value (evaluate! context @global)] + (in [global value definition])))))] + (implementation + (def: evaluate! evaluate!) + (def: execute! execute!) + (def: define! define!) + + (def: (ingest context content) + (|> content (\ utf8.codec decode) try.trusted (:as (_.Statement Any)))) + + (def: (re_learn context content) + (execute! content)) + + (def: (re_load context content) + (do try.monad + [_ (execute! content)] + (evaluate! context (_.var (reference.artifact context)))))))))))})) + +(with_expansions [<jvm> (as_is (exception: .public (invaid_phase_application {partial_application (List Any)} + {arity Nat}) + (exception.report + ["Partial Application" (%.nat (list.size partial_application))] + ["Arity" (%.nat arity)])) + + (def: (host_phase partial_application phase) + (All [s i o] + (-> (List Any) (Phase [extension.Bundle s] i o) + org/python/core/PyObject)) + (<| (ffi.:as org/python/core/PyObject) + (ffi.object [] org/python/core/PyObject [] + [] + ... Methods + (org/python/core/PyObject + [] (__call__ self + {inputs [org/python/core/PyObject]} + {keywords [java/lang/String]}) + org/python/core/PyObject + (try.trusted + (case (array.list inputs) + (^ (list)) + (\ try.monad in (host_phase (list) phase)) + + (^ (list input/0)) (do try.monad - [#let [definition (_.set (list @global) input)] - _ (execute! definition) - value (evaluate! context @global)] - (wrap [global value definition])))))] - (implementation - (def: evaluate! evaluate!) - (def: execute! execute!) - (def: define! define!) - - (def: (ingest context content) - (|> content (\ utf8.codec decode) try.trusted (:as (_.Statement Any)))) - - (def: (re_learn context content) - (execute! content)) - - (def: (re_load context content) - (do try.monad - [_ (execute! content)] - (evaluate! context (_.var (reference.artifact context)))))))))))}) - -(for {@.old - (as_is (exception: .public (invaid_phase_application {partial_application (List Any)} - {arity Nat}) - (exception.report - ["Partial Application" (%.nat (list.size partial_application))] - ["Arity" (%.nat arity)])) - - (def: (host_phase partial_application phase) - (All [s i o] - (-> (List Any) (Phase [extension.Bundle s] i o) - org/python/core/PyObject)) - (ffi.object [] org/python/core/PyObject [] - [] - ... Methods - (org/python/core/PyObject - [] (__call__ self - {inputs [org/python/core/PyObject]} - {keywords [java/lang/String]}) - org/python/core/PyObject - (try.trusted - (case (array.to_list inputs) - (^ (list)) - (\ try.monad wrap (host_phase (list) phase)) - - (^ (list input/0)) - (do try.monad - [input/0 (..read input/0)] - (case partial_application - (^ (list partial/0 partial/1)) - (wrap (..to_host ((:as (-> Any Any Any Any) phase) - partial/0 - partial/1 - input/0))) - - (^ (list partial/0)) - (wrap (host_phase (list partial/0 input/0) phase)) - - (^ (list)) - (wrap (host_phase (list input/0) phase)) - - _ - (exception.throw ..invaid_phase_application [partial_application (array.size inputs)]))) - - (^ (list input/0 input/1)) - (do try.monad - [input/0 (..read input/0) - input/1 (..read input/1)] - (case partial_application - (^ (list partial/0)) - (wrap (..to_host ((:as (-> Any Any Any Any) phase) - partial/0 - input/0 - input/1))) - - (^ (list)) - (wrap (host_phase (list input/0 input/1) phase)) - - _ - (exception.throw ..invaid_phase_application [partial_application (array.size inputs)]))) - - (^ (list input/0 input/1 input/2)) - (do try.monad - [input/0 (..read input/0) - input/1 (..read input/1) - input/2 (..read input/2)] - (case partial_application - (^ (list)) - (wrap (..to_host ((:as (-> Any Any Any Any) phase) - input/0 - input/1 - input/2))) - - _ - (exception.throw ..invaid_phase_application [partial_application (array.size inputs)]))) - - _ - (exception.throw ..invaid_phase_application [partial_application (array.size inputs)])))))) - - (def: (extender phase_wrapper) - (-> platform.Phase_Wrapper Extender) - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (_ handler)) - (:as Handler) - (function (_ name phase)) - (:as Phase) - (function (_ archive parameters)) - (:as Operation) - (function (_ state)) - (:as Try) - try.trusted - (:as Try) - (do try.monad - [handler (try.of_maybe (..ensure_function handler)) - output (org/python/core/PyFunction::__call__ (|> (ffi.array org/python/core/PyObject 5) - (ffi.array_write 0 (org/python/core/PyString::new name)) - (ffi.array_write 1 (:as org/python/core/PyObject (phase_wrapper phase))) - (ffi.array_write 2 (..to_host archive)) - (ffi.array_write 3 (..to_host parameters)) - (ffi.array_write 4 (..to_host state))) - handler)] - (..read output))))) - - @.python - (def: (extender phase_wrapper handler) - (-> platform.Phase_Wrapper Extender) - (:expected handler))}) + [input/0 (..read input/0)] + (case partial_application + (^ (list partial/0 partial/1)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + partial/0 + partial/1 + input/0))) + + (^ (list partial/0)) + (in (host_phase (list partial/0 input/0) phase)) + + (^ (list)) + (in (host_phase (list input/0) phase)) + + _ + (exception.except ..invaid_phase_application [partial_application (array.size inputs)]))) + + (^ (list input/0 input/1)) + (do try.monad + [input/0 (..read input/0) + input/1 (..read input/1)] + (case partial_application + (^ (list partial/0)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + partial/0 + input/0 + input/1))) + + (^ (list)) + (in (host_phase (list input/0 input/1) phase)) + + _ + (exception.except ..invaid_phase_application [partial_application (array.size inputs)]))) + + (^ (list input/0 input/1 input/2)) + (do try.monad + [input/0 (..read input/0) + input/1 (..read input/1) + input/2 (..read input/2)] + (case partial_application + (^ (list)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + input/0 + input/1 + input/2))) + + _ + (exception.except ..invaid_phase_application [partial_application (array.size inputs)]))) + + _ + (exception.except ..invaid_phase_application [partial_application (array.size inputs)]))))))) + + (def: (extender phase_wrapper) + (-> platform.Phase_Wrapper Extender) + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (_ handler)) + (:as Handler) + (function (_ name phase)) + (:as Phase) + (function (_ archive parameters)) + (:as Operation) + (function (_ state)) + (:as Try) + try.trusted + (:as Try) + (do try.monad + [handler (try.of_maybe (..ensure_function handler)) + output (org/python/core/PyFunction::__call__ (|> (ffi.array org/python/core/PyObject 5) + (ffi.write! 0 (:as org/python/core/PyObject (org/python/core/PyString::new name))) + (ffi.write! 1 (:as org/python/core/PyObject (phase_wrapper phase))) + (ffi.write! 2 (..to_host archive)) + (ffi.write! 3 (..to_host parameters)) + (ffi.write! 4 (..to_host state))) + handler)] + (..read output)))))] + (for {@.old (as_is <jvm>) + @.jvm (as_is <jvm>) + + @.python + (def: (extender phase_wrapper handler) + (-> platform.Phase_Wrapper Extender) + (:expected handler))})) (def: (phase_wrapper archive) (-> Archive (runtime.Operation platform.Phase_Wrapper)) (do phase.monad [] - (wrap (:as platform.Phase_Wrapper - (..host_phase (list)))))) + (in (:as platform.Phase_Wrapper + (..host_phase (list)))))) (def: platform (IO (Platform Register (_.Expression Any) (_.Statement Any))) (do io.monad [host ..host] - (wrap {#platform.&file_system (file.async file.default) - #platform.host host - #platform.phase python.generate - #platform.runtime runtime.generate - #platform.phase_wrapper ..phase_wrapper - #platform.write (|>> _.code (\ utf8.codec encode))}))) + (in {#platform.&file_system (file.async file.default) + #platform.host host + #platform.phase python.generate + #platform.runtime runtime.generate + #platform.phase_wrapper ..phase_wrapper + #platform.write (|>> _.code (\ utf8.codec encode))}))) (def: (program context program) (Program (_.Expression Any) (_.Statement Any)) @@ -497,29 +510,30 @@ (program: [service /cli.service] (let [extension ".py"] - (exec (do async.monad - [_ (/.compiler {#/static.host @.python - #/static.host_module_extension extension - #/static.target (/cli.target service) - #/static.artifact_extension extension} - ..expander - analysis.bundle - ..platform - generation.bundle - (function.constant extension/bundle.empty) - ..program - [Register - (type (_.Expression Any)) - (type (_.Statement Any))] - ..extender - service - [(packager.package (: (_.Statement Any) (_.manual "")) - _.code - _.then - ..scope) - (format (/cli.target service) - (\ file.default separator) - "program" - extension)])] - (..declare_success! [])) + (exec + (do async.monad + [_ (/.compiler {#/static.host @.python + #/static.host_module_extension extension + #/static.target (/cli.target service) + #/static.artifact_extension extension} + ..expander + analysis.bundle + ..platform + generation.bundle + (function.constant extension/bundle.empty) + ..program + [Register + (type (_.Expression Any)) + (type (_.Statement Any))] + ..extender + service + [(packager.package (: (_.Statement Any) (_.manual "")) + _.code + _.then + ..scope) + (format (/cli.target service) + (\ file.default separator) + "program" + extension)])] + (..declare_success! [])) (io.io [])))) |