diff options
author | Eduardo Julian | 2020-07-10 00:06:16 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-07-10 00:06:16 -0400 |
commit | d48c3ff75f23a62c7f13ff411c25073e618b19de (patch) | |
tree | d5d36a4343ca48b765a68b1a665a9089c0d394fd /lux-js/source | |
parent | 509259d91b07bce77864cf10123ce428461a3092 (diff) |
Fixes and improvements to JavaScript compilation.
Diffstat (limited to 'lux-js/source')
-rw-r--r-- | lux-js/source/program.lux | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux index cebede1ab..3ecd9891b 100644 --- a/lux-js/source/program.lux +++ b/lux-js/source/program.lux @@ -13,6 +13,7 @@ [concurrency ["." promise (#+ Promise)]]] [data + ["." product] ["." maybe] [number ["." i64] @@ -32,6 +33,8 @@ [tool [compiler [phase (#+ Operation Phase)] + [reference + [variable (#+ Register)]] [language [lux [program (#+ Program)] @@ -145,7 +148,7 @@ (|> value .nat runtime.low jvm-int) _ - (error! (exception.construct unknown-member [member (:coerce java/lang/Object value)])))) + (error! (exception.construct ..unknown-member [member (:coerce java/lang/Object value)])))) )) (def: (::toString js-object) @@ -228,7 +231,7 @@ (|> value (array.read 2) maybe.assume js-object (:coerce java/lang/Object)) _ - (error! (exception.construct unknown-member [(:coerce Text member) (:coerce java/lang/Object value)]))) + (error! (exception.construct ..unknown-member [(:coerce Text member) (:coerce java/lang/Object value)]))) ) (jdk/nashorn/api/scripting/AbstractJSObject [] (getSlot self {idx int}) java/lang/Object @@ -239,7 +242,14 @@ (:coerce java/lang/Object))) ))) -(exception: null-has-no-lux-representation) +(exception: (null-has-no-lux-representation {code (Maybe _.Expression)}) + (case code + (#.Some code) + (_.code code) + + #.None + "???")) + (exception: undefined-has-no-lux-representation) (exception: (unknown-kind-of-host-object {object java/lang/Object}) @@ -322,7 +332,7 @@ (def: (lux-object js-object) (-> java/lang/Object (Try Any)) (`` (<| (if (host.null? js-object) - (exception.throw ..null-has-no-lux-representation [])) + (exception.throw ..null-has-no-lux-representation [#.None])) (case (host.check jdk/nashorn/internal/runtime/Undefined js-object) (#.Some _) (exception.throw ..undefined-has-no-lux-representation []) @@ -391,7 +401,7 @@ (def: (expander macro inputs lux) Expander - (case (ensure-macro macro) + (case (..ensure-macro macro) (#.Some macro) (case (call-macro inputs lux macro) (#try.Success output) @@ -409,14 +419,13 @@ (def: (evaluate! interpreter alias input) (-> javax/script/ScriptEngine Text _.Expression (Try Any)) (do try.monad - [?output (javax/script/ScriptEngine::eval (_.code input) interpreter) - output (case ?output - (#.Some output) - (wrap output) + [?output (javax/script/ScriptEngine::eval (_.code input) interpreter)] + (case ?output + (#.Some output) + (..lux-object output) - #.None - (exception.throw ..null-has-no-lux-representation []))] - (..lux-object output))) + #.None + (exception.throw ..null-has-no-lux-representation [(#.Some input)])))) (def: (execute! interpreter alias input) (-> javax/script/ScriptEngine Text _.Statement (Try Any)) @@ -456,7 +465,7 @@ (..evaluate! interpreter "" (_.var (reference.artifact context)))))))))) (def: platform - (IO (Platform _.Var _.Expression _.Statement)) + (IO (Platform [Register Text] _.Expression _.Statement)) (do io.monad [host ..host] (wrap {#platform.&file-system (file.async file.system) |