From dda05bca0956af5e5b3875c4cc36e61aa04772e4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 12 Sep 2021 00:07:08 -0400 Subject: Made the "#" character great again! --- lux-js/source/program.lux | 163 ++++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 79 deletions(-) (limited to 'lux-js') diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux index 8f81cd72f..4c788c2c5 100644 --- a/lux-js/source/program.lux +++ b/lux-js/source/program.lux @@ -69,10 +69,10 @@ (exception: (null_has_no_lux_representation [code (Maybe _.Expression)]) (case code - {#.Some code} + {.#Some code} (_.code code) - #.None + {.#None} "???")) (for [@.old @@ -214,13 +214,15 @@ (let [js_object (: (-> java/lang/Object org/openjdk/nashorn/api/scripting/JSObject) (function (_ sub_value) (<| (case (ffi.check [java/lang/Object] sub_value) - {#.Some sub_value} + {.#Some sub_value} (|> sub_value (:as (Array java/lang/Object)) js_structure) - #.None) + + {.#None}) (case (ffi.check java/lang/Long sub_value) - {#.Some sub_value} + {.#Some sub_value} (|> sub_value (:as Int) js_int) - #.None) + + {.#None}) ... else (:as org/openjdk/nashorn/api/scripting/JSObject sub_value))))] (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [program/StructureValue] @@ -252,7 +254,7 @@ (^ (static runtime.variant_flag_field)) (case (array.read! 1 value) - {#.Some set!} + {.#Some set!} set! _ @@ -280,14 +282,14 @@ ["Class" (java/lang/Object::toString (java/lang/Object::getClass object))] ["Object" (java/lang/Object::toString object)] ["Keys" (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror object) - {#.Some object} + {.#Some object} (|> object (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys true) (:as (Array Text)) - (array.list #.None) + (array.list {.#None}) (%.list %.text)) - #.None + {.#None} "???")])) (def: (check_int js_object) @@ -295,20 +297,20 @@ (Maybe Int)) (case [(org/openjdk/nashorn/api/scripting/JSObject::getMember [runtime.i64_high_field] js_object) (org/openjdk/nashorn/api/scripting/JSObject::getMember [runtime.i64_low_field] js_object)] - (^multi [{#.Some high} {#.Some low}] + (^multi [{.#Some high} {.#Some low}] [[(ffi.check java/lang/Number high) (ffi.check java/lang/Number low)] - [{#.Some high} {#.Some low}]] + [{.#Some high} {.#Some low}]] [[(java/lang/Number::longValue high) (java/lang/Number::longValue low)] [high low]]) - {#.Some (.int (n.+ (|> high .nat (i64.left_shifted 32)) + {.#Some (.int (n.+ (|> high .nat (i64.left_shifted 32)) (if (i.< +0 (.int low)) (|> low .nat (i64.left_shifted 32) (i64.right_shifted 32)) (.nat low))))} _ - #.None)) + {.#None})) (def: (check_variant lux_object js_object) (-> (-> java/lang/Object (Try Any)) @@ -317,17 +319,17 @@ (case [(org/openjdk/nashorn/api/scripting/JSObject::getMember [runtime.variant_tag_field] js_object) (org/openjdk/nashorn/api/scripting/JSObject::getMember [runtime.variant_flag_field] js_object) (org/openjdk/nashorn/api/scripting/JSObject::getMember [runtime.variant_value_field] js_object)] - (^multi [{#.Some tag} ?flag {#.Some value}] + (^multi [{.#Some tag} ?flag {.#Some value}] [(ffi.check java/lang/Number tag) - {#.Some tag}] + {.#Some tag}] [(lux_object value) - {#try.Success value}]) - {#.Some [(java/lang/Number::intValue (:as java/lang/Number tag)) + {try.#Success value}]) + {.#Some [(java/lang/Number::intValue (:as java/lang/Number tag)) (maybe.else (ffi.null) ?flag) value]} _ - #.None)) + {.#None})) (def: (check_tuple lux_object js_object) (-> (-> java/lang/Object (Try Any)) @@ -340,74 +342,77 @@ (array.empty num_keys))] (if (n.< num_keys idx) (case (org/openjdk/nashorn/api/scripting/JSObject::getMember (%.nat idx) js_object) - {#.Some member} + {.#Some member} (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined member) - {#.Some _} + {.#Some _} (recur (++ idx) output) - #.None + {.#None} (case (lux_object member) - {#try.Success parsed_member} + {try.#Success parsed_member} (recur (++ idx) (array.write! idx (:as java/lang/Object parsed_member) output)) - {#try.Failure error} - #.None)) + {try.#Failure error} + {.#None})) - #.None + {.#None} (recur (++ idx) output)) - {#.Some output}))) - #.None)) + {.#Some output}))) + {.#None})) (def: (lux_object js_object) (-> java/lang/Object (Try Any)) (`` (<| (if (ffi.null? js_object) - (exception.except ..null_has_no_lux_representation [#.None])) + (exception.except ..null_has_no_lux_representation [{.#None}])) (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined js_object) - {#.Some _} + {.#Some _} (exception.except ..undefined_has_no_lux_representation []) - #.None) + + {.#None}) (~~ (template [] [(case (ffi.check js_object) - {#.Some js_object} - {#try.Success js_object} - #.None)] + {.#Some js_object} + {try.#Success js_object} + + {.#None})] [java/lang/Boolean] [java/lang/String])) (~~ (template [ ] [(case (ffi.check js_object) - {#.Some js_object} - {#try.Success ( js_object)} - #.None)] + {.#Some js_object} + {try.#Success ( js_object)} + + {.#None})] [java/lang/Number java/lang/Number::doubleValue] [program/StructureValue program/StructureValue::getValue] [program/IntValue program/IntValue::getValue])) (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object) - {#.Some js_object} + {.#Some js_object} (case (check_int js_object) - {#.Some value} - {#try.Success value} + {.#Some value} + {try.#Success value} - #.None + {.#None} (case (check_variant lux_object js_object) - {#.Some value} - {#try.Success value} + {.#Some value} + {try.#Success value} - #.None + {.#None} (case (check_tuple lux_object js_object) - {#.Some value} - {#try.Success value} + {.#Some value} + {try.#Success value} - #.None + {.#None} (if (org/openjdk/nashorn/api/scripting/JSObject::isFunction js_object) - {#try.Success js_object} + {try.#Success js_object} ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) - {#try.Success js_object} + {try.#Success js_object} )))) - #.None) + {.#None}) ... else ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) - {#try.Success js_object} + {try.#Success js_object} ))) (def: (ensure_function function) @@ -417,8 +422,8 @@ (:as java/lang/Object) (ffi.check org/openjdk/nashorn/api/scripting/JSObject))] (if (org/openjdk/nashorn/api/scripting/JSObject::isFunction function) - {#.Some function} - #.None))) + {.#Some function} + {.#None}))) ) @.js @@ -430,7 +435,7 @@ (let [to_js (: (-> Any java/lang/Object) (|>> (:as (Array java/lang/Object)) js_structure (:as java/lang/Object)))] (<| (:as (Try (Try [Lux (List Code)]))) - (org/openjdk/nashorn/api/scripting/JSObject::call #.None + (org/openjdk/nashorn/api/scripting/JSObject::call {.#None} (|> (array.empty 2) (: (Array java/lang/Object)) (array.write! 0 (to_js inputs)) @@ -444,25 +449,25 @@ (def: (expander macro inputs lux) Expander (case (..ensure_function macro) - {#.Some macro} + {.#Some macro} (case (call_macro inputs lux macro) - {#try.Success output} + {try.#Success output} (|> output (:as java/lang/Object) lux_object (:as (Try (Try [Lux (List Code)])))) - {#try.Failure error} - {#try.Failure error}) + {try.#Failure error} + {try.#Failure error}) - #.None + {.#None} (exception.except ..cannot_apply_a_non_function (:as java/lang/Object macro)))) ) @.js (def: (expander macro inputs lux) Expander - {#try.Success ((:as Macro' macro) inputs lux)}) + {try.#Success ((:as Macro' macro) inputs lux)}) ]) (for [@.old @@ -471,11 +476,11 @@ (do try.monad [?output (javax/script/ScriptEngine::eval (_.code input) interpreter)] (case ?output - {#.Some output} + {.#Some output} (..lux_object output) - #.None - (exception.except ..null_has_no_lux_representation [{#.Some input}])))) + {.#None} + (exception.except ..null_has_no_lux_representation [{.#Some input}])))) (def: (execute! interpreter input) (-> javax/script/ScriptEngine _.Statement (Try Any)) @@ -524,19 +529,19 @@ ... when the code is running under "use strict";. (try (let [return ("js apply" (function.identity ("js constant" "eval")) code)] (if ("js object null?" return) - #.None - {#.Some return})))) + {.#None} + {.#Some return})))) (def: (evaluate! alias input) (-> Context _.Expression (Try Any)) (do try.monad [?output (..eval (_.code input))] (case ?output - {#.Some output} + {.#Some output} (in output) - #.None - (exception.except ..null_has_no_lux_representation [{#.Some input}])))) + {.#None} + (exception.except ..null_has_no_lux_representation [{.#Some input}])))) (def: (execute! input) (-> _.Statement (Try Any)) @@ -592,14 +597,14 @@ (IO (Platform [Register Text] _.Expression _.Statement)) (do io.monad [host ..host] - (in [#platform.&file_system (for [@.old (file.async file.default) + (in [platform.#&file_system (for [@.old (file.async file.default) @.jvm (file.async file.default) @.js file.default]) - #platform.host host - #platform.phase js.generate - #platform.runtime runtime.generate - #platform.phase_wrapper ..phase_wrapper - #platform.write (|>> _.code (\ utf8.codec encoded))]))) + platform.#host host + platform.#phase js.generate + platform.#runtime runtime.generate + platform.#phase_wrapper ..phase_wrapper + platform.#write (|>> _.code (\ utf8.codec encoded))]))) (def: (program context program) (Program _.Expression _.Statement) @@ -637,7 +642,7 @@ [handler (try.of_maybe (..ensure_function handler)) .let [to_js (: (-> Any java/lang/Object) (|>> (:as (Array java/lang/Object)) js_structure (:as java/lang/Object)))] - output (org/openjdk/nashorn/api/scripting/JSObject::call #.None + output (org/openjdk/nashorn/api/scripting/JSObject::call {.#None} (|> (array.empty 5) (: (Array java/lang/Object)) (array.write! 0 name) @@ -665,10 +670,10 @@ (program: [service /cli.service] (let [extension ".js"] (exec (do async.monad - [_ (/.compiler [#/static.host @.js - #/static.host_module_extension extension - #/static.target (/cli.target service) - #/static.artifact_extension extension] + [_ (/.compiler [/static.#host @.js + /static.#host_module_extension extension + /static.#target (/cli.target service) + /static.#artifact_extension extension] ..expander analysis.bundle ..platform -- cgit v1.2.3