From 8f575da5095e3b259d4eb6b6f13d3e37ef1d38e4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 11 Jun 2021 02:48:13 -0400 Subject: Added import name formatting to "import:" macros for other backends. --- lux-python/source/program.lux | 49 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'lux-python') diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 366395232..27dc2e66a 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -1,7 +1,7 @@ (.module: [lux #* [program (#+ program:)] - ["." host (#+ import:)] + ["." ffi (#+ import:)] [abstract [monad (#+ do)]] [control @@ -15,7 +15,8 @@ ["." maybe] ["." text ("#\." hash) ["%" format (#+ format)] - ["." encoding]] + [encoding + ["." utf8]]] [collection ["." array (#+ Array)]]] [macro @@ -154,9 +155,9 @@ (#try.Success value)]) (#try.Success [tag (: Any - (case (host.check org/python/core/PyNone flag) + (case (ffi.check org/python/core/PyNone flag) (#.Some _) - (host.null) + (ffi.null) #.None synthesis.unit)) @@ -168,7 +169,7 @@ (def: (read host_object) Translator (`` (<| (~~ (template [ ] - [(case (host.check host_object) + [(case (ffi.check host_object) (#.Some host_object) (#try.Success (<| host_object)) @@ -185,7 +186,7 @@ [[java/lang/Object] (|>)] )) (~~ (template [ ] - [(case (host.check host_object) + [(case (ffi.check host_object) (#.Some host_object) (<| host_object) @@ -203,7 +204,7 @@ (def: (ensure_macro macro) (-> Macro (Maybe org/python/core/PyFunction)) - (host.check org/python/core/PyFunction (:coerce java/lang/Object macro))) + (ffi.check org/python/core/PyFunction (:coerce java/lang/Object macro))) (def: object_class (java/lang/Class java/lang/Object) @@ -216,7 +217,7 @@ (def: ensure_function (-> Any (Maybe org/python/core/PyFunction)) (|>> (:coerce java/lang/Object) - (host.check org/python/core/PyFunction))) + (ffi.check org/python/core/PyFunction))) ) @.python @@ -227,9 +228,9 @@ (-> (List Code) Lux org/python/core/PyFunction (Try (Try [Lux (List Code)]))) (:assume (do try.monad - [expansion (org/python/core/PyFunction::__call__ (|> (host.array org/python/core/PyObject 2) - (host.array_write 0 (..to_host inputs)) - (host.array_write 1 (..to_host lux))) + [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)))) @@ -282,7 +283,7 @@ (def: (ingest context content) (|> content - (\ encoding.utf8 decode) + (\ utf8.codec decode) try.assume (:coerce (_.Statement Any)))) @@ -295,8 +296,8 @@ (evaluate! context (_.var (reference.artifact context)))))))))) @.python - (as_is (import: (dict [] host.Dict)) - (import: (eval [host.String host.Dict] #try Any)) + (as_is (import: (dict [] ffi.Dict)) + (import: (eval [ffi.String ffi.Dict] #try Any)) (def: host (IO (Host (_.Expression Any) (_.Statement Any))) @@ -307,7 +308,7 @@ (..eval [(_.code input) globals]))) execute! (: (-> (_.Statement Any) (Try Any)) (function (execute! input) - (host.try ("python exec" (_.code input) globals)))) + (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) @@ -323,7 +324,7 @@ (def: define! define!) (def: (ingest context content) - (|> content (\ encoding.utf8 decode) try.assume (:coerce (_.Statement Any)))) + (|> content (\ utf8.codec decode) try.assume (:coerce (_.Statement Any)))) (def: (re_learn context content) (execute! content)) @@ -341,7 +342,7 @@ #platform.host host #platform.phase python.generate #platform.runtime runtime.generate - #platform.write (|>> _.code (\ encoding.utf8 encode))}))) + #platform.write (|>> _.code (\ utf8.codec encode))}))) (def: (program context program) (Program (_.Expression Any) (_.Statement Any)) @@ -365,7 +366,7 @@ (All [s i o] (-> (Phase [Bundle s] i o) org/python/core/PyObject)) - (host.object [] org/python/core/PyObject [] + (ffi.object [] org/python/core/PyObject [] [] ## Methods (org/python/core/PyObject @@ -429,12 +430,12 @@ (: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))) + 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 (..host_phase 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))))) -- cgit v1.2.3