From cd71a864ad5be13ed6ec6d046e0a2cb1087bdf94 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 10 Sep 2021 01:21:23 -0400 Subject: Migrated variants to the new syntax. --- lux-js/source/program.lux | 108 +++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'lux-js/source') diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux index 1e36e2906..8f81cd72f 100644 --- a/lux-js/source/program.lux +++ b/lux-js/source/program.lux @@ -69,7 +69,7 @@ (exception: (null_has_no_lux_representation [code (Maybe _.Expression)]) (case code - (#.Some code) + {#.Some code} (_.code code) #.None @@ -160,7 +160,7 @@ (-> Int org/openjdk/nashorn/api/scripting/JSObject) (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [program/IntValue] [] -... Methods + ... Methods (program/IntValue [] (getValue self []) java/lang/Object (:as java/lang/Object value)) @@ -214,18 +214,18 @@ (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) (case (ffi.check java/lang/Long sub_value) - (#.Some sub_value) + {#.Some sub_value} (|> sub_value (:as Int) js_int) #.None) -... else + ... else (:as org/openjdk/nashorn/api/scripting/JSObject sub_value))))] (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [program/StructureValue] [] -... Methods + ... Methods (program/StructureValue [] (getValue self []) java/lang/Object (:as (Array java/lang/Object) value)) @@ -252,7 +252,7 @@ (^ (static runtime.variant_flag_field)) (case (array.read! 1 value) - (#.Some set!) + {#.Some set!} set! _ @@ -280,7 +280,7 @@ ["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)) @@ -295,17 +295,17 @@ (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))))) + (.nat low))))} _ #.None)) @@ -317,14 +317,14 @@ (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]) + value]} _ #.None)) @@ -340,22 +340,22 @@ (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 (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) + {#try.Failure error} #.None)) #.None (recur (++ idx) output)) - (#.Some output)))) + {#.Some output}))) #.None)) (def: (lux_object js_object) @@ -363,51 +363,51 @@ (`` (<| (if (ffi.null? js_object) (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) (~~ (template [] [(case (ffi.check js_object) - (#.Some js_object) - (#try.Success js_object) + {#.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)) + {#.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 (case (check_variant lux_object js_object) - (#.Some value) - (#try.Success value) + {#.Some value} + {#try.Success value} #.None (case (check_tuple lux_object js_object) - (#.Some value) - (#try.Success value) + {#.Some value} + {#try.Success value} #.None (if (org/openjdk/nashorn/api/scripting/JSObject::isFunction 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} + ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) + {#try.Success js_object} )))) #.None) -... else -... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) - (#try.Success js_object) + ... else + ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) + {#try.Success js_object} ))) (def: (ensure_function function) @@ -417,7 +417,7 @@ (:as java/lang/Object) (ffi.check org/openjdk/nashorn/api/scripting/JSObject))] (if (org/openjdk/nashorn/api/scripting/JSObject::isFunction function) - (#.Some function) + {#.Some function} #.None))) ) @@ -444,16 +444,16 @@ (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 (exception.except ..cannot_apply_a_non_function (:as java/lang/Object macro)))) @@ -462,7 +462,7 @@ @.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 +471,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)])))) + (exception.except ..null_has_no_lux_representation [{#.Some input}])))) (def: (execute! interpreter input) (-> javax/script/ScriptEngine _.Statement (Try Any)) @@ -519,24 +519,24 @@ @.js (as_is (def: (eval code) (-> Text (Try (Maybe Any))) -... Note: I have to call "eval" this way -... in order to avoid a quirk of calling eval in Node -... when the code is running under "use strict";. + ... Note: I have to call "eval" this way + ... in order to avoid a quirk of calling eval in Node + ... 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))))) + {#.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)])))) + (exception.except ..null_has_no_lux_representation [{#.Some input}])))) (def: (execute! input) (-> _.Statement (Try Any)) -- cgit v1.2.3