aboutsummaryrefslogtreecommitdiff
path: root/lux-python/source
diff options
context:
space:
mode:
Diffstat (limited to 'lux-python/source')
-rw-r--r--lux-python/source/program.lux292
1 files changed, 146 insertions, 146 deletions
diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux
index 0e72141bf..513de48f0 100644
--- a/lux-python/source/program.lux
+++ b/lux-python/source/program.lux
@@ -150,8 +150,8 @@
(-> Translator Translator)
(let [size (|> host_object org/python/core/PyObject::__len__ ffi.of_int .nat)]
(loop [idx 0
- output (:as (Array Any)
- (array.empty size))]
+ output (as (Array Any)
+ (array.empty size))]
(if (n.< size idx)
(case (org/python/core/PyObject::__getitem__ (ffi.as_int (.int idx)) host_object)
{try.#Success value}
@@ -186,18 +186,18 @@
[(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)))
+ (is 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)])))
+ (exception.except ..unknown_kind_of_object [(as java/lang/Object host_object)])))
(ffi.interface: LuxValue
(value [] java/lang/Object))
@@ -209,7 +209,7 @@
(def: (read host_object)
Translator
(`` (<| (~~ (template [<class> <processing>]
- [(case (ffi.check <class> (:as <class> host_object))
+ [(case (ffi.check <class> (as <class> host_object))
{.#Some host_object}
{try.#Success (`` (|> host_object (~~ (template.spliced <processing>))))}
@@ -218,11 +218,11 @@
[LuxValue [LuxValue::value]]
[org/python/core/PyNone [(pipe.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)
+ ... [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"))]]
+ (is (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]]
@@ -233,14 +233,14 @@
(~~ (template [<class> <processing>]
[(case (ffi.check <class> host_object)
{.#Some host_object}
- (<| <processing> (:as org/python/core/PyObject) 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)])
+ ... (exception.except ..unknown_kind_of_object [(as java/lang/Object host_object)])
{try.#Success host_object})))
(def: (function/? arity)
@@ -254,11 +254,11 @@
(def: (pseudo_function to_host it)
(-> (-> Any org/python/core/PyObject) Any org/python/core/PyObject)
- (<| (:as org/python/core/PyObject)
+ (<| (as org/python/core/PyObject)
(ffi.object [] org/python/core/PyObject [LuxValue]
[]
... Methods
- (LuxValue [] (value self []) java/lang/Object (:as java/lang/Object it))
+ (LuxValue [] (value self []) java/lang/Object (as java/lang/Object it))
(org/python/core/PyObject
[] (__call__ self [inputs [org/python/core/PyObject]
@@ -271,11 +271,11 @@
inputs inputs]
(`` (`` (case inputs
(pattern (list))
- (:as org/python/core/PyObject self)
+ (as org/python/core/PyObject self)
(~~ (template [<arity>]
[(pattern (list (~~ (static.literals code.local_symbol (inputs/? <arity>)))))
- (to_host ((:as (~~ (static.literal function.identity (function/? <arity>))) it)
+ (to_host ((as (~~ (static.literal function.identity (function/? <arity>))) it)
(~~ (static.literals code.local_symbol (inputs/? <arity>)))))]
[1]
@@ -289,7 +289,7 @@
(pattern (list& (~~ (static.literals code.local_symbol (inputs/? 8)))
input/+))
- (again ((:as (~~ (static.literal function.identity (function/? 8))) it)
+ (again ((as (~~ (static.literal function.identity (function/? 8))) it)
(~~ (static.literals code.local_symbol (inputs/? 8))))
input/+))))))))))))
@@ -302,43 +302,43 @@
(def: (to_host|array to_host it)
(-> (-> Any org/python/core/PyObject) Any org/python/core/PyObject)
- (:as org/python/core/PyObject
- (ffi.object [] org/python/core/PyArray [LuxValue]
- [(java/lang/Class java/lang/Object) ..object_class
- java/lang/Object (:as java/lang/Object it)]
- ... Methods
- (LuxValue [] (value self []) java/lang/Object (:as java/lang/Object it))
-
- (org/python/core/PyArray
- [] (pyget self [index' int])
- org/python/core/PyObject
- (case (|> it
- (:as (Array Any))
- (array.read! (|> index' ffi.int_to_long (:as Nat))))
- {.#None}
- (::super! [index'])
-
- {.#Some it}
- (<| (case (ffi.check [java/lang/Object] (:as java/lang/Object it))
- {.#Some it}
- (to_host it)
-
- {.#None})
- (case (ffi.check library/lux/Function (:as java/lang/Object it))
- {.#Some it}
- (pseudo_function to_host it)
-
- {.#None})
- (::super! [index']))))
- )))
+ (as org/python/core/PyObject
+ (ffi.object [] org/python/core/PyArray [LuxValue]
+ [(java/lang/Class java/lang/Object) ..object_class
+ java/lang/Object (as java/lang/Object it)]
+ ... Methods
+ (LuxValue [] (value self []) java/lang/Object (as java/lang/Object it))
+
+ (org/python/core/PyArray
+ [] (pyget self [index' int])
+ org/python/core/PyObject
+ (case (|> it
+ (as (Array Any))
+ (array.read! (|> index' ffi.int_to_long (as Nat))))
+ {.#None}
+ (::super! [index'])
+
+ {.#Some it}
+ (<| (case (ffi.check [java/lang/Object] (as java/lang/Object it))
+ {.#Some it}
+ (to_host it)
+
+ {.#None})
+ (case (ffi.check library/lux/Function (as java/lang/Object it))
+ {.#Some it}
+ (pseudo_function to_host it)
+
+ {.#None})
+ (::super! [index']))))
+ )))
(def: (to_host it)
(-> Any org/python/core/PyObject)
(`` (<| (~~ (template [<jvm> <python>]
- [(case (ffi.check <jvm> (:as java/lang/Object it))
+ [(case (ffi.check <jvm> (as java/lang/Object it))
{.#Some it}
- (:as org/python/core/PyObject
- (<python> [it]))
+ (as org/python/core/PyObject
+ (<python> [it]))
{.#None})]
@@ -349,7 +349,7 @@
[library/lux/Function (pseudo_function to_host)]
[[java/lang/Object] (to_host|array to_host)]
))
- (:as org/python/core/PyObject it))))
+ (as org/python/core/PyObject it))))
)]
(for @.old (as_is <jvm>)
@.jvm (as_is <jvm>)
@@ -363,11 +363,11 @@
(ffi.write! 1 (..to_host lux))))
(try#each ..read)
try#conjoint
- :expected))
+ as_expected))
(def: python_function!
(-> Any (Maybe org/python/core/PyFunction))
- (|>> (:as java/lang/Object)
+ (|>> (as java/lang/Object)
(ffi.check org/python/core/PyFunction)))
(exception: (cannot_apply_a_non_function [object java/lang/Object])
@@ -382,68 +382,68 @@
(case (..call_macro inputs lux macro)
{try.#Success output}
(|> output
- (:as org/python/core/PyObject)
+ (as org/python/core/PyObject)
..read
- (:as (Try (Try [Lux (List Code)]))))
+ (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)]))))]
+ (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)})))
+ {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! (: (-> unit.ID [(Maybe unit.ID) (_.Expression Any)] (Try Any))
- (function (evaluate! context [_ input])
- (do try.monad
- [output (org/python/util/PythonInterpreter::eval (ffi.as_string (_.code input)) interpreter)]
- (..read output))))
- execute! (: (-> (_.Statement Any) (Try Any))
- (function (execute! input)
- (case (org/python/util/PythonInterpreter::exec (ffi.as_string (_.code input)) interpreter)
- {try.#Failure error}
- (if (text.contains? "maximum recursion depth exceeded" error)
- (execute! input)
- {try.#Failure error})
-
- output
- output)))]
- (: (Host (_.Expression Any) (_.Statement Any))
- (implementation
- (def: evaluate evaluate!)
- (def: execute execute!)
- (def: (define context custom [@def 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 [@def @global])]
- (in [global value definition]))))
-
- (def: (ingest context content)
- (|> content
- (# utf8.codec decoded)
- 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 [{.#None} (_.var (reference.artifact context))]))))))))]
+ evaluate! (is (-> unit.ID [(Maybe unit.ID) (_.Expression Any)] (Try Any))
+ (function (evaluate! context [_ input])
+ (do try.monad
+ [output (org/python/util/PythonInterpreter::eval (ffi.as_string (_.code input)) interpreter)]
+ (..read output))))
+ execute! (is (-> (_.Statement Any) (Try Any))
+ (function (execute! input)
+ (case (org/python/util/PythonInterpreter::exec (ffi.as_string (_.code input)) interpreter)
+ {try.#Failure error}
+ (if (text.contains? "maximum recursion depth exceeded" error)
+ (execute! input)
+ {try.#Failure error})
+
+ output
+ output)))]
+ (is (Host (_.Expression Any) (_.Statement Any))
+ (implementation
+ (def: evaluate evaluate!)
+ (def: execute execute!)
+ (def: (define context custom [@def 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 [@def @global])]
+ (in [global value definition]))))
+
+ (def: (ingest context content)
+ (|> content
+ (# utf8.codec decoded)
+ 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 [{.#None} (_.var (reference.artifact context))]))))))))]
(for @.old <jvm>
@.jvm <jvm>
@@ -453,58 +453,58 @@
(def: host
(IO (Host (_.Expression Any) (_.Statement Any)))
- (io (: (Host (_.Expression Any) (_.Statement Any))
- (let [globals (..dict [])
- evaluate! (: (-> unit.ID (_.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! (: (-> unit.ID (_.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 decoded) 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)))))))))))))
+ (io (is (Host (_.Expression Any) (_.Statement Any))
+ (let [globals (..dict [])
+ evaluate! (is (-> unit.ID (_.Expression Any) (Try Any))
+ (function (evaluate! context input)
+ (..eval [(_.code input) globals])))
+ execute! (is (-> (_.Statement Any) (Try Any))
+ (function (execute! input)
+ (ffi.try ("python exec" (_.code input) globals))))
+ define! (is (-> unit.ID (_.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 decoded) 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 (def: (extender phase_wrapper)
(-> phase.Wrapper Extender)
... TODO: Stop relying on coercions ASAP.
- (<| (:as Extender)
+ (<| (as Extender)
(function (_ handler))
- (:as Handler)
+ (as Handler)
(function (_ name phase))
- (:as Phase)
+ (as Phase)
(function (_ archive parameters))
- (:as Operation)
+ (as Operation)
(function (_ state))
- (:as Try)
+ (as Try)
try.trusted
- (:as Try)
+ (as Try)
(do try.monad
[handler (try.of_maybe (..python_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 (ffi.as_string name))))
- (ffi.write! 1 (:as org/python/core/PyObject (phase_wrapper phase)))
+ (ffi.write! 0 (as org/python/core/PyObject (org/python/core/PyString::new (ffi.as_string 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)))
@@ -516,12 +516,12 @@
@.python
(def: (extender phase_wrapper handler)
(-> phase.Wrapper Extender)
- (:expected handler))))
+ (as_expected handler))))
(def: (phase_wrapper archive)
(-> Archive (runtime.Operation phase.Wrapper))
(|> (..pseudo_function ..to_host)
- (:as phase.Wrapper)
+ (as phase.Wrapper)
phase#in))
(def: platform
@@ -586,7 +586,7 @@
(type (_.Statement Any))]
..extender
service
- [(packager.package (: (_.Statement Any) (_.manual ""))
+ [(packager.package (is (_.Statement Any) (_.manual ""))
_.code
_.then
..scope)