diff options
author | Eduardo Julian | 2022-03-14 06:14:57 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-14 06:14:57 -0400 |
commit | 4965597043aca57a05760113f1851e96dad1eaf8 (patch) | |
tree | 8126d3e6394e38bc52918eea95a67546350bb95e | |
parent | cfd438517a46e025b15345e3570b02f5ea6165c0 (diff) |
Leaner syntax for the "for" macro.
75 files changed, 4261 insertions, 4257 deletions
diff --git a/lux-cl/source/program.lux b/lux-cl/source/program.lux index 1fea7d020..834b2ff38 100644 --- a/lux-cl/source/program.lux +++ b/lux-cl/source/program.lux @@ -1,67 +1,67 @@ (.using - [lux "*" - [program {"+" program:}] - ["[0]" ffi] - ["[0]" debug] - [abstract - ["[0]" monad {"+" do}]] - [control - [pipe {"+" exec> case> new>}] - ["[0]" maybe] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - ["[0]" io {"+" IO io}] - [concurrency - ["[0]" promise {"+" Promise}]]] - [data - ["[0]" text ("[1]#[0]" hash) - ["%" format {"+" format}] - ["[0]" encoding]] - [collection - ["[0]" array {"+" Array}]]] - [macro - ["[0]" template]] - [math - [number {"+" hex} - ["n" nat] - ["[0]" i64]]] - ["[0]" world "_" - ["[0]" file] - ["[1]/[0]" program]] - ["@" target - ["_" common_lisp]] - [tool - [compiler - [phase {"+" Operation Phase}] - [reference - [variable {"+" Register}]] - [language - [lux - [program {"+" Program}] - [generation {"+" Context Host}] - ["[0]" synthesis] - [analysis - [macro {"+" Expander}]] - [phase - ["[0]" extension {"+" Extender Handler} - ["[1]/[0]" bundle] - ["[0]" analysis "_" - ["[1]" common_lisp]] - ["[0]" generation "_" - ["[1]" common_lisp]]] - [generation - ["[0]" reference] - ["[0]" common_lisp - ["[0]" runtime]]]]]] - [default - ["[0]" platform {"+" Platform}]] - [meta - ["[0]" packager "_" - ["[1]" script]]]]]] - [program - ["/" compositor - ["[1][0]" cli] - ["[1][0]" static]]]) + [lux "*" + [program {"+" program:}] + ["[0]" ffi] + ["[0]" debug] + [abstract + ["[0]" monad {"+" do}]] + [control + [pipe {"+" exec> case> new>}] + ["[0]" maybe] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + ["[0]" io {"+" IO io}] + [concurrency + ["[0]" promise {"+" Promise}]]] + [data + ["[0]" text ("[1]#[0]" hash) + ["%" format {"+" format}] + ["[0]" encoding]] + [collection + ["[0]" array {"+" Array}]]] + [macro + ["[0]" template]] + [math + [number {"+" hex} + ["n" nat] + ["[0]" i64]]] + ["[0]" world "_" + ["[0]" file] + ["[1]/[0]" program]] + ["@" target + ["_" common_lisp]] + [tool + [compiler + [phase {"+" Operation Phase}] + [reference + [variable {"+" Register}]] + [language + [lux + [program {"+" Program}] + [generation {"+" Context Host}] + ["[0]" synthesis] + [analysis + [macro {"+" Expander}]] + [phase + ["[0]" extension {"+" Extender Handler} + ["[1]/[0]" bundle] + ["[0]" analysis "_" + ["[1]" common_lisp]] + ["[0]" generation "_" + ["[1]" common_lisp]]] + [generation + ["[0]" reference] + ["[0]" common_lisp + ["[0]" runtime]]]]]] + [default + ["[0]" platform {"+" Platform}]] + [meta + ["[0]" packager "_" + ["[1]" script]]]]]] + [program + ["/" compositor + ["[1][0]" cli] + ["[1][0]" static]]]) (ffi.import: java/lang/String) @@ -365,29 +365,29 @@ (_.list/* (list))))] (_.call/2 [(runtime.lux//program_args raw_inputs) _.nil] program))) -(for [@.old - (def: extender - Extender - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (exec - ("lux io log" "TODO: Extender") - {try.#Failure "TODO: Extender"}))) - - @.common_lisp - (def: (extender handler) - Extender - (:expected handler))]) +(for @.old + (def: extender + Extender + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (exec + ("lux io log" "TODO: Extender") + {try.#Failure "TODO: Extender"}))) + + @.common_lisp + (def: (extender handler) + Extender + (:expected handler))) (def: (declare_success! _) (-> Any (Promise Any)) diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux index b4b82d9ce..487415185 100644 --- a/lux-js/source/program.lux +++ b/lux-js/source/program.lux @@ -76,558 +76,561 @@ {.#None} "???")) -(for [@.jvm - (as_is (import: java/lang/String) - - (import: (java/lang/Class a)) - - (import: java/lang/Object - ["[1]::[0]" - (toString [] java/lang/String) - (getClass [] (java/lang/Class java/lang/Object))]) - - (import: java/lang/Long - ["[1]::[0]" - (intValue [] int)]) - - (import: java/lang/Integer - ["[1]::[0]" - (longValue [] long)]) - - (import: java/lang/Number - ["[1]::[0]" - (intValue [] int) - (longValue [] long) - (doubleValue [] double)]) - - (import: java/util/Arrays - ["[1]::[0]" - ("static" [t] copyOfRange [[t] int int] [t])]) - - (import: javax/script/ScriptEngine - ["[1]::[0]" - (eval [java/lang/String] "try" "?" java/lang/Object)]) - - (import: javax/script/ScriptEngineFactory - ["[1]::[0]" - (getScriptEngine [] javax/script/ScriptEngine)]) - - (import: org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory - ["[1]::[0]" - (new [])]) - - (import: org/openjdk/nashorn/api/scripting/JSObject - ["[1]::[0]" - (isArray [] boolean) - (isFunction [] boolean) - (getSlot [int] "?" java/lang/Object) - (getMember [java/lang/String] "?" java/lang/Object) - (hasMember [java/lang/String] boolean) - (call ["?" java/lang/Object [java/lang/Object]] "try" java/lang/Object)]) - - (import: org/openjdk/nashorn/api/scripting/AbstractJSObject) - - (import: org/openjdk/nashorn/api/scripting/ScriptObjectMirror - ["[1]::[0]" - (size [] int) - (toString [] java/lang/String) - (getOwnKeys [boolean] [java/lang/String])]) - - (import: org/openjdk/nashorn/internal/runtime/Undefined) - - (template [<name>] - [(ffi.interface: <name> - (getValue [] java/lang/Object)) - - (import: <name> - ["[1]::[0]" - (getValue [] java/lang/Object)])] - - [IntValue] - [StructureValue] - ) - - (exception: (unknown_member [member Text - object java/lang/Object]) - (exception.report - ["Member" member] - ["Object" (debug.inspection object)])) - - (def: jvm_int - (-> (I64 Any) java/lang/Integer) - (|>> .int - ffi.as_long - java/lang/Long::intValue)) - - (def: (js_int value) - (-> Int org/openjdk/nashorn/api/scripting/JSObject) - (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) - (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [IntValue] - [] - ... Methods - (IntValue - [] (getValue self []) java/lang/Object - (ffi.:as java/lang/Object (ffi.as_long value))) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (getMember self [member java/lang/String]) java/lang/Object - (case (ffi.of_string member) - (^ (static runtime.i64_high_field)) - (|> value .nat runtime.high jvm_int - (ffi.:as java/lang/Object)) - - (^ (static runtime.i64_low_field)) - (|> value .nat runtime.low jvm_int - (ffi.:as java/lang/Object)) - - _ - (panic! (exception.error ..unknown_member [(ffi.of_string member) - (ffi.:as java/lang/Object (ffi.as_long value))])))) - ))) - - (def: (::toString js_object) - (-> Any org/openjdk/nashorn/api/scripting/JSObject) - (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) - (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [] - [] - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (isFunction self []) boolean - (ffi.as_boolean #1)) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (call self [this java/lang/Object - args [java/lang/Object]]) - java/lang/Object - (|> js_object - debug.inspection - ffi.as_string - (ffi.:as java/lang/Object))) - ))) - - (def: (::slice js_object value) - (-> (-> java/lang/Object org/openjdk/nashorn/api/scripting/JSObject) (Array java/lang/Object) org/openjdk/nashorn/api/scripting/JSObject) - (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) - (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [] - [] - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (isFunction self []) boolean - (ffi.as_boolean #1)) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (call self [this java/lang/Object - args [java/lang/Object]]) - java/lang/Object - (|> (java/util/Arrays::copyOfRange value - (|> args - (array.read! 0) - maybe.trusted - (:as Int) - ffi.as_int) - (ffi.as_int (.int (array.size value)))) - (:as java/lang/Object) - js_object - (ffi.:as java/lang/Object))) - ))) - - (def: (js_structure value) - (-> (Array java/lang/Object) org/openjdk/nashorn/api/scripting/JSObject) - (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} - (|> sub_value (:as (Array java/lang/Object)) js_structure) - - {.#None}) - (case (ffi.check java/lang/Long sub_value) - {.#Some sub_value} - (|> sub_value ffi.of_long js_int) - - {.#None}) - ... else - (:as org/openjdk/nashorn/api/scripting/JSObject sub_value))))] - (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) - (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [StructureValue] - [] - ... Methods - (StructureValue - [] (getValue self []) java/lang/Object - (ffi.:as java/lang/Object value)) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (isArray self []) boolean - (ffi.as_boolean #1)) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (getMember self [member java/lang/String]) - java/lang/Object - (case (ffi.of_string member) - (^or "toJSON" "toString") - (|> (::toString value) - (ffi.:as java/lang/Object)) - - "length" - (|> value - array.size - jvm_int - (ffi.:as java/lang/Object)) - - "slice" - (|> (::slice js_object value) - (ffi.:as java/lang/Object)) - - (^ (static runtime.variant_tag_field)) - (|> value - (array.read! 0) - maybe.trusted) - - (^ (static runtime.variant_flag_field)) - (case (array.read! 1 value) - {.#Some set!} - set! - - _ - (ffi.null)) - - (^ (static runtime.variant_value_field)) - (|> value - (array.read! 2) - maybe.trusted - js_object - (ffi.:as java/lang/Object)) - - _ - (panic! (exception.error ..unknown_member [(:as Text member) (:as java/lang/Object value)]))) - ) - (org/openjdk/nashorn/api/scripting/AbstractJSObject - [] (getSlot self [idx int]) java/lang/Object - (|> value - (array.read! (|> idx java/lang/Integer::longValue (:as Nat))) - maybe.trusted - js_object - (:as java/lang/Object))) - )))) - - (exception: undefined_has_no_lux_representation) - - (exception: (unknown_kind_of_host_object [object java/lang/Object]) - (exception.report - ["Class" (ffi.of_string (java/lang/Object::toString (java/lang/Object::getClass object)))] - ["Object" (ffi.of_string (java/lang/Object::toString object))] - ["Keys" (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror object) - {.#Some object} - (|> object - (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys true) - (array.list {.#None}) - (%.list (|>> ffi.of_string %.text))) - - {.#None} - "???")])) - - (def: (i32 half i64) - (-> Text org/openjdk/nashorn/api/scripting/ScriptObjectMirror (Maybe Int)) - (|> i64 - (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string half)]) - (maybe#each (|>> (ffi.check java/lang/Number))) - maybe#conjoint - (maybe#each (|>> java/lang/Number::longValue ffi.of_long)))) - - (def: (check_int js_object) - (-> org/openjdk/nashorn/api/scripting/ScriptObjectMirror - (Maybe Int)) - (case [(..i32 runtime.i64_high_field js_object) - (..i32 runtime.i64_low_field js_object)] - [{.#Some high} {.#Some low}] - {.#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})) - - (def: (check_variant lux_object js_object) - (-> (-> java/lang/Object (Try Any)) - org/openjdk/nashorn/api/scripting/ScriptObjectMirror - (Maybe Any)) - (case [(org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_tag_field)] js_object) - (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_flag_field)] js_object) - (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_value_field)] js_object)] - (^multi [{.#Some tag} ?flag {.#Some value}] - [[(ffi.check java/lang/Number tag) (lux_object value)] - [{.#Some tag} {try.#Success value}]]) - {.#Some [(java/lang/Number::intValue (:as java/lang/Number tag)) - (maybe.else (ffi.null) ?flag) - value]} - - _ - {.#None})) - - (def: (check_tuple lux_object js_object) - (-> (-> java/lang/Object (Try Any)) - org/openjdk/nashorn/api/scripting/ScriptObjectMirror - (Maybe (Array java/lang/Object))) - (if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isArray js_object)) - (let [num_keys (.nat (ffi.of_int (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::size js_object)))] - (loop [idx 0 - output (: (Array java/lang/Object) - (array.empty num_keys))] - (if (n.< num_keys idx) - (case (org/openjdk/nashorn/api/scripting/JSObject::getMember (ffi.as_string (%.nat idx)) js_object) - {.#Some member} - (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined member) - {.#Some _} - (again (++ idx) output) - - {.#None} - (case (lux_object member) - {try.#Success parsed_member} - (again (++ idx) (array.write! idx (:as java/lang/Object parsed_member) output)) - - {try.#Failure error} - {.#None})) +(for @.jvm + (as_is (import: java/lang/String) + + (import: (java/lang/Class a)) + + (import: java/lang/Object + ["[1]::[0]" + (toString [] java/lang/String) + (getClass [] (java/lang/Class java/lang/Object))]) + + (import: java/lang/Long + ["[1]::[0]" + (intValue [] int)]) + + (import: java/lang/Integer + ["[1]::[0]" + (longValue [] long)]) + + (import: java/lang/Number + ["[1]::[0]" + (intValue [] int) + (longValue [] long) + (doubleValue [] double)]) + + (import: java/util/Arrays + ["[1]::[0]" + ("static" [t] copyOfRange [[t] int int] [t])]) + + (import: javax/script/ScriptEngine + ["[1]::[0]" + (eval [java/lang/String] "try" "?" java/lang/Object)]) + + (import: javax/script/ScriptEngineFactory + ["[1]::[0]" + (getScriptEngine [] javax/script/ScriptEngine)]) + + (import: org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory + ["[1]::[0]" + (new [])]) + + (import: org/openjdk/nashorn/api/scripting/JSObject + ["[1]::[0]" + (isArray [] boolean) + (isFunction [] boolean) + (getSlot [int] "?" java/lang/Object) + (getMember [java/lang/String] "?" java/lang/Object) + (hasMember [java/lang/String] boolean) + (call ["?" java/lang/Object [java/lang/Object]] "try" java/lang/Object)]) + + (import: org/openjdk/nashorn/api/scripting/AbstractJSObject) + + (import: org/openjdk/nashorn/api/scripting/ScriptObjectMirror + ["[1]::[0]" + (size [] int) + (toString [] java/lang/String) + (getOwnKeys [boolean] [java/lang/String])]) + + (import: org/openjdk/nashorn/internal/runtime/Undefined) + + (template [<name>] + [(ffi.interface: <name> + (getValue [] java/lang/Object)) + + (import: <name> + ["[1]::[0]" + (getValue [] java/lang/Object)])] + + [IntValue] + [StructureValue] + ) + + (exception: (unknown_member [member Text + object java/lang/Object]) + (exception.report + ["Member" member] + ["Object" (debug.inspection object)])) + + (def: jvm_int + (-> (I64 Any) java/lang/Integer) + (|>> .int + ffi.as_long + java/lang/Long::intValue)) + + (def: (js_int value) + (-> Int org/openjdk/nashorn/api/scripting/JSObject) + (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) + (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [IntValue] + [] + ... Methods + (IntValue + [] (getValue self []) java/lang/Object + (ffi.:as java/lang/Object (ffi.as_long value))) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (getMember self [member java/lang/String]) java/lang/Object + (case (ffi.of_string member) + (^ (static runtime.i64_high_field)) + (|> value .nat runtime.high jvm_int + (ffi.:as java/lang/Object)) + + (^ (static runtime.i64_low_field)) + (|> value .nat runtime.low jvm_int + (ffi.:as java/lang/Object)) + + _ + (panic! (exception.error ..unknown_member [(ffi.of_string member) + (ffi.:as java/lang/Object (ffi.as_long value))])))) + ))) + + (def: (::toString js_object) + (-> Any org/openjdk/nashorn/api/scripting/JSObject) + (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) + (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [] + [] + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (isFunction self []) boolean + (ffi.as_boolean #1)) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (call self [this java/lang/Object + args [java/lang/Object]]) + java/lang/Object + (|> js_object + debug.inspection + ffi.as_string + (ffi.:as java/lang/Object))) + ))) + + (def: (::slice js_object value) + (-> (-> java/lang/Object org/openjdk/nashorn/api/scripting/JSObject) (Array java/lang/Object) org/openjdk/nashorn/api/scripting/JSObject) + (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) + (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [] + [] + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (isFunction self []) boolean + (ffi.as_boolean #1)) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (call self [this java/lang/Object + args [java/lang/Object]]) + java/lang/Object + (|> (java/util/Arrays::copyOfRange value + (|> args + (array.read! 0) + maybe.trusted + (:as Int) + ffi.as_int) + (ffi.as_int (.int (array.size value)))) + (:as java/lang/Object) + js_object + (ffi.:as java/lang/Object))) + ))) + + (def: (js_structure value) + (-> (Array java/lang/Object) org/openjdk/nashorn/api/scripting/JSObject) + (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} + (|> sub_value (:as (Array java/lang/Object)) js_structure) + + {.#None}) + (case (ffi.check java/lang/Long sub_value) + {.#Some sub_value} + (|> sub_value ffi.of_long js_int) + + {.#None}) + ... else + (:as org/openjdk/nashorn/api/scripting/JSObject sub_value))))] + (<| (ffi.:as org/openjdk/nashorn/api/scripting/JSObject) + (ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [StructureValue] + [] + ... Methods + (StructureValue + [] (getValue self []) java/lang/Object + (ffi.:as java/lang/Object value)) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (isArray self []) boolean + (ffi.as_boolean #1)) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (getMember self [member java/lang/String]) + java/lang/Object + (case (ffi.of_string member) + (^or "toJSON" "toString") + (|> (::toString value) + (ffi.:as java/lang/Object)) + + "length" + (|> value + array.size + jvm_int + (ffi.:as java/lang/Object)) + + "slice" + (|> (::slice js_object value) + (ffi.:as java/lang/Object)) + + (^ (static runtime.variant_tag_field)) + (|> value + (array.read! 0) + maybe.trusted) + + (^ (static runtime.variant_flag_field)) + (case (array.read! 1 value) + {.#Some set!} + set! + _ + (ffi.null)) + + (^ (static runtime.variant_value_field)) + (|> value + (array.read! 2) + maybe.trusted + js_object + (ffi.:as java/lang/Object)) + + _ + (panic! (exception.error ..unknown_member [(:as Text member) (:as java/lang/Object value)]))) + ) + (org/openjdk/nashorn/api/scripting/AbstractJSObject + [] (getSlot self [idx int]) java/lang/Object + (|> value + (array.read! (|> idx java/lang/Integer::longValue (:as Nat))) + maybe.trusted + js_object + (:as java/lang/Object))) + )))) + + (exception: undefined_has_no_lux_representation) + + (exception: (unknown_kind_of_host_object [object java/lang/Object]) + (exception.report + ["Class" (ffi.of_string (java/lang/Object::toString (java/lang/Object::getClass object)))] + ["Object" (ffi.of_string (java/lang/Object::toString object))] + ["Keys" (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror object) + {.#Some object} + (|> object + (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys true) + (array.list {.#None}) + (%.list (|>> ffi.of_string %.text))) + {.#None} - (again (++ idx) output)) - {.#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}])) - (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined js_object) - {.#Some _} - (exception.except ..undefined_has_no_lux_representation []) - - {.#None}) - (~~ (template [<class>] - [(case (ffi.check <class> js_object) - {.#Some js_object} - {try.#Success js_object} + "???")])) + + (def: (i32 half i64) + (-> Text org/openjdk/nashorn/api/scripting/ScriptObjectMirror (Maybe Int)) + (|> i64 + (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string half)]) + (maybe#each (|>> (ffi.check java/lang/Number))) + maybe#conjoint + (maybe#each (|>> java/lang/Number::longValue ffi.of_long)))) + + (def: (check_int js_object) + (-> org/openjdk/nashorn/api/scripting/ScriptObjectMirror + (Maybe Int)) + (case [(..i32 runtime.i64_high_field js_object) + (..i32 runtime.i64_low_field js_object)] + [{.#Some high} {.#Some low}] + {.#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})) + + (def: (check_variant lux_object js_object) + (-> (-> java/lang/Object (Try Any)) + org/openjdk/nashorn/api/scripting/ScriptObjectMirror + (Maybe Any)) + (case [(org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_tag_field)] js_object) + (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_flag_field)] js_object) + (org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string runtime.variant_value_field)] js_object)] + (^multi [{.#Some tag} ?flag {.#Some value}] + [[(ffi.check java/lang/Number tag) (lux_object value)] + [{.#Some tag} {try.#Success value}]]) + {.#Some [(java/lang/Number::intValue (:as java/lang/Number tag)) + (maybe.else (ffi.null) ?flag) + value]} + + _ + {.#None})) + + (def: (check_tuple lux_object js_object) + (-> (-> java/lang/Object (Try Any)) + org/openjdk/nashorn/api/scripting/ScriptObjectMirror + (Maybe (Array java/lang/Object))) + (if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isArray js_object)) + (let [num_keys (.nat (ffi.of_int (org/openjdk/nashorn/api/scripting/ScriptObjectMirror::size js_object)))] + (loop [idx 0 + output (: (Array java/lang/Object) + (array.empty num_keys))] + (if (n.< num_keys idx) + (case (org/openjdk/nashorn/api/scripting/JSObject::getMember (ffi.as_string (%.nat idx)) js_object) + {.#Some member} + (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined member) + {.#Some _} + (again (++ idx) output) + + {.#None} + (case (lux_object member) + {try.#Success parsed_member} + (again (++ idx) (array.write! idx (:as java/lang/Object parsed_member) output)) + + {try.#Failure error} + {.#None})) - {.#None})] - - [java/lang/Boolean] [java/lang/String])) - (~~ (template [<class> <method>] - [(case (ffi.check <class> js_object) - {.#Some js_object} - {try.#Success (<method> js_object)} - - {.#None})] - - [java/lang/Number java/lang/Number::doubleValue] - [StructureValue StructureValue::getValue] - [IntValue IntValue::getValue])) - (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object) - {.#Some js_object} - (case (check_int js_object) - {.#Some value} - {try.#Success value} - - {.#None} - (case (check_variant lux_object js_object) - {.#Some value} - {try.#Success value} - - {.#None} - (case (check_tuple lux_object js_object) - {.#Some value} - {try.#Success value} - - {.#None} - (if (ffi.of_boolean (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} - )))) - {.#None}) - ... else - ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) - {try.#Success js_object} - ))) - - (def: (ensure_function function) - (-> Any (Maybe org/openjdk/nashorn/api/scripting/JSObject)) - (do maybe.monad - [function (|> function - (:as java/lang/Object) - (ffi.check org/openjdk/nashorn/api/scripting/JSObject))] - (if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction function)) - {.#Some function} - {.#None}))) - ) - - @.js - (as_is)]) - -(for [@.jvm - (as_is (def: (call_macro inputs lux macro) - (-> (List Code) Lux org/openjdk/nashorn/api/scripting/JSObject (Try (Try [Lux (List Code)]))) - (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} - (|> (array.empty 2) - (: (Array java/lang/Object)) - (array.write! 0 (to_js inputs)) - (array.write! 1 (to_js lux))) - macro)))) - - (exception: (cannot_apply_a_non_function [object java/lang/Object]) - (exception.report - ["Object" (ffi.of_string (java/lang/Object::toString object))])) - - (def: (expander macro inputs lux) - Expander - (case (..ensure_function macro) - {.#Some macro} - (case (call_macro inputs lux macro) - {try.#Success output} - (|> output - (:as java/lang/Object) - lux_object - (: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)))) - ) - - @.js - (def: (expander macro inputs lux) - Expander - {try.#Success ((:as Macro' macro) inputs lux)}) - ]) - -(for [@.jvm - (as_is (def: (evaluate! interpreter alias input) - (-> javax/script/ScriptEngine unit.ID _.Expression (Try Any)) - (do try.monad - [?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)] - (case ?output - {.#Some output} - (..lux_object output) - - {.#None} - (exception.except ..null_has_no_lux_representation [{.#Some input}])))) - - (def: (execute! interpreter input) - (-> javax/script/ScriptEngine _.Statement (Try Any)) - (do try.monad - [?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)] - (in []))) - - (def: (define! interpreter context custom input) - (-> javax/script/ScriptEngine unit.ID (Maybe Text) _.Expression (Try [Text Any _.Statement])) - (let [global (maybe.else (reference.artifact context) - custom) - @global (_.var global)] - (do try.monad - [.let [definition (_.define @global input)] - _ (execute! interpreter definition) - value (evaluate! interpreter context @global)] - (in [global value definition])))) - - (def: host - (IO (Host _.Expression _.Statement)) - (io (let [interpreter (javax/script/ScriptEngineFactory::getScriptEngine - (org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory::new))] - (: (Host _.Expression _.Statement) - (implementation - (def: (evaluate alias [_ input]) (..evaluate! interpreter alias input)) - (def: execute (..execute! interpreter)) - (def: (define context custom [_ input]) (..define! interpreter context custom input)) - - (def: (ingest context content) - (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) - - (def: (re_learn context custom content) - (..execute! interpreter content)) - - (def: (re_load context custom content) - (do try.monad - [_ (..execute! interpreter content)] - (..evaluate! interpreter context (_.var (reference.artifact context)))))))))) - ) - - @.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";. - (try (let [return ("js apply" (function.identity ("js constant" "eval")) [code])] - (if ("js object null?" return) {.#None} - {.#Some return})))) - - (def: (evaluate! alias input) - (-> unit.ID _.Expression (Try Any)) - (do try.monad - [?output (..eval (_.code input))] - (case ?output - {.#Some output} - (in output) - - {.#None} - (exception.except ..null_has_no_lux_representation [{.#Some input}])))) - - (def: (execute! input) - (-> _.Statement (Try Any)) - (do try.monad - [?output (..eval (_.code input))] - (in []))) - - (def: (define! context custom input) - (-> unit.ID (Maybe Text) _.Expression (Try [Text Any _.Statement])) - (let [global (maybe.else (reference.artifact context) - custom) - @global (_.var global)] - (do try.monad - [.let [definition (_.define @global input)] - _ (..execute! definition) - value (..evaluate! context @global)] - (in [global value definition])))) - - (def: host - (IO (Host _.Expression _.Statement)) - (io (: (Host _.Expression _.Statement) - (implementation - (def: (evaluate alias [_ input]) (..evaluate! alias input)) - (def: execute ..execute!) - (def: (define context custom [_ input]) (..define! context custom input)) - - (def: (ingest context content) - (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) - - (def: (re_learn context custom content) - (..execute! content)) - - (def: (re_load context custom content) - (do try.monad - [_ (..execute! content)] - (..evaluate! context (_.var (reference.artifact context))))))))) - )]) + (again (++ idx) output)) + {.#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}])) + (case (ffi.check org/openjdk/nashorn/internal/runtime/Undefined js_object) + {.#Some _} + (exception.except ..undefined_has_no_lux_representation []) + + {.#None}) + (~~ (template [<class>] + [(case (ffi.check <class> js_object) + {.#Some js_object} + {try.#Success js_object} + + {.#None})] + + [java/lang/Boolean] [java/lang/String])) + (~~ (template [<class> <method>] + [(case (ffi.check <class> js_object) + {.#Some js_object} + {try.#Success (<method> js_object)} + + {.#None})] + + [java/lang/Number java/lang/Number::doubleValue] + [StructureValue StructureValue::getValue] + [IntValue IntValue::getValue])) + (case (ffi.check org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object) + {.#Some js_object} + (case (check_int js_object) + {.#Some value} + {try.#Success value} + + {.#None} + (case (check_variant lux_object js_object) + {.#Some value} + {try.#Success value} + + {.#None} + (case (check_tuple lux_object js_object) + {.#Some value} + {try.#Success value} + + {.#None} + (if (ffi.of_boolean (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} + )))) + {.#None}) + ... else + ... (exception.except ..unknown_kind_of_host_object [(:as java/lang/Object js_object)]) + {try.#Success js_object} + ))) + + (def: (ensure_function function) + (-> Any (Maybe org/openjdk/nashorn/api/scripting/JSObject)) + (do maybe.monad + [function (|> function + (:as java/lang/Object) + (ffi.check org/openjdk/nashorn/api/scripting/JSObject))] + (if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction function)) + {.#Some function} + {.#None}))) + ) + + @.js + (as_is)) + +(for @.jvm + (as_is (def: (call_macro inputs lux macro) + (-> (List Code) Lux org/openjdk/nashorn/api/scripting/JSObject (Try (Try [Lux (List Code)]))) + (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} + (|> (array.empty 2) + (: (Array java/lang/Object)) + (array.write! 0 (to_js inputs)) + (array.write! 1 (to_js lux))) + macro)))) + + (exception: (cannot_apply_a_non_function [object java/lang/Object]) + (exception.report + ["Object" (ffi.of_string (java/lang/Object::toString object))])) + + (def: (expander macro inputs lux) + Expander + (case (..ensure_function macro) + {.#Some macro} + (case (call_macro inputs lux macro) + {try.#Success output} + (|> output + (:as java/lang/Object) + lux_object + (: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)))) + ) + + @.js + (def: (expander macro inputs lux) + Expander + {try.#Success ((:as Macro' macro) inputs lux)}) + ) + +(for @.jvm + (as_is (def: (evaluate! interpreter alias input) + (-> javax/script/ScriptEngine unit.ID _.Expression (Try Any)) + (do try.monad + [?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)] + (case ?output + {.#Some output} + (..lux_object output) + + {.#None} + (exception.except ..null_has_no_lux_representation [{.#Some input}])))) + + (def: (execute! interpreter input) + (-> javax/script/ScriptEngine _.Statement (Try Any)) + (do try.monad + [?output (javax/script/ScriptEngine::eval (ffi.as_string (_.code input)) interpreter)] + (in []))) + + (def: (define! interpreter context custom input) + (-> javax/script/ScriptEngine unit.ID (Maybe Text) _.Expression (Try [Text Any _.Statement])) + (let [global (maybe.else (reference.artifact context) + custom) + @global (_.var global)] + (do try.monad + [.let [definition (_.define @global input)] + _ (execute! interpreter definition) + value (evaluate! interpreter context @global)] + (in [global value definition])))) + + (def: host + (IO (Host _.Expression _.Statement)) + (io (let [interpreter (javax/script/ScriptEngineFactory::getScriptEngine + (org/openjdk/nashorn/api/scripting/NashornScriptEngineFactory::new))] + (: (Host _.Expression _.Statement) + (implementation + (def: (evaluate alias [_ input]) (..evaluate! interpreter alias input)) + (def: execute (..execute! interpreter)) + (def: (define context custom [_ input]) (..define! interpreter context custom input)) + + (def: (ingest context content) + (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) + + (def: (re_learn context custom content) + (..execute! interpreter content)) + + (def: (re_load context custom content) + (do try.monad + [_ (..execute! interpreter content)] + (..evaluate! interpreter context (_.var (reference.artifact context)))))))))) + ) + + @.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";. + (try (let [return ("js apply" (function.identity ("js constant" "eval")) [code])] + (if ("js object null?" return) + {.#None} + {.#Some return})))) + + (def: (evaluate! alias input) + (-> unit.ID _.Expression (Try Any)) + (do try.monad + [?output (..eval (_.code input))] + (case ?output + {.#Some output} + (in output) + + {.#None} + (exception.except ..null_has_no_lux_representation [{.#Some input}])))) + + (def: (execute! input) + (-> _.Statement (Try Any)) + (do try.monad + [?output (..eval (_.code input))] + (in []))) + + (def: (define! context custom input) + (-> unit.ID (Maybe Text) _.Expression (Try [Text Any _.Statement])) + (let [global (maybe.else (reference.artifact context) + custom) + @global (_.var global)] + (do try.monad + [.let [definition (_.define @global input)] + _ (..execute! definition) + value (..evaluate! context @global)] + (in [global value definition])))) + + (def: host + (IO (Host _.Expression _.Statement)) + (io (: (Host _.Expression _.Statement) + (implementation + (def: (evaluate alias [_ input]) (..evaluate! alias input)) + (def: execute ..execute!) + (def: (define context custom [_ input]) (..define! context custom input)) + + (def: (ingest context content) + (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) + + (def: (re_learn context custom content) + (..execute! content)) + + (def: (re_load context custom content) + (do try.monad + [_ (..execute! content)] + (..evaluate! context (_.var (reference.artifact context))))))))) + )) (def: (phase_wrapper archive) (-> Archive (runtime.Operation phase.Wrapper)) (do phase.monad [] (in (:as phase.Wrapper - (for [ ... The implementation for @.jvm is technically incorrect. - ... However, the JS compiler runs fast enough on Node to be fully hosted there. - ... And running the JS compiler on the JVM (on top of Nashorn) is impractically slow. - ... This means that in practice, only the @.js implementation matters. - ... And since no cross-language boundary needs to be handled, it's a correct implementation. - @.jvm (|>>) - @.js (|>>)]))))) + (for @.jvm + ... The implementation for @.jvm is technically incorrect. + ... However, the JS compiler runs fast enough on Node to be fully hosted there. + ... And running the JS compiler on the JVM (on top of Nashorn) is impractically slow. + ... This means that in practice, only the @.js implementation matters. + ... And since no cross-language boundary needs to be handled, it's a correct implementation. + (|>>) + + @.js + (|>>)))))) (def: platform (IO (Platform [Register Text] _.Expression _.Statement)) (do io.monad [host ..host] - (in [platform.#&file_system (for [@.jvm (file.async file.default) - @.jvm (file.async file.default) - ... TODO: Handle this in a safer manner. - ... This would crash if the compiler was run on a browser. - @.js (maybe.trusted file.default)]) + (in [platform.#&file_system (for @.jvm (file.async file.default) + @.jvm (file.async file.default) + ... TODO: Handle this in a safer manner. + ... This would crash if the compiler was run on a browser. + @.js (maybe.trusted file.default)) platform.#host host platform.#phase js.generate platform.#runtime runtime.generate @@ -651,40 +654,40 @@ no_inputs))) (_.string ""))))) -(for [@.jvm - (def: (extender phase_wrapper) - (-> phase.Wrapper Extender) - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (do try.monad - [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} - (|> (array.empty 5) - (: (Array java/lang/Object)) - (array.write! 0 name) - (array.write! 1 (:as java/lang/Object (extender phase))) - (array.write! 2 (to_js archive)) - (array.write! 3 (to_js parameters)) - (array.write! 4 (to_js state))) - handler)] - (lux_object (:as java/lang/Object output))))) - - @.js - (def: (extender phase_wrapper handler) - (-> phase.Wrapper Extender) - (:expected handler))]) +(for @.jvm + (def: (extender phase_wrapper) + (-> phase.Wrapper Extender) + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (do try.monad + [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} + (|> (array.empty 5) + (: (Array java/lang/Object)) + (array.write! 0 name) + (array.write! 1 (:as java/lang/Object (extender phase))) + (array.write! 2 (to_js archive)) + (array.write! 3 (to_js parameters)) + (array.write! 4 (to_js state))) + handler)] + (lux_object (:as java/lang/Object output))))) + + @.js + (def: (extender phase_wrapper handler) + (-> phase.Wrapper Extender) + (:expected handler))) (def: (declare_success! _) (-> Any (Async Any)) diff --git a/lux-lua/source/program.lux b/lux-lua/source/program.lux index 6393f6fe1..631b55d9a 100644 --- a/lux-lua/source/program.lux +++ b/lux-lua/source/program.lux @@ -477,13 +477,13 @@ {.#None} (exception.except ..cannot_apply_a_non_function (:as java/lang/Object macro)))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.lua - (def: (expander macro inputs lux) - Expander - {try.#Success ((:as Macro' macro) inputs lux)})])) + @.lua + (def: (expander macro inputs lux) + Expander + {try.#Success ((:as Macro' macro) inputs lux)}))) (with_expansions [<jvm> (as_is (with_expansions [$var_args (_.var "...") $str_rel_to_abs (_.var "_utf8_str_rel_to_abs") @@ -727,46 +727,46 @@ (do try.monad [_ (run! content)] (run! (_.return (_.var (reference.artifact context))))))))]))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - @.lua (as_is (ffi.import: (load [ffi.String] "try" ffi.Function)) - (def: host - (IO (Host _.Expression _.Statement)) - (io (let [run! (: (-> _.Statement (Try Any)) - (function (_ code) - (do try.monad - [lua_function (..load (_.code code))] - (let [output ("lua apply" lua_function)] - {try.#Success (if ("lua object nil?" output) - [] - output)}))))] - (: (Host _.Expression _.Statement) - (implementation - (def: (evaluate! context [_ code]) - (run! (_.return code))) - - (def: execute! run!) - - (def: (define! context custom [_ input]) - (let [global (maybe.else (reference.artifact context) - custom) - @global (_.var global)] - (do try.monad - [.let [definition (_.set (list @global) input)] - _ (run! definition) - value (run! (_.return @global))] - (in [global value definition])))) - - (def: (ingest context content) - (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) - - (def: (re_learn context custom content) - (run! content)) - - (def: (re_load context custom content) - (do try.monad - [_ (run! content)] - (run! (_.return (_.var (reference.artifact context))))))))))))])) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.lua (as_is (ffi.import: (load [ffi.String] "try" ffi.Function)) + (def: host + (IO (Host _.Expression _.Statement)) + (io (let [run! (: (-> _.Statement (Try Any)) + (function (_ code) + (do try.monad + [lua_function (..load (_.code code))] + (let [output ("lua apply" lua_function)] + {try.#Success (if ("lua object nil?" output) + [] + output)}))))] + (: (Host _.Expression _.Statement) + (implementation + (def: (evaluate! context [_ code]) + (run! (_.return code))) + + (def: execute! run!) + + (def: (define! context custom [_ input]) + (let [global (maybe.else (reference.artifact context) + custom) + @global (_.var global)] + (do try.monad + [.let [definition (_.set (list @global) input)] + _ (run! definition) + value (run! (_.return @global))] + (in [global value definition])))) + + (def: (ingest context content) + (|> content (# utf8.codec decoded) try.trusted (:as _.Statement))) + + (def: (re_learn context custom content) + (run! content)) + + (def: (re_load context custom content) + (do try.monad + [_ (run! content)] + (run! (_.return (_.var (reference.artifact context)))))))))))))) (with_expansions [<jvm> (as_is (def: (to_host it) (-> Any java/lang/Object) @@ -813,22 +813,22 @@ maybe.trusted (:as java/lang/Object) ..read)))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.lua - (def: (extender phase_wrapper handler) - (-> phase.Wrapper Extender) - (:expected handler))])) + @.lua + (def: (extender phase_wrapper handler) + (-> phase.Wrapper Extender) + (:expected handler)))) (def: (phase_wrapper archive) (-> Archive (runtime.Operation phase.Wrapper)) (do phase.monad [] (in (:as phase.Wrapper - (for [@.old (..lua_function ..to_host) - @.jvm (..lua_function ..to_host) - @.lua (|>>)]))))) + (for @.old (..lua_function ..to_host) + @.jvm (..lua_function ..to_host) + @.lua (|>>)))))) (with_expansions [<jvm> (def: platform (IO [Baggage (Platform [Register _.Label] _.Expression _.Statement)]) @@ -841,18 +841,18 @@ platform.#runtime runtime.generate platform.#phase_wrapper ..phase_wrapper platform.#write (|>> _.code (# utf8.codec encoded))]])))] - (for [@.old <jvm> - @.jvm <jvm> - @.lua (def: platform - (IO (Platform [Register _.Label] _.Expression _.Statement)) - (do io.monad - [host ..host] - (in [platform.#&file_system (file.async file.default) - platform.#host host - platform.#phase lua.generate - platform.#runtime runtime.generate - platform.#phase_wrapper ..phase_wrapper - platform.#write (|>> _.code (# utf8.codec encoded))])))])) + (for @.old <jvm> + @.jvm <jvm> + @.lua (def: platform + (IO (Platform [Register _.Label] _.Expression _.Statement)) + (do io.monad + [host ..host] + (in [platform.#&file_system (file.async file.default) + platform.#host host + platform.#phase lua.generate + platform.#runtime runtime.generate + platform.#phase_wrapper ..phase_wrapper + platform.#write (|>> _.code (# utf8.codec encoded))]))))) (def: (program context program) (Program _.Expression _.Statement) @@ -872,16 +872,16 @@ (`` (program: [service cli.service] (let [context (context.lua (cli.target service))] (do io.monad - [(~~ (for [@.old [baggage platform] - @.jvm [baggage platform] - @.lua platform])) + [(~~ (for @.old [baggage platform] + @.jvm [baggage platform] + @.lua platform)) ..platform] (exec (do async.monad [_ (/.compiler ..lux_compiler context - (for [@.old (..expander ..to_host baggage) - @.jvm (..expander ..to_host baggage) - @.lua ..expander]) + (for @.old (..expander ..to_host baggage) + @.jvm (..expander ..to_host baggage) + @.lua ..expander) analysis.bundle (io.io platform) generation.bundle @@ -890,9 +890,9 @@ [(type [Register _.Label]) _.Expression _.Statement] - (for [@.old (..extender baggage) - @.jvm (..extender baggage) - @.lua ..extender]) + (for @.old (..extender baggage) + @.jvm (..extender baggage) + @.lua ..extender) service [(packager.package (_.manual "") _.code diff --git a/lux-php/source/program.lux b/lux-php/source/program.lux index 0e2758238..383e89e5d 100644 --- a/lux-php/source/program.lux +++ b/lux-php/source/program.lux @@ -1,68 +1,68 @@ (.using - [lux "*" - [program {"+" program:}] - ["[0]" ffi] - ["[0]" debug] - [abstract - ["[0]" monad {"+" do}]] - [control - [pipe {"+" exec> case>}] - ["[0]" maybe] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - ["[0]" io {"+" IO io}] - [concurrency - ["[0]" promise {"+" Promise}]]] - [data - ["[0]" text ("[1]#[0]" hash) - ["%" format {"+" format}] - [encoding - ["[0]" utf8]]] - [collection - ["[0]" array {"+" Array}]]] - [macro - ["[0]" template]] - [math - [number {"+" hex} - ["n" nat] - ["[0]" i64]]] - ["[0]" world "_" - ["[0]" file] - ["[1]/[0]" program]] - ["@" target - ["_" php]] - [tool - [compiler - [phase {"+" Operation Phase}] - [reference - [variable {"+" Register}]] - [language - [lux - [program {"+" Program}] - [generation {"+" Context Host}] - ["[0]" synthesis] - [analysis - [macro {"+" Expander}]] - [phase - ["[0]" extension {"+" Extender Handler} - ["[1]/[0]" bundle] - ["[0]" analysis "_" - ["[1]" php]] - ["[0]" generation "_" - ["[1]" php]]] - [generation - ["[0]" reference] - ["[0]" php - ["[0]" runtime]]]]]] - [default - ["[0]" platform {"+" Platform}]] - [meta - ["[0]" packager "_" - ["[1]" script]]]]]] - [program - ["/" compositor - ["[1][0]" cli] - ["[1][0]" static]]]) + [lux "*" + [program {"+" program:}] + ["[0]" ffi] + ["[0]" debug] + [abstract + ["[0]" monad {"+" do}]] + [control + [pipe {"+" exec> case>}] + ["[0]" maybe] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + ["[0]" io {"+" IO io}] + [concurrency + ["[0]" promise {"+" Promise}]]] + [data + ["[0]" text ("[1]#[0]" hash) + ["%" format {"+" format}] + [encoding + ["[0]" utf8]]] + [collection + ["[0]" array {"+" Array}]]] + [macro + ["[0]" template]] + [math + [number {"+" hex} + ["n" nat] + ["[0]" i64]]] + ["[0]" world "_" + ["[0]" file] + ["[1]/[0]" program]] + ["@" target + ["_" php]] + [tool + [compiler + [phase {"+" Operation Phase}] + [reference + [variable {"+" Register}]] + [language + [lux + [program {"+" Program}] + [generation {"+" Context Host}] + ["[0]" synthesis] + [analysis + [macro {"+" Expander}]] + [phase + ["[0]" extension {"+" Extender Handler} + ["[1]/[0]" bundle] + ["[0]" analysis "_" + ["[1]" php]] + ["[0]" generation "_" + ["[1]" php]]] + [generation + ["[0]" reference] + ["[0]" php + ["[0]" runtime]]]]]] + [default + ["[0]" platform {"+" Platform}]] + [meta + ["[0]" packager "_" + ["[1]" script]]]]]] + [program + ["/" compositor + ["[1][0]" cli] + ["[1][0]" static]]]) (ffi.import: java/lang/String) @@ -513,41 +513,41 @@ [(runtime.lux//program_args _.command_line_arguments) _.null]))) -(for [@.old - (def: extender - Extender - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (do try.monad - [handler (try.from_maybe (..ensure_macro handler)) - #let [to_php (: (-> Any php/runtime/Memory) - (|>> (:as (Array java/lang/Object)) lux_structure (:as php/runtime/Memory)))] - output (php/runtime/lang/Closure::call ..default_environment - (|> (ffi.array php/runtime/Memory 6) - (ffi.write! 0 handler) - (ffi.write! 1 (php/runtime/memory/StringMemory::new name)) - (ffi.write! 2 (to_php phase)) - (ffi.write! 3 (to_php archive)) - (ffi.write! 4 (to_php parameters)) - (ffi.write! 5 (to_php state))) - (:as php/runtime/lang/Closure - (php/runtime/memory/ObjectMemory::value handler)))] - (..read output)))) - - @.php - (def: (extender handler) - Extender - (:expected handler))]) +(for @.old + (def: extender + Extender + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (do try.monad + [handler (try.from_maybe (..ensure_macro handler)) + #let [to_php (: (-> Any php/runtime/Memory) + (|>> (:as (Array java/lang/Object)) lux_structure (:as php/runtime/Memory)))] + output (php/runtime/lang/Closure::call ..default_environment + (|> (ffi.array php/runtime/Memory 6) + (ffi.write! 0 handler) + (ffi.write! 1 (php/runtime/memory/StringMemory::new name)) + (ffi.write! 2 (to_php phase)) + (ffi.write! 3 (to_php archive)) + (ffi.write! 4 (to_php parameters)) + (ffi.write! 5 (to_php state))) + (:as php/runtime/lang/Closure + (php/runtime/memory/ObjectMemory::value handler)))] + (..read output)))) + + @.php + (def: (extender handler) + Extender + (:expected handler))) (def: (declare_success! _) (-> Any (Promise Any)) diff --git a/lux-python/source/program.lux b/lux-python/source/program.lux index 66adcaa27..e784a834e 100644 --- a/lux-python/source/program.lux +++ b/lux-python/source/program.lux @@ -340,9 +340,9 @@ )) (:as org/python/core/PyObject it)))) )] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - @.python (as_is)])) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.python (as_is))) (with_expansions [<jvm> (as_is (def: (call_macro inputs lux macro) (-> (List Code) Lux org/python/core/PyFunction (Try (Try [Lux (List Code)]))) @@ -380,13 +380,13 @@ {.#None} (exception.except ..cannot_apply_a_non_function [(:as java/lang/Object macro)]))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.python - (def: (expander macro inputs lux) - Expander - {try.#Success ((:as Macro' macro) inputs lux)})])) + @.python + (def: (expander macro inputs lux) + Expander + {try.#Success ((:as Macro' macro) inputs lux)}))) (with_expansions [<jvm> (def: host (IO (Host (_.Expression Any) (_.Statement Any))) @@ -433,47 +433,47 @@ (do try.monad [_ (execute! content)] (evaluate! context [{.#None} (_.var (reference.artifact context))]))))))))] - (for [@.old <jvm> - @.jvm <jvm> - - @.python - (as_is (import: (dict [] ffi.Dict)) - (import: (eval [ffi.String ffi.Dict] "try" Any)) - - (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)))))))))))])) + (for @.old <jvm> + @.jvm <jvm> + + @.python + (as_is (import: (dict [] ffi.Dict)) + (import: (eval [ffi.String ffi.Dict] "try" Any)) + + (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))))))))))))) (with_expansions [<jvm> (as_is (def: (extender phase_wrapper) (-> phase.Wrapper Extender) @@ -499,13 +499,13 @@ (ffi.write! 4 (..to_host state))) handler)] (..read output)))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.python - (def: (extender phase_wrapper handler) - (-> phase.Wrapper Extender) - (:expected handler))])) + @.python + (def: (extender phase_wrapper handler) + (-> phase.Wrapper Extender) + (:expected handler)))) (def: (phase_wrapper archive) (-> Archive (runtime.Operation phase.Wrapper)) diff --git a/lux-r/source/program.lux b/lux-r/source/program.lux index a9908b445..570a52b4e 100644 --- a/lux-r/source/program.lux +++ b/lux-r/source/program.lux @@ -1,72 +1,72 @@ (.using - [lux "*" - [program {"+" program:}] - ["[0]" ffi] - ["[0]" debug] - [abstract - ["[0]" monad {"+" do}]] - [control - [pipe {"+" exec> case> new>}] - ["[0]" maybe] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - ["[0]" io {"+" IO io}] - [concurrency - ["[0]" promise {"+" Promise}]] - [parser - ["<[0]>" code]]] - [data - ["[0]" text ("[1]#[0]" hash) - ["%" format {"+" format}] - [encoding - ["[0]" utf8]]] - [collection - ["[0]" array {"+" Array}]]] - ["[0]" macro - [syntax {"+" syntax:}] - ["[0]" template] - ["[0]" code]] - [math - [number {"+" hex} - ["n" nat] - ["[0]" i64]]] - ["[0]" world "_" - ["[0]" file] - ["[1]/[0]" program]] - ["@" target - ["_" r]] - [tool - [compiler - [phase {"+" Operation Phase}] - [reference - [variable {"+" Register}]] - [language - [lux - [program {"+" Program}] - [generation {"+" Context Host}] - ["[0]" synthesis] - [analysis - [macro {"+" Expander}]] - [phase - ["[0]" extension {"+" Extender Handler} - ["[1]/[0]" bundle] - ["[0]" analysis "_" - ["[1]" r]] - ["[0]" generation "_" - ["[1]" r]]] - [generation - ["[0]" reference] - ["[0]" r - ["[0]" runtime]]]]]] - [default - ["[0]" platform {"+" Platform}]] - [meta - ["[0]" packager "_" - ["[1]" script]]]]]] - [program - ["/" compositor - ["[1][0]" cli] - ["[1][0]" static]]]) + [lux "*" + [program {"+" program:}] + ["[0]" ffi] + ["[0]" debug] + [abstract + ["[0]" monad {"+" do}]] + [control + [pipe {"+" exec> case> new>}] + ["[0]" maybe] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + ["[0]" io {"+" IO io}] + [concurrency + ["[0]" promise {"+" Promise}]] + [parser + ["<[0]>" code]]] + [data + ["[0]" text ("[1]#[0]" hash) + ["%" format {"+" format}] + [encoding + ["[0]" utf8]]] + [collection + ["[0]" array {"+" Array}]]] + ["[0]" macro + [syntax {"+" syntax:}] + ["[0]" template] + ["[0]" code]] + [math + [number {"+" hex} + ["n" nat] + ["[0]" i64]]] + ["[0]" world "_" + ["[0]" file] + ["[1]/[0]" program]] + ["@" target + ["_" r]] + [tool + [compiler + [phase {"+" Operation Phase}] + [reference + [variable {"+" Register}]] + [language + [lux + [program {"+" Program}] + [generation {"+" Context Host}] + ["[0]" synthesis] + [analysis + [macro {"+" Expander}]] + [phase + ["[0]" extension {"+" Extender Handler} + ["[1]/[0]" bundle] + ["[0]" analysis "_" + ["[1]" r]] + ["[0]" generation "_" + ["[1]" r]]] + [generation + ["[0]" reference] + ["[0]" r + ["[0]" runtime]]]]]] + [default + ["[0]" platform {"+" Platform}]] + [meta + ["[0]" packager "_" + ["[1]" script]]]]]] + [program + ["/" compositor + ["[1][0]" cli] + ["[1][0]" static]]]) (ffi.import: java/lang/String) @@ -552,29 +552,29 @@ (Program _.Expression _.Expression) (_.apply/2 program [(runtime.lux::program_args (_.commandArgs/0 [])) _.null])) -(for [@.old - (def: extender - Extender - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (exec - ("lux io log" "TODO: Extender") - {try.#Failure "TODO: Extender"}))) - - @.r - (def: (extender handler) - Extender - (:expected handler))]) +(for @.old + (def: extender + Extender + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (exec + ("lux io log" "TODO: Extender") + {try.#Failure "TODO: Extender"}))) + + @.r + (def: (extender handler) + Extender + (:expected handler))) (def: (declare_success! _) (-> Any (Promise Any)) diff --git a/lux-ruby/source/program.lux b/lux-ruby/source/program.lux index bd3f1763e..30a276d58 100644 --- a/lux-ruby/source/program.lux +++ b/lux-ruby/source/program.lux @@ -759,189 +759,189 @@ [_ (run! content)] (run! (_.global (reference.artifact context)))))))))) -(for [@.jvm (as_is (exception: .public (invaid_phase_application [partial_application (List Any) - arity (List Any)]) - (exception.report - ["Partial Application" (%.nat (list.size partial_application))] - ["Arity" (%.nat (list.size arity))])) - - (def: proc_type - org/jruby/runtime/Block$Type - (|> (org/jruby/runtime/Block::NULL_BLOCK) - (org/jruby/runtime/Block::type))) - - (def: phase_block_signature - org/jruby/runtime/Signature - (org/jruby/runtime/Signature::THREE_ARGUMENTS)) - - (def: dummy_static_scope - org/jruby/parser/StaticScope - (|> (org/jruby/parser/StaticScopeFactory::new (!ruby_runtime)) - (org/jruby/parser/StaticScopeFactory::getDummyScope))) - - (def: phase_block_body - org/jruby/runtime/BlockBody - (<| (ffi.:as org/jruby/runtime/BlockBody) - (ffi.object [] org/jruby/runtime/BlockBody [] - [org/jruby/runtime/Signature ..phase_block_signature] - ... Methods - (org/jruby/runtime/BlockBody - [] (getFile this []) - java/lang/String - (ffi.as_string "YOLO")) - - (org/jruby/runtime/BlockBody - [] (getLine this []) - int - (ffi.as_int (hex "+ABC,123"))) - - (org/jruby/runtime/BlockBody - [] (getStaticScope this []) - org/jruby/parser/StaticScope - ..dummy_static_scope) - - (org/jruby/runtime/BlockBody - [] (setStaticScope self [_ org/jruby/parser/StaticScope]) - void - []) - - (org/jruby/runtime/BlockBody - [] (doYield self [_ org/jruby/runtime/ThreadContext - _ org/jruby/runtime/Block - _ org/jruby/runtime/builtin/IRubyObject]) - org/jruby/runtime/builtin/IRubyObject - (undefined)) - - (org/jruby/runtime/BlockBody - [] (doYield self [_ org/jruby/runtime/ThreadContext - _ org/jruby/runtime/Block - _ [org/jruby/runtime/builtin/IRubyObject] - _ org/jruby/runtime/builtin/IRubyObject]) - org/jruby/runtime/builtin/IRubyObject - (undefined)) - ))) - - (def: (host_phase partial_application phase) - (All (_ s i o) - (-> (List Any) (Phase [extension.Bundle s] i o) - org/jruby/RubyProc)) - (let [block (ffi.object [] org/jruby/runtime/Block [] - [org/jruby/runtime/BlockBody ..phase_block_body] - ... Methods - (org/jruby/runtime/Block - [] (call this [_thread_context org/jruby/runtime/ThreadContext - inputs [org/jruby/runtime/builtin/IRubyObject] - _block org/jruby/runtime/Block]) - org/jruby/runtime/builtin/IRubyObject - (<| try.trusted - (do [! try.monad] - [inputs (|> inputs - (array.list {.#None}) - (monad.each ! (|>> (ffi.:as java/lang/Object) ..read)))]) - (case inputs - ... It seems that org/jruby/runtime/Block::call can misbehave when getting called with a Lux state value. - (^ (list info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host)) - (case partial_application - (^ (list partial/0 partial/1)) - (in (..to_host ((:as (-> Any Any Any Any) phase) - partial/0 - partial/1 - [info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host]))) - - _ - (exception.except ..invaid_phase_application [partial_application inputs])) - - (^ (list)) - {try.#Success (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) - (host_phase partial_application phase))} - - (^ (list input/0)) - (case partial_application - (^ (list)) - (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) - (host_phase (list input/0) phase))) - - (^ (list partial/0)) - (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) - (host_phase (list partial/0 input/0) phase))) - - (^ (list partial/0 partial/1)) - (in (..to_host ((:as (-> Any Any Any Any) phase) - partial/0 - partial/1 - input/0))) - - _ - (exception.except ..invaid_phase_application [partial_application inputs])) - - (^ (list input/0 input/1)) - (case partial_application - (^ (list)) - (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) - (host_phase (list input/0 input/1) phase))) - - (^ (list partial/0)) - (in (..to_host ((:as (-> Any Any Any Any) phase) - partial/0 - input/0 - input/1))) - - _ - (exception.except ..invaid_phase_application [partial_application inputs])) - - (^ (list input/0 input/1 input/2)) - (case partial_application - (^ (list)) - (in (..to_host ((:as (-> Any Any Any Any) phase) - input/0 - input/1 - input/2))) - - _ - (exception.except ..invaid_phase_application [partial_application inputs])) - - _ - (exception.except ..invaid_phase_application [partial_application inputs])))))] - (org/jruby/RubyProc::newProc (!ruby_runtime) block ..proc_type))) - - (def: (extender phase_wrapper) - (-> phase.Wrapper Extender) - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (do try.monad - [handler (try.of_maybe (..macro! handler)) - output (org/jruby/RubyProc::call (!ruby_thread_context) - (|> (ffi.array org/jruby/runtime/builtin/IRubyObject 5) - (ffi.write! 0 (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) - (org/jruby/RubyString::newInternalFromJavaExternal (!ruby_runtime) (ffi.as_string name)))) - (ffi.write! 1 (:as org/jruby/runtime/builtin/IRubyObject (phase_wrapper phase))) - (ffi.write! 2 (..to_host archive)) - (ffi.write! 3 (..to_host parameters)) - (ffi.write! 4 (..to_host state))) - handler)] - (..read (ffi.:as java/lang/Object output)))))) - - @.ruby - (def: (extender phase_wrapper handler) - (-> phase.Wrapper Extender) - (:expected handler))]) +(for @.jvm (as_is (exception: .public (invaid_phase_application [partial_application (List Any) + arity (List Any)]) + (exception.report + ["Partial Application" (%.nat (list.size partial_application))] + ["Arity" (%.nat (list.size arity))])) + + (def: proc_type + org/jruby/runtime/Block$Type + (|> (org/jruby/runtime/Block::NULL_BLOCK) + (org/jruby/runtime/Block::type))) + + (def: phase_block_signature + org/jruby/runtime/Signature + (org/jruby/runtime/Signature::THREE_ARGUMENTS)) + + (def: dummy_static_scope + org/jruby/parser/StaticScope + (|> (org/jruby/parser/StaticScopeFactory::new (!ruby_runtime)) + (org/jruby/parser/StaticScopeFactory::getDummyScope))) + + (def: phase_block_body + org/jruby/runtime/BlockBody + (<| (ffi.:as org/jruby/runtime/BlockBody) + (ffi.object [] org/jruby/runtime/BlockBody [] + [org/jruby/runtime/Signature ..phase_block_signature] + ... Methods + (org/jruby/runtime/BlockBody + [] (getFile this []) + java/lang/String + (ffi.as_string "YOLO")) + + (org/jruby/runtime/BlockBody + [] (getLine this []) + int + (ffi.as_int (hex "+ABC,123"))) + + (org/jruby/runtime/BlockBody + [] (getStaticScope this []) + org/jruby/parser/StaticScope + ..dummy_static_scope) + + (org/jruby/runtime/BlockBody + [] (setStaticScope self [_ org/jruby/parser/StaticScope]) + void + []) + + (org/jruby/runtime/BlockBody + [] (doYield self [_ org/jruby/runtime/ThreadContext + _ org/jruby/runtime/Block + _ org/jruby/runtime/builtin/IRubyObject]) + org/jruby/runtime/builtin/IRubyObject + (undefined)) + + (org/jruby/runtime/BlockBody + [] (doYield self [_ org/jruby/runtime/ThreadContext + _ org/jruby/runtime/Block + _ [org/jruby/runtime/builtin/IRubyObject] + _ org/jruby/runtime/builtin/IRubyObject]) + org/jruby/runtime/builtin/IRubyObject + (undefined)) + ))) + + (def: (host_phase partial_application phase) + (All (_ s i o) + (-> (List Any) (Phase [extension.Bundle s] i o) + org/jruby/RubyProc)) + (let [block (ffi.object [] org/jruby/runtime/Block [] + [org/jruby/runtime/BlockBody ..phase_block_body] + ... Methods + (org/jruby/runtime/Block + [] (call this [_thread_context org/jruby/runtime/ThreadContext + inputs [org/jruby/runtime/builtin/IRubyObject] + _block org/jruby/runtime/Block]) + org/jruby/runtime/builtin/IRubyObject + (<| try.trusted + (do [! try.monad] + [inputs (|> inputs + (array.list {.#None}) + (monad.each ! (|>> (ffi.:as java/lang/Object) ..read)))]) + (case inputs + ... It seems that org/jruby/runtime/Block::call can misbehave when getting called with a Lux state value. + (^ (list info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host)) + (case partial_application + (^ (list partial/0 partial/1)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + partial/0 + partial/1 + [info source location current_module modules scopes type_context expected seed scope_type_vars extensions eval host]))) + + _ + (exception.except ..invaid_phase_application [partial_application inputs])) + + (^ (list)) + {try.#Success (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) + (host_phase partial_application phase))} + + (^ (list input/0)) + (case partial_application + (^ (list)) + (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) + (host_phase (list input/0) phase))) + + (^ (list partial/0)) + (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) + (host_phase (list partial/0 input/0) phase))) + + (^ (list partial/0 partial/1)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + partial/0 + partial/1 + input/0))) + + _ + (exception.except ..invaid_phase_application [partial_application inputs])) + + (^ (list input/0 input/1)) + (case partial_application + (^ (list)) + (in (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) + (host_phase (list input/0 input/1) phase))) + + (^ (list partial/0)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + partial/0 + input/0 + input/1))) + + _ + (exception.except ..invaid_phase_application [partial_application inputs])) + + (^ (list input/0 input/1 input/2)) + (case partial_application + (^ (list)) + (in (..to_host ((:as (-> Any Any Any Any) phase) + input/0 + input/1 + input/2))) + + _ + (exception.except ..invaid_phase_application [partial_application inputs])) + + _ + (exception.except ..invaid_phase_application [partial_application inputs])))))] + (org/jruby/RubyProc::newProc (!ruby_runtime) block ..proc_type))) + + (def: (extender phase_wrapper) + (-> phase.Wrapper Extender) + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (do try.monad + [handler (try.of_maybe (..macro! handler)) + output (org/jruby/RubyProc::call (!ruby_thread_context) + (|> (ffi.array org/jruby/runtime/builtin/IRubyObject 5) + (ffi.write! 0 (<| (ffi.:as org/jruby/runtime/builtin/IRubyObject) + (org/jruby/RubyString::newInternalFromJavaExternal (!ruby_runtime) (ffi.as_string name)))) + (ffi.write! 1 (:as org/jruby/runtime/builtin/IRubyObject (phase_wrapper phase))) + (ffi.write! 2 (..to_host archive)) + (ffi.write! 3 (..to_host parameters)) + (ffi.write! 4 (..to_host state))) + handler)] + (..read (ffi.:as java/lang/Object output)))))) + + @.ruby + (def: (extender phase_wrapper handler) + (-> phase.Wrapper Extender) + (:expected handler))) (def: (phase_wrapper archive) (-> Archive (runtime.Operation phase.Wrapper)) (<| phase#in (:as phase.Wrapper) - (for [@.jvm (..host_phase (list)) - @.ruby (|>>)]))) + (for @.jvm (..host_phase (list)) + @.ruby (|>>)))) (def: platform (IO (Platform Register _.Expression _.Statement)) diff --git a/lux-scheme/source/program.lux b/lux-scheme/source/program.lux index 9ffda365a..e04ba5ac2 100644 --- a/lux-scheme/source/program.lux +++ b/lux-scheme/source/program.lux @@ -1,69 +1,69 @@ (.using - [lux "*" - [program {"+" program:}] - ["[0]" ffi] - ["[0]" debug] - [abstract - ["[0]" monad {"+" do}]] - [control - [pipe {"+" exec> case> new>}] - ["[0]" maybe] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - ["[0]" io {"+" IO io}] - [concurrency - ["[0]" promise {"+" Promise}]]] - [data - ["[0]" text ("[1]#[0]" hash) - ["%" format {"+" format}] - ["[0]" encoding]] - [collection - ["[0]" array {"+" Array}]]] - [macro - ["[0]" template]] - [math - [number {"+" hex} - ["n" nat] - ["[0]" i64]]] - [time - ["[0]" instant]] - ["[0]" world "_" - ["[0]" file] - ["[1]/[0]" program]] - ["@" target - ["_" scheme]] - [tool - [compiler - [phase {"+" Operation Phase}] - [reference - [variable {"+" Register}]] - [language - [lux - [program {"+" Program}] - [generation {"+" Context Host}] - ["[0]" synthesis] - [analysis - [macro {"+" Expander}]] - [phase - ["[0]" extension {"+" Extender Handler} - ["[1]/[0]" bundle] - ["[0]" analysis "_" - ["[1]" scheme]] - ["[0]" generation "_" - ["[1]" scheme]]] - [generation - ["[0]" reference] - ["[0]" scheme - ["[0]" runtime]]]]]] - [default - ["[0]" platform {"+" Platform}]] - [meta - ["[0]" packager "_" - ["[1]" scheme]]]]]] - [program - ["/" compositor - ["[1][0]" cli] - ["[1][0]" static]]]) + [lux "*" + [program {"+" program:}] + ["[0]" ffi] + ["[0]" debug] + [abstract + ["[0]" monad {"+" do}]] + [control + [pipe {"+" exec> case> new>}] + ["[0]" maybe] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + ["[0]" io {"+" IO io}] + [concurrency + ["[0]" promise {"+" Promise}]]] + [data + ["[0]" text ("[1]#[0]" hash) + ["%" format {"+" format}] + ["[0]" encoding]] + [collection + ["[0]" array {"+" Array}]]] + [macro + ["[0]" template]] + [math + [number {"+" hex} + ["n" nat] + ["[0]" i64]]] + [time + ["[0]" instant]] + ["[0]" world "_" + ["[0]" file] + ["[1]/[0]" program]] + ["@" target + ["_" scheme]] + [tool + [compiler + [phase {"+" Operation Phase}] + [reference + [variable {"+" Register}]] + [language + [lux + [program {"+" Program}] + [generation {"+" Context Host}] + ["[0]" synthesis] + [analysis + [macro {"+" Expander}]] + [phase + ["[0]" extension {"+" Extender Handler} + ["[1]/[0]" bundle] + ["[0]" analysis "_" + ["[1]" scheme]] + ["[0]" generation "_" + ["[1]" scheme]]] + [generation + ["[0]" reference] + ["[0]" scheme + ["[0]" runtime]]]]]] + [default + ["[0]" platform {"+" Platform}]] + [meta + ["[0]" packager "_" + ["[1]" scheme]]]]]] + [program + ["/" compositor + ["[1][0]" cli] + ["[1][0]" static]]]) (ffi.import: java/lang/Boolean) (ffi.import: java/lang/String) @@ -414,35 +414,35 @@ (runtime.lux//program_args _.nil) _.nil)) -(for [@.old - (def: extender - Extender - ... TODO: Stop relying on coercions ASAP. - (<| (:as Extender) - (function (@self handler)) - (:as Handler) - (function (@self name phase)) - (:as Phase) - (function (@self archive parameters)) - (:as Operation) - (function (@self state)) - (:as Try) - try.trusted - (:as Try) - (do try.monad - [handler (try.from_maybe (..ensure_macro (:as Macro handler))) - output (gnu/mapping/Procedure::applyN (array.from_list (list (lux_value (:as java/lang/Object name)) - (lux_value (:as java/lang/Object phase)) - (lux_value (:as java/lang/Object archive)) - (lux_value (:as java/lang/Object parameters)) - (lux_value (:as java/lang/Object state)))) - handler)] - (..read output)))) - - @.scheme - (def: (extender handler) - Extender - (:expected handler))]) +(for @.old + (def: extender + Extender + ... TODO: Stop relying on coercions ASAP. + (<| (:as Extender) + (function (@self handler)) + (:as Handler) + (function (@self name phase)) + (:as Phase) + (function (@self archive parameters)) + (:as Operation) + (function (@self state)) + (:as Try) + try.trusted + (:as Try) + (do try.monad + [handler (try.from_maybe (..ensure_macro (:as Macro handler))) + output (gnu/mapping/Procedure::applyN (array.from_list (list (lux_value (:as java/lang/Object name)) + (lux_value (:as java/lang/Object phase)) + (lux_value (:as java/lang/Object archive)) + (lux_value (:as java/lang/Object parameters)) + (lux_value (:as java/lang/Object state)))) + handler)] + (..read output)))) + + @.scheme + (def: (extender handler) + Extender + (:expected handler))) (def: (declare_success! _) (-> Any (Promise Any)) diff --git a/stdlib/source/documentation/lux.lux b/stdlib/source/documentation/lux.lux index 64241e5ff..efa13a913 100644 --- a/stdlib/source/documentation/lux.lux +++ b/stdlib/source/documentation/lux.lux @@ -853,8 +853,8 @@ [(def: js "JavaScript") - (for ["JVM" (do jvm stuff) - js (do js stuff)] + (for "JVM" (do jvm stuff) + js (do js stuff) (do default stuff))]) (documentation: /.`` diff --git a/stdlib/source/documentation/lux/extension.lux b/stdlib/source/documentation/lux/extension.lux index bda9aaa7b..f2a0dca26 100644 --- a/stdlib/source/documentation/lux/extension.lux +++ b/stdlib/source/documentation/lux/extension.lux @@ -1,29 +1,29 @@ (.using - [library - [lux "*" - ["$" documentation {"+" documentation:}] - ["[0]" debug] - [control - ["<>" parser - ["<[0]>" code]]] - [data - [text - ["%" format {"+" format}]] - [collection - ["[0]" sequence]]] - [macro - ["[0]" template]] - ["@" target - ["[0]" jvm]] - [tool - [compiler - ["[0]" phase] - [language - [lux - [phase - ["[0]" directive]]]]]]]] - [\\library - ["[0]" /]]) + [library + [lux "*" + ["$" documentation {"+" documentation:}] + ["[0]" debug] + [control + ["<>" parser + ["<[0]>" code]]] + [data + [text + ["%" format {"+" format}]] + [collection + ["[0]" sequence]]] + [macro + ["[0]" template]] + ["@" target + ["[0]" jvm]] + [tool + [compiler + ["[0]" phase] + [language + [lux + [phase + ["[0]" directive]]]]]]]] + [\\library + ["[0]" /]]) (documentation: /.analysis: "Mechanism for defining extensions to Lux's analysis/type-checking infrastructure." @@ -38,10 +38,10 @@ (documentation: /.generation: "" [(generation: ("my generation" self phase archive [pass_through <synthesis>.any]) - (for [@.jvm - (# phase.monad each (|>> {jvm.#Embedded} - sequence.sequence) - (phase archive pass_through))] + (for @.jvm + (# phase.monad each (|>> {jvm.#Embedded} + sequence.sequence) + (phase archive pass_through)) (phase archive pass_through)))]) (documentation: /.directive: diff --git a/stdlib/source/documentation/lux/world/console.lux b/stdlib/source/documentation/lux/world/console.lux index c091e6d36..63c9c60f5 100644 --- a/stdlib/source/documentation/lux/world/console.lux +++ b/stdlib/source/documentation/lux/world/console.lux @@ -38,8 +38,8 @@ ..Mock ..mock ($.default /.async) - (~~ (for [@.jvm (~~ (as_is ($.default /.cannot_open) - ($.default /.cannot_close) - ($.default /.default)))] + (~~ (for @.jvm (~~ (as_is ($.default /.cannot_open) + ($.default /.cannot_close) + ($.default /.default))) (~~ (as_is))))] [])))) diff --git a/stdlib/source/documentation/lux/world/file.lux b/stdlib/source/documentation/lux/world/file.lux index e2f203abe..c9f9168a1 100644 --- a/stdlib/source/documentation/lux/world/file.lux +++ b/stdlib/source/documentation/lux/world/file.lux @@ -72,10 +72,10 @@ ($.default /.cannot_make_directory) ($.default /.cannot_find_directory) ($.default /.cannot_read_all_data) - (~~ (for [@.jvm (~~ (as_is ($.default /.cannot_modify_file) - ($.default /.default))) - @.js (~~ (as_is ($.default /.default))) - @.python (~~ (as_is ($.default /.default))) - @.ruby (~~ (as_is ($.default /.default)))] + (~~ (for @.jvm (~~ (as_is ($.default /.cannot_modify_file) + ($.default /.default))) + @.js (~~ (as_is ($.default /.default))) + @.python (~~ (as_is ($.default /.default))) + @.ruby (~~ (as_is ($.default /.default))) (~~ (as_is))))] [/watch.documentation])))) diff --git a/stdlib/source/documentation/lux/world/file/watch.lux b/stdlib/source/documentation/lux/world/file/watch.lux index 14b9faa0a..3db866343 100644 --- a/stdlib/source/documentation/lux/world/file/watch.lux +++ b/stdlib/source/documentation/lux/world/file/watch.lux @@ -34,8 +34,8 @@ \n "Must be given a path separator for the file-system.") [(mock separator)]) -(for [@.jvm (as_is (documentation: /.default - "The default watcher for the default file-system."))] +(for @.jvm (as_is (documentation: /.default + "The default watcher for the default file-system.")) (as_is)) (.def: .public documentation @@ -56,6 +56,6 @@ ($.default /.all) ($.default /.not_being_watched) ($.default /.cannot_poll_a_non_existent_directory) - (~~ (for [@.jvm (~~ (as_is ..default))] + (~~ (for @.jvm (~~ (as_is ..default)) (~~ (as_is))))] [])))) diff --git a/stdlib/source/documentation/lux/world/net/http/client.lux b/stdlib/source/documentation/lux/world/net/http/client.lux index a11e8a0bb..17912d11e 100644 --- a/stdlib/source/documentation/lux/world/net/http/client.lux +++ b/stdlib/source/documentation/lux/world/net/http/client.lux @@ -48,6 +48,6 @@ ..trace ($.default /.async) ($.default /.headers) - (~~ (for [@.jvm (~~ (as_is ($.default /.default)))] + (~~ (for @.jvm (~~ (as_is ($.default /.default))) (~~ (as_is))))] [])))) diff --git a/stdlib/source/documentation/lux/world/shell.lux b/stdlib/source/documentation/lux/world/shell.lux index 0a39e0c6a..b1b8a1de5 100644 --- a/stdlib/source/documentation/lux/world/shell.lux +++ b/stdlib/source/documentation/lux/world/shell.lux @@ -50,7 +50,7 @@ ($.default /.normal) ($.default /.error) ($.default /.async) - (~~ (for [@.jvm (~~ (as_is ($.default /.no_more_output) - ($.default /.default)))] + (~~ (for @.jvm (~~ (as_is ($.default /.no_more_output) + ($.default /.default))) (~~ (as_is))))] [])))) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 09f0a9e4c..6120a52be 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -2584,6 +2584,17 @@ {#None} {#Some [tokens (list)]})) +(def:' .private (maybeP itP tokens) + (All (_ a) + (-> (Parser a) + (Parser (Maybe a)))) + (case (itP tokens) + {#Some [tokens it]} + {#Some [tokens {#Some it}]} + + {#None} + {#Some [tokens {#None}]})) + (def:' .private (tupleP itP tokens) (All (_ a) (-> (Parser a) (Parser a))) @@ -4882,52 +4893,41 @@ (target_pick target options' default))))) (macro: .public (for tokens) - (do meta_monad - [target ..target] - (case tokens - (^ (list [_ {#Tuple options}])) - (case (pairs options) - {#Some options} - (target_pick target options {#None}) - - {#None} - (failure (..wrong_syntax_error (symbol ..for)))) - - (^ (list [_ {#Tuple options}] default)) - (case (pairs options) - {#Some options} - (target_pick target options {#Some default}) - - {#None} - (failure (..wrong_syntax_error (symbol ..for)))) + (case (..parsed (..andP (..someP (..andP ..anyP ..anyP)) + (..maybeP ..anyP)) + tokens) + {.#Some [options default]} + (do meta_monad + [target ..target] + (target_pick target options default)) - _ - (failure (..wrong_syntax_error (symbol ..for)))))) + {.#None} + (failure (..wrong_syntax_error (symbol ..for))))) ... TODO: Delete "scope_type_vars" (including the #scope_type_vars Lux state) and ":parameter" ASAP. -(for ["{old}" (as_is (def: (scope_type_vars state) - (Meta (List Nat)) - (case state - [..#info info ..#source source ..#current_module _ ..#modules modules - ..#scopes scopes ..#type_context types ..#host host - ..#seed seed ..#expected expected ..#location location ..#extensions extensions - ..#scope_type_vars scope_type_vars ..#eval _eval] - {#Right [state scope_type_vars]})) - - (macro: .public (:parameter tokens) - (case tokens - (^ (list [_ {#Nat idx}])) - (do meta_monad - [stvs ..scope_type_vars] - (case (..item idx (list#reversed stvs)) - {#Some var_id} - (in (list (` {.#Ex (~ (nat$ var_id))}))) - - {#None} - (failure (text#composite "Indexed-type does not exist: " (nat#encoded idx))))) +(for "{old}" (as_is (def: (scope_type_vars state) + (Meta (List Nat)) + (case state + [..#info info ..#source source ..#current_module _ ..#modules modules + ..#scopes scopes ..#type_context types ..#host host + ..#seed seed ..#expected expected ..#location location ..#extensions extensions + ..#scope_type_vars scope_type_vars ..#eval _eval] + {#Right [state scope_type_vars]})) + + (macro: .public (:parameter tokens) + (case tokens + (^ (list [_ {#Nat idx}])) + (do meta_monad + [stvs ..scope_type_vars] + (case (..item idx (list#reversed stvs)) + {#Some var_id} + (in (list (` {.#Ex (~ (nat$ var_id))}))) - _ - (failure (..wrong_syntax_error (symbol ..$))))))] + {#None} + (failure (text#composite "Indexed-type does not exist: " (nat#encoded idx))))) + + _ + (failure (..wrong_syntax_error (symbol ..$)))))) (as_is)) (macro: .public (using _imports) @@ -4946,13 +4946,14 @@ =module (` ("lux def module" (~ =imports)))] g!_ (..generated_symbol "")] (in {#Item =module - (for [... TODO: Remove this hack once Jython is no longer being used as the Python interpreter. - ... Without it, I get this strange error - ... {library/lux/tool/compiler/language/lux/generation.no_buffer_for_saving_code} - ... Artifact ID: 0 - ... Which only ever happens for the Python compiler. - "Python" (list& (` ("lux def" (~ g!_) [] #0)) - =refers)] + (for "Python" + ... TODO: Remove this hack once Jython is no longer being used as the Python interpreter. + ... Without it, I get this strange error + ... {library/lux/tool/compiler/language/lux/generation.no_buffer_for_saving_code} + ... Artifact ID: 0 + ... Which only ever happens for the Python compiler. + (list& (` ("lux def" (~ g!_) [] #0)) + =refers) =refers)}))) (def: (embedded_expansions code) diff --git a/stdlib/source/library/lux/abstract/apply.lux b/stdlib/source/library/lux/abstract/apply.lux index a7cc3d764..6a509bb0a 100644 --- a/stdlib/source/library/lux/abstract/apply.lux +++ b/stdlib/source/library/lux/abstract/apply.lux @@ -26,10 +26,10 @@ (def: (on fgx fgf) ... TODO: Switch from this version to the one below (in comments) ASAP. - (for [@.old (let [fgf' (# f_apply on - fgf - (# f_monad in (function (_ gf gx) (# g_apply on gx gf))))] - (:expected (# f_apply on (:expected fgx) (:expected fgf'))))] + (for @.old (let [fgf' (# f_apply on + fgf + (# f_monad in (function (_ gf gx) (# g_apply on gx gf))))] + (:expected (# f_apply on (:expected fgx) (:expected fgf')))) (let [fgf' (# f_apply on fgf (# f_monad in (function (_ gf gx) (# g_apply on gx gf))))] diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 5685495a2..5ce90157e 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -20,57 +20,57 @@ (new [a]) (get [] "io" a) (compareAndSet [a a] boolean)]))] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (as_is))) -(with_expansions [<new> (for [@.js "js array new" - @.python "python array new" - @.lua "lua array new" - @.ruby "ruby array new" - @.php "php array new" - @.scheme "scheme array new"] +(with_expansions [<new> (for @.js "js array new" + @.python "python array new" + @.lua "lua array new" + @.ruby "ruby array new" + @.php "php array new" + @.scheme "scheme array new" (as_is)) - <write> (for [@.js "js array write" - @.python "python array write" - @.lua "lua array write" - @.ruby "ruby array write" - @.php "php array write" - @.scheme "scheme array write"] + <write> (for @.js "js array write" + @.python "python array write" + @.lua "lua array write" + @.ruby "ruby array write" + @.php "php array write" + @.scheme "scheme array write" (as_is)) - <read> (for [@.js "js array read" - @.python "python array read" - @.lua "lua array read" - @.ruby "ruby array read" - @.php "php array read" - @.scheme "scheme array read"] + <read> (for @.js "js array read" + @.python "python array read" + @.lua "lua array read" + @.ruby "ruby array read" + @.php "php array read" + @.scheme "scheme array read" (as_is))] (abstract: .public (Atom a) (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference a)] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (array.Array a))) (def: .public (atom value) (All (_ a) (-> a (Atom a))) (:abstraction (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference::new value)] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (<write> 0 value (<new> 1)))))) (def: .public (read! atom) (All (_ a) (-> (Atom a) (IO a))) (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference::get (:representation atom))] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (io.io (<read> 0 (:representation atom)))))) (def: .public (compare_and_swap! current new atom) (All (_ a) (-> a a (Atom a) (IO Bit))) (io.io (with_expansions [<jvm> (ffi.of_boolean (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom)))] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (let [old (<read> 0 (:representation atom))] (if (same? old current) (exec diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 7a21363b1..5f164eaae 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -48,17 +48,17 @@ ["[1]::[0]" (new [int]) (schedule [java/lang/Runnable long java/util/concurrent/TimeUnit] "io" (java/util/concurrent/ScheduledFuture java/lang/Object))]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.js - (as_is (ffi.import: (setTimeout [ffi.Function ffi.Number] "io" Any))) + @.js + (as_is (ffi.import: (setTimeout [ffi.Function ffi.Number] "io" Any))) - @.python - (ffi.import: threading/Timer - "[1]::[0]" - (new [ffi.Float ffi.Function]) - (start [] "io" "?" Any))] + @.python + (ffi.import: threading/Timer + "[1]::[0]" + (new [ffi.Float ffi.Function]) + (start [] "io" "?" Any)) ... Default (type: Thread @@ -71,15 +71,15 @@ (def: .public parallelism Nat (with_expansions [<default> 1 - <jvm> (<| (configuration.for [... TODO: Remove this when Rembulan is no longer being used. - ["lua_compiler?" ""] - <default>]) + <jvm> (<| (configuration.for ["lua_compiler?" ""] + ... TODO: Remove this when Rembulan is no longer being used. + <default>) (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) ffi.of_int .nat))] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> ... Default <default>))) @@ -89,10 +89,10 @@ .int ffi.as_int java/util/concurrent/ScheduledThreadPoolExecutor::new)))] - (for [@.old <jvm> - @.jvm <jvm> - @.js (as_is) - @.python (as_is)] + (for @.old <jvm> + @.jvm <jvm> + @.js (as_is) + @.python (as_is) ... Default (as_is (def: started? @@ -125,19 +125,19 @@ 0 (java/util/concurrent/Executor::execute runnable runner) _ (java/util/concurrent/ScheduledThreadPoolExecutor::schedule runnable (.int milli_seconds) java/util/concurrent/TimeUnit::MILLISECONDS runner))))] - (for [@.old <jvm> - @.jvm <jvm> - - @.js - (..setTimeout (ffi.function (_ []) Any (..execute! action)) - (n.frac milli_seconds)) - - @.python - (do io.monad - [_ (|> (ffi.function (_ []) Any (..execute! action)) - (threading/Timer::new (|> milli_seconds n.frac (f./ +1,000.0))) - threading/Timer::start)] - (in []))] + (for @.old <jvm> + @.jvm <jvm> + + @.js + (..setTimeout (ffi.function (_ []) Any (..execute! action)) + (n.frac milli_seconds)) + + @.python + (do io.monad + [_ (|> (ffi.function (_ []) Any (..execute! action)) + (threading/Timer::new (|> milli_seconds n.frac (f./ +1,000.0))) + threading/Timer::start)] + (in [])) ... Default (do [! io.monad] @@ -148,10 +148,10 @@ ..runner)] (in []))))) -(for [@.old (as_is) - @.jvm (as_is) - @.js (as_is) - @.python (as_is)] +(for @.old (as_is) + @.jvm (as_is) + @.js (as_is) + @.python (as_is) ... Default (as_is (exception: .public cannot_continue_running_threads) diff --git a/stdlib/source/library/lux/control/thread.lux b/stdlib/source/library/lux/control/thread.lux index 02fc925c5..b07c213a1 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -1,18 +1,18 @@ (.using - [library - [lux "*" - ["@" target] - [abstract - [functor {"+" Functor}] - [apply {"+" Apply}] - [monad {"+" Monad do}]] - [control - ["[0]" io {"+" IO}]] - [data - [collection - ["[0]" array {"+" Array}]]] - [type - abstract]]]) + [library + [lux "*" + ["@" target] + [abstract + [functor {"+" Functor}] + [apply {"+" Apply}] + [monad {"+" Monad do}]] + [control + ["[0]" io {"+" IO}]] + [data + [collection + ["[0]" array {"+" Array}]]] + [type + abstract]]]) (type: .public (Thread ! a) (-> ! a)) @@ -30,23 +30,23 @@ (def: .public (read! box) (All (_ ! a) (-> (Box ! a) (Thread ! a))) (function (_ !) - (for [@.old - ("jvm aaload" (:representation box) 0) - - @.jvm - ("jvm array read object" - (|> 0 - (:as (Primitive "java.lang.Long")) - "jvm object cast" - "jvm conversion long-to-int") - (:representation box)) - - @.js ("js array read" 0 (:representation box)) - @.python ("python array read" 0 (:representation box)) - @.lua ("lua array read" 0 (:representation box)) - @.ruby ("ruby array read" 0 (:representation box)) - @.php ("php array read" 0 (:representation box)) - @.scheme ("scheme array read" 0 (:representation box))]))) + (for @.old + ("jvm aaload" (:representation box) 0) + + @.jvm + ("jvm array read object" + (|> 0 + (:as (Primitive "java.lang.Long")) + "jvm object cast" + "jvm conversion long-to-int") + (:representation box)) + + @.js ("js array read" 0 (:representation box)) + @.python ("python array read" 0 (:representation box)) + @.lua ("lua array read" 0 (:representation box)) + @.ruby ("ruby array read" 0 (:representation box)) + @.php ("php array read" 0 (:representation box)) + @.scheme ("scheme array read" 0 (:representation box))))) (def: .public (write! value box) (All (_ a) (-> a (All (_ !) (-> (Box ! a) (Thread ! Any))))) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 06676e8eb..852891255 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -62,13 +62,13 @@ (def: (conjoint MlMla) (do monad - [[l1 Mla] (for [@.old - (: {.#Apply (Writer (:parameter 0) - {.#Apply (Writer (:parameter 0) - (:parameter 2)) - (:parameter 1)}) - (:parameter 1)} - MlMla)] + [[l1 Mla] (for @.old + (: {.#Apply (Writer (:parameter 0) + {.#Apply (Writer (:parameter 0) + (:parameter 2)) + (:parameter 1)}) + (:parameter 1)} + MlMla) ... On new compiler MlMla) [l2 a] Mla] diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 41e616a8e..4992f3ae0 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -212,17 +212,17 @@ (def: .public (all check xs) (All (_ a b) (-> (-> a (Maybe b)) (List a) (List b))) - (for [... TODO: Stop relying on this ASAP. - @.js - (mix (function (_ head tail) - (case (check head) - {.#Some head} - {.#Item head tail} - - {.#None} - tail)) - {.#End} - (reversed xs))] + (for @.js + ... TODO: Stop relying on this ASAP. + (mix (function (_ head tail) + (case (check head) + {.#Some head} + {.#Item head tail} + + {.#None} + tail)) + {.#End} + (reversed xs)) (case xs {.#End} {.#End} @@ -585,10 +585,9 @@ (do [! monad] [lMla MlMla ... TODO: Remove this version ASAP and use one below. - lla (for [@.old - (: {.#Apply (type (List (List (:parameter 1)))) - (:parameter 0)} - (monad.all ! lMla))] + lla (for @.old (: {.#Apply (type (List (List (:parameter 1)))) + (:parameter 0)} + (monad.all ! lMla)) (monad.all ! lMla))] (in (..together lla))))) diff --git a/stdlib/source/library/lux/data/collection/tree/zipper.lux b/stdlib/source/library/lux/data/collection/tree/zipper.lux index 108a486d2..da4a69951 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -103,13 +103,13 @@ (do maybe.monad [family (the #family zipper)] (in (let [(^open "_[0]") family] - (for [@.old - (revised #node (: (-> (Tree (:parameter 0)) - (Tree (:parameter 0))) - (has //.#children (list#composite (list.reversed _#lefts) - {.#Item (the #node zipper) - _#rights}))) - _#parent)] + (for @.old + (revised #node (: (-> (Tree (:parameter 0)) + (Tree (:parameter 0))) + (has //.#children (list#composite (list.reversed _#lefts) + {.#Item (the #node zipper) + _#rights}))) + _#parent) (has [#node //.#children] (list#composite (list.reversed _#lefts) {.#Item (the #node zipper) @@ -123,11 +123,11 @@ {.#Some family} (case (the <side> family) {.#Item next side'} - {.#Some (for [@.old - [#family {.#Some (|> family - (has <side> side') - (revised <op_side> (|>> {.#Item (the #node zipper)})))} - #node next]] + {.#Some (for @.old + [#family {.#Some (|> family + (has <side> side') + (revised <op_side> (|>> {.#Item (the #node zipper)})))} + #node next] (let [move (: (All (_ a) (-> (List (Tree a)) (Zipper a) (Family Zipper a) (Family Zipper a))) (function (_ side' zipper) (|>> (has <side> side') @@ -153,11 +153,11 @@ {.#None} {.#Item last prevs} - {.#Some (for [@.old [#family {.#Some (|> family - (has <side> {.#End}) - (revised <op_side> (|>> {.#Item (the #node zipper)} - (list#composite prevs))))} - #node last]] + {.#Some (for @.old [#family {.#Some (|> family + (has <side> {.#End}) + (revised <op_side> (|>> {.#Item (the #node zipper)} + (list#composite prevs))))} + #node last] (let [move (: (All (_ a) (-> (List (Tree a)) (Zipper a) (Family Zipper a) (Family Zipper a))) (function (_ prevs zipper) (|>> (has <side> {.#End}) diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 2f6d9fe7e..043736329 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -182,29 +182,29 @@ [[pre post] (..split_by pattern template)] (in ($_ "lux text concat" pre replacement post))))) -(for [@.js (as_is (macro: (defined? tokens lux) - (case tokens - (^ (list it)) - {.#Right [lux (list (` (.case ("js type-of" ("js constant" (~ it))) - "undefined" - .false - - (~' _) - .true)))]} - - _ - {.#Left ""})) - (macro: (if_nashorn tokens lux) - (case tokens - (^ (list then else)) - {.#Right [lux (list (if (and (..defined? "java") - (..defined? "java.lang") - (..defined? "java.lang.Object")) - then - else))]} - - _ - {.#Left ""})))] +(for @.js (as_is (macro: (defined? tokens lux) + (case tokens + (^ (list it)) + {.#Right [lux (list (` (.case ("js type-of" ("js constant" (~ it))) + "undefined" + .false + + (~' _) + .true)))]} + + _ + {.#Left ""})) + (macro: (if_nashorn tokens lux) + (case tokens + (^ (list then else)) + {.#Right [lux (list (if (and (..defined? "java") + (..defined? "java.lang") + (..defined? "java.lang.Object")) + then + else))]} + + _ + {.#Left ""}))) (as_is)) (def: .public (replaced pattern replacement template) @@ -218,39 +218,39 @@ {.#None} ("lux text concat" left right)))] - (for [@.old + (for @.old + (:as Text + ("jvm invokevirtual:java.lang.String:replace:java.lang.CharSequence,java.lang.CharSequence" + (:as (Primitive "java.lang.String") template) + (:as (Primitive "java.lang.CharSequence") pattern) + (:as (Primitive "java.lang.CharSequence") replacement))) + @.jvm + (:as Text + ("jvm member invoke virtual" [] "java.lang.String" "replace" [] + (:as (Primitive "java.lang.String") template) + ["Ljava/lang/CharSequence;" (:as (Primitive "java.lang.CharSequence") pattern)] + ["Ljava/lang/CharSequence;" (:as (Primitive "java.lang.CharSequence") replacement)])) + @.js + ... TODO: Remove this when Nashorn is no longer being used. + (..if_nashorn + <default> (:as Text - ("jvm invokevirtual:java.lang.String:replace:java.lang.CharSequence,java.lang.CharSequence" - (:as (Primitive "java.lang.String") template) - (:as (Primitive "java.lang.CharSequence") pattern) - (:as (Primitive "java.lang.CharSequence") replacement))) - @.jvm - (:as Text - ("jvm member invoke virtual" [] "java.lang.String" "replace" [] - (:as (Primitive "java.lang.String") template) - ["Ljava/lang/CharSequence;" (:as (Primitive "java.lang.CharSequence") pattern)] - ["Ljava/lang/CharSequence;" (:as (Primitive "java.lang.CharSequence") replacement)])) - @.js - ... TODO: Remove this when Nashorn is no longer being used. - (..if_nashorn - <default> - (:as Text - ("js object do" "replaceAll" template [pattern replacement]))) - @.python - (:as Text - ("python object do" "replace" template [pattern replacement])) - ... TODO @.lua - @.ruby - (:as Text - ("ruby object do" "gsub" template [pattern replacement])) - @.php - (:as Text - ("php apply" (:expected ("php constant" "str_replace")) - pattern replacement template)) - ... TODO @.scheme - ... TODO @.common_lisp - ... TODO @.r - ] + ("js object do" "replaceAll" template [pattern replacement]))) + @.python + (:as Text + ("python object do" "replace" template [pattern replacement])) + ... TODO @.lua + @.ruby + (:as Text + ("ruby object do" "gsub" template [pattern replacement])) + @.php + (:as Text + ("php apply" (:expected ("php constant" "str_replace")) + pattern replacement template)) + ... TODO @.scheme + ... TODO @.common_lisp + ... TODO @.r + ... Inefficient default <default>))) @@ -282,21 +282,21 @@ (def: &equivalence ..equivalence) (def: (hash input) - (for [@.old - (|> input - (: (Primitive "java.lang.String")) - "jvm invokevirtual:java.lang.String:hashCode:" - "jvm convert int-to-long" - (:as Nat)) - - @.jvm - (|> input - (:as (Primitive "java.lang.String")) - ("jvm member invoke virtual" [] "java.lang.String" "hashCode" []) - "jvm conversion int-to-long" - "jvm object cast" - (: (Primitive "java.lang.Long")) - (:as Nat))] + (for @.old + (|> input + (: (Primitive "java.lang.String")) + "jvm invokevirtual:java.lang.String:hashCode:" + "jvm convert int-to-long" + (:as Nat)) + + @.jvm + (|> input + (:as (Primitive "java.lang.String")) + ("jvm member invoke virtual" [] "java.lang.String" "hashCode" []) + "jvm conversion int-to-long" + "jvm object cast" + (: (Primitive "java.lang.Long")) + (:as Nat)) ... Platform-independent default. (let [length ("lux text size" input)] (loop [index 0 @@ -352,46 +352,46 @@ (def: .public (lower_cased value) (-> Text Text) - (for [@.old - (:as Text - ("jvm invokevirtual:java.lang.String:toLowerCase:" - (:as (Primitive "java.lang.String") value))) - @.jvm - (:as Text - ("jvm member invoke virtual" [] "java.lang.String" "toLowerCase" [] - (:as (Primitive "java.lang.String") value))) - @.js - (:as Text - ("js object do" "toLowerCase" value [])) - @.python - (:as Text - ("python object do" "lower" value [])) - @.lua - (:as Text - ("lua apply" ("lua constant" "string.lower") [value])) - @.ruby - (:as Text - ("ruby object do" "downcase" value []))])) + (for @.old + (:as Text + ("jvm invokevirtual:java.lang.String:toLowerCase:" + (:as (Primitive "java.lang.String") value))) + @.jvm + (:as Text + ("jvm member invoke virtual" [] "java.lang.String" "toLowerCase" [] + (:as (Primitive "java.lang.String") value))) + @.js + (:as Text + ("js object do" "toLowerCase" value [])) + @.python + (:as Text + ("python object do" "lower" value [])) + @.lua + (:as Text + ("lua apply" ("lua constant" "string.lower") [value])) + @.ruby + (:as Text + ("ruby object do" "downcase" value [])))) (def: .public (upper_cased value) (-> Text Text) - (for [@.old - (:as Text - ("jvm invokevirtual:java.lang.String:toUpperCase:" - (:as (Primitive "java.lang.String") value))) - @.jvm - (:as Text - ("jvm member invoke virtual" [] "java.lang.String" "toUpperCase" [] - (:as (Primitive "java.lang.String") value))) - @.js - (:as Text - ("js object do" "toUpperCase" value [])) - @.python - (:as Text - ("python object do" "upper" value [])) - @.lua - (:as Text - ("lua apply" ("lua constant" "string.upper") [value])) - @.ruby - (:as Text - ("ruby object do" "upcase" value []))])) + (for @.old + (:as Text + ("jvm invokevirtual:java.lang.String:toUpperCase:" + (:as (Primitive "java.lang.String") value))) + @.jvm + (:as Text + ("jvm member invoke virtual" [] "java.lang.String" "toUpperCase" [] + (:as (Primitive "java.lang.String") value))) + @.js + (:as Text + ("js object do" "toUpperCase" value [])) + @.python + (:as Text + ("python object do" "upper" value [])) + @.lua + (:as Text + ("lua apply" ("lua constant" "string.upper") [value])) + @.ruby + (:as Text + ("ruby object do" "upcase" value [])))) diff --git a/stdlib/source/library/lux/data/text/buffer.lux b/stdlib/source/library/lux/data/text/buffer.lux index 18b4e74c7..78652d3fe 100644 --- a/stdlib/source/library/lux/data/text/buffer.lux +++ b/stdlib/source/library/lux/data/text/buffer.lux @@ -34,34 +34,34 @@ ["[1]::[0]" (new [int]) (toString [] java/lang/String)]))] - (`` (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - @.js (as_is (import: (JS_Array a) - "[1]::[0]" - (push [a] a) - (join [Text] Text))) - @.lua (as_is (import: (table/concat [(array.Array Text) Text] Text)) - ...https://www.lua.org/manual/5.3/manual.html#pdf-table.concat - (import: (table/insert [(array.Array Text) Text] "?" Nothing)) - ... https://www.lua.org/manual/5.3/manual.html#pdf-table.insert - )] + (`` (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.js (as_is (import: (JS_Array a) + "[1]::[0]" + (push [a] a) + (join [Text] Text))) + @.lua (as_is (import: (table/concat [(array.Array Text) Text] Text)) + ...https://www.lua.org/manual/5.3/manual.html#pdf-table.concat + (import: (table/insert [(array.Array Text) Text] "?" Nothing)) + ... https://www.lua.org/manual/5.3/manual.html#pdf-table.insert + ) (as_is)))) (`` (abstract: .public Buffer - (for [@.old [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)] - @.jvm [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)] - @.js [Nat (-> (JS_Array Text) (JS_Array Text))] - @.lua [Nat (-> (array.Array Text) (array.Array Text))]] + (for @.old [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)] + @.jvm [Nat (-> java/lang/StringBuilder java/lang/StringBuilder)] + @.js [Nat (-> (JS_Array Text) (JS_Array Text))] + @.lua [Nat (-> (array.Array Text) (array.Array Text))] ... default (Sequence Text)) (def: .public empty Buffer (:abstraction (with_expansions [<jvm> [0 function.identity]] - (for [@.old <jvm> - @.jvm <jvm> - @.js [0 function.identity] - @.lua [0 function.identity]] + (for @.old <jvm> + @.jvm <jvm> + @.js [0 function.identity] + @.lua [0 function.identity] ... default sequence.empty)))) @@ -76,34 +76,34 @@ builder)))] (:abstraction [(n.+ (//.size chunk) capacity) (|>> transform (then! chunk))]))] - (for [@.old <jvm> - @.jvm <jvm> - @.js (let [[capacity transform] (:representation buffer) - then! (: (-> (JS_Array Text) (JS_Array Text)) + (for @.old <jvm> + @.jvm <jvm> + @.js (let [[capacity transform] (:representation buffer) + then! (: (-> (JS_Array Text) (JS_Array Text)) + (function (_ array) + (exec + (JS_Array::push chunk array) + array)))] + (:abstraction [(n.+ (//.size chunk) capacity) + (|>> transform then!)])) + @.lua (let [[capacity transform] (:representation buffer) + then! (: (-> (array.Array Text) (array.Array Text)) (function (_ array) (exec - (JS_Array::push chunk array) + (table/insert array chunk) array)))] (:abstraction [(n.+ (//.size chunk) capacity) (|>> transform then!)])) - @.lua (let [[capacity transform] (:representation buffer) - then! (: (-> (array.Array Text) (array.Array Text)) - (function (_ array) - (exec - (table/insert array chunk) - array)))] - (:abstraction [(n.+ (//.size chunk) capacity) - (|>> transform then!)]))] ... default (|> buffer :representation (sequence.suffix chunk) :abstraction)))) (def: .public size (-> Buffer Nat) (with_expansions [<jvm> (|>> :representation product.left)] - (for [@.old <jvm> - @.jvm <jvm> - @.js <jvm> - @.lua <jvm>] + (for @.old <jvm> + @.jvm <jvm> + @.js <jvm> + @.lua <jvm> ... default (|>> :representation (sequence#mix (function (_ chunk total) @@ -117,15 +117,15 @@ transform java/lang/StringBuilder::toString ffi.of_string))] - (for [@.old <jvm> - @.jvm <jvm> - @.js (let [[capacity transform] (:representation buffer)] - (|> (array.empty 0) - (:as (JS_Array Text)) - transform - (JS_Array::join ""))) - @.lua (let [[capacity transform] (:representation buffer)] - (table/concat (transform (array.empty 0)) ""))] + (for @.old <jvm> + @.jvm <jvm> + @.js (let [[capacity transform] (:representation buffer)] + (|> (array.empty 0) + (:as (JS_Array Text)) + transform + (JS_Array::join ""))) + @.lua (let [[capacity transform] (:representation buffer)] + (table/concat (transform (array.empty 0)) "")) ... default (sequence#mix (function (_ chunk total) (format total chunk)) diff --git a/stdlib/source/library/lux/data/text/encoding/utf8.lux b/stdlib/source/library/lux/data/text/encoding/utf8.lux index 915d6b895..9b13114a4 100644 --- a/stdlib/source/library/lux/data/text/encoding/utf8.lux +++ b/stdlib/source/library/lux/data/text/encoding/utf8.lux @@ -15,145 +15,145 @@ ["[1]::[0]" (new [[byte] java/lang/String]) (getBytes [java/lang/String] [byte])]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) - @.js - (as_is (ffi.import: Uint8Array - "[1]::[0]") + @.js + (as_is (ffi.import: Uint8Array + "[1]::[0]") - ... On Node - (ffi.import: Buffer - "[1]::[0]" - ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) - ("static" from "as" from|decoded [Uint8Array] Buffer) - (toString [ffi.String] ffi.String)) + ... On Node + (ffi.import: Buffer + "[1]::[0]" + ("static" from "as" from|encoded [ffi.String ffi.String] Buffer) + ("static" from "as" from|decoded [Uint8Array] Buffer) + (toString [ffi.String] ffi.String)) - ... On the browser - (ffi.import: TextEncoder - "[1]::[0]" - (new [ffi.String]) - (encode [ffi.String] Uint8Array)) - - (ffi.import: TextDecoder - "[1]::[0]" - (new [ffi.String]) - (decode [Uint8Array] ffi.String))) - - @.ruby - (as_is (ffi.import: String - "[1]::[0]" - (encode [Text] String) - (force_encoding [Text] Text) - (bytes [] Binary)) - - (ffi.import: Array - "[1]::[0]" - (pack [Text] String))) - - @.php - (as_is (ffi.import: Almost_Binary) - (ffi.import: (unpack [ffi.String ffi.String] Almost_Binary)) - (ffi.import: (array_values [Almost_Binary] Binary)) - (def: php_byte_array_format "C*")) - - @.scheme - ... https://srfi.schemers.org/srfi-140/srfi-140.html - (as_is (ffi.import: (string->utf8 [Text] Binary)) - (ffi.import: (utf8->string [Binary] Text)))] + ... On the browser + (ffi.import: TextEncoder + "[1]::[0]" + (new [ffi.String]) + (encode [ffi.String] Uint8Array)) + + (ffi.import: TextDecoder + "[1]::[0]" + (new [ffi.String]) + (decode [Uint8Array] ffi.String))) + + @.ruby + (as_is (ffi.import: String + "[1]::[0]" + (encode [Text] String) + (force_encoding [Text] Text) + (bytes [] Binary)) + + (ffi.import: Array + "[1]::[0]" + (pack [Text] String))) + + @.php + (as_is (ffi.import: Almost_Binary) + (ffi.import: (unpack [ffi.String ffi.String] Almost_Binary)) + (ffi.import: (array_values [Almost_Binary] Binary)) + (def: php_byte_array_format "C*")) + + @.scheme + ... https://srfi.schemers.org/srfi-140/srfi-140.html + (as_is (ffi.import: (string->utf8 [Text] Binary)) + (ffi.import: (utf8->string [Binary] Text))) (as_is))) (def: (encoded value) (-> Text Binary) - (for [@.old - (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) - (ffi.as_string value)) - - @.jvm - (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) - (ffi.as_string value)) - - @.js - (cond ffi.on_nashorn? - (:as Binary ("js object do" "getBytes" value ["utf8"])) - - ffi.on_node_js? - (|> (Buffer::from|encoded value "utf8") - ... This coercion is valid as per NodeJS's documentation: - ... https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays - (:as Uint8Array)) - - ... On the browser - (|> (TextEncoder::new (//.name //.utf_8)) - (TextEncoder::encode [value])) - ) - - @.python - (:as Binary ("python apply" (:expected ("python constant" "bytearray")) [value "utf-8"])) - - @.lua - ("lua utf8 encode" value) - - @.ruby - (|> value - (:as String) - (String::encode "UTF-8") - (String::bytes)) - - @.php - (|> (..unpack [..php_byte_array_format value]) - ..array_values - ("php object new" "ArrayObject") - (:as Binary)) - - @.scheme - (..string->utf8 value)])) + (for @.old + (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) + (ffi.as_string value)) + + @.jvm + (java/lang/String::getBytes (ffi.as_string (//.name //.utf_8)) + (ffi.as_string value)) + + @.js + (cond ffi.on_nashorn? + (:as Binary ("js object do" "getBytes" value ["utf8"])) + + ffi.on_node_js? + (|> (Buffer::from|encoded value "utf8") + ... This coercion is valid as per NodeJS's documentation: + ... https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays + (:as Uint8Array)) + + ... On the browser + (|> (TextEncoder::new (//.name //.utf_8)) + (TextEncoder::encode [value])) + ) + + @.python + (:as Binary ("python apply" (:expected ("python constant" "bytearray")) [value "utf-8"])) + + @.lua + ("lua utf8 encode" value) + + @.ruby + (|> value + (:as String) + (String::encode "UTF-8") + (String::bytes)) + + @.php + (|> (..unpack [..php_byte_array_format value]) + ..array_values + ("php object new" "ArrayObject") + (:as Binary)) + + @.scheme + (..string->utf8 value))) (def: (decoded value) (-> Binary (Try Text)) (with_expansions [<jvm> {try.#Success (ffi.of_string (java/lang/String::new value (ffi.as_string (//.name //.utf_8))))}] - (for [@.old <jvm> - @.jvm <jvm> - - @.js - (cond ffi.on_nashorn? - (|> ("js object new" ("js constant" "java.lang.String") [value "utf8"]) - (:as Text) - {try.#Success}) - - ffi.on_node_js? - (|> (Buffer::from|decoded value) - (Buffer::toString "utf8") - {try.#Success}) - - ... On the browser - (|> (TextDecoder::new (//.name //.utf_8)) - (TextDecoder::decode value) - {try.#Success})) - - @.python - (try (:as Text ("python object do" "decode" (:expected value) ["utf-8"]))) - - @.lua - {try.#Success ("lua utf8 decode" value)} - - @.ruby - (|> value - (:as Array) - (Array::pack "C*") - (:as String) - (String::force_encoding "UTF-8") - {try.#Success}) - - @.php - (|> value - ("php pack" ..php_byte_array_format) - {try.#Success}) - - @.scheme - (|> value - ..utf8->string - {try.#Success})]))) + (for @.old <jvm> + @.jvm <jvm> + + @.js + (cond ffi.on_nashorn? + (|> ("js object new" ("js constant" "java.lang.String") [value "utf8"]) + (:as Text) + {try.#Success}) + + ffi.on_node_js? + (|> (Buffer::from|decoded value) + (Buffer::toString "utf8") + {try.#Success}) + + ... On the browser + (|> (TextDecoder::new (//.name //.utf_8)) + (TextDecoder::decode value) + {try.#Success})) + + @.python + (try (:as Text ("python object do" "decode" (:expected value) ["utf-8"]))) + + @.lua + {try.#Success ("lua utf8 decode" value)} + + @.ruby + (|> value + (:as Array) + (Array::pack "C*") + (:as String) + (String::force_encoding "UTF-8") + {try.#Success}) + + @.php + (|> value + ("php pack" ..php_byte_array_format) + {try.#Success}) + + @.scheme + (|> value + ..utf8->string + {try.#Success})))) (implementation: .public codec (Codec Binary Text) diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index a807c8ba1..ef90dc663 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -66,73 +66,73 @@ (intValue [] int) (longValue [] long) (doubleValue [] double)]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - - @.js - (as_is (import: JSON - "[1]::[0]" - ("static" stringify [.Any] ffi.String)) - (import: Array - "[1]::[0]" - ("static" isArray [.Any] ffi.Boolean))) - - @.python - (as_is (type: PyType - (Primitive "python_type")) - - (import: (type [.Any] PyType)) - (import: (str [.Any] ffi.String))) - - @.lua - (as_is (import: (type [.Any] ffi.String)) - (import: (tostring [.Any] ffi.String)) - - (import: math - "[1]::[0]" - ("static" type [.Any] "?" ffi.String))) - - @.ruby - (as_is (import: Class - "[1]::[0]") - - (import: Object - "[1]::[0]" - (class [] Class) - (to_s [] ffi.String))) - - @.php - (as_is (import: (gettype [.Any] ffi.String)) - (import: (strval [.Any] ffi.String))) - - @.scheme - (as_is (import: (boolean? [.Any] Bit)) - (import: (integer? [.Any] Bit)) - (import: (real? [.Any] Bit)) - (import: (string? [.Any] Bit)) - (import: (vector? [.Any] Bit)) - (import: (pair? [.Any] Bit)) - (import: (car [.Any] .Any)) - (import: (cdr [.Any] .Any)) - (import: (format [Text .Any] Text))) - ])) + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + + @.js + (as_is (import: JSON + "[1]::[0]" + ("static" stringify [.Any] ffi.String)) + (import: Array + "[1]::[0]" + ("static" isArray [.Any] ffi.Boolean))) + + @.python + (as_is (type: PyType + (Primitive "python_type")) + + (import: (type [.Any] PyType)) + (import: (str [.Any] ffi.String))) + + @.lua + (as_is (import: (type [.Any] ffi.String)) + (import: (tostring [.Any] ffi.String)) + + (import: math + "[1]::[0]" + ("static" type [.Any] "?" ffi.String))) + + @.ruby + (as_is (import: Class + "[1]::[0]") + + (import: Object + "[1]::[0]" + (class [] Class) + (to_s [] ffi.String))) + + @.php + (as_is (import: (gettype [.Any] ffi.String)) + (import: (strval [.Any] ffi.String))) + + @.scheme + (as_is (import: (boolean? [.Any] Bit)) + (import: (integer? [.Any] Bit)) + (import: (real? [.Any] Bit)) + (import: (string? [.Any] Bit)) + (import: (vector? [.Any] Bit)) + (import: (pair? [.Any] Bit)) + (import: (car [.Any] .Any)) + (import: (cdr [.Any] .Any)) + (import: (format [Text .Any] Text))) + )) (def: Inspector (.type (Format Any))) -(for [@.lua (def: (tuple_array tuple) - (-> (array.Array Any) (array.Array Any)) - (array.of_list - (loop [idx 0] - (let [member ("lua array read" idx tuple)] - (if ("lua object nil?" member) - {.#End} - {.#Item member (again (++ idx))})))))] +(for @.lua (def: (tuple_array tuple) + (-> (array.Array Any) (array.Array Any)) + (array.of_list + (loop [idx 0] + (let [member ("lua array read" idx tuple)] + (if ("lua object nil?" member) + {.#End} + {.#Item member (again (++ idx))}))))) (as_is)) (def: (tuple_inspection inspection) (-> Inspector Inspector) - (with_expansions [<adaption> (for [@.lua (~~ (as_is ..tuple_array))] + (with_expansions [<adaption> (for @.lua (~~ (as_is ..tuple_array)) (~~ (as_is)))] (`` (|>> (:as (array.Array Any)) <adaption> @@ -177,206 +177,206 @@ (tuple_inspection inspection value))) {.#None}) (ffi.of_string (java/lang/Object::toString object)))))] - (for [@.old <jvm> - @.jvm <jvm> - - @.js - (case (ffi.type_of value) - (^template [<type_of> <then>] - [<type_of> - (`` (|> value (~~ (template.spliced <then>))))]) - (["boolean" [(:as .Bit) %.bit]] - ["number" [(:as .Frac) %.frac]] - ["string" [(:as .Text) %.text]] - ["undefined" [JSON::stringify]]) - - "object" - (let [variant_tag ("js object get" "_lux_tag" value) - variant_flag ("js object get" "_lux_flag" value) - variant_value ("js object get" "_lux_value" value)] - (cond (not (or ("js object undefined?" variant_tag) - ("js object undefined?" variant_flag) - ("js object undefined?" variant_value))) - (|> (%.format (JSON::stringify variant_tag) - " " (%.bit (not ("js object null?" variant_flag))) - " " (inspection variant_value)) - (text.enclosed ["{" "}"])) - - (not (or ("js object undefined?" ("js object get" "_lux_low" value)) - ("js object undefined?" ("js object get" "_lux_high" value)))) - (|> value (:as .Int) %.int) - - (Array::isArray value) - (tuple_inspection inspection value) - - ... else - (JSON::stringify value))) - - _ - (JSON::stringify value)) - - @.python - (case (..str (..type value)) - (^template [<type_of> <class_of> <then>] - [(^or <type_of> <class_of>) - (`` (|> value (~~ (template.spliced <then>))))]) - (["<type 'bool'>" "<class 'bool'>" [(:as .Bit) %.bit]] - ["<type 'int'>" "<class 'int'>" [(:as .Int) %.int]] - ["<type 'float'>" "<class 'float'>" [(:as .Frac) %.frac]] - ["<type 'str'>" "<class 'str'>" [(:as .Text) %.text]] - ["<type 'unicode'>" "<class 'unicode'>" [(:as .Text) %.text]]) - - (^or "<type 'list'>" "<class 'list'>") - (tuple_inspection inspection value) - - (^or "<type 'tuple'>" "<class 'tuple'>") - (let [variant (:as (array.Array Any) value)] - (case (array.size variant) - 3 (let [variant_tag ("python array read" 0 variant) - variant_flag ("python array read" 1 variant) - variant_value ("python array read" 2 variant)] - (if (or ("python object none?" variant_tag) - ("python object none?" variant_value)) - (..str value) - (|> (%.format (|> variant_tag (:as .Nat) %.nat) - " " (|> variant_flag "python object none?" not %.bit) - " " (inspection variant_value)) - (text.enclosed ["{" "}"])))) - _ (..str value))) - - _ - (..str value)) - - @.lua - (case (..type value) - (^template [<type_of> <then>] - [<type_of> - (`` (|> value (~~ (template.spliced <then>))))]) - (["boolean" [(:as .Bit) %.bit]] - ["string" [(:as .Text) %.text]] - ["nil" [(new> "nil" [])]]) - - "number" - (case (math::type value) - {.#Some "integer"} (|> value (:as .Int) %.int) - {.#Some "float"} (|> value (:as .Frac) %.frac) - - _ - (..tostring value)) - - "table" - (let [variant_tag ("lua object get" "_lux_tag" value) - variant_flag ("lua object get" "_lux_flag" value) - variant_value ("lua object get" "_lux_value" value)] - (if (or ("lua object nil?" variant_tag) - ("lua object nil?" variant_value)) - (tuple_inspection inspection value) - (|> (%.format (|> variant_tag (:as .Nat) %.nat) - " " (%.bit (not ("lua object nil?" variant_flag))) - " " (inspection variant_value)) - (text.enclosed ["{" "}"])))) - - _ - (..tostring value)) - - @.ruby - (template.let [(class_of <literal>) - [(|> <literal> - (:as ..Object) - Object::class)] - - (to_s <object>) - [(|> <object> - (:as ..Object) - Object::to_s)]] - (let [value_class (class_of value)] - (`` (cond (~~ (template [<literal> <type> <format>] - [(same? (class_of <literal>) value_class) - (|> value (:as <type>) <format>)] - - [#0 Bit %.bit] - [#1 Bit %.bit] - [+1 Int %.int] - [+1.0 Frac %.frac] - ["" Text %.text] - [("ruby object nil") Any (new> "nil" [])] - )) - - (same? (class_of {.#None}) value_class) - (let [variant_tag ("ruby object get" "_lux_tag" value) - variant_flag ("ruby object get" "_lux_flag" value) - variant_value ("ruby object get" "_lux_value" value)] - (if (or ("ruby object nil?" variant_tag) - ("ruby object nil?" variant_value)) - (tuple_inspection inspection value) - (|> (%.format (|> variant_tag (:as .Nat) %.nat) - " " (%.bit (not ("ruby object nil?" variant_flag))) - " " (inspection variant_value)) - (text.enclosed ["{" "}"])))) - - (same? (class_of [[] []]) value_class) - (tuple_inspection inspection value) - - ... else - (to_s value))))) - - @.php - (case (..gettype value) - (^template [<type_of> <then>] - [<type_of> - (`` (|> value (~~ (template.spliced <then>))))]) - (["boolean" [(:as .Bit) %.bit]] - ["integer" [(:as .Int) %.int]] - ["double" [(:as .Frac) %.frac]] - ["string" [(:as .Text) %.text]] - ["NULL" [(new> "null" [])]] - ["array" [(tuple_inspection inspection)]]) - - "object" - (let [variant_tag ("php object get" "_lux_tag" value) - variant_flag ("php object get" "_lux_flag" value) - variant_value ("php object get" "_lux_value" value)] - (if (or ("php object null?" variant_tag) - ("php object null?" variant_value)) - (..strval value) - (|> (%.format (|> variant_tag (:as .Nat) %.nat) - " " (%.bit (not ("php object null?" variant_flag))) - " " (inspection variant_value)) - (text.enclosed ["{" "}"])))) - - _ - (..strval value)) - - @.scheme - (`` (cond (~~ (template [<when> <then>] - [(<when> value) - (`` (|> value (~~ (template.spliced <then>))))] - - [..boolean? [(:as .Bit) %.bit]] - [..integer? [(:as .Int) %.int]] - [..real? [(:as .Frac) %.frac]] - [..string? [(:as .Text) %.text]] - ["scheme object nil?" [(new> "()" [])]] - [..vector? [(tuple_inspection inspection)]])) - - (..pair? value) - (let [variant_tag (..car value) - variant_rest (..cdr value)] - (if (and (..integer? variant_tag) - (i.> +0 (:as Int variant_tag)) - (..pair? variant_rest)) - (let [variant_flag (..car variant_rest) - variant_value (..cdr variant_rest)] - (|> (%.format (|> variant_tag (:as .Nat) %.nat) - " " (%.bit (not ("scheme object nil?" variant_flag))) - " " (inspection variant_value)) - (text.enclosed ["{" "}"]))) - (..format ["~s" value]))) - - ... else - (..format ["~s" value]) - )) - ]))) + (for @.old <jvm> + @.jvm <jvm> + + @.js + (case (ffi.type_of value) + (^template [<type_of> <then>] + [<type_of> + (`` (|> value (~~ (template.spliced <then>))))]) + (["boolean" [(:as .Bit) %.bit]] + ["number" [(:as .Frac) %.frac]] + ["string" [(:as .Text) %.text]] + ["undefined" [JSON::stringify]]) + + "object" + (let [variant_tag ("js object get" "_lux_tag" value) + variant_flag ("js object get" "_lux_flag" value) + variant_value ("js object get" "_lux_value" value)] + (cond (not (or ("js object undefined?" variant_tag) + ("js object undefined?" variant_flag) + ("js object undefined?" variant_value))) + (|> (%.format (JSON::stringify variant_tag) + " " (%.bit (not ("js object null?" variant_flag))) + " " (inspection variant_value)) + (text.enclosed ["{" "}"])) + + (not (or ("js object undefined?" ("js object get" "_lux_low" value)) + ("js object undefined?" ("js object get" "_lux_high" value)))) + (|> value (:as .Int) %.int) + + (Array::isArray value) + (tuple_inspection inspection value) + + ... else + (JSON::stringify value))) + + _ + (JSON::stringify value)) + + @.python + (case (..str (..type value)) + (^template [<type_of> <class_of> <then>] + [(^or <type_of> <class_of>) + (`` (|> value (~~ (template.spliced <then>))))]) + (["<type 'bool'>" "<class 'bool'>" [(:as .Bit) %.bit]] + ["<type 'int'>" "<class 'int'>" [(:as .Int) %.int]] + ["<type 'float'>" "<class 'float'>" [(:as .Frac) %.frac]] + ["<type 'str'>" "<class 'str'>" [(:as .Text) %.text]] + ["<type 'unicode'>" "<class 'unicode'>" [(:as .Text) %.text]]) + + (^or "<type 'list'>" "<class 'list'>") + (tuple_inspection inspection value) + + (^or "<type 'tuple'>" "<class 'tuple'>") + (let [variant (:as (array.Array Any) value)] + (case (array.size variant) + 3 (let [variant_tag ("python array read" 0 variant) + variant_flag ("python array read" 1 variant) + variant_value ("python array read" 2 variant)] + (if (or ("python object none?" variant_tag) + ("python object none?" variant_value)) + (..str value) + (|> (%.format (|> variant_tag (:as .Nat) %.nat) + " " (|> variant_flag "python object none?" not %.bit) + " " (inspection variant_value)) + (text.enclosed ["{" "}"])))) + _ (..str value))) + + _ + (..str value)) + + @.lua + (case (..type value) + (^template [<type_of> <then>] + [<type_of> + (`` (|> value (~~ (template.spliced <then>))))]) + (["boolean" [(:as .Bit) %.bit]] + ["string" [(:as .Text) %.text]] + ["nil" [(new> "nil" [])]]) + + "number" + (case (math::type value) + {.#Some "integer"} (|> value (:as .Int) %.int) + {.#Some "float"} (|> value (:as .Frac) %.frac) + + _ + (..tostring value)) + + "table" + (let [variant_tag ("lua object get" "_lux_tag" value) + variant_flag ("lua object get" "_lux_flag" value) + variant_value ("lua object get" "_lux_value" value)] + (if (or ("lua object nil?" variant_tag) + ("lua object nil?" variant_value)) + (tuple_inspection inspection value) + (|> (%.format (|> variant_tag (:as .Nat) %.nat) + " " (%.bit (not ("lua object nil?" variant_flag))) + " " (inspection variant_value)) + (text.enclosed ["{" "}"])))) + + _ + (..tostring value)) + + @.ruby + (template.let [(class_of <literal>) + [(|> <literal> + (:as ..Object) + Object::class)] + + (to_s <object>) + [(|> <object> + (:as ..Object) + Object::to_s)]] + (let [value_class (class_of value)] + (`` (cond (~~ (template [<literal> <type> <format>] + [(same? (class_of <literal>) value_class) + (|> value (:as <type>) <format>)] + + [#0 Bit %.bit] + [#1 Bit %.bit] + [+1 Int %.int] + [+1.0 Frac %.frac] + ["" Text %.text] + [("ruby object nil") Any (new> "nil" [])] + )) + + (same? (class_of {.#None}) value_class) + (let [variant_tag ("ruby object get" "_lux_tag" value) + variant_flag ("ruby object get" "_lux_flag" value) + variant_value ("ruby object get" "_lux_value" value)] + (if (or ("ruby object nil?" variant_tag) + ("ruby object nil?" variant_value)) + (tuple_inspection inspection value) + (|> (%.format (|> variant_tag (:as .Nat) %.nat) + " " (%.bit (not ("ruby object nil?" variant_flag))) + " " (inspection variant_value)) + (text.enclosed ["{" "}"])))) + + (same? (class_of [[] []]) value_class) + (tuple_inspection inspection value) + + ... else + (to_s value))))) + + @.php + (case (..gettype value) + (^template [<type_of> <then>] + [<type_of> + (`` (|> value (~~ (template.spliced <then>))))]) + (["boolean" [(:as .Bit) %.bit]] + ["integer" [(:as .Int) %.int]] + ["double" [(:as .Frac) %.frac]] + ["string" [(:as .Text) %.text]] + ["NULL" [(new> "null" [])]] + ["array" [(tuple_inspection inspection)]]) + + "object" + (let [variant_tag ("php object get" "_lux_tag" value) + variant_flag ("php object get" "_lux_flag" value) + variant_value ("php object get" "_lux_value" value)] + (if (or ("php object null?" variant_tag) + ("php object null?" variant_value)) + (..strval value) + (|> (%.format (|> variant_tag (:as .Nat) %.nat) + " " (%.bit (not ("php object null?" variant_flag))) + " " (inspection variant_value)) + (text.enclosed ["{" "}"])))) + + _ + (..strval value)) + + @.scheme + (`` (cond (~~ (template [<when> <then>] + [(<when> value) + (`` (|> value (~~ (template.spliced <then>))))] + + [..boolean? [(:as .Bit) %.bit]] + [..integer? [(:as .Int) %.int]] + [..real? [(:as .Frac) %.frac]] + [..string? [(:as .Text) %.text]] + ["scheme object nil?" [(new> "()" [])]] + [..vector? [(tuple_inspection inspection)]])) + + (..pair? value) + (let [variant_tag (..car value) + variant_rest (..cdr value)] + (if (and (..integer? variant_tag) + (i.> +0 (:as Int variant_tag)) + (..pair? variant_rest)) + (let [variant_flag (..car variant_rest) + variant_value (..cdr variant_rest)] + (|> (%.format (|> variant_tag (:as .Nat) %.nat) + " " (%.bit (not ("scheme object nil?" variant_flag))) + " " (inspection variant_value)) + (text.enclosed ["{" "}"]))) + (..format ["~s" value]))) + + ... else + (..format ["~s" value]) + )) + ))) (exception: .public (cannot_represent_value [type Type]) (exception.report diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux index 81a569b6e..f5b578b62 100644 --- a/stdlib/source/library/lux/ffi.lux +++ b/stdlib/source/library/lux/ffi.lux @@ -23,44 +23,44 @@ [type abstract]]]) -(with_expansions [<constant> (for [@.js "js constant" - @.python "python constant" - @.lua "lua constant" - @.ruby "ruby constant"]) - <apply> (for [@.js "js apply" - @.python "python apply" - @.lua "lua apply" - @.ruby "ruby apply"]) - <new> (for [@.js "js object new" - @.python "python apply"] +(with_expansions [<constant> (for @.js "js constant" + @.python "python constant" + @.lua "lua constant" + @.ruby "ruby constant") + <apply> (for @.js "js apply" + @.python "python apply" + @.lua "lua apply" + @.ruby "ruby apply") + <new> (for @.js "js object new" + @.python "python apply" (as_is)) - <do> (for [@.js "js object do" - @.python "python object do" - @.lua "lua object do" - @.ruby "ruby object do"]) - <get> (for [@.js "js object get" - @.python "python object get" - @.lua "lua object get" - @.ruby "ruby object get"] + <do> (for @.js "js object do" + @.python "python object do" + @.lua "lua object do" + @.ruby "ruby object do") + <get> (for @.js "js object get" + @.python "python object get" + @.lua "lua object get" + @.ruby "ruby object get" (as_is)) - <import> (for [@.python "python import" - @.lua "lua import" - @.ruby "ruby import"] + <import> (for @.python "python import" + @.lua "lua import" + @.ruby "ruby import" (as_is)) - <function> (for [@.js "js function" - @.python "python function" - @.lua "lua function"] + <function> (for @.js "js function" + @.python "python function" + @.lua "lua function" (as_is))] (abstract: .public (Object brand) Any) - (with_expansions [<un_common> (for [@.js (as_is [Symbol] - [Null] - [Undefined]) - @.python (as_is [None] - [Dict]) - @.lua (as_is [Nil] - [Table]) - @.ruby (as_is [Nil])]) + (with_expansions [<un_common> (for @.js (as_is [Symbol] + [Null] + [Undefined]) + @.python (as_is [None] + [Dict]) + @.lua (as_is [Nil] + [Table]) + @.ruby (as_is [Nil])) <un_common> <un_common>] (template [<name>] [(with_expansions [<brand> (template.symbol [<name> "'"])] @@ -74,13 +74,13 @@ <un_common> )) - (with_expansions [<un_common> (for [@.js (as_is [Number Frac]) - @.python (as_is [Integer Int] - [Float Frac]) - @.lua (as_is [Integer Int] - [Float Frac]) - @.ruby (as_is [Integer Int] - [Float Frac])]) + (with_expansions [<un_common> (for @.js (as_is [Number Frac]) + @.python (as_is [Integer Int] + [Float Frac]) + @.lua (as_is [Integer Int] + [Float Frac]) + @.ruby (as_is [Integer Int] + [Float Frac])) <un_common> <un_common>] (template [<name> <type>] [(type: .public <name> @@ -231,8 +231,8 @@ (`` (`` (type: Sub (Variant - (~~ (for [@.lua (~~ (as_is)) - @.ruby (~~ (as_is))] + (~~ (for @.lua (~~ (as_is)) + @.ruby (~~ (as_is)) {#Constructor Constructor})) {#Field Field} {#Method Method})))) @@ -240,8 +240,8 @@ (`` (`` (def: sub (Parser Sub) ($_ <>.or - (~~ (for [@.lua (~~ (as_is)) - @.ruby (~~ (as_is))] + (~~ (for @.lua (~~ (as_is)) + @.ruby (~~ (as_is)) ..constructor)) ..field ..method @@ -294,14 +294,14 @@ (~ g!it') (.panic! "Invalid output."))))))))))] - (~~ (for [@.js [null "js object null" - null? "js object null?"] - @.python [none "python object none" - none? "python object none?"] - @.lua [nil "lua object nil" - nil? "lua object nil?"] - @.ruby [nil "ruby object nil" - nil? "ruby object nil?"]])) + (~~ (for @.js [null "js object null" + null? "js object null?"] + @.python [none "python object none" + none? "python object none?"] + @.lua [nil "lua object nil" + nil? "lua object nil?"] + @.ruby [nil "ruby object nil" + nil? "ruby object nil?"])) )) (type: Declaration @@ -402,7 +402,7 @@ (def: host_path (text.replaced .module_separator ..class_separator)) - (for [@.js (as_is)] + (for @.js (as_is) (def: (imported class) (-> Text Code) (case (text.all_split_by .module_separator class) @@ -431,8 +431,8 @@ (~ (<| (lux_optional :output:) (` (<constant> (~ (code.text (..host_path (the #name it)))))))))))))) - (for [@.lua (as_is) - @.ruby (as_is)] + (for @.lua (as_is) + @.ruby (as_is) (def: (constructor_definition [class_name class_parameters] alias namespace it) (-> Declaration Alias Namespace Constructor Code) (let [g!it (|> it @@ -458,9 +458,9 @@ (.:expected (~ (<| (..input_term input) (..lux_optional :output:) - (` (<new> (~ (for [@.js (` (<constant> (~ (code.text (..host_path class_name))))) - @.python (` (.:as ..Function - (~ (..imported class_name))))])) + (` (<new> (~ (for @.js (` (<constant> (~ (code.text (..host_path class_name))))) + @.python (` (.:as ..Function + (~ (..imported class_name)))))) [(~+ (list#each ..host_optional g!parameters))])))))))))) (def: (static_field_definition import! [class_name class_parameters] alias namespace it) @@ -477,8 +477,8 @@ (~+ import!) (.:as (~ (..output_type :field:)) (~ (<| (lux_optional :field:) - (for [@.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." field))))) - @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" field)))))] + (for @.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." field))))) + @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" field))))) (` (<get> (~ (code.text field)) (~ (..imported class_name)))))))))))))))) @@ -516,8 +516,8 @@ (|> it (has #alias {.#Some name}) (..procedure_definition import! - (for [@.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." method))))) - @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" method)))))] + (for @.js (` (<constant> (~ (code.text (%.format (..host_path class_name) "." method))))) + @.ruby (` (<constant> (~ (code.text (%.format (..host_path class_name) "::" method))))) (` (<get> (~ (code.text method)) (.:as (..Object .Any) (~ (..imported class_name)))))))))) @@ -588,8 +588,8 @@ [(~+ g!class_variables)])))) (list#each (.function (_ member) (`` (`` (case member - (~~ (for [@.lua (~~ (as_is)) - @.ruby (~~ (as_is))] + (~~ (for @.lua (~~ (as_is)) + @.ruby (~~ (as_is)) (~~ (as_is {#Constructor it} (..constructor_definition class alias namespace it))))) @@ -601,7 +601,7 @@ (the #members it))))) ))) - (for [@.ruby (as_is)] + (for @.ruby (as_is) (syntax: .public (function [[self inputs] (<code>.form ($_ <>.and <code>.local_symbol @@ -617,59 +617,59 @@ (.function ((~ (code.local_symbol self)) [(~+ (list#each product.left inputs))]) (~ term)))))))) - (for [@.js (as_is (template: .public (type_of object) - [("js type-of" object)]) - - (syntax: .public (global [type <code>.any - [head tail] (<code>.tuple (<>.and <code>.local_symbol (<>.some <code>.local_symbol)))]) - (with_symbols [g!_] - (let [global (` ("js constant" (~ (code.text head))))] - (case tail - {.#End} - (in (list (` (: (.Maybe (~ type)) - (case (..type_of (~ global)) - "undefined" - {.#None} - - (~ g!_) - {.#Some (:as (~ type) (~ global))}))))) - - {.#Item [next tail]} - (let [separator "."] - (in (list (` (: (.Maybe (~ type)) - (case (..type_of (~ global)) - "undefined" - {.#None} - - (~ g!_) - (..global (~ type) [(~ (code.local_symbol (%.format head "." next))) - (~+ (list#each code.local_symbol tail))]))))))))))) - - (template: (!defined? <global>) - [(.case (..global Any <global>) - {.#None} - .false - - {.#Some _} - .true)]) - - (template [<name> <global>] - [(def: .public <name> - Bit - (!defined? <global>))] - - [on_browser? [window]] - [on_nashorn? [java lang Object]] - ) - - (def: .public on_node_js? - Bit - (|> (..global (Object Any) [process]) - (maybe#each (|>> [] - ("js apply" ("js constant" "Object.prototype.toString.call")) - (:as Text) - (text#= "[object process]"))) - (maybe.else false))) - )] + (for @.js (as_is (template: .public (type_of object) + [("js type-of" object)]) + + (syntax: .public (global [type <code>.any + [head tail] (<code>.tuple (<>.and <code>.local_symbol (<>.some <code>.local_symbol)))]) + (with_symbols [g!_] + (let [global (` ("js constant" (~ (code.text head))))] + (case tail + {.#End} + (in (list (` (: (.Maybe (~ type)) + (case (..type_of (~ global)) + "undefined" + {.#None} + + (~ g!_) + {.#Some (:as (~ type) (~ global))}))))) + + {.#Item [next tail]} + (let [separator "."] + (in (list (` (: (.Maybe (~ type)) + (case (..type_of (~ global)) + "undefined" + {.#None} + + (~ g!_) + (..global (~ type) [(~ (code.local_symbol (%.format head "." next))) + (~+ (list#each code.local_symbol tail))]))))))))))) + + (template: (!defined? <global>) + [(.case (..global Any <global>) + {.#None} + .false + + {.#Some _} + .true)]) + + (template [<name> <global>] + [(def: .public <name> + Bit + (!defined? <global>))] + + [on_browser? [window]] + [on_nashorn? [java lang Object]] + ) + + (def: .public on_node_js? + Bit + (|> (..global (Object Any) [process]) + (maybe#each (|>> [] + ("js apply" ("js constant" "Object.prototype.toString.call")) + (:as Text) + (text#= "[object process]"))) + (maybe.else false))) + ) (as_is)) ) diff --git a/stdlib/source/library/lux/math.lux b/stdlib/source/library/lux/math.lux index ec1e0c5d9..f9df0dd73 100644 --- a/stdlib/source/library/lux/math.lux +++ b/stdlib/source/library/lux/math.lux @@ -18,287 +18,287 @@ [tau +6.28318530717958647692] ) -(for [@.old - (as_is (template [<name> <method>] - [(def: .public (<name> it) - (-> Frac Frac) - (<method> it))] - - [cos "jvm invokestatic:java.lang.Math:cos:double"] - [sin "jvm invokestatic:java.lang.Math:sin:double"] - [tan "jvm invokestatic:java.lang.Math:tan:double"] - - [acos "jvm invokestatic:java.lang.Math:acos:double"] - [asin "jvm invokestatic:java.lang.Math:asin:double"] - [atan "jvm invokestatic:java.lang.Math:atan:double"] - - [exp "jvm invokestatic:java.lang.Math:exp:double"] - [log "jvm invokestatic:java.lang.Math:log:double"] - - [ceil "jvm invokestatic:java.lang.Math:ceil:double"] - [floor "jvm invokestatic:java.lang.Math:floor:double"] - - [root/2 "jvm invokestatic:java.lang.Math:sqrt:double"] - [root/3 "jvm invokestatic:java.lang.Math:cbrt:double"] - ) - (def: .public (pow param subject) - (-> Frac Frac Frac) - ("jvm invokestatic:java.lang.Math:pow:double,double" subject param))) - - @.jvm - (as_is (template: (!double value) - [(|> value - (:as (Primitive "java.lang.Double")) - "jvm object cast")]) - - (template: (!frac value) - [(|> value - "jvm object cast" - (: (Primitive "java.lang.Double")) - (:as Frac))]) - - (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> !double - ["D"] - ("jvm member invoke static" [] "java.lang.Math" <method> []) - !frac))] - - [cos "cos"] - [sin "sin"] - [tan "tan"] - - [acos "acos"] - [asin "asin"] - [atan "atan"] - - [exp "exp"] - [log "log"] - - [ceil "ceil"] - [floor "floor"] - - [root/2 "sqrt"] - [root/3 "cbrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (|> ("jvm member invoke static" [] "java.lang.Math" "pow" [] - ["D" (!double subject)] ["D" (!double param)]) - !frac))) - - @.js - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> [] - ("js apply" ("js constant" <method>)) - (:as Frac)))] - - [cos "Math.cos"] - [sin "Math.sin"] - [tan "Math.tan"] - - [acos "Math.acos"] - [asin "Math.asin"] - [atan "Math.atan"] - - [exp "Math.exp"] - [log "Math.log"] - - [ceil "Math.ceil"] - [floor "Math.floor"] - - [root/2 "Math.sqrt"] - [root/3 "Math.cbrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (:as Frac ("js apply" ("js constant" "Math.pow") [subject param])))) - - @.python - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> [] - ("python object do" <method> ("python import" "math")) - (:as Frac)))] - - [cos "cos"] - [sin "sin"] - [tan "tan"] - - [acos "acos"] - [asin "asin"] - [atan "atan"] - - [exp "exp"] - [log "log"] - - [ceil "ceil"] - [floor "floor"] - - [root/2 "sqrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (:as Frac ("python object do" "pow" ("python import" "math") [subject param]))) - - (def: .public (root/3 it) - (-> Frac Frac) - (if ("lux f64 <" +0.0 it) - (|> it - ("lux f64 *" -1.0) - (..pow ("lux f64 /" +3.0 +1.0)) - ("lux f64 *" -1.0)) - (|> it - (..pow ("lux f64 /" +3.0 +1.0)))))) - - @.lua - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> [] - ("lua apply" ("lua constant" <method>)) - (:as Frac)))] - - [cos "math.cos"] - [sin "math.sin"] - [tan "math.tan"] - - [acos "math.acos"] - [asin "math.asin"] - [atan "math.atan"] - - [exp "math.exp"] - [log "math.log"] - - [ceil "math.ceil"] - [floor "math.floor"] - - [root/2 "math.sqrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - ("lua power" param subject)) - - (def: .public (root/3 it) - (-> Frac Frac) - (if ("lux f64 <" +0.0 it) - (|> it - ("lux f64 *" -1.0) - (..pow ("lux f64 /" +3.0 +1.0)) - ("lux f64 *" -1.0)) - (|> it - (..pow ("lux f64 /" +3.0 +1.0)))))) - - @.ruby - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> [] - ("ruby apply" ("ruby constant" <method>)) - (:as Frac)))] - - [cos "Math.cos"] - [sin "Math.sin"] - [tan "Math.tan"] - - [acos "Math.acos"] - [asin "Math.asin"] - [atan "Math.atan"] - - [exp "Math.exp"] - [log "Math.log"] - - [root/2 "Math.sqrt"] - [root/3 "Math.cbrt"] - ) - - (template [<name> <method>] - [(def: .public (<name> it) - (-> Frac Frac) - (|> ("ruby object do" <method> it []) - (:as Int) - ("lux i64 f64")))] - - [ceil "ceil"] - [floor "floor"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (:as Frac ("ruby object do" "**" subject [param])))) - - @.php - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> ("php apply" ("php constant" <method>)) - (:as Frac)))] - - [cos "cos"] - [sin "sin"] - [tan "tan"] - - [acos "acos"] - [asin "asin"] - [atan "atan"] - - [exp "exp"] - [log "log"] - - [ceil "ceil"] - [floor "floor"] - - [root/2 "sqrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (:as Frac ("php apply" ("php constant" "pow") subject param))) - - (def: .public root/3 - (-> Frac Frac) - (..pow ("lux f64 /" +3.0 +1.0)))) - - @.scheme - (as_is (template [<name> <method>] - [(def: .public <name> - (-> Frac Frac) - (|>> ("scheme apply" ("scheme constant" <method>)) - (:as Frac)))] - - [cos "cos"] - [sin "sin"] - [tan "tan"] - - [acos "acos"] - [asin "asin"] - [atan "atan"] - - [exp "exp"] - [log "log"] - - [ceil "ceiling"] - [floor "floor"] - - [root/2 "sqrt"] - ) - - (def: .public (pow param subject) - (-> Frac Frac Frac) - (:as Frac ("scheme apply" ("scheme constant" "expt") subject param))) - - (def: .public root/3 - (-> Frac Frac) - (..pow ("lux f64 /" +3.0 +1.0)))) - ]) +(for @.old + (as_is (template [<name> <method>] + [(def: .public (<name> it) + (-> Frac Frac) + (<method> it))] + + [cos "jvm invokestatic:java.lang.Math:cos:double"] + [sin "jvm invokestatic:java.lang.Math:sin:double"] + [tan "jvm invokestatic:java.lang.Math:tan:double"] + + [acos "jvm invokestatic:java.lang.Math:acos:double"] + [asin "jvm invokestatic:java.lang.Math:asin:double"] + [atan "jvm invokestatic:java.lang.Math:atan:double"] + + [exp "jvm invokestatic:java.lang.Math:exp:double"] + [log "jvm invokestatic:java.lang.Math:log:double"] + + [ceil "jvm invokestatic:java.lang.Math:ceil:double"] + [floor "jvm invokestatic:java.lang.Math:floor:double"] + + [root/2 "jvm invokestatic:java.lang.Math:sqrt:double"] + [root/3 "jvm invokestatic:java.lang.Math:cbrt:double"] + ) + (def: .public (pow param subject) + (-> Frac Frac Frac) + ("jvm invokestatic:java.lang.Math:pow:double,double" subject param))) + + @.jvm + (as_is (template: (!double value) + [(|> value + (:as (Primitive "java.lang.Double")) + "jvm object cast")]) + + (template: (!frac value) + [(|> value + "jvm object cast" + (: (Primitive "java.lang.Double")) + (:as Frac))]) + + (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> !double + ["D"] + ("jvm member invoke static" [] "java.lang.Math" <method> []) + !frac))] + + [cos "cos"] + [sin "sin"] + [tan "tan"] + + [acos "acos"] + [asin "asin"] + [atan "atan"] + + [exp "exp"] + [log "log"] + + [ceil "ceil"] + [floor "floor"] + + [root/2 "sqrt"] + [root/3 "cbrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (|> ("jvm member invoke static" [] "java.lang.Math" "pow" [] + ["D" (!double subject)] ["D" (!double param)]) + !frac))) + + @.js + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> [] + ("js apply" ("js constant" <method>)) + (:as Frac)))] + + [cos "Math.cos"] + [sin "Math.sin"] + [tan "Math.tan"] + + [acos "Math.acos"] + [asin "Math.asin"] + [atan "Math.atan"] + + [exp "Math.exp"] + [log "Math.log"] + + [ceil "Math.ceil"] + [floor "Math.floor"] + + [root/2 "Math.sqrt"] + [root/3 "Math.cbrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (:as Frac ("js apply" ("js constant" "Math.pow") [subject param])))) + + @.python + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> [] + ("python object do" <method> ("python import" "math")) + (:as Frac)))] + + [cos "cos"] + [sin "sin"] + [tan "tan"] + + [acos "acos"] + [asin "asin"] + [atan "atan"] + + [exp "exp"] + [log "log"] + + [ceil "ceil"] + [floor "floor"] + + [root/2 "sqrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (:as Frac ("python object do" "pow" ("python import" "math") [subject param]))) + + (def: .public (root/3 it) + (-> Frac Frac) + (if ("lux f64 <" +0.0 it) + (|> it + ("lux f64 *" -1.0) + (..pow ("lux f64 /" +3.0 +1.0)) + ("lux f64 *" -1.0)) + (|> it + (..pow ("lux f64 /" +3.0 +1.0)))))) + + @.lua + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> [] + ("lua apply" ("lua constant" <method>)) + (:as Frac)))] + + [cos "math.cos"] + [sin "math.sin"] + [tan "math.tan"] + + [acos "math.acos"] + [asin "math.asin"] + [atan "math.atan"] + + [exp "math.exp"] + [log "math.log"] + + [ceil "math.ceil"] + [floor "math.floor"] + + [root/2 "math.sqrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + ("lua power" param subject)) + + (def: .public (root/3 it) + (-> Frac Frac) + (if ("lux f64 <" +0.0 it) + (|> it + ("lux f64 *" -1.0) + (..pow ("lux f64 /" +3.0 +1.0)) + ("lux f64 *" -1.0)) + (|> it + (..pow ("lux f64 /" +3.0 +1.0)))))) + + @.ruby + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> [] + ("ruby apply" ("ruby constant" <method>)) + (:as Frac)))] + + [cos "Math.cos"] + [sin "Math.sin"] + [tan "Math.tan"] + + [acos "Math.acos"] + [asin "Math.asin"] + [atan "Math.atan"] + + [exp "Math.exp"] + [log "Math.log"] + + [root/2 "Math.sqrt"] + [root/3 "Math.cbrt"] + ) + + (template [<name> <method>] + [(def: .public (<name> it) + (-> Frac Frac) + (|> ("ruby object do" <method> it []) + (:as Int) + ("lux i64 f64")))] + + [ceil "ceil"] + [floor "floor"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (:as Frac ("ruby object do" "**" subject [param])))) + + @.php + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> ("php apply" ("php constant" <method>)) + (:as Frac)))] + + [cos "cos"] + [sin "sin"] + [tan "tan"] + + [acos "acos"] + [asin "asin"] + [atan "atan"] + + [exp "exp"] + [log "log"] + + [ceil "ceil"] + [floor "floor"] + + [root/2 "sqrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (:as Frac ("php apply" ("php constant" "pow") subject param))) + + (def: .public root/3 + (-> Frac Frac) + (..pow ("lux f64 /" +3.0 +1.0)))) + + @.scheme + (as_is (template [<name> <method>] + [(def: .public <name> + (-> Frac Frac) + (|>> ("scheme apply" ("scheme constant" <method>)) + (:as Frac)))] + + [cos "cos"] + [sin "sin"] + [tan "tan"] + + [acos "acos"] + [asin "asin"] + [atan "atan"] + + [exp "exp"] + [log "log"] + + [ceil "ceiling"] + [floor "floor"] + + [root/2 "sqrt"] + ) + + (def: .public (pow param subject) + (-> Frac Frac Frac) + (:as Frac ("scheme apply" ("scheme constant" "expt") subject param))) + + (def: .public root/3 + (-> Frac Frac) + (..pow ("lux f64 /" +3.0 +1.0)))) + ) (def: .public (round it) (-> Frac Frac) diff --git a/stdlib/source/library/lux/meta/configuration.lux b/stdlib/source/library/lux/meta/configuration.lux index 057466051..372189c39 100644 --- a/stdlib/source/library/lux/meta/configuration.lux +++ b/stdlib/source/library/lux/meta/configuration.lux @@ -86,7 +86,7 @@ (maybe.else false)) (subsumes? expected tail)))) -(syntax: .public (for [specializations (<code>.tuple (<>.some (<>.and ..configuration <code>.any))) +(syntax: .public (for [specializations (<>.some (<>.and ..configuration <code>.any)) default (<>.maybe <code>.any)]) (do meta.monad [actual meta.configuration] diff --git a/stdlib/source/library/lux/meta/version.lux b/stdlib/source/library/lux/meta/version.lux index 66bf8e6f5..4a8800ff4 100644 --- a/stdlib/source/library/lux/meta/version.lux +++ b/stdlib/source/library/lux/meta/version.lux @@ -30,7 +30,7 @@ (exception: .public invalid) -(syntax: .public (for [specializations (<code>.tuple (<>.some (<>.and <code>.text <code>.any))) +(syntax: .public (for [specializations (<>.some (<>.and <code>.text <code>.any)) default (<>.maybe <code>.any)]) (do meta.monad [current meta.version] diff --git a/stdlib/source/library/lux/program.lux b/stdlib/source/library/lux/program.lux index 469aa68e6..253bf9b54 100644 --- a/stdlib/source/library/lux/program.lux +++ b/stdlib/source/library/lux/program.lux @@ -28,10 +28,10 @@ (syntax: .public (program: [args ..arguments^ body <code>.any]) (with_symbols [g!program g!args g!_ g!output g!message] - (let [initialization+event_loop (for [@.old body - @.jvm body - @.js body - @.python body] + (let [initialization+event_loop (for @.old body + @.jvm body + @.js body + @.python body (` ((~! do) (~! io.monad) [(~ g!output) (~ body) (~ g!_) (~! thread.run!)] diff --git a/stdlib/source/library/lux/target/jvm/constant.lux b/stdlib/source/library/lux/target/jvm/constant.lux index 8f6358470..2dddcee7b 100644 --- a/stdlib/source/library/lux/target/jvm/constant.lux +++ b/stdlib/source/library/lux/target/jvm/constant.lux @@ -1,36 +1,36 @@ (.using - [library - [lux "*" - ["@" target] - ["[0]" ffi {"+" import:}] - [abstract - [monad {"+" do}] - ["[0]" equivalence {"+" Equivalence}]] - [data - ["[0]" sum] - ["[0]" product] - ["[0]" text] - [format - ["[0]F" binary {"+" Writer} ("[1]#[0]" monoid)]]] - [macro - ["[0]" template]] - [math - [number - ["[0]" i32 {"+" I32}] - ["[0]" i64] - ["[0]" int] - ["[0]" frac]]] - [type - abstract]]] - ["[0]" / "_" - ["[1][0]" tag] - ["/[1]" // "_" - ["[1][0]" index {"+" Index}] - [type - ["[1][0]" category] - ["[1][0]" descriptor {"+" Descriptor}]] - [encoding - ["[1][0]" unsigned]]]]) + [library + [lux "*" + ["@" target] + ["[0]" ffi {"+" import:}] + [abstract + [monad {"+" do}] + ["[0]" equivalence {"+" Equivalence}]] + [data + ["[0]" sum] + ["[0]" product] + ["[0]" text] + [format + ["[0]F" binary {"+" Writer} ("[1]#[0]" monoid)]]] + [macro + ["[0]" template]] + [math + [number + ["[0]" i32 {"+" I32}] + ["[0]" i64] + ["[0]" int] + ["[0]" frac]]] + [type + abstract]]] + ["[0]" / "_" + ["[1][0]" tag] + ["/[1]" // "_" + ["[1][0]" index {"+" Index}] + [type + ["[1][0]" category] + ["[1][0]" descriptor {"+" Descriptor}]] + [encoding + ["[1][0]" unsigned]]]]) (type: .public UTF8 Text) @@ -69,13 +69,13 @@ (Equivalence java/lang/Float) (def: (= parameter subject) - (for [@.old - ("jvm feq" parameter subject) - - @.jvm - ("jvm float =" - ("jvm object cast" parameter) - ("jvm object cast" subject))]))) + (for @.old + ("jvm feq" parameter subject) + + @.jvm + ("jvm float =" + ("jvm object cast" parameter) + ("jvm object cast" subject))))) (import: java/lang/Double ["[1]::[0]" diff --git a/stdlib/source/library/lux/target/jvm/loader.lux b/stdlib/source/library/lux/target/jvm/loader.lux index 26e67f2e9..ce31e2e12 100644 --- a/stdlib/source/library/lux/target/jvm/loader.lux +++ b/stdlib/source/library/lux/target/jvm/loader.lux @@ -102,11 +102,11 @@ (def: .public (memory library) (-> Library java/lang/ClassLoader) - (with_expansions [<cast> (for [@.old - (<|) - - @.jvm - "jvm object cast"])] + (with_expansions [<cast> (for @.old + (<|) + + @.jvm + "jvm object cast")] (<| <cast> (object [] java/lang/ClassLoader [] [] diff --git a/stdlib/source/library/lux/target/python.lux b/stdlib/source/library/lux/target/python.lux index 237baadd7..2e991c91f 100644 --- a/stdlib/source/library/lux/target/python.lux +++ b/stdlib/source/library/lux/target/python.lux @@ -34,10 +34,10 @@ (-> Text Text) (text.enclosed ["(" ")"])) -(for [@.old (as_is (ffi.import: java/lang/CharSequence) - (ffi.import: java/lang/String - ["[1]::[0]" - (replace [java/lang/CharSequence java/lang/CharSequence] java/lang/String)]))] +(for @.old (as_is (ffi.import: java/lang/CharSequence) + (ffi.import: java/lang/String + ["[1]::[0]" + (replace [java/lang/CharSequence java/lang/CharSequence] java/lang/String)])) (as_is)) ... Added the carriage return for better Windows compatibility. @@ -48,10 +48,10 @@ (def: nested (-> Text Text) (.let [nested_new_line (format text.new_line text.tab)] - (for [@.old (|>> (format \n+) - (:as java/lang/String) - (java/lang/String::replace (:as java/lang/CharSequence text.new_line) - (:as java/lang/CharSequence nested_new_line)))] + (for @.old (|>> (format \n+) + (:as java/lang/String) + (java/lang/String::replace (:as java/lang/CharSequence text.new_line) + (:as java/lang/CharSequence nested_new_line))) (|>> (format \n+) (text.replaced text.new_line nested_new_line))))) diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index ad817a70b..2ace74aa6 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -252,12 +252,12 @@ (..description duration tally) text.new_line)] _ (with_expansions [<else> (in (debug.log! report))] - (.for [@.js (case console.default - {.#None} - <else> + (.for @.js (case console.default + {.#None} + <else> - {.#Some console} - (console.write_line report console))] + {.#Some console} + (console.write_line report console)) <else>))] (async.future (# program.default exit (case (the #failures tally) diff --git a/stdlib/source/library/lux/time/instant.lux b/stdlib/source/library/lux/time/instant.lux index d435afeb3..c83d994e4 100644 --- a/stdlib/source/library/lux/time/instant.lux +++ b/stdlib/source/library/lux/time/instant.lux @@ -150,43 +150,43 @@ (def: .public now (IO Instant) - (io (..of_millis (for [@.old ("jvm invokestatic:java.lang.System:currentTimeMillis:") - @.jvm (|> ("jvm member invoke static" [] "java.lang.System" "currentTimeMillis" []) - ("jvm object cast") - (: (Primitive "java.lang.Long")) - (:as Int)) - @.js (let [date ("js object new" ("js constant" "Date") [])] - (|> ("js object do" "getTime" date []) - (:as Frac) - "lux f64 i64")) - @.python (let [time ("python import" "time")] - (|> ("python object do" "time" time []) - (:as Frac) - (f.* +1,000.0) - "lux f64 i64")) - @.lua (|> ("lua apply" ("lua constant" "os.time") []) - (:as Int) - (i.* +1,000)) - @.ruby (let [% ("ruby constant" "Time") - % ("ruby object do" "now" % [])] - (|> ("ruby object do" "to_f" % []) - (:as Frac) - (f.* +1,000.0) - "lux f64 i64")) - @.php (|> ("php constant" "time") - "php apply" - (:as Int) - (i.* +1,000)) - @.scheme (|> ("scheme constant" "current-second") - (:as Int) - (i.* +1,000) - ("scheme apply" ("scheme constant" "exact")) - ("scheme apply" ("scheme constant" "truncate"))) - @.common_lisp (|> ("common_lisp constant" "get-universal-time") - "common_lisp apply" - (:as Int) - (i.* +1,000)) - ])))) + (io (..of_millis (for @.old ("jvm invokestatic:java.lang.System:currentTimeMillis:") + @.jvm (|> ("jvm member invoke static" [] "java.lang.System" "currentTimeMillis" []) + ("jvm object cast") + (: (Primitive "java.lang.Long")) + (:as Int)) + @.js (let [date ("js object new" ("js constant" "Date") [])] + (|> ("js object do" "getTime" date []) + (:as Frac) + "lux f64 i64")) + @.python (let [time ("python import" "time")] + (|> ("python object do" "time" time []) + (:as Frac) + (f.* +1,000.0) + "lux f64 i64")) + @.lua (|> ("lua apply" ("lua constant" "os.time") []) + (:as Int) + (i.* +1,000)) + @.ruby (let [% ("ruby constant" "Time") + % ("ruby object do" "now" % [])] + (|> ("ruby object do" "to_f" % []) + (:as Frac) + (f.* +1,000.0) + "lux f64 i64")) + @.php (|> ("php constant" "time") + "php apply" + (:as Int) + (i.* +1,000)) + @.scheme (|> ("scheme constant" "current-second") + (:as Int) + (i.* +1,000) + ("scheme apply" ("scheme constant" "exact")) + ("scheme apply" ("scheme constant" "truncate"))) + @.common_lisp (|> ("common_lisp constant" "get-universal-time") + "common_lisp apply" + (:as Int) + (i.* +1,000)) + )))) (template [<field> <type> <post_processing>] [(def: .public (<field> instant) diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 1bccf29e7..6f4cd29e2 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -119,12 +119,12 @@ (do [! ..monad] [_ (: (Async (Try Any)) (cache/module.enable! async.monad system context @module)) - _ (for [@.python (|> entry - (the archive.#output) - sequence.list - (list.sub 128) - (monad.each ! (monad.each ! write_artifact!)) - (: (Action (List (List Any)))))] + _ (for @.python (|> entry + (the archive.#output) + sequence.list + (list.sub 128) + (monad.each ! (monad.each ! write_artifact!)) + (: (Action (List (List Any))))) (|> entry (the archive.#output) sequence.list @@ -776,12 +776,12 @@ (do ! [_ (let [report (..module_compilation_log module state)] (with_expansions [<else> (in (debug.log! report))] - (for [@.js (case console.default - {.#None} - <else> - - {.#Some console} - (console.write_line report console))] + (for @.js (case console.default + {.#None} + <else> + + {.#Some console} + (console.write_line report console)) <else>))) .let [entry (has [archive.#module module.#descriptor descriptor.#references] all_dependencies entry)] _ (..cache_module context platform @module $.key $.writer (:as (archive.Entry .Module) entry))] @@ -795,17 +795,17 @@ [_ (cache/archive.cache! (the #&file_system platform) context archive)] (async#in {try.#Failure error}))))))) - (for [@.old (as_is (def: Fake_State - Type - {.#Primitive (%.nat (static.random_nat)) (list)}) + (for @.old (as_is (def: Fake_State + Type + {.#Primitive (%.nat (static.random_nat)) (list)}) - (def: Fake_Document - Type - {.#Primitive (%.nat (static.random_nat)) (list)}) + (def: Fake_Document + Type + {.#Primitive (%.nat (static.random_nat)) (list)}) - (def: Fake_Object - Type - {.#Primitive (%.nat (static.random_nat)) (list)}))] + (def: Fake_Object + Type + {.#Primitive (%.nat (static.random_nat)) (list)})) (as_is)) (def: (serial_compiler import context platform compilation_sources compiler) @@ -820,8 +820,8 @@ compilation_sources (the context.#host_module_extension context) module)] - (loop [customs (for [@.old (:as (List (///.Custom Fake_State Fake_Document Fake_Object)) - all_customs)] + (loop [customs (for @.old (:as (List (///.Custom Fake_State Fake_Document Fake_Object)) + all_customs) all_customs)] (case customs {.#End} diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux index 9cb9fcf96..888c39155 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux @@ -202,7 +202,7 @@ [.let [inputT (type.tuple (list.repeated arity Any))] abstractionA (analysis/type.expecting (-> inputT Any) (phase archive abstractionC)) - _ (analysis/type.inference (for [@.js ffi.Function] + _ (analysis/type.inference (for @.js ffi.Function Any))] (in {analysis.#Extension extension (list (analysis.nat arity) abstractionA)})))])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux index e65c2db5e..ca7dfe9bb 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux @@ -27,15 +27,15 @@ ["[0]" phase]]]]]) (def: Nil - (for [@.lua ffi.Nil] + (for @.lua ffi.Nil Any)) (def: Object - (for [@.lua (type (ffi.Object Any))] + (for @.lua (type (ffi.Object Any)) Any)) (def: Function - (for [@.lua ffi.Function] + (for @.lua ffi.Function Any)) (def: array::new diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux index 7312fb9de..a90a68096 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux @@ -113,15 +113,15 @@ ))) (def: Null - (for [@.php ffi.Null] + (for @.php ffi.Null Any)) (def: Object - (for [@.php (type (ffi.Object Any))] + (for @.php (type (ffi.Object Any)) Any)) (def: Function - (for [@.php ffi.Function] + (for @.php ffi.Function Any)) (def: object::new diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux index 86affb036..f07d818d5 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux @@ -111,23 +111,19 @@ ))) (def: None - (for [@.python - ffi.None] + (for @.python ffi.None Any)) (def: Object - (for [@.python - (type (ffi.Object Any))] + (for @.python (type (ffi.Object Any)) Any)) (def: Function - (for [@.python - ffi.Function] + (for @.python ffi.Function Any)) (def: Dict - (for [@.python - ffi.Dict] + (for @.python ffi.Dict Any)) (def: object::get diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux index 91259acc3..32c57de4e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/ruby.lux @@ -111,15 +111,15 @@ ))) (def: Nil - (for [@.ruby ffi.Nil] + (for @.ruby ffi.Nil Any)) (def: Object - (for [@.ruby (type (ffi.Object Any))] + (for @.ruby (type (ffi.Object Any)) Any)) (def: Function - (for [@.ruby ffi.Function] + (for @.ruby ffi.Function Any)) (def: object::get diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/scheme.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/scheme.lux index 659191e2f..488b39e2c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/scheme.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/scheme.lux @@ -113,12 +113,11 @@ ))) (def: Nil - (for [@.scheme - ffi.Nil] + (for @.scheme ffi.Nil Any)) (def: Function - (for [@.scheme ffi.Function] + (for @.scheme ffi.Function Any)) (def: bundle::object diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux index 15bc133a7..40b036496 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux @@ -206,7 +206,7 @@ (/.install "index" (trinary ..text//index)) (/.install "size" (unary //runtime.text//size)) ... TODO: Use version below once the Lua compiler becomes self-hosted. - ... (/.install "size" (unary (for [@.lua (!unary "utf8.len")] + ... (/.install "size" (unary (for @.lua (!unary "utf8.len") ... (!unary "string.len")))) (/.install "char" (binary ..text//char)) (/.install "clip" (trinary ..text//clip)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux index 794bc1fd7..6cf9f2ff0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/runtime.lux @@ -344,7 +344,7 @@ (..char_index subject) ..lux_index)))))] (with_vars [byte_index] - (for [@.lua <normal>] + (for @.lua <normal> (_.if ..on_rembulan? <rembulan> <normal>))))) @@ -359,7 +359,7 @@ (..byte_index text) (_.- (_.int +1)))) (_.var "string.sub")))] - (for [@.lua <normal>] + (for @.lua <normal> (_.if ..on_rembulan? <rembulan> <normal>)))) @@ -367,7 +367,7 @@ (runtime: (text//size subject) (with_expansions [<rembulan> (_.return (_.apply (list subject) (_.var "string.len"))) <normal> (_.return (_.apply (list subject) (_.var "utf8.len")))] - (for [@.lua <normal>] + (for @.lua <normal> (_.if ..on_rembulan? <rembulan> <normal>)))) @@ -386,7 +386,7 @@ (_.if (_.= _.nil offset) (_.statement (_.error/1 (_.string "[Lux Error] Cannot get char from text."))) (_.return (_.apply (list text offset) (_.var "utf8.codepoint"))))))] - (for [@.lua <normal>] + (for @.lua <normal> (_.if ..on_rembulan? <rembulan> <normal>)))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux index 4e293bb74..13b55ccbd 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/runtime.lux @@ -292,7 +292,7 @@ [(_.> ..i64::+limit) ..i64::+iteration ..i64::+cap ..i64::-limit] [(_.< ..i64::-limit) ..i64::-iteration ..i64::-cap ..i64::+limit] )) - (_.return (for [@.python input] + (_.return (for @.python input ... This +- is only necessary to guarantee that values within the limits are always longs in Python 2 (|> input (_.+ ..i64::+limit) (_.- ..i64::+limit)))))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/reference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/reference.lux index 2ef214588..50fae65d9 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/reference.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/reference.lux @@ -20,23 +20,30 @@ ... This universe constant is for languages where one can't just turn all compiled definitions ... into the local variables of some scoping function. (def: .public universe - (for [ ... In the case of Lua, there is a limit of 200 locals in a function's scope. - @.lua (not ("lua script universe")) - ... Cannot make all definitions be local variables because of limitations with JRuby. - @.ruby (not ("ruby script universe")) - ... Cannot make all definitions be local variables because of limitations with PHP itself. - @.php (not ("php script universe")) - ... Cannot make all definitions be local variables because of limitations with Kawa. - @.scheme (not ("scheme script universe"))] + (for @.lua + ... In the case of Lua, there is a limit of 200 locals in a function's scope. + (not ("lua script universe")) + + @.ruby + ... Cannot make all definitions be local variables because of limitations with JRuby. + (not ("ruby script universe")) + + @.php + ... Cannot make all definitions be local variables because of limitations with PHP itself. + (not ("php script universe")) + + @.scheme + ... Cannot make all definitions be local variables because of limitations with Kawa. + (not ("scheme script universe")) #0)) (def: universe_label Text (with_expansions [<label> (format "u" (%.nat (if ..universe 1 0)))] - (for [@.lua <label> - @.ruby <label> - @.php <label> - @.scheme <label>] + (for @.lua <label> + @.ruby <label> + @.php <label> + @.scheme <label> ""))) (def: .public (artifact [module artifact]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux index 0b1d000b4..971b9391f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/syntax.lux @@ -53,9 +53,9 @@ ["[0]" frac]]]]]) (template: (inline: <declaration> <type> <body>) - [(for [@.python (def: <declaration> <type> <body>) - ... TODO: No longer skip inlining Lua after Rembulan isn't being used anymore. - @.lua (def: <declaration> <type> <body>)] + [(for @.python (def: <declaration> <type> <body>) + ... TODO: No longer skip inlining Lua after Rembulan isn't being used anymore. + @.lua (def: <declaration> <type> <body>) (template: <declaration> [<body>]))]) ... TODO: Implement "lux syntax char case!" as a custom extension. diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux index 143b3bce9..e397214b4 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/module.lux @@ -97,5 +97,5 @@ (|> path (# fs read) (# ! each (|>> [name]))))))] - (in (dictionary.of_list text.hash (for [@.old (:as (List [Text Binary]) pairs)] + (in (dictionary.of_list text.hash (for @.old (:as (List [Text Binary]) pairs) pairs))))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux index a807e083c..f4125ab61 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux @@ -267,8 +267,8 @@ (def: (cache_parser customs) (-> (List Custom) (Parser [(module.Module Any) Registry])) - (case (for [@.old (:as (List (Custom Any Any Any)) - customs)] + (case (for @.old (:as (List (Custom Any Any Any)) + customs) customs) {.#End} (..parser $.key $.parser) diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index cd1aaa867..e0b7a4f0e 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -179,8 +179,9 @@ (Equivalence Type) (def: (= x y) - (or (for [... TODO: Remove this once JPHP is gone. - @.php false] + (or (for @.php + ... TODO: Remove this once JPHP is gone. + false (same? x y)) (case [x y] [{.#Primitive xname xparams} {.#Primitive yname yparams}] diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index e7ed19839..757eac347 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -637,8 +637,9 @@ ... Type-check to ensure that the 'expected' type subsumes the 'actual' type. (def: (check' assumptions expected actual) (Checker Type) - (if (for [... TODO: Remove this once JPHP is gone. - @.php false] + (if (for @.php + ... TODO: Remove this once JPHP is gone. + false (same? expected actual)) (check#in assumptions) (with_exception ..type_check_failed [expected actual] diff --git a/stdlib/source/library/lux/world/console.lux b/stdlib/source/library/lux/world/console.lux index 781a11c29..b8f3f6cbc 100644 --- a/stdlib/source/library/lux/world/console.lux +++ b/stdlib/source/library/lux/world/console.lux @@ -93,74 +93,74 @@ (def: close (|>> (exception.except ..cannot_close) in)))))))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - @.js (as_is (ffi.import: Buffer - "[1]::[0]" - (toString [] ffi.String)) - - (ffi.import: Readable_Stream - "[1]::[0]" - (read [] "?" Buffer) - (unshift "as" unshift|String [ffi.String] ffi.Boolean) - (unshift "as" unshift|Buffer [Buffer] ffi.Boolean)) - - (ffi.import: Writable_Stream - "[1]::[0]" - (write [ffi.String ffi.Function] ffi.Boolean) - (once [ffi.String ffi.Function] Any)) - - (ffi.import: process - "[1]::[0]" - ("static" stdout Writable_Stream) - ("static" stdin Readable_Stream)) - - (exception: .public cannot_read) - - (template: (!read <type> <query>) - [(let [it (process::stdin)] - (case (Readable_Stream::read it) - {.#Some buffer} - (let [input (Buffer::toString buffer)] - (case (: (Maybe [<type> Text]) - <query>) - {.#Some [head tail]} - (exec - (Readable_Stream::unshift|String tail it) - (async#in {try.#Success head})) - - {.#None} - (exec - (Readable_Stream::unshift|Buffer buffer it) - (async#in (exception.except ..cannot_read []))))) - - {.#None} - (async#in (exception.except ..cannot_read []))))]) - - (def: .public default - (Maybe (Console Async)) - (if ffi.on_node_js? - {.#Some (implementation - (def: (read _) - (!read Char (do maybe.monad - [head (text.char 0 input) - [_ tail] (text.split_at 1 input)] - (in [head tail])))) - - (def: (read_line _) - (!read Text (text.split_by text.\n input))) - - (def: (write it) - (let [[read! write!] (: [(async.Async (Try [])) (async.Resolver (Try []))] - (async.async []))] - (exec - (Writable_Stream::write it (ffi.function (_ []) Any (io.run! (write! {try.#Success []}))) - (process::stdout)) - read!))) - - (def: close - (|>> (exception.except ..cannot_close) async#in)))} - {.#None})))] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.js (as_is (ffi.import: Buffer + "[1]::[0]" + (toString [] ffi.String)) + + (ffi.import: Readable_Stream + "[1]::[0]" + (read [] "?" Buffer) + (unshift "as" unshift|String [ffi.String] ffi.Boolean) + (unshift "as" unshift|Buffer [Buffer] ffi.Boolean)) + + (ffi.import: Writable_Stream + "[1]::[0]" + (write [ffi.String ffi.Function] ffi.Boolean) + (once [ffi.String ffi.Function] Any)) + + (ffi.import: process + "[1]::[0]" + ("static" stdout Writable_Stream) + ("static" stdin Readable_Stream)) + + (exception: .public cannot_read) + + (template: (!read <type> <query>) + [(let [it (process::stdin)] + (case (Readable_Stream::read it) + {.#Some buffer} + (let [input (Buffer::toString buffer)] + (case (: (Maybe [<type> Text]) + <query>) + {.#Some [head tail]} + (exec + (Readable_Stream::unshift|String tail it) + (async#in {try.#Success head})) + + {.#None} + (exec + (Readable_Stream::unshift|Buffer buffer it) + (async#in (exception.except ..cannot_read []))))) + + {.#None} + (async#in (exception.except ..cannot_read []))))]) + + (def: .public default + (Maybe (Console Async)) + (if ffi.on_node_js? + {.#Some (implementation + (def: (read _) + (!read Char (do maybe.monad + [head (text.char 0 input) + [_ tail] (text.split_at 1 input)] + (in [head tail])))) + + (def: (read_line _) + (!read Text (text.split_by text.\n input))) + + (def: (write it) + (let [[read! write!] (: [(async.Async (Try [])) (async.Resolver (Try []))] + (async.async []))] + (exec + (Writable_Stream::write it (ffi.function (_ []) Any (io.run! (write! {try.#Success []}))) + (process::stdout)) + read!))) + + (def: close + (|>> (exception.except ..cannot_close) async#in)))} + {.#None}))) (as_is))) (def: .public (write_line message console) diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index c2e799be8..63fa2e88b 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -25,8 +25,8 @@ ["[0]" list ("[1]#[0]" functor)] ["[0]" dictionary {"+" Dictionary}]]] ["[0]" ffi - (~~ (.for ["JavaScript" (~~ (.as_is ["[0]" node_js])) - "{old}" (~~ (.as_is ["node_js" //control/thread]))] + (~~ (.for "JavaScript" (~~ (.as_is ["[0]" node_js])) + "{old}" (~~ (.as_is ["node_js" //control/thread])) (~~ (.as_is))))] [macro ["[0]" template]] @@ -298,662 +298,662 @@ java/io/File::new (java/io/File::renameTo (java/io/File::new (ffi.as_string destination))))) )))] - (for [@.old (as_is <for_jvm>) - @.jvm (as_is <for_jvm>) - - @.js - (as_is (ffi.import: Buffer - "[1]::[0]" - ("static" from [Binary] ..Buffer)) - - (ffi.import: FileDescriptor - "[1]::[0]") - - (ffi.import: Stats - "[1]::[0]" - (size ffi.Number) - (mtimeMs ffi.Number) - (isFile [] ffi.Boolean) - (isDirectory [] ffi.Boolean)) - - (ffi.import: FsConstants - "[1]::[0]" - (F_OK ffi.Number) - (R_OK ffi.Number) - (W_OK ffi.Number) - (X_OK ffi.Number)) - - (ffi.import: Error - "[1]::[0]" - (toString [] ffi.String)) - - (template: (with_async <write> <type> <body>) - [(template.with_locals [<read>] - (let [[<read> <write>] (: [(Async <type>) (async.Resolver <type>)] - (async.async []))] - (exec - <body> - <read>)))]) - - (ffi.import: Fs - "[1]::[0]" - (constants FsConstants) - (readFile [ffi.String ffi.Function] Any) - (appendFile [ffi.String Buffer ffi.Function] Any) - (writeFile [ffi.String Buffer ffi.Function] Any) - (stat [ffi.String ffi.Function] Any) - (access [ffi.String ffi.Number ffi.Function] Any) - (rename [ffi.String ffi.String ffi.Function] Any) - (utimes [ffi.String ffi.Number ffi.Number ffi.Function] Any) - (readdir [ffi.String ffi.Function] Any) - (mkdir [ffi.String ffi.Function] Any) - (unlink [ffi.String ffi.Function] Any) - (rmdir [ffi.String ffi.Function] Any)) - - (def: (any_callback write!) - (-> (async.Resolver (Try Any)) ffi.Function) - (<| (ffi.function (_ [error Error]) Any) - io.run! - write! - (if (ffi.null? error) - {try.#Success []} - {try.#Failure (Error::toString error)}))) - - (def: (value_callback write!) - (All (_ a) (-> (async.Resolver (Try a)) ffi.Function)) - (<| (ffi.function (_ [error Error datum Any]) Any) - io.run! - write! - (if (ffi.null? error) - {try.#Success (:expected datum)} - {try.#Failure (Error::toString error)}))) - - (ffi.import: JsPath - "[1]::[0]" - (sep ffi.String)) - - (def: .public default - (Maybe (System Async)) - (do maybe.monad - [node_fs (node_js.require "fs") - node_path (node_js.require "path") - .let [node_fs (:as ..Fs node_fs) - js_separator (if ffi.on_node_js? - (JsPath::sep (:as ..JsPath node_path)) - "/")]] - (in (: (System Async) - (`` (implementation - (def: separator - js_separator) - - (~~ (template [<name> <method>] - [(def: (<name> path) - (do async.monad - [?stats (with_async write! (Try Stats) - (Fs::stat path (..value_callback write!) - node_fs))] - (in (case ?stats - {try.#Success stats} - (<method> stats) - - {try.#Failure _} - false))))] - - [file? Stats::isFile] - [directory? Stats::isDirectory] - )) - - (def: (make_directory path) - (do async.monad - [outcome (with_async write! (Try Any) - (Fs::access path - (|> node_fs Fs::constants FsConstants::F_OK) - (..any_callback write!) - node_fs))] - (case outcome - {try.#Success _} - (in (exception.except ..cannot_make_directory [path])) - - {try.#Failure _} - (with_async write! (Try Any) - (Fs::mkdir path (..any_callback write!) node_fs))))) - - (~~ (template [<name> <method>] - [(def: (<name> path) - (do [! (try.with async.monad)] - [subs (with_async write! (Try (Array ffi.String)) - (Fs::readdir path (..value_callback write!) node_fs))] - (|> subs - (array.list {.#None}) - (list#each (|>> (format path js_separator))) - (monad.each ! (function (_ sub) - (# ! each (|>> <method> [sub]) - (with_async write! (Try Stats) - (Fs::stat sub (..value_callback write!) node_fs))))) - (# ! each (|>> (list.only product.right) - (list#each product.left))))))] - - [directory_files Stats::isFile] - [sub_directories Stats::isDirectory] - )) - - (def: (file_size path) - (do (try.with async.monad) - [stats (with_async write! (Try Stats) - (Fs::stat path (..value_callback write!) - node_fs))] - (in (|> stats - Stats::size - f.nat)))) - - (def: (last_modified path) - (do (try.with async.monad) - [stats (with_async write! (Try Stats) - (Fs::stat path (..value_callback write!) - node_fs))] - (in (|> stats - Stats::mtimeMs - f.int - duration.of_millis - instant.absolute)))) - - (def: (can_execute? path) - (# async.monad each - (|>> (case> {try.#Success _} - true - - {try.#Failure _} - false) - {try.#Success}) + (for @.old (as_is <for_jvm>) + @.jvm (as_is <for_jvm>) + + @.js + (as_is (ffi.import: Buffer + "[1]::[0]" + ("static" from [Binary] ..Buffer)) + + (ffi.import: FileDescriptor + "[1]::[0]") + + (ffi.import: Stats + "[1]::[0]" + (size ffi.Number) + (mtimeMs ffi.Number) + (isFile [] ffi.Boolean) + (isDirectory [] ffi.Boolean)) + + (ffi.import: FsConstants + "[1]::[0]" + (F_OK ffi.Number) + (R_OK ffi.Number) + (W_OK ffi.Number) + (X_OK ffi.Number)) + + (ffi.import: Error + "[1]::[0]" + (toString [] ffi.String)) + + (template: (with_async <write> <type> <body>) + [(template.with_locals [<read>] + (let [[<read> <write>] (: [(Async <type>) (async.Resolver <type>)] + (async.async []))] + (exec + <body> + <read>)))]) + + (ffi.import: Fs + "[1]::[0]" + (constants FsConstants) + (readFile [ffi.String ffi.Function] Any) + (appendFile [ffi.String Buffer ffi.Function] Any) + (writeFile [ffi.String Buffer ffi.Function] Any) + (stat [ffi.String ffi.Function] Any) + (access [ffi.String ffi.Number ffi.Function] Any) + (rename [ffi.String ffi.String ffi.Function] Any) + (utimes [ffi.String ffi.Number ffi.Number ffi.Function] Any) + (readdir [ffi.String ffi.Function] Any) + (mkdir [ffi.String ffi.Function] Any) + (unlink [ffi.String ffi.Function] Any) + (rmdir [ffi.String ffi.Function] Any)) + + (def: (any_callback write!) + (-> (async.Resolver (Try Any)) ffi.Function) + (<| (ffi.function (_ [error Error]) Any) + io.run! + write! + (if (ffi.null? error) + {try.#Success []} + {try.#Failure (Error::toString error)}))) + + (def: (value_callback write!) + (All (_ a) (-> (async.Resolver (Try a)) ffi.Function)) + (<| (ffi.function (_ [error Error datum Any]) Any) + io.run! + write! + (if (ffi.null? error) + {try.#Success (:expected datum)} + {try.#Failure (Error::toString error)}))) + + (ffi.import: JsPath + "[1]::[0]" + (sep ffi.String)) + + (def: .public default + (Maybe (System Async)) + (do maybe.monad + [node_fs (node_js.require "fs") + node_path (node_js.require "path") + .let [node_fs (:as ..Fs node_fs) + js_separator (if ffi.on_node_js? + (JsPath::sep (:as ..JsPath node_path)) + "/")]] + (in (: (System Async) + (`` (implementation + (def: separator + js_separator) + + (~~ (template [<name> <method>] + [(def: (<name> path) + (do async.monad + [?stats (with_async write! (Try Stats) + (Fs::stat path (..value_callback write!) + node_fs))] + (in (case ?stats + {try.#Success stats} + (<method> stats) + + {try.#Failure _} + false))))] + + [file? Stats::isFile] + [directory? Stats::isDirectory] + )) + + (def: (make_directory path) + (do async.monad + [outcome (with_async write! (Try Any) + (Fs::access path + (|> node_fs Fs::constants FsConstants::F_OK) + (..any_callback write!) + node_fs))] + (case outcome + {try.#Success _} + (in (exception.except ..cannot_make_directory [path])) + + {try.#Failure _} (with_async write! (Try Any) - (Fs::access path - (|> node_fs Fs::constants FsConstants::X_OK) - (..any_callback write!) - node_fs)))) - - (def: (read path) - (with_async write! (Try Binary) - (Fs::readFile path (..value_callback write!) - node_fs))) - - (def: (delete path) - (do (try.with async.monad) - [stats (with_async write! (Try Stats) - (Fs::stat path (..value_callback write!) node_fs))] + (Fs::mkdir path (..any_callback write!) node_fs))))) + + (~~ (template [<name> <method>] + [(def: (<name> path) + (do [! (try.with async.monad)] + [subs (with_async write! (Try (Array ffi.String)) + (Fs::readdir path (..value_callback write!) node_fs))] + (|> subs + (array.list {.#None}) + (list#each (|>> (format path js_separator))) + (monad.each ! (function (_ sub) + (# ! each (|>> <method> [sub]) + (with_async write! (Try Stats) + (Fs::stat sub (..value_callback write!) node_fs))))) + (# ! each (|>> (list.only product.right) + (list#each product.left))))))] + + [directory_files Stats::isFile] + [sub_directories Stats::isDirectory] + )) + + (def: (file_size path) + (do (try.with async.monad) + [stats (with_async write! (Try Stats) + (Fs::stat path (..value_callback write!) + node_fs))] + (in (|> stats + Stats::size + f.nat)))) + + (def: (last_modified path) + (do (try.with async.monad) + [stats (with_async write! (Try Stats) + (Fs::stat path (..value_callback write!) + node_fs))] + (in (|> stats + Stats::mtimeMs + f.int + duration.of_millis + instant.absolute)))) + + (def: (can_execute? path) + (# async.monad each + (|>> (case> {try.#Success _} + true + + {try.#Failure _} + false) + {try.#Success}) (with_async write! (Try Any) - (if (Stats::isFile stats) - (Fs::unlink path (..any_callback write!) node_fs) - (Fs::rmdir path (..any_callback write!) node_fs))))) - - (def: (modify time_stamp path) - (with_async write! (Try Any) - (let [when (|> time_stamp instant.relative duration.millis i.frac)] - (Fs::utimes path when when (..any_callback write!) + (Fs::access path + (|> node_fs Fs::constants FsConstants::X_OK) + (..any_callback write!) node_fs)))) - (~~ (template [<name> <method>] - [(def: (<name> data path) - (with_async write! (Try Any) - (<method> path (Buffer::from data) (..any_callback write!) - node_fs)))] - - [write Fs::writeFile] - [append Fs::appendFile] - )) - - (def: (move destination origin) - (with_async write! (Try Any) - (Fs::rename origin destination (..any_callback write!) - node_fs)))))))))) - - @.python - (as_is (type: (Tuple/2 left right) - (Primitive "python_tuple[2]" [left right])) - - (ffi.import: PyFile - "[1]::[0]" - (read [] "io" "try" Binary) - (write [Binary] "io" "try" "?" Any) - (close [] "io" "try" "?" Any)) - - (ffi.import: (open [ffi.String ffi.String] "io" "try" PyFile)) - (ffi.import: (tuple [[ffi.Integer ffi.Integer]] (Tuple/2 ffi.Integer ffi.Integer))) - - (ffi.import: os - "[1]::[0]" - ("static" F_OK ffi.Integer) - ("static" R_OK ffi.Integer) - ("static" W_OK ffi.Integer) - ("static" X_OK ffi.Integer) - - ("static" mkdir [ffi.String] "io" "try" "?" Any) - ("static" access [ffi.String ffi.Integer] "io" "try" ffi.Boolean) - ("static" remove [ffi.String] "io" "try" "?" Any) - ("static" rmdir [ffi.String] "io" "try" "?" Any) - ("static" rename [ffi.String ffi.String] "io" "try" "?" Any) - ("static" utime [ffi.String (Tuple/2 ffi.Integer ffi.Integer)] "io" "try" "?" Any) - ("static" listdir [ffi.String] "io" "try" (Array ffi.String))) - - (ffi.import: os/path - "[1]::[0]" - ("static" isfile [ffi.String] "io" "try" ffi.Boolean) - ("static" isdir [ffi.String] "io" "try" ffi.Boolean) - ("static" sep ffi.String) - ("static" getsize [ffi.String] "io" "try" ffi.Integer) - ("static" getmtime [ffi.String] "io" "try" ffi.Float)) - - (def: python_separator - (os/path::sep)) - - (`` (implementation: .public default - (System IO) - - (def: separator - ..python_separator) - - (~~ (template [<name> <method>] - [(def: <name> - (|>> <method> - (io#each (|>> (try.else false)))))] - - [file? os/path::isfile] - [directory? os/path::isdir] - )) - - (def: make_directory - os::mkdir) - - (~~ (template [<name> <method>] - [(def: (<name> path) - (let [! (try.with io.monad)] - (|> path - os::listdir - (# ! each (|>> (array.list {.#None}) - (list#each (|>> (format path ..python_separator))) - (monad.each ! (function (_ sub) - (# ! each (|>> [sub]) (<method> sub)))) - (# ! each (|>> (list.only product.right) - (list#each product.left))))) - (# ! conjoint))))] - - [directory_files os/path::isfile] - [sub_directories os/path::isdir] - )) - - (def: file_size - (|>> os/path::getsize - (# (try.with io.monad) each (|>> .nat)))) - - (def: last_modified - (|>> os/path::getmtime - (# (try.with io.monad) each (|>> f.int - (i.* +1,000) - duration.of_millis - instant.absolute)))) - - (def: (can_execute? path) - (os::access path (os::X_OK))) - - (def: (read path) - (do (try.with io.monad) - [file (..open path "rb") - data (PyFile::read file) - _ (PyFile::close file)] - (in data))) - - (def: (delete path) - (do (try.with io.monad) - [? (os/path::isfile path)] - (if ? - (os::remove path) - (os::rmdir path)))) - - (def: (modify time_stamp path) - (let [when (|> time_stamp instant.relative duration.millis (i./ +1,000))] - (os::utime path (..tuple [when when])))) - - (~~ (template [<name> <mode>] - [(def: (<name> data path) - (do (try.with io.monad) - [file (..open path <mode>) - _ (PyFile::write data file)] - (PyFile::close file)))] - - [write "w+b"] - [append "ab"] - )) - - (def: (move destination origin) - (os::rename origin destination)) - ))) - - @.ruby - (as_is (ffi.import: Time - "[1]::[0]" - ("static" at [Frac] Time) - (to_f [] Frac)) - - (ffi.import: Stat - "[1]::[0]" - (executable? [] Bit) - (size Int) - (mtime [] Time)) - - (ffi.import: File "as" RubyFile - "[1]::[0]" - ("static" SEPARATOR ffi.String) - ("static" open [Path ffi.String] "io" "try" RubyFile) - ("static" stat [Path] "io" "try" Stat) - ("static" delete [Path] "io" "try" Int) - ("static" file? [Path] "io" "try" Bit) - ("static" directory? [Path] "io" "try" Bit) - ("static" utime [Time Time Path] "io" "try" Int) - - (read [] "io" "try" Binary) - (write [Binary] "io" "try" Int) - (flush [] "io" "try" "?" Any) - (close [] "io" "try" "?" Any)) - - (ffi.import: Dir - "[1]::[0]" - ("static" open [Path] "io" "try" Dir) - - (children [] "io" "try" (Array Path)) - (close [] "io" "try" "?" Any)) - - (ffi.import: "fileutils" FileUtils - "[1]::[0]" - ("static" move [Path Path] "io" "try" "?" Any) - ("static" rmdir [Path] "io" "try" "?" Any) - ("static" mkdir [Path] "io" "try" "?" Any)) - - (def: ruby_separator - Text - (..RubyFile::SEPARATOR)) - - (`` (implementation: .public default - (System IO) - - (def: separator - ..ruby_separator) - - (~~ (template [<name> <test>] - [(def: <name> - (|>> <test> - (io#each (|>> (try.else false)))))] - - [file? RubyFile::file?] - [directory? RubyFile::directory?] - )) - - (def: make_directory - FileUtils::mkdir) - - (~~ (template [<name> <test>] - [(def: (<name> path) - (do [! (try.with io.monad)] - [self (Dir::open path) - children (Dir::children self) - output (loop [input (|> children - (array.list {.#None}) - (list#each (|>> (format path ..ruby_separator)))) - output (: (List ..Path) - (list))] - (case input - {.#End} - (in output) - - {.#Item head tail} - (do ! - [verdict (<test> head)] - (again tail (if verdict - {.#Item head output} - output))))) - _ (Dir::close self)] - (in output)))] - - [directory_files RubyFile::file?] - [sub_directories RubyFile::directory?] - )) - - (~~ (template [<name> <pipeline>] - [(def: <name> - (let [! (try.with io.monad)] - (|>> RubyFile::stat - (# ! each (`` (|>> (~~ (template.spliced <pipeline>))))))))] - - [file_size [Stat::size .nat]] - [last_modified [Stat::mtime - Time::to_f - (f.* +1,000.0) - f.int - duration.of_millis - instant.absolute]] - [can_execute? [Stat::executable?]] - )) - - (def: (read path) - (do (try.with io.monad) - [file (RubyFile::open path "rb") - data (RubyFile::read file) - _ (RubyFile::close file)] - (in data))) - - (def: (delete path) - (do (try.with io.monad) - [? (RubyFile::file? path)] - (if ? - (RubyFile::delete path) - (FileUtils::rmdir path)))) - - (def: (modify moment path) - (let [moment (|> moment - instant.relative - duration.millis - i.frac - (f./ +1,000.0) - Time::at)] - (RubyFile::utime moment moment path))) - - (~~ (template [<mode> <name>] - [(def: (<name> data path) - (do [! (try.with io.monad)] - [file (RubyFile::open path <mode>) - data (RubyFile::write data file) - _ (RubyFile::flush file) - _ (RubyFile::close file)] - (in [])))] - - ["wb" write] - ["ab" append] - )) - - (def: (move destination origin) - (do (try.with io.monad) - [_ (FileUtils::move origin destination)] - (in []))) - ))) - - ... @.php - ... (as_is (ffi.import: (FILE_APPEND Int)) - ... ... https://www.php.net/manual/en/dir.constants.php - ... (ffi.import: (DIRECTORY_SEPARATOR ffi.String)) - ... ... https://www.php.net/manual/en/function.pack.php - ... ... https://www.php.net/manual/en/function.unpack.php - ... (ffi.import: (unpack [ffi.String ffi.String] Binary)) - ... ... https://www.php.net/manual/en/ref.filesystem.php - ... ... https://www.php.net/manual/en/function.file-get-contents.php - ... (ffi.import: (file_get_contents [Path] "io" "try" ffi.String)) - ... ... https://www.php.net/manual/en/function.file-put-contents.php - ... (ffi.import: (file_put_contents [Path ffi.String Int] "io" "try" ffi.Integer)) - ... (ffi.import: (filemtime [Path] "io" "try" ffi.Integer)) - ... (ffi.import: (filesize [Path] "io" "try" ffi.Integer)) - ... (ffi.import: (is_executable [Path] "io" "try" ffi.Boolean)) - ... (ffi.import: (touch [Path ffi.Integer] "io" "try" ffi.Boolean)) - ... (ffi.import: (rename [Path Path] "io" "try" ffi.Boolean)) - ... (ffi.import: (unlink [Path] "io" "try" ffi.Boolean)) - - ... ... https://www.php.net/manual/en/function.rmdir.php - ... (ffi.import: (rmdir [Path] "io" "try" ffi.Boolean)) - ... ... https://www.php.net/manual/en/function.scandir.php - ... (ffi.import: (scandir [Path] "io" "try" (Array Path))) - ... ... https://www.php.net/manual/en/function.is-file.php - ... (ffi.import: (is_file [Path] "io" "try" ffi.Boolean)) - ... ... https://www.php.net/manual/en/function.is-dir.php - ... (ffi.import: (is_dir [Path] "io" "try" ffi.Boolean)) - ... ... https://www.php.net/manual/en/function.mkdir.php - ... (ffi.import: (mkdir [Path] "io" "try" ffi.Boolean)) - - ... (def: byte_array_format "C*") - ... (def: default_separator (..DIRECTORY_SEPARATOR)) - - ... (template [<name>] - ... [(exception: .public (<name> [file Path]) - ... (exception.report - ... ["Path" file]))] - - ... [cannot_write_to_file] - ... ) - - ... (`` (implementation: (file path) - ... (-> Path (File IO)) - - ... (~~ (template [<name> <mode>] - ... [(def: (<name> data) - ... (do [! (try.with io.monad)] - ... [outcome (..file_put_contents [path ("php pack" ..byte_array_format data) <mode>])] - ... (if (bit#= false (:as Bit outcome)) - ... (# io.monad in (exception.except ..cannot_write_to_file [path])) - ... (in []))))] - - ... [over_write +0] - ... [append (..FILE_APPEND)] - ... )) - - ... (def: (content _) - ... (do [! (try.with io.monad)] - ... [data (..file_get_contents [path])] - ... (if (bit#= false (:as Bit data)) - ... (# io.monad in (exception.except ..cannot_find_file [path])) - ... (in (..unpack [..byte_array_format data]))))) - - ... (def: path - ... path) - - ... (~~ (template [<name> <ffi> <pipeline>] - ... [(def: (<name> _) - ... (do [! (try.with io.monad)] - ... [value (<ffi> [path])] - ... (if (bit#= false (:as Bit value)) - ... (# io.monad in (exception.except ..cannot_find_file [path])) - ... (in (`` (|> value (~~ (template.spliced <pipeline>))))))))] - - ... [size ..filesize [.nat]] - ... [last_modified ..filemtime [(i.* +1,000) duration.of_millis instant.absolute]] - ... )) - - ... (def: (can_execute? _) - ... (..is_executable [path])) - - ... (def: (modify moment) - ... (do [! (try.with io.monad)] - ... [verdict (..touch [path (|> moment instant.relative duration.millis (i./ +1,000))])] - ... (if (bit#= false (:as Bit verdict)) - ... (# io.monad in (exception.except ..cannot_find_file [path])) - ... (in [])))) - - ... (def: (move destination) - ... (do [! (try.with io.monad)] - ... [verdict (..rename [path destination])] - ... (if (bit#= false (:as Bit verdict)) - ... (# io.monad in (exception.except ..cannot_find_file [path])) - ... (in (file destination))))) - - ... (def: (delete _) - ... (do (try.with io.monad) - ... [verdict (..unlink [path])] - ... (if (bit#= false (:as Bit verdict)) - ... (# io.monad in (exception.except ..cannot_find_file [path])) - ... (in [])))) - ... )) - - ... (`` (implementation: (directory path) - ... (-> Path (Directory IO)) - - ... (def: scope - ... path) - - ... (~~ (template [<name> <test> <constructor> <capability>] - ... [(def: (<name> _) - ... (do [! (try.with io.monad)] - ... [children (..scandir [path])] - ... (loop [input (|> children - ... (array.list {.#None}) - ... (list.only (function (_ child) - ... (not (or (text#= "." child) - ... (text#= ".." child)))))) - ... output (: (List (<capability> IO)) - ... (list))] - ... (case input - ... {.#End} - ... (in output) - - ... {.#Item head tail} - ... (do ! - ... [verdict (<test> head)] - ... (if verdict - ... (again tail {.#Item (<constructor> head) output}) - ... (again tail output)))))))] - - ... [files ..is_file ..file File] - ... [directories ..is_dir directory Directory] - ... )) - - ... (def: (discard _) - ... (do (try.with io.monad) - ... [verdict (..rmdir [path])] - ... (if (bit#= false (:as Bit verdict)) - ... (# io.monad in (exception.except ..cannot_find_directory [path])) - ... (in [])))) - ... )) - - ... (`` (implementation: .public default - ... (System IO) - - ... (~~ (template [<name> <test> <constructor> <exception>] - ... [(def: (<name> path) - ... (do [! (try.with io.monad)] - ... [verdict (<test> path)] - ... (# io.monad in - ... (if verdict - ... {try.#Success (<constructor> path)} - ... (exception.except <exception> [path])))))] - - ... [file ..is_file ..file ..cannot_find_file] - ... [directory ..is_dir ..directory ..cannot_find_directory] - ... )) - - ... (def: (make_file path) - ... (do [! (try.with io.monad)] - ... [verdict (..touch [path (|> instant.now io.run! instant.relative duration.millis (i./ +1,000))])] - ... (# io.monad in - ... (if verdict - ... {try.#Success (..file path)} - ... (exception.except ..cannot_make_file [path]))))) - - ... (def: (make_directory path) - ... (do [! (try.with io.monad)] - ... [verdict (..mkdir path)] - ... (# io.monad in - ... (if verdict - ... {try.#Success (..directory path)} - ... (exception.except ..cannot_make_directory [path]))))) - - ... (def: separator - ... ..default_separator) - ... )) - ... ) - ] + (def: (read path) + (with_async write! (Try Binary) + (Fs::readFile path (..value_callback write!) + node_fs))) + + (def: (delete path) + (do (try.with async.monad) + [stats (with_async write! (Try Stats) + (Fs::stat path (..value_callback write!) node_fs))] + (with_async write! (Try Any) + (if (Stats::isFile stats) + (Fs::unlink path (..any_callback write!) node_fs) + (Fs::rmdir path (..any_callback write!) node_fs))))) + + (def: (modify time_stamp path) + (with_async write! (Try Any) + (let [when (|> time_stamp instant.relative duration.millis i.frac)] + (Fs::utimes path when when (..any_callback write!) + node_fs)))) + + (~~ (template [<name> <method>] + [(def: (<name> data path) + (with_async write! (Try Any) + (<method> path (Buffer::from data) (..any_callback write!) + node_fs)))] + + [write Fs::writeFile] + [append Fs::appendFile] + )) + + (def: (move destination origin) + (with_async write! (Try Any) + (Fs::rename origin destination (..any_callback write!) + node_fs)))))))))) + + @.python + (as_is (type: (Tuple/2 left right) + (Primitive "python_tuple[2]" [left right])) + + (ffi.import: PyFile + "[1]::[0]" + (read [] "io" "try" Binary) + (write [Binary] "io" "try" "?" Any) + (close [] "io" "try" "?" Any)) + + (ffi.import: (open [ffi.String ffi.String] "io" "try" PyFile)) + (ffi.import: (tuple [[ffi.Integer ffi.Integer]] (Tuple/2 ffi.Integer ffi.Integer))) + + (ffi.import: os + "[1]::[0]" + ("static" F_OK ffi.Integer) + ("static" R_OK ffi.Integer) + ("static" W_OK ffi.Integer) + ("static" X_OK ffi.Integer) + + ("static" mkdir [ffi.String] "io" "try" "?" Any) + ("static" access [ffi.String ffi.Integer] "io" "try" ffi.Boolean) + ("static" remove [ffi.String] "io" "try" "?" Any) + ("static" rmdir [ffi.String] "io" "try" "?" Any) + ("static" rename [ffi.String ffi.String] "io" "try" "?" Any) + ("static" utime [ffi.String (Tuple/2 ffi.Integer ffi.Integer)] "io" "try" "?" Any) + ("static" listdir [ffi.String] "io" "try" (Array ffi.String))) + + (ffi.import: os/path + "[1]::[0]" + ("static" isfile [ffi.String] "io" "try" ffi.Boolean) + ("static" isdir [ffi.String] "io" "try" ffi.Boolean) + ("static" sep ffi.String) + ("static" getsize [ffi.String] "io" "try" ffi.Integer) + ("static" getmtime [ffi.String] "io" "try" ffi.Float)) + + (def: python_separator + (os/path::sep)) + + (`` (implementation: .public default + (System IO) + + (def: separator + ..python_separator) + + (~~ (template [<name> <method>] + [(def: <name> + (|>> <method> + (io#each (|>> (try.else false)))))] + + [file? os/path::isfile] + [directory? os/path::isdir] + )) + + (def: make_directory + os::mkdir) + + (~~ (template [<name> <method>] + [(def: (<name> path) + (let [! (try.with io.monad)] + (|> path + os::listdir + (# ! each (|>> (array.list {.#None}) + (list#each (|>> (format path ..python_separator))) + (monad.each ! (function (_ sub) + (# ! each (|>> [sub]) (<method> sub)))) + (# ! each (|>> (list.only product.right) + (list#each product.left))))) + (# ! conjoint))))] + + [directory_files os/path::isfile] + [sub_directories os/path::isdir] + )) + + (def: file_size + (|>> os/path::getsize + (# (try.with io.monad) each (|>> .nat)))) + + (def: last_modified + (|>> os/path::getmtime + (# (try.with io.monad) each (|>> f.int + (i.* +1,000) + duration.of_millis + instant.absolute)))) + + (def: (can_execute? path) + (os::access path (os::X_OK))) + + (def: (read path) + (do (try.with io.monad) + [file (..open path "rb") + data (PyFile::read file) + _ (PyFile::close file)] + (in data))) + + (def: (delete path) + (do (try.with io.monad) + [? (os/path::isfile path)] + (if ? + (os::remove path) + (os::rmdir path)))) + + (def: (modify time_stamp path) + (let [when (|> time_stamp instant.relative duration.millis (i./ +1,000))] + (os::utime path (..tuple [when when])))) + + (~~ (template [<name> <mode>] + [(def: (<name> data path) + (do (try.with io.monad) + [file (..open path <mode>) + _ (PyFile::write data file)] + (PyFile::close file)))] + + [write "w+b"] + [append "ab"] + )) + + (def: (move destination origin) + (os::rename origin destination)) + ))) + + @.ruby + (as_is (ffi.import: Time + "[1]::[0]" + ("static" at [Frac] Time) + (to_f [] Frac)) + + (ffi.import: Stat + "[1]::[0]" + (executable? [] Bit) + (size Int) + (mtime [] Time)) + + (ffi.import: File "as" RubyFile + "[1]::[0]" + ("static" SEPARATOR ffi.String) + ("static" open [Path ffi.String] "io" "try" RubyFile) + ("static" stat [Path] "io" "try" Stat) + ("static" delete [Path] "io" "try" Int) + ("static" file? [Path] "io" "try" Bit) + ("static" directory? [Path] "io" "try" Bit) + ("static" utime [Time Time Path] "io" "try" Int) + + (read [] "io" "try" Binary) + (write [Binary] "io" "try" Int) + (flush [] "io" "try" "?" Any) + (close [] "io" "try" "?" Any)) + + (ffi.import: Dir + "[1]::[0]" + ("static" open [Path] "io" "try" Dir) + + (children [] "io" "try" (Array Path)) + (close [] "io" "try" "?" Any)) + + (ffi.import: "fileutils" FileUtils + "[1]::[0]" + ("static" move [Path Path] "io" "try" "?" Any) + ("static" rmdir [Path] "io" "try" "?" Any) + ("static" mkdir [Path] "io" "try" "?" Any)) + + (def: ruby_separator + Text + (..RubyFile::SEPARATOR)) + + (`` (implementation: .public default + (System IO) + + (def: separator + ..ruby_separator) + + (~~ (template [<name> <test>] + [(def: <name> + (|>> <test> + (io#each (|>> (try.else false)))))] + + [file? RubyFile::file?] + [directory? RubyFile::directory?] + )) + + (def: make_directory + FileUtils::mkdir) + + (~~ (template [<name> <test>] + [(def: (<name> path) + (do [! (try.with io.monad)] + [self (Dir::open path) + children (Dir::children self) + output (loop [input (|> children + (array.list {.#None}) + (list#each (|>> (format path ..ruby_separator)))) + output (: (List ..Path) + (list))] + (case input + {.#End} + (in output) + + {.#Item head tail} + (do ! + [verdict (<test> head)] + (again tail (if verdict + {.#Item head output} + output))))) + _ (Dir::close self)] + (in output)))] + + [directory_files RubyFile::file?] + [sub_directories RubyFile::directory?] + )) + + (~~ (template [<name> <pipeline>] + [(def: <name> + (let [! (try.with io.monad)] + (|>> RubyFile::stat + (# ! each (`` (|>> (~~ (template.spliced <pipeline>))))))))] + + [file_size [Stat::size .nat]] + [last_modified [Stat::mtime + Time::to_f + (f.* +1,000.0) + f.int + duration.of_millis + instant.absolute]] + [can_execute? [Stat::executable?]] + )) + + (def: (read path) + (do (try.with io.monad) + [file (RubyFile::open path "rb") + data (RubyFile::read file) + _ (RubyFile::close file)] + (in data))) + + (def: (delete path) + (do (try.with io.monad) + [? (RubyFile::file? path)] + (if ? + (RubyFile::delete path) + (FileUtils::rmdir path)))) + + (def: (modify moment path) + (let [moment (|> moment + instant.relative + duration.millis + i.frac + (f./ +1,000.0) + Time::at)] + (RubyFile::utime moment moment path))) + + (~~ (template [<mode> <name>] + [(def: (<name> data path) + (do [! (try.with io.monad)] + [file (RubyFile::open path <mode>) + data (RubyFile::write data file) + _ (RubyFile::flush file) + _ (RubyFile::close file)] + (in [])))] + + ["wb" write] + ["ab" append] + )) + + (def: (move destination origin) + (do (try.with io.monad) + [_ (FileUtils::move origin destination)] + (in []))) + ))) + + ... @.php + ... (as_is (ffi.import: (FILE_APPEND Int)) + ... ... https://www.php.net/manual/en/dir.constants.php + ... (ffi.import: (DIRECTORY_SEPARATOR ffi.String)) + ... ... https://www.php.net/manual/en/function.pack.php + ... ... https://www.php.net/manual/en/function.unpack.php + ... (ffi.import: (unpack [ffi.String ffi.String] Binary)) + ... ... https://www.php.net/manual/en/ref.filesystem.php + ... ... https://www.php.net/manual/en/function.file-get-contents.php + ... (ffi.import: (file_get_contents [Path] "io" "try" ffi.String)) + ... ... https://www.php.net/manual/en/function.file-put-contents.php + ... (ffi.import: (file_put_contents [Path ffi.String Int] "io" "try" ffi.Integer)) + ... (ffi.import: (filemtime [Path] "io" "try" ffi.Integer)) + ... (ffi.import: (filesize [Path] "io" "try" ffi.Integer)) + ... (ffi.import: (is_executable [Path] "io" "try" ffi.Boolean)) + ... (ffi.import: (touch [Path ffi.Integer] "io" "try" ffi.Boolean)) + ... (ffi.import: (rename [Path Path] "io" "try" ffi.Boolean)) + ... (ffi.import: (unlink [Path] "io" "try" ffi.Boolean)) + + ... ... https://www.php.net/manual/en/function.rmdir.php + ... (ffi.import: (rmdir [Path] "io" "try" ffi.Boolean)) + ... ... https://www.php.net/manual/en/function.scandir.php + ... (ffi.import: (scandir [Path] "io" "try" (Array Path))) + ... ... https://www.php.net/manual/en/function.is-file.php + ... (ffi.import: (is_file [Path] "io" "try" ffi.Boolean)) + ... ... https://www.php.net/manual/en/function.is-dir.php + ... (ffi.import: (is_dir [Path] "io" "try" ffi.Boolean)) + ... ... https://www.php.net/manual/en/function.mkdir.php + ... (ffi.import: (mkdir [Path] "io" "try" ffi.Boolean)) + + ... (def: byte_array_format "C*") + ... (def: default_separator (..DIRECTORY_SEPARATOR)) + + ... (template [<name>] + ... [(exception: .public (<name> [file Path]) + ... (exception.report + ... ["Path" file]))] + + ... [cannot_write_to_file] + ... ) + + ... (`` (implementation: (file path) + ... (-> Path (File IO)) + + ... (~~ (template [<name> <mode>] + ... [(def: (<name> data) + ... (do [! (try.with io.monad)] + ... [outcome (..file_put_contents [path ("php pack" ..byte_array_format data) <mode>])] + ... (if (bit#= false (:as Bit outcome)) + ... (# io.monad in (exception.except ..cannot_write_to_file [path])) + ... (in []))))] + + ... [over_write +0] + ... [append (..FILE_APPEND)] + ... )) + + ... (def: (content _) + ... (do [! (try.with io.monad)] + ... [data (..file_get_contents [path])] + ... (if (bit#= false (:as Bit data)) + ... (# io.monad in (exception.except ..cannot_find_file [path])) + ... (in (..unpack [..byte_array_format data]))))) + + ... (def: path + ... path) + + ... (~~ (template [<name> <ffi> <pipeline>] + ... [(def: (<name> _) + ... (do [! (try.with io.monad)] + ... [value (<ffi> [path])] + ... (if (bit#= false (:as Bit value)) + ... (# io.monad in (exception.except ..cannot_find_file [path])) + ... (in (`` (|> value (~~ (template.spliced <pipeline>))))))))] + + ... [size ..filesize [.nat]] + ... [last_modified ..filemtime [(i.* +1,000) duration.of_millis instant.absolute]] + ... )) + + ... (def: (can_execute? _) + ... (..is_executable [path])) + + ... (def: (modify moment) + ... (do [! (try.with io.monad)] + ... [verdict (..touch [path (|> moment instant.relative duration.millis (i./ +1,000))])] + ... (if (bit#= false (:as Bit verdict)) + ... (# io.monad in (exception.except ..cannot_find_file [path])) + ... (in [])))) + + ... (def: (move destination) + ... (do [! (try.with io.monad)] + ... [verdict (..rename [path destination])] + ... (if (bit#= false (:as Bit verdict)) + ... (# io.monad in (exception.except ..cannot_find_file [path])) + ... (in (file destination))))) + + ... (def: (delete _) + ... (do (try.with io.monad) + ... [verdict (..unlink [path])] + ... (if (bit#= false (:as Bit verdict)) + ... (# io.monad in (exception.except ..cannot_find_file [path])) + ... (in [])))) + ... )) + + ... (`` (implementation: (directory path) + ... (-> Path (Directory IO)) + + ... (def: scope + ... path) + + ... (~~ (template [<name> <test> <constructor> <capability>] + ... [(def: (<name> _) + ... (do [! (try.with io.monad)] + ... [children (..scandir [path])] + ... (loop [input (|> children + ... (array.list {.#None}) + ... (list.only (function (_ child) + ... (not (or (text#= "." child) + ... (text#= ".." child)))))) + ... output (: (List (<capability> IO)) + ... (list))] + ... (case input + ... {.#End} + ... (in output) + + ... {.#Item head tail} + ... (do ! + ... [verdict (<test> head)] + ... (if verdict + ... (again tail {.#Item (<constructor> head) output}) + ... (again tail output)))))))] + + ... [files ..is_file ..file File] + ... [directories ..is_dir directory Directory] + ... )) + + ... (def: (discard _) + ... (do (try.with io.monad) + ... [verdict (..rmdir [path])] + ... (if (bit#= false (:as Bit verdict)) + ... (# io.monad in (exception.except ..cannot_find_directory [path])) + ... (in [])))) + ... )) + + ... (`` (implementation: .public default + ... (System IO) + + ... (~~ (template [<name> <test> <constructor> <exception>] + ... [(def: (<name> path) + ... (do [! (try.with io.monad)] + ... [verdict (<test> path)] + ... (# io.monad in + ... (if verdict + ... {try.#Success (<constructor> path)} + ... (exception.except <exception> [path])))))] + + ... [file ..is_file ..file ..cannot_find_file] + ... [directory ..is_dir ..directory ..cannot_find_directory] + ... )) + + ... (def: (make_file path) + ... (do [! (try.with io.monad)] + ... [verdict (..touch [path (|> instant.now io.run! instant.relative duration.millis (i./ +1,000))])] + ... (# io.monad in + ... (if verdict + ... {try.#Success (..file path)} + ... (exception.except ..cannot_make_file [path]))))) + + ... (def: (make_directory path) + ... (do [! (try.with io.monad)] + ... [verdict (..mkdir path)] + ... (# io.monad in + ... (if verdict + ... {try.#Success (..directory path)} + ... (exception.except ..cannot_make_directory [path]))))) + + ... (def: separator + ... ..default_separator) + ... )) + ... ) + (as_is))) (def: .public (exists? monad fs path) diff --git a/stdlib/source/library/lux/world/file/watch.lux b/stdlib/source/library/lux/world/file/watch.lux index 5ad94c22e..a5828f116 100644 --- a/stdlib/source/library/lux/world/file/watch.lux +++ b/stdlib/source/library/lux/world/file/watch.lux @@ -457,6 +457,6 @@ (async.future (..default_poll watcher))) ))))) )] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>)] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) (as_is))) diff --git a/stdlib/source/library/lux/world/net/http/client.lux b/stdlib/source/library/lux/world/net/http/client.lux index 85e9c2cbd..9ce51d32a 100644 --- a/stdlib/source/library/lux/world/net/http/client.lux +++ b/stdlib/source/library/lux/world/net/http/client.lux @@ -215,8 +215,8 @@ (in [(.nat (ffi.of_int status)) [//.#headers headers //.#body (..default_body input)]]))))))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>)] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) (as_is))) (implementation: .public (async client) diff --git a/stdlib/source/library/lux/world/program.lux b/stdlib/source/library/lux/world/program.lux index cb3c96f19..c3870d14d 100644 --- a/stdlib/source/library/lux/world/program.lux +++ b/stdlib/source/library/lux/world/program.lux @@ -24,8 +24,8 @@ ["[0]" dictionary {"+" Dictionary}] ["[0]" list ("[1]#[0]" functor)]]] ["[0]" ffi {"+" import:} - (~~ (.for ["JavaScript" (~~ (.as_is ["[0]" node_js])) - "{old}" (~~ (.as_is ["node_js" //math]))] + (~~ (.for "JavaScript" (~~ (.as_is ["[0]" node_js])) + "{old}" (~~ (.as_is ["node_js" //math])) (~~ (.as_is))))] ["[0]" macro ["[0]" template]] @@ -144,144 +144,144 @@ (jvm##consume iterator)} {.#End})) )] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - @.js (as_is (def: default_exit! - (-> Exit (IO Nothing)) - (|>> %.int panic! io.io)) - - (import: NodeJs_Process - "[1]::[0]" - (exit [ffi.Number] "io" Nothing) - (cwd [] "io" Path)) - - (def: (exit_node_js! code) - (-> Exit (IO Nothing)) - (case (ffi.global ..NodeJs_Process [process]) - {.#Some process} - (NodeJs_Process::exit (i.frac code) process) - - {.#None} - (..default_exit! code))) - - (import: Browser_Window + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + @.js (as_is (def: default_exit! + (-> Exit (IO Nothing)) + (|>> %.int panic! io.io)) + + (import: NodeJs_Process + "[1]::[0]" + (exit [ffi.Number] "io" Nothing) + (cwd [] "io" Path)) + + (def: (exit_node_js! code) + (-> Exit (IO Nothing)) + (case (ffi.global ..NodeJs_Process [process]) + {.#Some process} + (NodeJs_Process::exit (i.frac code) process) + + {.#None} + (..default_exit! code))) + + (import: Browser_Window + "[1]::[0]" + (close [] Nothing)) + + (import: Browser_Location + "[1]::[0]" + (reload [] Nothing)) + + (def: (exit_browser! code) + (-> Exit (IO Nothing)) + (case [(ffi.global ..Browser_Window [window]) + (ffi.global ..Browser_Location [location])] + [{.#Some window} {.#Some location}] + (exec + (Browser_Window::close window) + (Browser_Location::reload location) + (..default_exit! code)) + + [{.#Some window} {.#None}] + (exec + (Browser_Window::close window) + (..default_exit! code)) + + [{.#None} {.#Some location}] + (exec + (Browser_Location::reload location) + (..default_exit! code)) + + [{.#None} {.#None}] + (..default_exit! code))) + + (import: Object + "[1]::[0]" + ("static" entries [Object] (Array (Array ffi.String)))) + + (import: NodeJs_OS + "[1]::[0]" + (homedir [] "io" Path))) + @.python (as_is (import: os + "[1]::[0]" + ("static" getcwd [] "io" ffi.String) + ("static" _exit [ffi.Integer] "io" Nothing)) + + (import: os/path + "[1]::[0]" + ("static" expanduser [ffi.String] "io" ffi.String)) + + (import: os/environ + "[1]::[0]" + ("static" keys [] "io" (Array ffi.String)) + ("static" get [ffi.String] "io" "?" ffi.String))) + @.lua (as_is (ffi.import: LuaFile "[1]::[0]" - (close [] Nothing)) + (read [ffi.String] "io" "?" ffi.String) + (close [] "io" ffi.Boolean)) + + (ffi.import: (io/popen [ffi.String] "io" "try" "?" LuaFile)) + (ffi.import: (os/getenv [ffi.String] "io" "?" ffi.String)) + (ffi.import: (os/exit [ffi.Integer] "io" Nothing)) + + (def: (run_command default command) + (-> Text Text (IO Text)) + (do [! io.monad] + [outcome (io/popen [command])] + (case outcome + {try.#Success outcome} + (case outcome + {.#Some file} + (do ! + [?output (LuaFile::read "*l" file) + _ (LuaFile::close file)] + (in (maybe.else default ?output))) + + {.#None} + (in default)) + + {try.#Failure _} + (in default))))) + @.ruby (as_is (ffi.import: Env + "[1]::[0]" + ("static" keys [] (Array Text)) + ("static" fetch [Text] "io" "?" Text)) - (import: Browser_Location - "[1]::[0]" - (reload [] Nothing)) - - (def: (exit_browser! code) - (-> Exit (IO Nothing)) - (case [(ffi.global ..Browser_Window [window]) - (ffi.global ..Browser_Location [location])] - [{.#Some window} {.#Some location}] - (exec - (Browser_Window::close window) - (Browser_Location::reload location) - (..default_exit! code)) - - [{.#Some window} {.#None}] - (exec - (Browser_Window::close window) - (..default_exit! code)) - - [{.#None} {.#Some location}] - (exec - (Browser_Location::reload location) - (..default_exit! code)) - - [{.#None} {.#None}] - (..default_exit! code))) - - (import: Object - "[1]::[0]" - ("static" entries [Object] (Array (Array ffi.String)))) + (ffi.import: "fileutils" FileUtils + "[1]::[0]" + ("static" pwd Path)) + + (ffi.import: Dir + "[1]::[0]" + ("static" home Path)) - (import: NodeJs_OS - "[1]::[0]" - (homedir [] "io" Path))) - @.python (as_is (import: os - "[1]::[0]" - ("static" getcwd [] "io" ffi.String) - ("static" _exit [ffi.Integer] "io" Nothing)) - - (import: os/path - "[1]::[0]" - ("static" expanduser [ffi.String] "io" ffi.String)) - - (import: os/environ - "[1]::[0]" - ("static" keys [] "io" (Array ffi.String)) - ("static" get [ffi.String] "io" "?" ffi.String))) - @.lua (as_is (ffi.import: LuaFile + (ffi.import: Kernel "[1]::[0]" - (read [ffi.String] "io" "?" ffi.String) - (close [] "io" ffi.Boolean)) - - (ffi.import: (io/popen [ffi.String] "io" "try" "?" LuaFile)) - (ffi.import: (os/getenv [ffi.String] "io" "?" ffi.String)) - (ffi.import: (os/exit [ffi.Integer] "io" Nothing)) - - (def: (run_command default command) - (-> Text Text (IO Text)) - (do [! io.monad] - [outcome (io/popen [command])] - (case outcome - {try.#Success outcome} - (case outcome - {.#Some file} - (do ! - [?output (LuaFile::read "*l" file) - _ (LuaFile::close file)] - (in (maybe.else default ?output))) - - {.#None} - (in default)) - - {try.#Failure _} - (in default))))) - @.ruby (as_is (ffi.import: Env - "[1]::[0]" - ("static" keys [] (Array Text)) - ("static" fetch [Text] "io" "?" Text)) - - (ffi.import: "fileutils" FileUtils - "[1]::[0]" - ("static" pwd Path)) - - (ffi.import: Dir - "[1]::[0]" - ("static" home Path)) - - (ffi.import: Kernel - "[1]::[0]" - ("static" exit [Int] "io" Nothing))) - - ... @.php - ... (as_is (ffi.import: (exit [Int] "io" Nothing)) - ... ... https://www.php.net/manual/en/function.exit.php - ... (ffi.import: (getcwd [] "io" ffi.String)) - ... ... https://www.php.net/manual/en/function.getcwd.php - ... (ffi.import: (getenv "as" getenv/1 [ffi.String] "io" ffi.String)) - ... (ffi.import: (getenv "as" getenv/0 [] "io" (Array ffi.String))) - ... ... https://www.php.net/manual/en/function.getenv.php - ... ... https://www.php.net/manual/en/function.array-keys.php - ... (ffi.import: (array_keys [(Array ffi.String)] (Array ffi.String))) - ... ) - - ... @.scheme - ... (as_is (ffi.import: (exit [Int] "io" Nothing)) - ... ... https://srfi.schemers.org/srfi-98/srfi-98.html - ... (abstract: Pair Any) - ... (abstract: PList Any) - ... (ffi.import: (get-environment-variables [] "io" PList)) - ... (ffi.import: (car [Pair] Text)) - ... (ffi.import: (cdr [Pair] Text)) - ... (ffi.import: (car "as" head [PList] Pair)) - ... (ffi.import: (cdr "as" tail [PList] PList))) - ] + ("static" exit [Int] "io" Nothing))) + + ... @.php + ... (as_is (ffi.import: (exit [Int] "io" Nothing)) + ... ... https://www.php.net/manual/en/function.exit.php + ... (ffi.import: (getcwd [] "io" ffi.String)) + ... ... https://www.php.net/manual/en/function.getcwd.php + ... (ffi.import: (getenv "as" getenv/1 [ffi.String] "io" ffi.String)) + ... (ffi.import: (getenv "as" getenv/0 [] "io" (Array ffi.String))) + ... ... https://www.php.net/manual/en/function.getenv.php + ... ... https://www.php.net/manual/en/function.array-keys.php + ... (ffi.import: (array_keys [(Array ffi.String)] (Array ffi.String))) + ... ) + + ... @.scheme + ... (as_is (ffi.import: (exit [Int] "io" Nothing)) + ... ... https://srfi.schemers.org/srfi-98/srfi-98.html + ... (abstract: Pair Any) + ... (abstract: PList Any) + ... (ffi.import: (get-environment-variables [] "io" PList)) + ... (ffi.import: (car [Pair] Text)) + ... (ffi.import: (cdr [Pair] Text)) + ... (ffi.import: (car "as" head [PList] Pair)) + ... (ffi.import: (cdr "as" tail [PList] PList))) + (as_is))) (implementation: .public default @@ -294,40 +294,40 @@ ..jvm##consume (list#each (|>> ffi.of_string)) io.io)] - (for [@.old <jvm> - @.jvm <jvm> - @.js (io.io (if ffi.on_node_js? - (case (ffi.global Object [process env]) - {.#Some process/env} - (|> (Object::entries [process/env]) - (array.list {.#None}) - (list#each (|>> (array.read! 0) maybe.trusted))) - - {.#None} - (list)) - (list))) - @.python (# io.monad each (array.list {.#None}) (os/environ::keys [])) - ... Lua offers no way to get all the environment variables available. - @.lua (io.io (list)) - @.ruby (io.io (array.list {.#None} (Env::keys []))) - ... @.php (do io.monad - ... [environment (..getenv/0 [])] - ... (in (|> environment - ... ..array_keys - ... (array.list {.#None}) - ... (list#each (function (_ variable) - ... [variable ("php array read" (:as Nat variable) environment)])) - ... (dictionary.of_list text.hash)))) - ... @.scheme (do io.monad - ... [input (..get-environment-variables [])] - ... (loop [input input - ... output environment.empty] - ... (if ("scheme object nil?" input) - ... (in output) - ... (let [entry (..head input)] - ... (again (..tail input) - ... (dictionary.has (..car entry) (..cdr entry) output)))))) - ]))) + (for @.old <jvm> + @.jvm <jvm> + @.js (io.io (if ffi.on_node_js? + (case (ffi.global Object [process env]) + {.#Some process/env} + (|> (Object::entries [process/env]) + (array.list {.#None}) + (list#each (|>> (array.read! 0) maybe.trusted))) + + {.#None} + (list)) + (list))) + @.python (# io.monad each (array.list {.#None}) (os/environ::keys [])) + ... Lua offers no way to get all the environment variables available. + @.lua (io.io (list)) + @.ruby (io.io (array.list {.#None} (Env::keys []))) + ... @.php (do io.monad + ... [environment (..getenv/0 [])] + ... (in (|> environment + ... ..array_keys + ... (array.list {.#None}) + ... (list#each (function (_ variable) + ... [variable ("php array read" (:as Nat variable) environment)])) + ... (dictionary.of_list text.hash)))) + ... @.scheme (do io.monad + ... [input (..get-environment-variables [])] + ... (loop [input input + ... output environment.empty] + ... (if ("scheme object nil?" input) + ... (in output) + ... (let [entry (..head input)] + ... (again (..tail input) + ... (dictionary.has (..car entry) (..cdr entry) output)))))) + ))) (def: (variable name) (template.let [(!fetch <method> <post>) @@ -340,23 +340,23 @@ {.#None} (exception.except ..unknown_environment_variable [name]))))]] (with_expansions [<jvm> (!fetch (<| java/lang/System::resolveEnv ffi.as_string) ffi.of_string)] - (for [@.old <jvm> - @.jvm <jvm> - @.js (io.io (if ffi.on_node_js? - (case (do maybe.monad - [process/env (ffi.global Object [process env])] - (array.read! (:as Nat name) - (:as (Array Text) process/env))) - {.#Some value} - {try.#Success value} - - {.#None} - (exception.except ..unknown_environment_variable [name])) - (exception.except ..unknown_environment_variable [name]))) - @.python (!fetch os/environ::get |>) - @.lua (!fetch os/getenv |>) - @.ruby (!fetch Env::fetch |>) - ])))) + (for @.old <jvm> + @.jvm <jvm> + @.js (io.io (if ffi.on_node_js? + (case (do maybe.monad + [process/env (ffi.global Object [process env])] + (array.read! (:as Nat name) + (:as (Array Text) process/env))) + {.#Some value} + {try.#Success value} + + {.#None} + (exception.except ..unknown_environment_variable [name])) + (exception.except ..unknown_environment_variable [name]))) + @.python (!fetch os/environ::get |>) + @.lua (!fetch os/getenv |>) + @.ruby (!fetch Env::fetch |>) + )))) (def: home (io.run! @@ -365,23 +365,23 @@ (maybe#each (|>> ffi.of_string)) (maybe.else "") io.io)] - (for [@.old <jvm> - @.jvm <jvm> - @.js (if ffi.on_node_js? - (|> (node_js.require "os") - maybe.trusted - (:as NodeJs_OS) - NodeJs_OS::homedir) - <default>) - @.python (os/path::expanduser "~") - @.lua (..run_command "~" "echo ~") - @.ruby (io.io (Dir::home)) - ... @.php (do io.monad - ... [output (..getenv/1 ["HOME"])] - ... (in (if (bit#= false (:as Bit output)) - ... "~" - ... output))) - ] + (for @.old <jvm> + @.jvm <jvm> + @.js (if ffi.on_node_js? + (|> (node_js.require "os") + maybe.trusted + (:as NodeJs_OS) + NodeJs_OS::homedir) + <default>) + @.python (os/path::expanduser "~") + @.lua (..run_command "~" "echo ~") + @.ruby (io.io (Dir::home)) + ... @.php (do io.monad + ... [output (..getenv/1 ["HOME"])] + ... (in (if (bit#= false (:as Bit output)) + ... "~" + ... output))) + ... TODO: Replace dummy implementation. <default>)))) @@ -392,30 +392,30 @@ (maybe#each (|>> ffi.of_string)) (maybe.else "") io.io)] - (for [@.old <jvm> - @.jvm <jvm> - @.js (if ffi.on_node_js? - (case (ffi.global ..NodeJs_Process [process]) - {.#Some process} - (NodeJs_Process::cwd process) - - {.#None} - (io.io <default>)) - (io.io <default>)) - @.python (os::getcwd []) - @.lua (do io.monad - [.let [default <default>] - on_windows (..run_command default "cd")] - (if (same? default on_windows) - (..run_command default "pwd") - (in on_windows))) - @.ruby (io.io (FileUtils::pwd)) - ... @.php (do io.monad - ... [output (..getcwd [])] - ... (in (if (bit#= false (:as Bit output)) - ... "." - ... output))) - ] + (for @.old <jvm> + @.jvm <jvm> + @.js (if ffi.on_node_js? + (case (ffi.global ..NodeJs_Process [process]) + {.#Some process} + (NodeJs_Process::cwd process) + + {.#None} + (io.io <default>)) + (io.io <default>)) + @.python (os::getcwd []) + @.lua (do io.monad + [.let [default <default>] + on_windows (..run_command default "cd")] + (if (same? default on_windows) + (..run_command default "pwd") + (in on_windows))) + @.ruby (io.io (FileUtils::pwd)) + ... @.php (do io.monad + ... [output (..getcwd [])] + ... (in (if (bit#= false (:as Bit output)) + ... "." + ... output))) + ... TODO: Replace dummy implementation. (io.io <default>))))) @@ -423,19 +423,19 @@ (with_expansions [<jvm> (do io.monad [_ (java/lang/System::exit (ffi.as_int code))] (in (undefined)))] - (for [@.old <jvm> - @.jvm <jvm> - @.js (cond ffi.on_node_js? - (..exit_node_js! code) - - ffi.on_browser? - (..exit_browser! code) - - ... else - (..default_exit! code)) - @.python (os::_exit code) - @.lua (os/exit code) - @.ruby (Kernel::exit code) - ... @.php (..exit [code]) - ... @.scheme (..exit [code]) - ])))) + (for @.old <jvm> + @.jvm <jvm> + @.js (cond ffi.on_node_js? + (..exit_node_js! code) + + ffi.on_browser? + (..exit_browser! code) + + ... else + (..default_exit! code)) + @.python (os::_exit code) + @.lua (os/exit code) + @.ruby (Kernel::exit code) + ... @.php (..exit [code]) + ... @.scheme (..exit [code]) + )))) diff --git a/stdlib/source/library/lux/world/shell.lux b/stdlib/source/library/lux/world/shell.lux index 22f63e05b..154fb6290 100644 --- a/stdlib/source/library/lux/world/shell.lux +++ b/stdlib/source/library/lux/world/shell.lux @@ -306,8 +306,8 @@ process (java/lang/ProcessBuilder::start builder)] (..default_process process)))) )] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>)] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) (as_is))) (type: .public (Mock s) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 69bae4f82..13b2e434e 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -69,12 +69,12 @@ error text.new_line)] (do ! [_ (with_expansions [<else> (in (debug.log! report))] - (for [@.js (case console.default - {.#None} - <else> + (for @.js (case console.default + {.#None} + <else> - {.#Some console} - (console.write_line report console))] + {.#Some console} + (console.write_line report console)) <else>))] (io.run! (# world/program.default exit +1)))) @@ -174,11 +174,11 @@ (:expected (platform.compile lux_compiler phase_wrapper import file_context expander platform compilation [archive state]))) _ (cache.cache! (the platform.#&file_system platform) file_context archive) host_dependencies (..load_host_dependencies (the platform.#&file_system platform) compilation_host_dependencies) - _ (..package! (for [@.old (file.async file.default) - @.jvm (file.async file.default) - ... TODO: Handle this in a safer manner. - ... This would crash if the compiler was run on a browser. - @.js (maybe.trusted file.default)]) + _ (..package! (for @.old (file.async file.default) + @.jvm (file.async file.default) + ... TODO: Handle this in a safer manner. + ... This would crash if the compiler was run on a browser. + @.js (maybe.trusted file.default)) host_dependencies packager,package archive diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 743c108f7..bd30cf30e 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -62,12 +62,12 @@ ["[1][0]" ffi] ["[1][0]" extension] ["[1][0]" target "_" - (~~ (.for ["{old}" (~~ (.as_is ["[1]/[0]" jvm])) - "JVM" (~~ (.as_is ["[1]/[0]" jvm])) - "JavaScript" (~~ (.as_is ["[1]/[0]" js])) - "Lua" (~~ (.as_is ["[1]/[0]" lua])) - "Python" (~~ (.as_is ["[1]/[0]" python])) - "Ruby" (~~ (.as_is ["[1]/[0]" ruby]))] + (~~ (.for "{old}" (~~ (.as_is ["[1]/[0]" jvm])) + "JVM" (~~ (.as_is ["[1]/[0]" jvm])) + "JavaScript" (~~ (.as_is ["[1]/[0]" js])) + "Lua" (~~ (.as_is ["[1]/[0]" lua])) + "Python" (~~ (.as_is ["[1]/[0]" python])) + "Ruby" (~~ (.as_is ["[1]/[0]" ruby])) (~~ (.as_is))))]]))) (def: for_bit @@ -421,7 +421,7 @@ (same? (: Any macro)))) (_.cover [/.macro:] (same? expected (..identity_macro expected))) - (~~ (for [@.old (~~ (as_is))] + (~~ (for @.old (~~ (as_is)) (_.cover [/.Source] (..found_crosshair?)))) (_.cover [/.macro] @@ -454,14 +454,14 @@ (let [scenario (: (-> Any Bit) (function (_ _) ... TODO: Remove this hack once Jython is no longer being used as the Python interpreter. - (`` (for [@.python (case (' [<input>']) - (^code [<module> - ("lux def" (~ [_ {.#Symbol ["" _]}]) [] #0) - (~~ (template.spliced <referrals>))]) - true - - _ - false)] + (`` (for @.python (case (' [<input>']) + (^code [<module> + ("lux def" (~ [_ {.#Symbol ["" _]}]) [] #0) + (~~ (template.spliced <referrals>))]) + true + + _ + false) (case (' [<input>']) (^code [<module> (~~ (template.spliced <referrals>))]) true @@ -880,16 +880,16 @@ (~~ (/.comment dummy)))))) (_.cover [/.for] (and (n.= expected - (/.for ["fake host" dummy] + (/.for "fake host" dummy expected)) (n.= expected - (/.for [@.old expected - @.jvm expected - @.js expected - @.python expected - @.lua expected - @.ruby expected - @.php expected] + (/.for @.old expected + @.jvm expected + @.js expected + @.python expected + @.lua expected + @.ruby expected + @.php expected dummy)))) ))) @@ -1178,7 +1178,7 @@ (bit#= /.private /.local))) )) -(for [@.old (as_is)] +(for @.old (as_is) (as_is (syntax: (for_bindings|test [fn/0 <code>.local_symbol var/0 <code>.local_symbol let/0 <code>.local_symbol @@ -1283,7 +1283,7 @@ ..for_def: ..for_meta ..for_export - (~~ (for [@.old (~~ (as_is))] + (~~ (for @.old (~~ (as_is)) (~~ (as_is ..for_bindings)))) )))) @@ -1316,23 +1316,23 @@ /world.test /ffi.test - (~~ (for [@.old (~~ (as_is))] + (~~ (for @.old (~~ (as_is)) (~~ (as_is /extension.test)))) - (~~ (for [@.jvm (~~ (as_is /target/jvm.test)) - @.old (~~ (as_is /target/jvm.test)) - @.js (~~ (as_is /target/js.test)) - @.lua (~~ (as_is /target/lua.test)) - @.python (~~ (as_is /target/python.test)) - @.ruby (~~ (as_is /target/ruby.test))])) + (~~ (for @.jvm (~~ (as_is /target/jvm.test)) + @.old (~~ (as_is /target/jvm.test)) + @.js (~~ (as_is /target/js.test)) + @.lua (~~ (as_is /target/lua.test)) + @.python (~~ (as_is /target/python.test)) + @.ruby (~~ (as_is /target/ruby.test)))) )))))) (program: args - (let [times (for [@.old 100 - @.jvm 100 - @.js 10 - @.python 1 - @.lua 1 - @.ruby 1] + (let [times (for @.old 100 + @.jvm 100 + @.js 10 + @.python 1 + @.lua 1 + @.ruby 1 100)] (<| io.io _.run! diff --git a/stdlib/source/test/lux/control/concurrency/async.lux b/stdlib/source/test/lux/control/concurrency/async.lux index 76b331bb9..7f844f558 100644 --- a/stdlib/source/test/lux/control/concurrency/async.lux +++ b/stdlib/source/test/lux/control/concurrency/async.lux @@ -1,30 +1,30 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - ["@" target] - [abstract - [monad {"+" do}] - [\\specification - ["$[0]" functor {"+" Injection Comparison}] - ["$[0]" apply] - ["$[0]" monad]]] - [control - [pipe {"+" case>}] - ["[0]" io]] - [time - ["[0]" instant] - ["[0]" duration]] - [math - ["[0]" random] - [number - ["n" nat] - ["i" int] - ["[0]" i64]]]]] - [\\library - ["[0]" / - [// - ["[0]" atom {"+" Atom}]]]]) + [library + [lux "*" + ["_" test {"+" Test}] + ["@" target] + [abstract + [monad {"+" do}] + [\\specification + ["$[0]" functor {"+" Injection Comparison}] + ["$[0]" apply] + ["$[0]" monad]]] + [control + [pipe {"+" case>}] + ["[0]" io]] + [time + ["[0]" instant] + ["[0]" duration]] + [math + ["[0]" random] + [number + ["n" nat] + ["i" int] + ["[0]" i64]]]]] + [\\library + ["[0]" / + [// + ["[0]" atom {"+" Atom}]]]]) (def: injection (Injection /.Async) @@ -46,8 +46,7 @@ false)))))) (def: delay - (for [@.js - (i64.left_shifted 4 1)] + (for @.js (i64.left_shifted 4 1) (i64.left_shifted 3 1))) (def: .public test diff --git a/stdlib/source/test/lux/control/concurrency/semaphore.lux b/stdlib/source/test/lux/control/concurrency/semaphore.lux index 91646488c..1b07c0e65 100644 --- a/stdlib/source/test/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/test/lux/control/concurrency/semaphore.lux @@ -1,37 +1,36 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - ["@" target] - [abstract - ["[0]" monad {"+" do}] - ["[0]" enum]] - [control - ["[0]" io] - ["[0]" maybe] - ["[0]" try] - ["[0]" exception {"+" exception:}] - [concurrency - ["[0]" async {"+" Async}] - ["[0]" atom {"+" Atom}]]] - [data - ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" format}]] - [collection - ["[0]" list ("[1]#[0]" functor)]]] - [math - ["[0]" random] - [number - ["n" nat] - ["[0]" i64]]] - [type - ["[0]" refinement]]]] - [\\library - ["[0]" /]]) + [library + [lux "*" + ["_" test {"+" Test}] + ["@" target] + [abstract + ["[0]" monad {"+" do}] + ["[0]" enum]] + [control + ["[0]" io] + ["[0]" maybe] + ["[0]" try] + ["[0]" exception {"+" exception:}] + [concurrency + ["[0]" async {"+" Async}] + ["[0]" atom {"+" Atom}]]] + [data + ["[0]" text ("[1]#[0]" equivalence) + ["%" format {"+" format}]] + [collection + ["[0]" list ("[1]#[0]" functor)]]] + [math + ["[0]" random] + [number + ["n" nat] + ["[0]" i64]]] + [type + ["[0]" refinement]]]] + [\\library + ["[0]" /]]) (def: delay - (for [@.js - (i64.left_shifted 4 1)] + (for @.js (i64.left_shifted 4 1) (i64.left_shifted 3 1))) (def: semaphore diff --git a/stdlib/source/test/lux/debug.lux b/stdlib/source/test/lux/debug.lux index f815d485e..9f619b3c0 100644 --- a/stdlib/source/test/lux/debug.lux +++ b/stdlib/source/test/lux/debug.lux @@ -1,52 +1,52 @@ (.using - [library - [lux "*" - ["_" test {"+" Test}] - ["@" target] - [abstract - [monad {"+" do}]] - [control - ["[0]" try ("[1]#[0]" functor)] - ["[0]" exception] - [parser - ["<[0]>" code]]] - [data - ["[0]" text ("[1]#[0]" equivalence) - ["%" format {"+" format}]] - [collection - ["[0]" list ("[1]#[0]" functor)]] - [format - [json {"+" JSON}] - [xml {"+" XML}]]] - ["[0]" macro - [syntax {"+" syntax:}] - ["[0]" code]] - [math - ["[0]" random {"+" Random}] - [number - [ratio {"+" Ratio}]]] - [time {"+" Time} - [instant {"+" Instant}] - [date {"+" Date}] - [duration {"+" Duration}] - [month {"+" Month}] - [day {"+" Day}]]]] - [\\library - ["[0]" /]] - ["$[0]" // "_" - ["[1][0]" type] + [library + [lux "*" + ["_" test {"+" Test}] + ["@" target] + [abstract + [monad {"+" do}]] + [control + ["[0]" try ("[1]#[0]" functor)] + ["[0]" exception] + [parser + ["<[0]>" code]]] [data + ["[0]" text ("[1]#[0]" equivalence) + ["%" format {"+" format}]] + [collection + ["[0]" list ("[1]#[0]" functor)]] [format - ["[1][0]" json] - ["[1][0]" xml]]] - [macro - ["[1][0]" code]] + [json {"+" JSON}] + [xml {"+" XML}]]] + ["[0]" macro + [syntax {"+" syntax:}] + ["[0]" code]] [math + ["[0]" random {"+" Random}] [number - ["[1][0]" ratio]]] - [meta - ["[1][0]" location] - ["[1][0]" symbol]]]) + [ratio {"+" Ratio}]]] + [time {"+" Time} + [instant {"+" Instant}] + [date {"+" Date}] + [duration {"+" Duration}] + [month {"+" Month}] + [day {"+" Day}]]]] + [\\library + ["[0]" /]] + ["$[0]" // "_" + ["[1][0]" type] + [data + [format + ["[1][0]" json] + ["[1][0]" xml]]] + [macro + ["[1][0]" code]] + [math + [number + ["[1][0]" ratio]]] + [meta + ["[1][0]" location] + ["[1][0]" symbol]]]) (def: can_represent_simple_types (Random Bit) @@ -245,7 +245,7 @@ bar random.nat baz random.bit] (_.cover [/.here] - (with_expansions [<no_parameters> (for [@.js (~~ (as_is))] + (with_expansions [<no_parameters> (for @.js (~~ (as_is)) (~~ (as_is (/.here))))] (`` (exec <no_parameters> diff --git a/stdlib/source/test/lux/extension.lux b/stdlib/source/test/lux/extension.lux index b2dde4019..410d006b4 100644 --- a/stdlib/source/test/lux/extension.lux +++ b/stdlib/source/test/lux/extension.lux @@ -10,11 +10,11 @@ ["[0]" php] ["[0]" scheme] ["[0]" jvm "_" - (~~ (.for ["JVM" (~~ (.as_is ["[1]" bytecode] - ["[0]" class] - ["[0]" version] - [encoding - ["[0]" name]]))] + (~~ (.for "JVM" (~~ (.as_is ["[1]" bytecode] + ["[0]" class] + ["[0]" version] + [encoding + ["[0]" name]])) (~~ (.as_is))))]] [abstract ["[0]" monad {"+" do}]] @@ -55,8 +55,8 @@ ["[0]" type]] [phase [generation - (~~ (.for ["JVM" (~~ (.as_is ["[0]" jvm "_" - ["[1]/[0]" runtime]]))] + (~~ (.for "JVM" (~~ (.as_is ["[0]" jvm "_" + ["[1]/[0]" runtime]])) (~~ (.as_is))))]]]]]] ["_" test {"+" Test}]]] [\\library @@ -76,14 +76,15 @@ ) ... Generation -(for [@.old - (as_is)] +(for @.old + (as_is) (as_is - (for [@.python - ... TODO: Remove this hack once Jython is no longer being used as the Python interpreter. - (analysis: ("dummy dum dum" self phase archive []) - (undefined))] + (for @.python + ... TODO: Remove this hack once Jython is no longer being used as the Python interpreter. + (analysis: ("dummy dum dum" self phase archive []) + (undefined)) + (as_is)) ... Analysis @@ -114,11 +115,7 @@ (# ! each (|>> {synthesis.#Extension self}))))) (generation: (..generation self phase archive [pass_through <synthesis>.any]) - (for [... @.jvm - ... (# phase.monad each (|>> {jvm.#Embedded} sequence.sequence) - ... (phase archive pass_through)) - ] - (phase archive pass_through))) + (phase archive pass_through)) (analysis: (..dummy_generation self phase archive []) (# phase.monad in {analysis.#Extension self (list)})) @@ -128,16 +125,13 @@ (generation: (..dummy_generation self phase archive []) (# phase.monad in - (for [@.jvm - (jvm.string self) - ... (sequence.sequence {jvm.#Constant {jvm.#LDC {jvm.#String self}}}) - - @.js (js.string self) - @.python (python.unicode self) - @.lua (lua.string self) - @.ruby (ruby.string self) - @.php (php.string self) - @.scheme (scheme.string self)]))) + (for @.jvm (jvm.string self) + @.js (js.string self) + @.python (python.unicode self) + @.lua (lua.string self) + @.ruby (ruby.string self) + @.php (php.string self) + @.scheme (scheme.string self)))) ... Directive (directive: (..directive self phase archive [expression <code>.any]) @@ -161,26 +155,26 @@ [[module_id artifact_id] (generation.context archive) .let [commentary (format "Successfully installed directive " (%.text self) "!")] _ (generation.save! artifact_id {.#None} - (for [@.jvm (let [$class (jvm/runtime.class_name [module_id artifact_id])] - (<| [$class] - (try.else (binary.empty 0)) - (try#each (binaryF.result class.writer)) - (class.class version.v6_0 class.public - (name.internal $class) - {.#None} - (name.internal "java.lang.Object") - (list) - (list) - (list) - sequence.empty))) - @.js (js.comment commentary - (js.statement (js.string commentary))) - @.python (python.comment commentary - (python.statement (python.string commentary))) - @.lua (lua.comment commentary - (lua.statement expressionG)) - @.ruby (ruby.comment commentary - (ruby.statement (ruby.string commentary)))]))] + (for @.jvm (let [$class (jvm/runtime.class_name [module_id artifact_id])] + (<| [$class] + (try.else (binary.empty 0)) + (try#each (binaryF.result class.writer)) + (class.class version.v6_0 class.public + (name.internal $class) + {.#None} + (name.internal "java.lang.Object") + (list) + (list) + (list) + sequence.empty))) + @.js (js.comment commentary + (js.statement (js.string commentary))) + @.python (python.comment commentary + (python.statement (python.string commentary))) + @.lua (lua.comment commentary + (lua.statement expressionG)) + @.ruby (ruby.comment commentary + (ruby.statement (ruby.string commentary)))))] (generation.log! commentary))))] (in directive.no_requirements))) @@ -195,16 +189,14 @@ (`` ($_ _.and (~~ (template [<macro> <extension>] [(_.cover [<macro>] - (for [@.old - false] + (for @.old false (n.= expected (`` ((~~ (static <extension>)) expected)))))] [/.analysis: ..analysis] [/.synthesis: ..synthesis])) (_.cover [/.generation:] - (for [@.old - false] + (for @.old false (and (n.= expected (`` ((~~ (static ..generation)) expected))) (text#= ..dummy_generation diff --git a/stdlib/source/test/lux/math/number/frac.lux b/stdlib/source/test/lux/math/number/frac.lux index b74a80786..c8b786701 100644 --- a/stdlib/source/test/lux/math/number/frac.lux +++ b/stdlib/source/test/lux/math/number/frac.lux @@ -122,8 +122,8 @@ ["[1]::[0]" ("static" doubleToRawLongBits [double] long) ("static" longBitsToDouble [long] double)]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>)] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) (as_is))) (def: .public test @@ -210,8 +210,8 @@ (and (/.not_a_number? expected) (/.not_a_number? actual)))))) )] - (for [@.old <jvm> - @.jvm <jvm>] + (for @.old <jvm> + @.jvm <jvm> (let [test (: (-> Frac Bit) (function (_ expected) (let [actual (|> expected /.bits /.of_bits)] diff --git a/stdlib/source/test/lux/meta/configuration.lux b/stdlib/source/test/lux/meta/configuration.lux index c96a5593d..fc300a01d 100644 --- a/stdlib/source/test/lux/meta/configuration.lux +++ b/stdlib/source/test/lux/meta/configuration.lux @@ -66,25 +66,32 @@ (try#each (# /.equivalence = expected)) (try.else false))) (_.cover [/.for] - (and (and (/.for [["left" "<<<" - "right" ">>>"] - true] + (and (and (/.for ["left" "<<<" + "right" ">>>"] + true + ... else false) - (/.for [["left" "<<<"] - true] + (/.for ["left" "<<<"] + true + ... else false) - (/.for [["right" ">>>"] - true] + (/.for ["right" ">>>"] + true + ... else false)) - (and (/.for [["yolo" ""] - false] + (and (/.for ["yolo" ""] + false + ... else true) - (/.for [["left" "yolo"] - false] + (/.for ["left" "yolo"] + false + ... else true)))) (_.cover [/.invalid] (and (text.contains? (the exception.#label /.invalid) - (..failure (/.for []))) + (..failure (/.for))) (text.contains? (the exception.#label /.invalid) - (..failure (/.for [["left" "yolo"] false]))))) + (..failure (/.for ["left" "yolo"] + ... else + false))))) )))) diff --git a/stdlib/source/test/lux/meta/version.lux b/stdlib/source/test/lux/meta/version.lux index ca219323a..b5c2c0c97 100644 --- a/stdlib/source/test/lux/meta/version.lux +++ b/stdlib/source/test/lux/meta/version.lux @@ -43,13 +43,13 @@ (_.cover [/.current] (not (text.empty? (/.current)))) (_.cover [/.for] - (and (/.for [<current> true] + (and (/.for <current> true false) - (/.for [<fake> false] + (/.for <fake> false true))) (_.cover [/.invalid] (and (text.contains? (the exception.#label /.invalid) - (..failure (/.for []))) + (..failure (/.for))) (text.contains? (the exception.#label /.invalid) - (..failure (/.for [<fake> false]))))) + (..failure (/.for <fake> false))))) ))) diff --git a/stdlib/source/test/lux/static.lux b/stdlib/source/test/lux/static.lux index 691749810..44413d5e0 100644 --- a/stdlib/source/test/lux/static.lux +++ b/stdlib/source/test/lux/static.lux @@ -24,7 +24,7 @@ (def: .public test Test (<| (_.covering /._) - (for [@.old (_.test "PLACEHOLDER" true)]) + (for @.old (_.test "PLACEHOLDER" true)) (_.for [meta.eval]) (`` ($_ _.and (~~ (template [<static> <random> <=> <+> <tag>] diff --git a/stdlib/source/test/lux/target/jvm.lux b/stdlib/source/test/lux/target/jvm.lux index cdeefb573..562473fb0 100644 --- a/stdlib/source/test/lux/target/jvm.lux +++ b/stdlib/source/test/lux/target/jvm.lux @@ -309,10 +309,11 @@ (do [! random.monad] [expected (# ! each (i64.and (i64.mask <bits>)) random.nat)] (<| (_.lifted <message>) - (..bytecode (for [@.old - (|>> (:as <type>) <to_long> ("jvm leq" expected)) - @.jvm - (|>> (:as <type>) <to_long> "jvm object cast" ("jvm long =" ("jvm object cast" (:as java/lang/Long expected))))])) + (..bytecode (for @.old + (|>> (:as <type>) <to_long> ("jvm leq" expected)) + + @.jvm + (|>> (:as <type>) <to_long> "jvm object cast" ("jvm long =" ("jvm object cast" (:as java/lang/Long expected)))))) (do /.monad [_ (<push> (|> expected .int <signed> try.trusted))] <wrap>))))] @@ -325,13 +326,13 @@ [(template: (<name> <old_extension> <new_extension>) [(: (-> <type> <type> <type>) (function (_ parameter subject) - (for [@.old - (<old_extension> subject parameter) - - @.jvm - ("jvm object cast" - (<new_extension> ("jvm object cast" parameter) - ("jvm object cast" subject)))])))])] + (for @.old + (<old_extension> subject parameter) + + @.jvm + ("jvm object cast" + (<new_extension> ("jvm object cast" parameter) + ("jvm object cast" subject))))))])] [int/2 java/lang/Integer] [long/2 java/lang/Long] @@ -342,23 +343,23 @@ (template: (int+long/2 <old_extension> <new_extension>) [(: (-> java/lang/Integer java/lang/Long java/lang/Long) (function (_ parameter subject) - (for [@.old - (<old_extension> subject parameter) - - @.jvm - ("jvm object cast" - (<new_extension> ("jvm object cast" parameter) - ("jvm object cast" subject)))])))]) + (for @.old + (<old_extension> subject parameter) + + @.jvm + ("jvm object cast" + (<new_extension> ("jvm object cast" parameter) + ("jvm object cast" subject))))))]) (def: int Test (let [int (: (-> java/lang/Integer (Bytecode Any) (Random Bit)) (function (_ expected bytecode) - (<| (..bytecode (for [@.old - (|>> (:as java/lang/Integer) ("jvm ieq" expected)) - - @.jvm - (|>> (:as java/lang/Integer) "jvm object cast" ("jvm int =" ("jvm object cast" expected)))])) + (<| (..bytecode (for @.old + (|>> (:as java/lang/Integer) ("jvm ieq" expected)) + + @.jvm + (|>> (:as java/lang/Integer) "jvm object cast" ("jvm int =" ("jvm object cast" expected))))) (do /.monad [_ bytecode] ..$Integer::wrap)))) @@ -435,11 +436,11 @@ Test (let [long (: (-> java/lang/Long (Bytecode Any) (Random Bit)) (function (_ expected bytecode) - (<| (..bytecode (for [@.old - (|>> (:as Int) (i.= expected)) - - @.jvm - (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" expected)))])) + (<| (..bytecode (for @.old + (|>> (:as Int) (i.= expected)) + + @.jvm + (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" expected))))) (do /.monad [_ bytecode] ..$Long::wrap)))) @@ -508,11 +509,11 @@ ... (i.< (:as Int reference) (:as Int subject)) (:as java/lang/Long -1))]] - (<| (..bytecode (for [@.old - (|>> (:as Int) (i.= expected)) - - @.jvm - (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" expected)))])) + (<| (..bytecode (for @.old + (|>> (:as Int) (i.= expected)) + + @.jvm + (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" expected))))) (do /.monad [_ (..$Long::literal subject) _ (..$Long::literal reference) @@ -534,17 +535,17 @@ Test (let [float (: (-> java/lang/Float (Bytecode Any) (Random Bit)) (function (_ expected bytecode) - (<| (..bytecode (for [@.old - (function (_ actual) - (or (|> actual (:as java/lang/Float) ("jvm feq" expected)) - (and (f.not_a_number? (:as Frac (ffi.float_to_double expected))) - (f.not_a_number? (:as Frac (ffi.float_to_double (:as java/lang/Float actual))))))) - - @.jvm - (function (_ actual) - (or (|> actual (:as java/lang/Float) "jvm object cast" ("jvm float =" ("jvm object cast" expected))) - (and (f.not_a_number? (:as Frac (ffi.float_to_double expected))) - (f.not_a_number? (:as Frac (ffi.float_to_double (:as java/lang/Float actual)))))))])) + (<| (..bytecode (for @.old + (function (_ actual) + (or (|> actual (:as java/lang/Float) ("jvm feq" expected)) + (and (f.not_a_number? (:as Frac (ffi.float_to_double expected))) + (f.not_a_number? (:as Frac (ffi.float_to_double (:as java/lang/Float actual))))))) + + @.jvm + (function (_ actual) + (or (|> actual (:as java/lang/Float) "jvm object cast" ("jvm float =" ("jvm object cast" expected))) + (and (f.not_a_number? (:as Frac (ffi.float_to_double expected))) + (f.not_a_number? (:as Frac (ffi.float_to_double (:as java/lang/Float actual))))))))) (do /.monad [_ bytecode] ..$Float::wrap)))) @@ -596,11 +597,11 @@ ..$Float::random)] reference valid_float subject valid_float - .let [expected (if (for [@.old - ("jvm feq" reference subject) - - @.jvm - ("jvm float =" ("jvm object cast" reference) ("jvm object cast" subject))]) + .let [expected (if (for @.old + ("jvm feq" reference subject) + + @.jvm + ("jvm float =" ("jvm object cast" reference) ("jvm object cast" subject))) +0 (if (standard reference subject) +1 @@ -614,11 +615,11 @@ ..$Long::wrap))))) comparison_standard (: (-> java/lang/Float java/lang/Float Bit) (function (_ reference subject) - (for [@.old - ("jvm fgt" subject reference) - - @.jvm - ("jvm float <" ("jvm object cast" subject) ("jvm object cast" reference))]))) + (for @.old + ("jvm fgt" subject reference) + + @.jvm + ("jvm float <" ("jvm object cast" subject) ("jvm object cast" reference))))) comparison ($_ _.and (_.lifted "FCMPL" (comparison /.fcmpl comparison_standard)) (_.lifted "FCMPG" (comparison /.fcmpg comparison_standard)))] @@ -635,17 +636,17 @@ Test (let [double (: (-> java/lang/Double (Bytecode Any) (Random Bit)) (function (_ expected bytecode) - (<| (..bytecode (for [@.old - (function (_ actual) - (or (|> actual (:as java/lang/Double) ("jvm deq" expected)) - (and (f.not_a_number? (:as Frac expected)) - (f.not_a_number? (:as Frac actual))))) - - @.jvm - (function (_ actual) - (or (|> actual (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected))) - (and (f.not_a_number? (:as Frac expected)) - (f.not_a_number? (:as Frac actual)))))])) + (<| (..bytecode (for @.old + (function (_ actual) + (or (|> actual (:as java/lang/Double) ("jvm deq" expected)) + (and (f.not_a_number? (:as Frac expected)) + (f.not_a_number? (:as Frac actual))))) + + @.jvm + (function (_ actual) + (or (|> actual (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected))) + (and (f.not_a_number? (:as Frac expected)) + (f.not_a_number? (:as Frac actual))))))) (do /.monad [_ bytecode] ..$Double::wrap)))) @@ -690,11 +691,11 @@ (do random.monad [reference ..valid_double subject ..valid_double - .let [expected (if (for [@.old - ("jvm deq" reference subject) - - @.jvm - ("jvm double =" ("jvm object cast" reference) ("jvm object cast" subject))]) + .let [expected (if (for @.old + ("jvm deq" reference subject) + + @.jvm + ("jvm double =" ("jvm object cast" reference) ("jvm object cast" subject))) +0 (if (standard reference subject) +1 @@ -709,11 +710,11 @@ ... https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dcmp_op comparison_standard (: (-> java/lang/Double java/lang/Double Bit) (function (_ reference subject) - (for [@.old - ("jvm dgt" subject reference) - - @.jvm - ("jvm double <" ("jvm object cast" subject) ("jvm object cast" reference))]))) + (for @.old + ("jvm dgt" subject reference) + + @.jvm + ("jvm double <" ("jvm object cast" subject) ("jvm object cast" reference))))) comparison ($_ _.and (_.lifted "DCMPL" (comparison /.dcmpl comparison_standard)) (_.lifted "DCMPG" (comparison /.dcmpg comparison_standard)))] @@ -791,11 +792,11 @@ (do random.monad [expected (random.only (|>> (:as Frac) f.not_a_number? not) ..$Double::random)]) - (..bytecode (for [@.old - (|>> (:as java/lang/Double) ("jvm deq" expected)) - - @.jvm - (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected)))])) + (..bytecode (for @.old + (|>> (:as java/lang/Double) ("jvm deq" expected)) + + @.jvm + (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected))))) (do /.monad [_ (/.double expected)] (/.invokestatic ..$Double "valueOf" (/type.method [(list) (list /type.double) ..$Double (list)])))) @@ -812,11 +813,11 @@ (do random.monad [expected (random.only (|>> (:as Frac) f.not_a_number? not) ..$Double::random)]) - (..bytecode (for [@.old - (|>> (:as java/lang/Double) ("jvm deq" expected)) - - @.jvm - (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected)))])) + (..bytecode (for @.old + (|>> (:as java/lang/Double) ("jvm deq" expected)) + + @.jvm + (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" expected))))) (do /.monad [_ (/.new ..$Double) _ /.dup @@ -840,12 +841,12 @@ part0 ..$Long::random part1 ..$Long::random .let [expected (: java/lang/Long - (for [@.old - ("jvm ladd" part0 part1) - - @.jvm - ("jvm object cast" - ("jvm long +" ("jvm object cast" part0) ("jvm object cast" part1)))])) + (for @.old + ("jvm ladd" part0 part1) + + @.jvm + ("jvm object cast" + ("jvm long +" ("jvm object cast" part0) ("jvm object cast" part1))))) $Self (/type.class class_name (list)) class_field "class_field" object_field "object_field" @@ -960,59 +961,59 @@ (_.context "byte" (array (/.newarray /instruction.t_byte) $Byte::random $Byte::literal [/.bastore /.baload $Byte::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Byte) ffi.byte_to_long ("jvm leq" (ffi.byte_to_long expected))) - - @.jvm - (|>> (:as java/lang/Byte) ffi.byte_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.byte_to_long (:as java/lang/Byte expected)))))])))) + (for @.old + (|>> (:as java/lang/Byte) ffi.byte_to_long ("jvm leq" (ffi.byte_to_long expected))) + + @.jvm + (|>> (:as java/lang/Byte) ffi.byte_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.byte_to_long (:as java/lang/Byte expected))))))))) (_.context "short" (array (/.newarray /instruction.t_short) $Short::random $Short::literal [/.sastore /.saload $Short::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Short) ffi.short_to_long ("jvm leq" (ffi.short_to_long expected))) - - @.jvm - (|>> (:as java/lang/Short) ffi.short_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.short_to_long (:as java/lang/Short expected)))))])))) + (for @.old + (|>> (:as java/lang/Short) ffi.short_to_long ("jvm leq" (ffi.short_to_long expected))) + + @.jvm + (|>> (:as java/lang/Short) ffi.short_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.short_to_long (:as java/lang/Short expected))))))))) (_.context "int" (array (/.newarray /instruction.t_int) $Integer::random $Integer::literal [/.iastore /.iaload $Integer::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Integer) ("jvm ieq" (:as java/lang/Integer expected))) - - @.jvm - (|>> (:as java/lang/Integer) "jvm object cast" ("jvm int =" ("jvm object cast" (:as java/lang/Integer expected))))])))) + (for @.old + (|>> (:as java/lang/Integer) ("jvm ieq" (:as java/lang/Integer expected))) + + @.jvm + (|>> (:as java/lang/Integer) "jvm object cast" ("jvm int =" ("jvm object cast" (:as java/lang/Integer expected)))))))) (_.context "long" (array (/.newarray /instruction.t_long) $Long::random $Long::literal [/.lastore /.laload $Long::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Long) ("jvm leq" expected)) - - @.jvm - (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" (:as java/lang/Long expected))))])))) + (for @.old + (|>> (:as java/lang/Long) ("jvm leq" expected)) + + @.jvm + (|>> (:as java/lang/Long) "jvm object cast" ("jvm long =" ("jvm object cast" (:as java/lang/Long expected)))))))) (_.context "float" (array (/.newarray /instruction.t_float) ..valid_float $Float::literal [/.fastore /.faload $Float::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Float) ("jvm feq" expected)) - - @.jvm - (|>> (:as java/lang/Float) "jvm object cast" ("jvm float =" ("jvm object cast" (:as java/lang/Float expected))))])))) + (for @.old + (|>> (:as java/lang/Float) ("jvm feq" expected)) + + @.jvm + (|>> (:as java/lang/Float) "jvm object cast" ("jvm float =" ("jvm object cast" (:as java/lang/Float expected)))))))) (_.context "double" (array (/.newarray /instruction.t_double) ..valid_double $Double::literal [/.dastore /.daload $Double::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Double) ("jvm deq" expected)) - - @.jvm - (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" (:as java/lang/Double expected))))])))) + (for @.old + (|>> (:as java/lang/Double) ("jvm deq" expected)) + + @.jvm + (|>> (:as java/lang/Double) "jvm object cast" ("jvm double =" ("jvm object cast" (:as java/lang/Double expected)))))))) (_.context "char" (array (/.newarray /instruction.t_char) $Character::random $Character::literal [/.castore /.caload $Character::wrap] (function (_ expected) - (for [@.old - (|>> (:as java/lang/Character) ("jvm ceq" expected)) - - @.jvm - (|>> (:as java/lang/Character) "jvm object cast" ("jvm char =" ("jvm object cast" (:as java/lang/Character expected))))])))) + (for @.old + (|>> (:as java/lang/Character) ("jvm ceq" expected)) + + @.jvm + (|>> (:as java/lang/Character) "jvm object cast" ("jvm char =" ("jvm object cast" (:as java/lang/Character expected)))))))) (_.context "object" (array (/.anewarray ..$String) $String::random $String::literal [/.aastore /.aaload /.nop] (function (_ expected) (|>> (:as Text) (text#= (:as Text expected)))))) @@ -1042,11 +1043,11 @@ (template: (!::= <type> <old> <new>) [(: (-> <type> Any Bit) (function (_ expected) - (for [@.old - (|>> (:as <type>) (<old> expected)) - - @.jvm - (|>> (:as <type>) "jvm object cast" (<new> ("jvm object cast" (:as <type> expected))))])))]) + (for @.old + (|>> (:as <type>) (<old> expected)) + + @.jvm + (|>> (:as <type>) "jvm object cast" (<new> ("jvm object cast" (:as <type> expected)))))))]) (def: conversion Test @@ -1073,20 +1074,20 @@ (_.lifted "I2D" (conversion ..$Integer::primitive ..$Double::primitive /.i2d (|>> ffi.int_to_double) double::=)) (_.lifted "I2B" (conversion ..$Integer::primitive ..$Byte::primitive /.i2b (|>> ffi.int_to_byte) (function (_ expected) - (for [@.old - (|>> (:as java/lang/Byte) ffi.byte_to_long ("jvm leq" (ffi.byte_to_long expected))) - - @.jvm - (|>> (:as java/lang/Byte) ffi.byte_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.byte_to_long (:as java/lang/Byte expected)))))])))) + (for @.old + (|>> (:as java/lang/Byte) ffi.byte_to_long ("jvm leq" (ffi.byte_to_long expected))) + + @.jvm + (|>> (:as java/lang/Byte) ffi.byte_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.byte_to_long (:as java/lang/Byte expected))))))))) (_.lifted "I2C" (conversion ..$Integer::primitive ..$Character::primitive /.i2c (|>> ffi.int_to_char) (!::= java/lang/Character "jvm ceq" "jvm char ="))) (_.lifted "I2S" (conversion ..$Integer::primitive ..$Short::primitive /.i2s (|>> ffi.int_to_short) (function (_ expected) - (for [@.old - (|>> (:as java/lang/Short) ffi.short_to_long ("jvm leq" (ffi.short_to_long expected))) - - @.jvm - (|>> (:as java/lang/Short) ffi.short_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.short_to_long (:as java/lang/Short expected)))))])))))) + (for @.old + (|>> (:as java/lang/Short) ffi.short_to_long ("jvm leq" (ffi.short_to_long expected))) + + @.jvm + (|>> (:as java/lang/Short) ffi.short_to_long "jvm object cast" ("jvm long =" ("jvm object cast" (ffi.short_to_long (:as java/lang/Short expected))))))))))) (<| (_.context "long") ($_ _.and (_.lifted "L2I" (conversion ..$Long::primitive ..$Integer::primitive /.l2i (|>> ffi.long_to_int) int::=)) @@ -1158,16 +1159,16 @@ increment (# ! each (|>> (n.% 100) /unsigned.u1 try.trusted) random.nat) .let [expected (: java/lang/Long - (for [@.old - ("jvm ladd" - (ffi.byte_to_long base) - (.int (/unsigned.value increment))) - - @.jvm - ("jvm object cast" - ("jvm long +" - ("jvm object cast" (ffi.byte_to_long base)) - ("jvm object cast" (:as java/lang/Long (/unsigned.value increment)))))]))]] + (for @.old + ("jvm ladd" + (ffi.byte_to_long base) + (.int (/unsigned.value increment))) + + @.jvm + ("jvm object cast" + ("jvm long +" + ("jvm object cast" (ffi.byte_to_long base)) + ("jvm object cast" (:as java/lang/Long (/unsigned.value increment)))))))]] (..bytecode (|>> (:as Int) (i.= (:as Int expected))) (do /.monad [_ (..$Byte::literal base) @@ -1419,11 +1420,11 @@ reference ..$Integer::random subject (|> ..$Integer::random (random.only (|>> ((!::= java/lang/Integer "jvm ieq" "jvm int =") reference) not))) - .let [[lesser greater] (if (for [@.old - ("jvm ilt" reference subject) - - @.jvm - ("jvm int <" ("jvm object cast" subject) ("jvm object cast" reference))]) + .let [[lesser greater] (if (for @.old + ("jvm ilt" reference subject) + + @.jvm + ("jvm int <" ("jvm object cast" subject) ("jvm object cast" reference))) [reference subject] [subject reference]) int_comparison ($_ _.and diff --git a/stdlib/source/test/lux/type/poly/equivalence.lux b/stdlib/source/test/lux/type/poly/equivalence.lux index 2b335ca6a..1b1695122 100644 --- a/stdlib/source/test/lux/type/poly/equivalence.lux +++ b/stdlib/source/test/lux/type/poly/equivalence.lux @@ -1,27 +1,27 @@ (.using - [library - [lux {"-" Variant Record} - ["_" test {"+" Test}] - ["@" target] - [abstract - [monad {"+" do}] - [equivalence {"+" Equivalence} - [\\poly - ["[0]" /]]] - [\\specification - ["$[0]" equivalence]]] - [control - ["[0]" maybe]] - [data - ["[0]" bit] - ["[0]" text] - [collection - ["[0]" list]]] - [math - ["[0]" random {"+" Random}] - [number - ["n" nat] - ["i" int]]]]]) + [library + [lux {"-" Variant Record} + ["_" test {"+" Test}] + ["@" target] + [abstract + [monad {"+" do}] + [equivalence {"+" Equivalence} + [\\poly + ["[0]" /]]] + [\\specification + ["$[0]" equivalence]]] + [control + ["[0]" maybe]] + [data + ["[0]" bit] + ["[0]" text] + [collection + ["[0]" list]]] + [math + ["[0]" random {"+" Random}] + [number + ["n" nat] + ["i" int]]]]]) (type: Variant (.Variant @@ -76,7 +76,7 @@ (random.unicode size)) gen_recursive))) -(for [@.old (as_is)] +(for @.old (as_is) (as_is (def: equivalence (Equivalence ..Record) (/.equivalence ..Record)))) @@ -85,5 +85,5 @@ Test (<| (_.covering /._) (_.for [/.equivalence] - (for [@.old (_.test "PLACEHOLDER" true)] + (for @.old (_.test "PLACEHOLDER" true) ($equivalence.spec ..equivalence ..random))))) diff --git a/stdlib/source/test/lux/type/poly/functor.lux b/stdlib/source/test/lux/type/poly/functor.lux index 466656cf0..727f658af 100644 --- a/stdlib/source/test/lux/type/poly/functor.lux +++ b/stdlib/source/test/lux/type/poly/functor.lux @@ -1,20 +1,20 @@ (.using - [library - [lux "*" - ["@" target] - [abstract - [monad {"+" do}] - [functor {"+" Functor} - [\\poly - ["[0]" /]]]] - ["r" math/random {"+" Random}] - ["_" test {"+" Test}] - [control - ["[0]" state]] - [data - ["[0]" identity]]]]) + [library + [lux "*" + ["@" target] + [abstract + [monad {"+" do}] + [functor {"+" Functor} + [\\poly + ["[0]" /]]]] + ["r" math/random {"+" Random}] + ["_" test {"+" Test}] + [control + ["[0]" state]] + [data + ["[0]" identity]]]]) -(for [@.old (as_is)] +(for @.old (as_is) (as_is (def: maybe_functor (Functor .Maybe) (/.functor .Maybe)) diff --git a/stdlib/source/test/lux/type/poly/json.lux b/stdlib/source/test/lux/type/poly/json.lux index 56b6f13d9..668b8ea21 100644 --- a/stdlib/source/test/lux/type/poly/json.lux +++ b/stdlib/source/test/lux/type/poly/json.lux @@ -1,52 +1,52 @@ (.using - [library - [lux {"-" Variant Record} - ["_" test {"+" Test}] - ["@" target] - ["[0]" debug] - [abstract - codec - [monad {"+" do}] - ["[0]" equivalence {"+" Equivalence} - ["poly/[1]" \\poly]] - [\\specification - ["$[0]" equivalence] - ["$[0]" codec]]] - [control - pipe - ["[0]" try] - ["p" parser - ... TODO: Get rid of this import ASAP - [json {"+"}]]] - [data - ["[0]" bit] - ["[0]" text] - [format - [json {"+" JSON} - [\\poly - ["[0]" /]]]] - [collection - [sequence {"+" sequence}] - ["d" dictionary] - ["[0]" list]]] - [type - ["[0]" unit]] - [math - ["[0]" random {"+" Random}] - [number - ["n" nat] - ["[0]" frac]]] - [time - ["ti" instant] - ["tda" date] - ... ["tdu" duration] - ]]] - [test - [lux - [time - ["_[0]" instant] - ... ["_[0]" duration] - ]]]) + [library + [lux {"-" Variant Record} + ["_" test {"+" Test}] + ["@" target] + ["[0]" debug] + [abstract + codec + [monad {"+" do}] + ["[0]" equivalence {"+" Equivalence} + ["poly/[1]" \\poly]] + [\\specification + ["$[0]" equivalence] + ["$[0]" codec]]] + [control + pipe + ["[0]" try] + ["p" parser + ... TODO: Get rid of this import ASAP + [json {"+"}]]] + [data + ["[0]" bit] + ["[0]" text] + [format + [json {"+" JSON} + [\\poly + ["[0]" /]]]] + [collection + [sequence {"+" sequence}] + ["d" dictionary] + ["[0]" list]]] + [type + ["[0]" unit]] + [math + ["[0]" random {"+" Random}] + [number + ["n" nat] + ["[0]" frac]]] + [time + ["ti" instant] + ["tda" date] + ... ["tdu" duration] + ]]] + [test + [lux + [time + ["_[0]" instant] + ... ["_[0]" duration] + ]]]) (type: Variant (.Variant @@ -108,7 +108,7 @@ ..qty ))) -(for [@.old (as_is)] +(for @.old (as_is) (as_is (def: equivalence (Equivalence Record) (poly/equivalence.equivalence Record)) @@ -121,5 +121,5 @@ Test (<| (_.covering /._) (_.for [/.codec] - (for [@.old (_.test "PLACEHOLDER" true)] + (for @.old (_.test "PLACEHOLDER" true) ($codec.spec ..equivalence ..codec ..gen_record))))) diff --git a/stdlib/source/unsafe/lux/data/binary.lux b/stdlib/source/unsafe/lux/data/binary.lux index 1e3ef2118..e7936fd06 100644 --- a/stdlib/source/unsafe/lux/data/binary.lux +++ b/stdlib/source/unsafe/lux/data/binary.lux @@ -27,30 +27,30 @@ ["[1]::[0]" ("static" copyOfRange [[byte] int int] [byte]) ("static" equals [[byte] [byte]] boolean)]))] - (for [@.old (as_is <jvm>) - @.jvm (as_is <jvm>) - - @.js - (as_is (ffi.import: ArrayBuffer - "[1]::[0]") - (ffi.import: Uint8Array - "[1]::[0]") - - (type: .public Binary - Uint8Array)) - - @.python - (type: .public Binary - (Primitive "bytearray")) - - @.scheme - (as_is (type: .public Binary - (Primitive "bytevector")) - - (ffi.import: (make-bytevector [Nat] Binary)) - (ffi.import: (bytevector-u8-ref [Binary Nat] I64)) - (ffi.import: (bytevector-u8-set! [Binary Nat (I64 Any)] Any)) - (ffi.import: (bytevector-length [Binary] Nat)))] + (for @.old (as_is <jvm>) + @.jvm (as_is <jvm>) + + @.js + (as_is (ffi.import: ArrayBuffer + "[1]::[0]") + (ffi.import: Uint8Array + "[1]::[0]") + + (type: .public Binary + Uint8Array)) + + @.python + (type: .public Binary + (Primitive "bytearray")) + + @.scheme + (as_is (type: .public Binary + (Primitive "bytevector")) + + (ffi.import: (make-bytevector [Nat] Binary)) + (ffi.import: (bytevector-u8-ref [Binary Nat] I64)) + (ffi.import: (bytevector-u8-set! [Binary Nat (I64 Any)] Any)) + (ffi.import: (bytevector-length [Binary] Nat))) ... Default (type: .public Binary @@ -61,27 +61,27 @@ <jvm> (.: ..Binary <jvm>)] (template: .public (empty size) [(: ..Binary - (for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm> - - (~~ (.static @.js)) - (.|> <size> - .int - "lux i64 f64" - [] - ("js object new" ("js constant" "ArrayBuffer")) - [] - ("js object new" ("js constant" "Uint8Array")) - (.:as ..Binary)) - - (~~ (.static @.python)) - (.|> <size> - [] - ("python apply" (.:as ffi.Function ("python constant" "bytearray"))) - (.:as ..Binary)) - - (~~ (.static @.scheme)) - (..make-bytevector <size>)] + (for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> + + (~~ (.static @.js)) + (.|> <size> + .int + "lux i64 f64" + [] + ("js object new" ("js constant" "ArrayBuffer")) + [] + ("js object new" ("js constant" "Uint8Array")) + (.:as ..Binary)) + + (~~ (.static @.python)) + (.|> <size> + [] + ("python apply" (.:as ffi.Function ("python constant" "bytearray"))) + (.:as ..Binary)) + + (~~ (.static @.scheme)) + (..make-bytevector <size>) ... Default (array.empty <size>)))]))) @@ -90,23 +90,23 @@ <jvm> (ffi.length <it>)] (template: .public (size it) [(.: .Nat - (.for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm> + (.for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> - (~~ (.static @.js)) - (.|> <it> - ("js object get" "length") - (.:as .Frac) - "lux f64 i64" - .nat) + (~~ (.static @.js)) + (.|> <it> + ("js object get" "length") + (.:as .Frac) + "lux f64 i64" + .nat) - (~~ (.static @.python)) - (.|> <it> - (.:as (array.Array (.I64 .Any))) - "python array length") + (~~ (.static @.python)) + (.|> <it> + (.:as (array.Array (.I64 .Any))) + "python array length") - (~~ (.static @.scheme)) - (..bytevector-length [<it>])] + (~~ (.static @.scheme)) + (..bytevector-length [<it>]) ... Default (array.size <it>)))]))) @@ -126,23 +126,23 @@ (template: .public (bytes/1 index it) [(.<| (.:as .I64) (.: (.I64 .Any)) - (`` (.for [(~~ (.static @.old)) (~~ <jvm>) - (~~ (.static @.jvm)) (~~ <jvm>) + (`` (.for (~~ (.static @.old)) (~~ <jvm>) + (~~ (.static @.jvm)) (~~ <jvm>) - (~~ (.static @.js)) - (.|> <it> - (.:as (array.Array .Frac)) - ("js array read" <index>) - "lux f64 i64" - .i64) + (~~ (.static @.js)) + (.|> <it> + (.:as (array.Array .Frac)) + ("js array read" <index>) + "lux f64 i64" + .i64) - (~~ (.static @.python)) - (.|> <it> - (.:as (array.Array .I64)) - ("python array read" <index>)) + (~~ (.static @.python)) + (.|> <it> + (.:as (array.Array .I64)) + ("python array read" <index>)) - (~~ (.static @.scheme)) - (..bytevector-u8-ref [<it> <index>])] + (~~ (.static @.scheme)) + (..bytevector-u8-ref [<it> <index>]) ... Default (.if (array.lacks? <index> <it>) @@ -188,43 +188,43 @@ <it> (.: ..Binary it) <index> (.: .Nat index) <value> (.: (.I64 .Any) value) - <jvm_value> (`` (.for [(~~ (.static @.old)) - (.:as .Int <value>) + <jvm_value> (`` (.for (~~ (.static @.old)) + (.:as .Int <value>) - (~~ (.static @.jvm)) - (.:as (.Primitive "java.lang.Long") <value>)] + (~~ (.static @.jvm)) + (.:as (.Primitive "java.lang.Long") <value>) <value>)) <jvm_value> <jvm_value> <jvm_value> (ffi.long_to_byte <jvm_value>) <jvm> (ffi.write! <index> <jvm_value> <it>)] (`` (template: .public (with/1! index value it) [(.: ..Binary - (.for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm> - - (~~ (.static @.js)) - (.|> <it> - (.: ..Binary) - (.:as (array.Array .Frac)) - ("js array write" <index> - (.|> <value> - .int - ("lux i64 and" (.int <byte>)) - "lux i64 f64")) - (.:as ..Binary)) - - (~~ (.static @.python)) - (.|> <it> - (.: ..Binary) - (.:as (array.Array (.I64 .Any))) - ("python array write" <index> (.|> <value> ("lux i64 and" <byte>) (.: (.I64 .Any)))) - (.:as ..Binary)) - - (~~ (.static @.scheme)) - (.let [it' <it>] - (.exec - (..bytevector-u8-set! [it' <index> <value>]) - it'))] + (.for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> + + (~~ (.static @.js)) + (.|> <it> + (.: ..Binary) + (.:as (array.Array .Frac)) + ("js array write" <index> + (.|> <value> + .int + ("lux i64 and" (.int <byte>)) + "lux i64 f64")) + (.:as ..Binary)) + + (~~ (.static @.python)) + (.|> <it> + (.: ..Binary) + (.:as (array.Array (.I64 .Any))) + ("python array write" <index> (.|> <value> ("lux i64 and" <byte>) (.: (.I64 .Any)))) + (.:as ..Binary)) + + (~~ (.static @.scheme)) + (.let [it' <it>] + (.exec + (..bytevector-u8-set! [it' <index> <value>]) + it')) ... Default (array.has! <index> (.|> <value> .int ("lux i64 and" (.int <byte>))) <it>)))]))) @@ -248,19 +248,19 @@ (`` (template: .public (with/8! index' value' it) [(.let [index (.: .Nat index') value (.: (.I64 .Any) value')] - (.for [(~~ (.static @.scheme)) (.let [write_high (.: (.-> ..Binary ..Binary) - (.|>> (..with/1! index ("lux i64 right-shift" 56 value)) - (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) - (..with/1! ("lux i64 +" 2 index) ("lux i64 right-shift" 40 value)) - (..with/1! ("lux i64 +" 3 index) ("lux i64 right-shift" 32 value)))) - write_low (.: (.-> ..Binary ..Binary) - (.|>> (..with/1! ("lux i64 +" 4 index) ("lux i64 right-shift" 24 value)) - (..with/1! ("lux i64 +" 5 index) ("lux i64 right-shift" 16 value)) - (..with/1! ("lux i64 +" 6 index) ("lux i64 right-shift" 8 value)) - (..with/1! ("lux i64 +" 7 index) value)))] - (.|> it - write_high - write_low))] + (.for (~~ (.static @.scheme)) (.let [write_high (.: (.-> ..Binary ..Binary) + (.|>> (..with/1! index ("lux i64 right-shift" 56 value)) + (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) + (..with/1! ("lux i64 +" 2 index) ("lux i64 right-shift" 40 value)) + (..with/1! ("lux i64 +" 3 index) ("lux i64 right-shift" 32 value)))) + write_low (.: (.-> ..Binary ..Binary) + (.|>> (..with/1! ("lux i64 +" 4 index) ("lux i64 right-shift" 24 value)) + (..with/1! ("lux i64 +" 5 index) ("lux i64 right-shift" 16 value)) + (..with/1! ("lux i64 +" 6 index) ("lux i64 right-shift" 8 value)) + (..with/1! ("lux i64 +" 7 index) value)))] + (.|> it + write_high + write_low)) (.|> it (..with/1! index ("lux i64 right-shift" 56 value)) (..with/1! ("lux i64 +" 1 index) ("lux i64 right-shift" 48 value)) @@ -276,8 +276,8 @@ <jvm> (java/util/Arrays::equals <reference> <sample>) <jvm> (ffi.of_boolean <jvm>)] (`` (template: .public (= reference' sample') - [(.for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm>] + [(.for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> (.let [reference <reference> sample <sample> limit (..size reference)] @@ -299,8 +299,8 @@ <jvm> (.exec <jvm> target)] - (.for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm>] + (.for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> ... Default (.loop [index 0] @@ -320,8 +320,8 @@ <jvm>)] (inline: .public (slice offset size binary) (-> .Nat .Nat ..Binary ..Binary) - (.for [(~~ (.static @.old)) <jvm> - (~~ (.static @.jvm)) <jvm>] + (.for (~~ (.static @.old)) <jvm> + (~~ (.static @.jvm)) <jvm> ... Default (..copy! size offset binary 0 (..empty size)))))) diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index 83b7e5202..d3435b6ee 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -17,55 +17,54 @@ (with_expansions [<index_type> (.Primitive "java.lang.Long") <elem_type> (.Primitive "java.lang.Object") <array_type> (.type (..Array <elem_type>))] - (for [@.jvm - (template: (int! value) - [(.|> value - (.:as <index_type>) - "jvm object cast" - "jvm conversion long-to-int")])] + (for @.jvm (template: (int! value) + [(.|> value + (.:as <index_type>) + "jvm object cast" + "jvm conversion long-to-int")]) (as_is)) (`` (template: .public (empty <size>) [((.: (.All (_ a) (.-> .Nat (..Array a))) (.function (empty size) - (.for [(~~ (.static @.old)) - (.:expected ("jvm anewarray" "(java.lang.Object )" size)) - - (~~ (.static @.jvm)) - (|> (~~ (..int! size)) - "jvm array new object" - (.: <array_type>) - .:expected) - - (~~ (.static @.js)) ("js array new" size) - (~~ (.static @.python)) ("python array new" size) - (~~ (.static @.lua)) ("lua array new" size) - (~~ (.static @.ruby)) ("ruby array new" size) - (~~ (.static @.php)) ("php array new" size) - (~~ (.static @.scheme)) ("scheme array new" size)]))) + (.for (~~ (.static @.old)) + (.:expected ("jvm anewarray" "(java.lang.Object )" size)) + + (~~ (.static @.jvm)) + (|> (~~ (..int! size)) + "jvm array new object" + (.: <array_type>) + .:expected) + + (~~ (.static @.js)) ("js array new" size) + (~~ (.static @.python)) ("python array new" size) + (~~ (.static @.lua)) ("lua array new" size) + (~~ (.static @.ruby)) ("ruby array new" size) + (~~ (.static @.php)) ("php array new" size) + (~~ (.static @.scheme)) ("scheme array new" size)))) <size>)])) (`` (template: .public (size <array>) [((.: (.All (_ a) (.-> (..Array a) .Nat)) (.function (size array) - (.for [(~~ (.static @.old)) - ("jvm arraylength" array) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - "jvm array length object" - "jvm conversion int-to-long" - "jvm object cast" - (.: <index_type>) - (.:as .Nat)) - - (~~ (.static @.js)) ("js array length" array) - (~~ (.static @.python)) ("python array length" array) - (~~ (.static @.lua)) ("lua array length" array) - (~~ (.static @.ruby)) ("ruby array length" array) - (~~ (.static @.php)) ("php array length" array) - (~~ (.static @.scheme)) ("scheme array length" array)]))) + (.for (~~ (.static @.old)) + ("jvm arraylength" array) + + (~~ (.static @.jvm)) + (.|> array + (.:as <array_type>) + "jvm array length object" + "jvm conversion int-to-long" + "jvm object cast" + (.: <index_type>) + (.:as .Nat)) + + (~~ (.static @.js)) ("js array length" array) + (~~ (.static @.python)) ("python array length" array) + (~~ (.static @.lua)) ("lua array length" array) + (~~ (.static @.ruby)) ("ruby array length" array) + (~~ (.static @.php)) ("php array length" array) + (~~ (.static @.scheme)) ("scheme array length" array)))) <array>)])) (template: (lacks?' <read!> <null?> index array) @@ -77,21 +76,21 @@ (.function (lacks? index array) (.let [size (..size array)] (.if ("lux i64 <" (.int size) (.int index)) - (.for [(~~ (.static @.old)) - ("jvm object null?" ("jvm aaload" array index)) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array read object" (~~ (int! index))) - "jvm object null?") - - (~~ (.static @.js)) (~~ (lacks?' "js array read" "js object undefined?" index array)) - (~~ (.static @.python)) (~~ (lacks?' "python array read" "python object none?" index array)) - (~~ (.static @.lua)) (~~ (lacks?' "lua array read" "lua object nil?" index array)) - (~~ (.static @.ruby)) (~~ (lacks?' "ruby array read" "ruby object nil?" index array)) - (~~ (.static @.php)) (~~ (lacks?' "php array read" "php object null?" index array)) - (~~ (.static @.scheme)) (~~ (lacks?' "scheme array read" "scheme object nil?" index array))]) + (.for (~~ (.static @.old)) + ("jvm object null?" ("jvm aaload" array index)) + + (~~ (.static @.jvm)) + (.|> array + (.:as <array_type>) + ("jvm array read object" (~~ (int! index))) + "jvm object null?") + + (~~ (.static @.js)) (~~ (lacks?' "js array read" "js object undefined?" index array)) + (~~ (.static @.python)) (~~ (lacks?' "python array read" "python object none?" index array)) + (~~ (.static @.lua)) (~~ (lacks?' "lua array read" "lua object nil?" index array)) + (~~ (.static @.ruby)) (~~ (lacks?' "ruby array read" "ruby object nil?" index array)) + (~~ (.static @.php)) (~~ (lacks?' "php array read" "php object null?" index array)) + (~~ (.static @.scheme)) (~~ (lacks?' "scheme array read" "scheme object nil?" index array))) .true)))) <index> <array>)])) @@ -102,42 +101,42 @@ [((.: (.All (_ a) (.-> .Nat (..Array a) a)) (.function (item index array) - (.for [(~~ (.static @.old)) - ("jvm aaload" array index) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array read object" (~~ (int! index))) - .:expected) - - (~~ (.static @.js)) ("js array read" index array) - (~~ (.static @.python)) ("python array read" index array) - (~~ (.static @.lua)) ("lua array read" index array) - (~~ (.static @.ruby)) ("ruby array read" index array) - (~~ (.static @.php)) ("php array read" index array) - (~~ (.static @.scheme)) ("scheme array read" index array)]))) + (.for (~~ (.static @.old)) + ("jvm aaload" array index) + + (~~ (.static @.jvm)) + (.|> array + (.:as <array_type>) + ("jvm array read object" (~~ (int! index))) + .:expected) + + (~~ (.static @.js)) ("js array read" index array) + (~~ (.static @.python)) ("python array read" index array) + (~~ (.static @.lua)) ("lua array read" index array) + (~~ (.static @.ruby)) ("ruby array read" index array) + (~~ (.static @.php)) ("php array read" index array) + (~~ (.static @.scheme)) ("scheme array read" index array)))) <index> <array>)])) (`` (template: .public (has! <index> <value> <array>) [((.: (.All (_ a) (.-> .Nat a (..Array a) (..Array a))) (.function (has! index value array) - (.for [(~~ (.static @.old)) - ("jvm aastore" array index value) - - (~~ (.static @.jvm)) - (.|> array - (.:as <array_type>) - ("jvm array write object" (~~ (int! index)) (.:as <elem_type> value)) - .:expected) - - (~~ (.static @.js)) ("js array write" index value array) - (~~ (.static @.python)) ("python array write" index value array) - (~~ (.static @.lua)) ("lua array write" index value array) - (~~ (.static @.ruby)) ("ruby array write" index value array) - (~~ (.static @.php)) ("php array write" index value array) - (~~ (.static @.scheme)) ("scheme array write" index value array)]))) + (.for (~~ (.static @.old)) + ("jvm aastore" array index value) + + (~~ (.static @.jvm)) + (.|> array + (.:as <array_type>) + ("jvm array write object" (~~ (int! index)) (.:as <elem_type> value)) + .:expected) + + (~~ (.static @.js)) ("js array write" index value array) + (~~ (.static @.python)) ("python array write" index value array) + (~~ (.static @.lua)) ("lua array write" index value array) + (~~ (.static @.ruby)) ("ruby array write" index value array) + (~~ (.static @.php)) ("php array write" index value array) + (~~ (.static @.scheme)) ("scheme array write" index value array)))) <index> <value> <array>)])) (`` (template: .public (lacks! <index> <array>) @@ -146,18 +145,18 @@ (.function (lacks! index array) (.let [size (..size array)] (.if ("lux i64 <" (.int size) (.int index)) - (.for [(~~ (.static @.old)) - (..has! index (.:expected ("jvm object null")) array) - - (~~ (.static @.jvm)) - (..has! index (.:expected (: <elem_type> ("jvm object null"))) array) - - (~~ (.static @.js)) ("js array delete" index array) - (~~ (.static @.python)) ("python array delete" index array) - (~~ (.static @.lua)) ("lua array delete" index array) - (~~ (.static @.ruby)) ("ruby array delete" index array) - (~~ (.static @.php)) ("php array delete" index array) - (~~ (.static @.scheme)) ("scheme array delete" index array)]) + (.for (~~ (.static @.old)) + (..has! index (.:expected ("jvm object null")) array) + + (~~ (.static @.jvm)) + (..has! index (.:expected (: <elem_type> ("jvm object null"))) array) + + (~~ (.static @.js)) ("js array delete" index array) + (~~ (.static @.python)) ("python array delete" index array) + (~~ (.static @.lua)) ("lua array delete" index array) + (~~ (.static @.ruby)) ("ruby array delete" index array) + (~~ (.static @.php)) ("php array delete" index array) + (~~ (.static @.scheme)) ("scheme array delete" index array)) array)))) <index> <array>)])) ) |