From 4965597043aca57a05760113f1851e96dad1eaf8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 14 Mar 2022 06:14:57 -0400 Subject: Leaner syntax for the "for" macro. --- lux-cl/source/program.lux | 172 +-- lux-js/source/program.lux | 1145 ++++++++--------- lux-lua/source/program.lux | 152 +-- lux-php/source/program.lux | 198 +-- lux-python/source/program.lux | 112 +- lux-r/source/program.lux | 182 +-- lux-ruby/source/program.lux | 356 +++--- lux-scheme/source/program.lux | 188 +-- stdlib/source/documentation/lux.lux | 4 +- stdlib/source/documentation/lux/extension.lux | 58 +- stdlib/source/documentation/lux/world/console.lux | 6 +- stdlib/source/documentation/lux/world/file.lux | 10 +- .../source/documentation/lux/world/file/watch.lux | 6 +- .../documentation/lux/world/net/http/client.lux | 2 +- stdlib/source/documentation/lux/world/shell.lux | 4 +- stdlib/source/library/lux.lux | 99 +- stdlib/source/library/lux/abstract/apply.lux | 8 +- .../library/lux/control/concurrency/atom.lux | 56 +- .../library/lux/control/concurrency/thread.lux | 70 +- stdlib/source/library/lux/control/thread.lux | 62 +- stdlib/source/library/lux/control/writer.lux | 14 +- stdlib/source/library/lux/data/collection/list.lux | 29 +- .../library/lux/data/collection/tree/zipper.lux | 34 +- stdlib/source/library/lux/data/text.lux | 220 ++-- stdlib/source/library/lux/data/text/buffer.lux | 90 +- .../source/library/lux/data/text/encoding/utf8.lux | 256 ++-- stdlib/source/library/lux/debug.lux | 518 ++++---- stdlib/source/library/lux/ffi.lux | 236 ++-- stdlib/source/library/lux/math.lux | 562 ++++----- stdlib/source/library/lux/meta/configuration.lux | 2 +- stdlib/source/library/lux/meta/version.lux | 2 +- stdlib/source/library/lux/program.lux | 8 +- stdlib/source/library/lux/target/jvm/constant.lux | 78 +- stdlib/source/library/lux/target/jvm/loader.lux | 10 +- stdlib/source/library/lux/target/python.lux | 16 +- stdlib/source/library/lux/test.lux | 10 +- stdlib/source/library/lux/time/instant.lux | 74 +- .../library/lux/tool/compiler/default/platform.lux | 46 +- .../language/lux/phase/extension/analysis/js.lux | 2 +- .../language/lux/phase/extension/analysis/lua.lux | 6 +- .../language/lux/phase/extension/analysis/php.lux | 6 +- .../lux/phase/extension/analysis/python.lux | 12 +- .../language/lux/phase/extension/analysis/ruby.lux | 6 +- .../lux/phase/extension/analysis/scheme.lux | 5 +- .../lux/phase/extension/generation/lua/common.lux | 2 +- .../language/lux/phase/generation/lua/runtime.lux | 8 +- .../lux/phase/generation/python/runtime.lux | 2 +- .../language/lux/phase/generation/reference.lux | 31 +- .../lux/tool/compiler/language/lux/syntax.lux | 6 +- .../lux/tool/compiler/meta/cache/module.lux | 2 +- .../library/lux/tool/compiler/meta/io/archive.lux | 4 +- stdlib/source/library/lux/type.lux | 5 +- stdlib/source/library/lux/type/check.lux | 5 +- stdlib/source/library/lux/world/console.lux | 136 +- stdlib/source/library/lux/world/file.lux | 1308 ++++++++++---------- stdlib/source/library/lux/world/file/watch.lux | 4 +- .../source/library/lux/world/net/http/client.lux | 4 +- stdlib/source/library/lux/world/program.lux | 488 ++++---- stdlib/source/library/lux/world/shell.lux | 4 +- stdlib/source/program/compositor.lux | 20 +- stdlib/source/test/lux.lux | 76 +- .../source/test/lux/control/concurrency/async.lux | 55 +- .../test/lux/control/concurrency/semaphore.lux | 61 +- stdlib/source/test/lux/debug.lux | 90 +- stdlib/source/test/lux/extension.lux | 96 +- stdlib/source/test/lux/math/number/frac.lux | 8 +- stdlib/source/test/lux/meta/configuration.lux | 33 +- stdlib/source/test/lux/meta/version.lux | 8 +- stdlib/source/test/lux/static.lux | 2 +- stdlib/source/test/lux/target/jvm.lux | 313 ++--- stdlib/source/test/lux/type/poly/equivalence.lux | 50 +- stdlib/source/test/lux/type/poly/functor.lux | 30 +- stdlib/source/test/lux/type/poly/json.lux | 100 +- stdlib/source/unsafe/lux/data/binary.lux | 244 ++-- stdlib/source/unsafe/lux/data/collection/array.lux | 191 ++- 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 [] - [(ffi.interface: - (getValue [] java/lang/Object)) - - (import: - ["[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 [] + [(ffi.interface: + (getValue [] java/lang/Object)) + + (import: + ["[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 [] - [(case (ffi.check 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 [ ] - [(case (ffi.check js_object) - {.#Some js_object} - {try.#Success ( 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 [] + [(case (ffi.check js_object) + {.#Some js_object} + {try.#Success js_object} + + {.#None})] + + [java/lang/Boolean] [java/lang/String])) + (~~ (template [ ] + [(case (ffi.check js_object) + {.#Some js_object} + {try.#Success ( js_object)} + + {.#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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 [ (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 (as_is ) - @.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 (as_is ) + @.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 [ (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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 [ (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 - @.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 + @.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 (as_is ) - @.python (as_is)])) + (for @.old (as_is ) + @.jvm (as_is ) + @.python (as_is))) (with_expansions [ (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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 [ (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 - - @.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 + + @.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 [ (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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 .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 ] + (for @.old + @.jvm (as_is))) -(with_expansions [ (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 [ (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)) - (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"] + (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)) - (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"] + (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 [ (java/util/concurrent/atomic/AtomicReference a)] - (for [@.old - @.jvm ] + (for @.old + @.jvm (array.Array a))) (def: .public (atom value) (All (_ a) (-> a (Atom a))) (:abstraction (with_expansions [ (java/util/concurrent/atomic/AtomicReference::new value)] - (for [@.old - @.jvm ] + (for @.old + @.jvm ( 0 value ( 1)))))) (def: .public (read! atom) (All (_ a) (-> (Atom a) (IO a))) (with_expansions [ (java/util/concurrent/atomic/AtomicReference::get (:representation atom))] - (for [@.old - @.jvm ] + (for @.old + @.jvm (io.io ( 0 (:representation atom)))))) (def: .public (compare_and_swap! current new atom) (All (_ a) (-> a a (Atom a) (IO Bit))) (io.io (with_expansions [ (ffi.of_boolean (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom)))] - (for [@.old - @.jvm ] + (for @.old + @.jvm (let [old ( 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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 [ 1 - (<| (configuration.for [... TODO: Remove this when Rembulan is no longer being used. - ["lua_compiler?" ""] - ]) + (<| (configuration.for ["lua_compiler?" ""] + ... TODO: Remove this when Rembulan is no longer being used. + ) (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) ffi.of_int .nat))] - (for [@.old - @.jvm ] + (for @.old + @.jvm ... Default ))) @@ -89,10 +89,10 @@ .int ffi.as_int java/util/concurrent/ScheduledThreadPoolExecutor::new)))] - (for [@.old - @.jvm - @.js (as_is) - @.python (as_is)] + (for @.old + @.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 - - @.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 + + @.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 family) {.#Item next side'} - {.#Some (for [@.old - [#family {.#Some (|> family - (has side') - (revised (|>> {.#Item (the #node zipper)})))} - #node next]] + {.#Some (for @.old + [#family {.#Some (|> family + (has side') + (revised (|>> {.#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') @@ -153,11 +153,11 @@ {.#None} {.#Item last prevs} - {.#Some (for [@.old [#family {.#Some (|> family - (has {.#End}) - (revised (|>> {.#Item (the #node zipper)} - (list#composite prevs))))} - #node last]] + {.#Some (for @.old [#family {.#Some (|> family + (has {.#End}) + (revised (|>> {.#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 {.#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 + (: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 - - (: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 ))) @@ -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 (as_is ) - @.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 (as_is ) + @.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 [ [0 function.identity]] - (for [@.old - @.jvm - @.js [0 function.identity] - @.lua [0 function.identity]] + (for @.old + @.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 - @.js (let [[capacity transform] (:representation buffer) - then! (: (-> (JS_Array Text) (JS_Array Text)) + (for @.old + @.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 [ (|>> :representation product.left)] - (for [@.old - @.jvm - @.js - @.lua ] + (for @.old + @.jvm + @.js + @.lua ... default (|>> :representation (sequence#mix (function (_ chunk total) @@ -117,15 +117,15 @@ transform java/lang/StringBuilder::toString ffi.of_string))] - (for [@.old - @.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 + @.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 (as_is ) + (for @.old (as_is ) + @.jvm (as_is ) - @.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 [ {try.#Success (ffi.of_string (java/lang/String::new value (ffi.as_string (//.name //.utf_8))))}] - (for [@.old - @.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 + + @.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 (as_is ) - - @.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 (as_is ) + + @.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 [ (for [@.lua (~~ (as_is ..tuple_array))] + (with_expansions [ (for @.lua (~~ (as_is ..tuple_array)) (~~ (as_is)))] (`` (|>> (:as (array.Array Any)) @@ -177,206 +177,206 @@ (tuple_inspection inspection value))) {.#None}) (ffi.of_string (java/lang/Object::toString object)))))] - (for [@.old - @.jvm - - @.js - (case (ffi.type_of value) - (^template [ ] - [ - (`` (|> value (~~ (template.spliced ))))]) - (["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 [ ] - [(^or ) - (`` (|> value (~~ (template.spliced ))))]) - (["" "" [(:as .Bit) %.bit]] - ["" "" [(:as .Int) %.int]] - ["" "" [(:as .Frac) %.frac]] - ["" "" [(:as .Text) %.text]] - ["" "" [(:as .Text) %.text]]) - - (^or "" "") - (tuple_inspection inspection value) - - (^or "" "") - (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 [ ] - [ - (`` (|> value (~~ (template.spliced ))))]) - (["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 ) - [(|> - (:as ..Object) - Object::class)] - - (to_s ) - [(|> - (:as ..Object) - Object::to_s)]] - (let [value_class (class_of value)] - (`` (cond (~~ (template [ ] - [(same? (class_of ) value_class) - (|> value (:as ) )] - - [#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 [ ] - [ - (`` (|> value (~~ (template.spliced ))))]) - (["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 [ ] - [( value) - (`` (|> value (~~ (template.spliced ))))] - - [..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 + + @.js + (case (ffi.type_of value) + (^template [ ] + [ + (`` (|> value (~~ (template.spliced ))))]) + (["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 [ ] + [(^or ) + (`` (|> value (~~ (template.spliced ))))]) + (["" "" [(:as .Bit) %.bit]] + ["" "" [(:as .Int) %.int]] + ["" "" [(:as .Frac) %.frac]] + ["" "" [(:as .Text) %.text]] + ["" "" [(:as .Text) %.text]]) + + (^or "" "") + (tuple_inspection inspection value) + + (^or "" "") + (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 [ ] + [ + (`` (|> value (~~ (template.spliced ))))]) + (["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 ) + [(|> + (:as ..Object) + Object::class)] + + (to_s ) + [(|> + (:as ..Object) + Object::to_s)]] + (let [value_class (class_of value)] + (`` (cond (~~ (template [ ] + [(same? (class_of ) value_class) + (|> value (:as ) )] + + [#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 [ ] + [ + (`` (|> value (~~ (template.spliced ))))]) + (["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 [ ] + [( value) + (`` (|> value (~~ (template.spliced ))))] + + [..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 [ (for [@.js "js constant" - @.python "python constant" - @.lua "lua constant" - @.ruby "ruby constant"]) - (for [@.js "js apply" - @.python "python apply" - @.lua "lua apply" - @.ruby "ruby apply"]) - (for [@.js "js object new" - @.python "python apply"] +(with_expansions [ (for @.js "js constant" + @.python "python constant" + @.lua "lua constant" + @.ruby "ruby constant") + (for @.js "js apply" + @.python "python apply" + @.lua "lua apply" + @.ruby "ruby apply") + (for @.js "js object new" + @.python "python apply" (as_is)) - (for [@.js "js object do" - @.python "python object do" - @.lua "lua object do" - @.ruby "ruby object do"]) - (for [@.js "js object get" - @.python "python object get" - @.lua "lua object get" - @.ruby "ruby object get"] + (for @.js "js object do" + @.python "python object do" + @.lua "lua object do" + @.ruby "ruby object do") + (for @.js "js object get" + @.python "python object get" + @.lua "lua object get" + @.ruby "ruby object get" (as_is)) - (for [@.python "python import" - @.lua "lua import" - @.ruby "ruby import"] + (for @.python "python import" + @.lua "lua import" + @.ruby "ruby import" (as_is)) - (for [@.js "js function" - @.python "python function" - @.lua "lua function"] + (for @.js "js function" + @.python "python function" + @.lua "lua function" (as_is))] (abstract: .public (Object brand) Any) - (with_expansions [ (for [@.js (as_is [Symbol] - [Null] - [Undefined]) - @.python (as_is [None] - [Dict]) - @.lua (as_is [Nil] - [Table]) - @.ruby (as_is [Nil])]) + (with_expansions [ (for @.js (as_is [Symbol] + [Null] + [Undefined]) + @.python (as_is [None] + [Dict]) + @.lua (as_is [Nil] + [Table]) + @.ruby (as_is [Nil])) ] (template [] [(with_expansions [ (template.symbol [ "'"])] @@ -74,13 +74,13 @@ )) - (with_expansions [ (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 [ (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])) ] (template [ ] [(type: .public @@ -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:) (` ( (~ (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:) - (` ( (~ (for [@.js (` ( (~ (code.text (..host_path class_name))))) - @.python (` (.:as ..Function - (~ (..imported class_name))))])) + (` ( (~ (for @.js (` ( (~ (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 (` ( (~ (code.text (%.format (..host_path class_name) "." field))))) - @.ruby (` ( (~ (code.text (%.format (..host_path class_name) "::" field)))))] + (for @.js (` ( (~ (code.text (%.format (..host_path class_name) "." field))))) + @.ruby (` ( (~ (code.text (%.format (..host_path class_name) "::" field))))) (` ( (~ (code.text field)) (~ (..imported class_name)))))))))))))))) @@ -516,8 +516,8 @@ (|> it (has #alias {.#Some name}) (..procedure_definition import! - (for [@.js (` ( (~ (code.text (%.format (..host_path class_name) "." method))))) - @.ruby (` ( (~ (code.text (%.format (..host_path class_name) "::" method)))))] + (for @.js (` ( (~ (code.text (%.format (..host_path class_name) "." method))))) + @.ruby (` ( (~ (code.text (%.format (..host_path class_name) "::" method))))) (` ( (~ (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] (.form ($_ <>.and .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 .any - [head tail] (.tuple (<>.and .local_symbol (<>.some .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? ) - [(.case (..global Any ) - {.#None} - .false - - {.#Some _} - .true)]) - - (template [ ] - [(def: .public - Bit - (!defined? ))] - - [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 .any + [head tail] (.tuple (<>.and .local_symbol (<>.some .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? ) + [(.case (..global Any ) + {.#None} + .false + + {.#Some _} + .true)]) + + (template [ ] + [(def: .public + Bit + (!defined? ))] + + [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 [ ] - [(def: .public ( it) - (-> Frac Frac) - ( 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 [ ] - [(def: .public - (-> Frac Frac) - (|>> !double - ["D"] - ("jvm member invoke static" [] "java.lang.Math" []) - !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 [ ] - [(def: .public - (-> Frac Frac) - (|>> [] - ("js apply" ("js constant" )) - (: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 [ ] - [(def: .public - (-> Frac Frac) - (|>> [] - ("python object do" ("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 [ ] - [(def: .public - (-> Frac Frac) - (|>> [] - ("lua apply" ("lua constant" )) - (: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 [ ] - [(def: .public - (-> Frac Frac) - (|>> [] - ("ruby apply" ("ruby constant" )) - (: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 [ ] - [(def: .public ( it) - (-> Frac Frac) - (|> ("ruby object do" 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 [ ] - [(def: .public - (-> Frac Frac) - (|>> ("php apply" ("php constant" )) - (: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 [ ] - [(def: .public - (-> Frac Frac) - (|>> ("scheme apply" ("scheme constant" )) - (: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 [ ] + [(def: .public ( it) + (-> Frac Frac) + ( 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 [ ] + [(def: .public + (-> Frac Frac) + (|>> !double + ["D"] + ("jvm member invoke static" [] "java.lang.Math" []) + !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 [ ] + [(def: .public + (-> Frac Frac) + (|>> [] + ("js apply" ("js constant" )) + (: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 [ ] + [(def: .public + (-> Frac Frac) + (|>> [] + ("python object do" ("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 [ ] + [(def: .public + (-> Frac Frac) + (|>> [] + ("lua apply" ("lua constant" )) + (: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 [ ] + [(def: .public + (-> Frac Frac) + (|>> [] + ("ruby apply" ("ruby constant" )) + (: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 [ ] + [(def: .public ( it) + (-> Frac Frac) + (|> ("ruby object do" 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 [ ] + [(def: .public + (-> Frac Frac) + (|>> ("php apply" ("php constant" )) + (: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 [ ] + [(def: .public + (-> Frac Frac) + (|>> ("scheme apply" ("scheme constant" )) + (: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 (.tuple (<>.some (<>.and ..configuration .any))) +(syntax: .public (for [specializations (<>.some (<>.and ..configuration .any)) default (<>.maybe .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 (.tuple (<>.some (<>.and .text .any))) +(syntax: .public (for [specializations (<>.some (<>.and .text .any)) default (<>.maybe .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 .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 [ (for [@.old - (<|) - - @.jvm - "jvm object cast"])] + (with_expansions [ (for @.old + (<|) + + @.jvm + "jvm object 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 [ (in (debug.log! report))] - (.for [@.js (case console.default - {.#None} - + (.for @.js (case console.default + {.#None} + - {.#Some console} - (console.write_line report console))] + {.#Some console} + (console.write_line report console)) ))] (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 [ ] [(def: .public ( 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 [ (in (debug.log! report))] - (for [@.js (case console.default - {.#None} - - - {.#Some console} - (console.write_line report console))] + (for @.js (case console.default + {.#None} + + + {.#Some console} + (console.write_line report console)) ))) .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 ] + (for @.lua (_.if ..on_rembulan? ))))) @@ -359,7 +359,7 @@ (..byte_index text) (_.- (_.int +1)))) (_.var "string.sub")))] - (for [@.lua ] + (for @.lua (_.if ..on_rembulan? )))) @@ -367,7 +367,7 @@ (runtime: (text//size subject) (with_expansions [ (_.return (_.apply (list subject) (_.var "string.len"))) (_.return (_.apply (list subject) (_.var "utf8.len")))] - (for [@.lua ] + (for @.lua (_.if ..on_rembulan? )))) @@ -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 ] + (for @.lua (_.if ..on_rembulan? )))) 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 [