aboutsummaryrefslogtreecommitdiff
path: root/lux-js/source/program.lux
diff options
context:
space:
mode:
authorEduardo Julian2022-07-26 18:08:04 -0400
committerEduardo Julian2022-07-26 18:08:04 -0400
commitfeacd79496ae9c76492d5a12d30b78724b642654 (patch)
treea85708d1bfe43a98ba62b7f8589dcc95a71f86f5 /lux-js/source/program.lux
parentdec796a9838e39148c007f3f3d360964d7cb68de (diff)
Made inlined functions into first-class macros.
Diffstat (limited to '')
-rw-r--r--lux-js/source/program.lux102
1 files changed, 58 insertions, 44 deletions
diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux
index c692a41a0..69656c4bc 100644
--- a/lux-js/source/program.lux
+++ b/lux-js/source/program.lux
@@ -22,9 +22,6 @@
["[0]" utf8]]]
[collection
["[0]" array (.only Array)]]]
- [macro
- ["^" pattern]
- ["[0]" template]]
[math
[number
["n" nat]
@@ -32,10 +29,13 @@
["[0]" i64]]]
["[0]" world
["[0]" file]
- ["[1]/[0]" program]]
- ["@" target (.only)
- ["_" js]]
+ ["[1]/[0]" environment]]
[meta
+ ["@" target (.only)
+ ["_" js]]
+ [macro
+ ["^" pattern]
+ ["[0]" template]]
[compiler
["[0]" phase (.only Operation Phase)]
[reference
@@ -56,7 +56,8 @@
[generation
["[0]" reference]
["[0]" js (.only)
- ["[0]" runtime]]]]]]
+ ["[0]" runtime]
+ ["[1]/[0]" reference]]]]]]
[default
["[0]" platform (.only Platform)]]
[meta
@@ -177,11 +178,17 @@
[] (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
+ (|> value
+ .nat
+ runtime.high
+ jvm_int
(ffi.is java/lang/Object))
(static runtime.i64_low_field)
- (|> value .nat runtime.low jvm_int
+ (|> value
+ .nat
+ runtime.low
+ jvm_int
(ffi.is java/lang/Object))
_
@@ -221,7 +228,7 @@
java/lang/Object
(|> (java/util/Arrays::copyOfRange value
(|> args
- (array.read! 0)
+ (array.item 0)
maybe.trusted
(as Int)
ffi.as_int)
@@ -235,14 +242,18 @@
(-> (Array java/lang/Object) org/openjdk/nashorn/api/scripting/JSObject)
(let [js_object (is (-> java/lang/Object org/openjdk/nashorn/api/scripting/JSObject)
(function (_ sub_value)
- (<| (case (ffi.is [java/lang/Object] sub_value)
+ (<| (case (ffi.as [java/lang/Object] sub_value)
{.#Some sub_value}
- (|> sub_value (as (Array java/lang/Object)) js_structure)
+ (|> sub_value
+ (as (Array java/lang/Object))
+ js_structure)
{.#None})
- (case (ffi.is java/lang/Long sub_value)
+ (case (ffi.as java/lang/Long sub_value)
{.#Some sub_value}
- (|> sub_value ffi.of_long js_int)
+ (|> sub_value
+ ffi.of_long
+ js_int)
{.#None})
... else
@@ -252,10 +263,12 @@
[]
... Methods
(StructureValue
- [] (getValue self []) java/lang/Object
- (ffi.is java/lang/Object value))
+ [] (getValue self [])
+ java/lang/Object
+ (as java/lang/Object value))
(org/openjdk/nashorn/api/scripting/AbstractJSObject
- [] (isArray self []) boolean
+ [] (isArray self [])
+ boolean
(ffi.as_boolean #1))
(org/openjdk/nashorn/api/scripting/AbstractJSObject
[] (getMember self [member java/lang/String])
@@ -277,11 +290,11 @@
(static runtime.variant_tag_field)
(|> value
- (array.read! 0)
+ (array.item 0)
maybe.trusted)
(static runtime.variant_flag_field)
- (case (array.read! 1 value)
+ (case (array.item 1 value)
{.#Some set!}
set!
@@ -290,18 +303,18 @@
(static runtime.variant_value_field)
(|> value
- (array.read! 2)
+ (array.item 2)
maybe.trusted
js_object
(ffi.is java/lang/Object))
_
- (panic! (exception.error ..unknown_member [(as Text member) (as java/lang/Object value)])))
- )
+ (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
+ [] (getSlot self [idx int])
+ java/lang/Object
(|> value
- (array.read! (|> idx java/lang/Integer::longValue (as Nat)))
+ (array.item (|> idx java/lang/Integer::longValue (as Nat)))
maybe.trusted
js_object
(as java/lang/Object)))
@@ -313,7 +326,7 @@
(exception.report
(list ["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.is org/openjdk/nashorn/api/scripting/ScriptObjectMirror object)
+ ["Keys" (case (ffi.as org/openjdk/nashorn/api/scripting/ScriptObjectMirror object)
{.#Some object}
(|> object
(org/openjdk/nashorn/api/scripting/ScriptObjectMirror::getOwnKeys true)
@@ -327,7 +340,7 @@
(-> Text org/openjdk/nashorn/api/scripting/ScriptObjectMirror (Maybe Int))
(|> i64
(org/openjdk/nashorn/api/scripting/JSObject::getMember [(ffi.as_string half)])
- (maybe#each (|>> (ffi.is java/lang/Number)))
+ (maybe#each (|>> (ffi.as java/lang/Number)))
maybe#conjoint
(maybe#each (|>> java/lang/Number::longValue ffi.of_long))))
@@ -353,7 +366,7 @@
(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.is java/lang/Number tag) (lux_object value)]
+ [[(ffi.as 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)
@@ -374,14 +387,14 @@
(if (n.< num_keys idx)
(case (org/openjdk/nashorn/api/scripting/JSObject::getMember (ffi.as_string (%.nat idx)) js_object)
{.#Some member}
- (case (ffi.is org/openjdk/nashorn/internal/runtime/Undefined member)
+ (case (ffi.as 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))
+ (again (++ idx) (array.has! idx (as java/lang/Object parsed_member) output))
{try.#Failure error}
{.#None}))
@@ -395,13 +408,13 @@
(-> java/lang/Object (Try Any))
(`` (<| (if (ffi.null? js_object)
(exception.except ..null_has_no_lux_representation [{.#None}]))
- (case (ffi.is org/openjdk/nashorn/internal/runtime/Undefined js_object)
+ (case (ffi.as org/openjdk/nashorn/internal/runtime/Undefined js_object)
{.#Some _}
(exception.except ..undefined_has_no_lux_representation [])
{.#None})
(,, (with_template [<class>]
- [(case (ffi.is <class> js_object)
+ [(case (ffi.as <class> js_object)
{.#Some js_object}
{try.#Success js_object}
@@ -409,7 +422,7 @@
[java/lang/Boolean] [java/lang/String]))
(,, (with_template [<class> <method>]
- [(case (ffi.is <class> js_object)
+ [(case (ffi.as <class> js_object)
{.#Some js_object}
{try.#Success (<method> js_object)}
@@ -418,7 +431,7 @@
[java/lang/Number java/lang/Number::doubleValue]
[StructureValue StructureValue::getValue]
[IntValue IntValue::getValue]))
- (case (ffi.is org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object)
+ (case (ffi.as org/openjdk/nashorn/api/scripting/ScriptObjectMirror js_object)
{.#Some js_object}
(case (check_int js_object)
{.#Some value}
@@ -451,7 +464,7 @@
(do maybe.monad
[function (|> function
(as java/lang/Object)
- (ffi.is org/openjdk/nashorn/api/scripting/JSObject))]
+ (ffi.as org/openjdk/nashorn/api/scripting/JSObject))]
(if (ffi.of_boolean (org/openjdk/nashorn/api/scripting/JSObject::isFunction function))
{.#Some function}
{.#None})))
@@ -469,8 +482,8 @@
(org/openjdk/nashorn/api/scripting/JSObject::call {.#None}
(|> (array.empty 2)
(is (Array java/lang/Object))
- (array.write! 0 (to_js inputs))
- (array.write! 1 (to_js lux)))
+ (array.has! 0 (to_js inputs))
+ (array.has! 1 (to_js lux)))
macro))))
(exception (cannot_apply_a_non_function [object java/lang/Object])
@@ -642,7 +655,7 @@
platform.#phase_wrapper ..phase_wrapper
platform.#write (|>> _.code (at utf8.codec encoded))])))
-(def (program context program)
+(def (lux_program context program)
(Program _.Expression _.Statement)
(let [@process (_.var "process")
on_node_js? (|> @process
@@ -681,11 +694,11 @@
output (org/openjdk/nashorn/api/scripting/JSObject::call {.#None}
(|> (array.empty 5)
(is (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)))
+ (array.has! 0 name)
+ (array.has! 1 (as java/lang/Object (extender phase)))
+ (array.has! 2 (to_js archive))
+ (array.has! 3 (to_js parameters))
+ (array.has! 4 (to_js state)))
handler)]
(lux_object (as java/lang/Object output)))))
@@ -696,7 +709,7 @@
(def (declare_success! _)
(-> Any (Async Any))
- (async.future (at world/program.default exit +0)))
+ (async.future (at world/environment.default exit +0)))
(def (scope body)
(-> _.Statement _.Statement)
@@ -720,7 +733,8 @@
(io.io platform)
generation.bundle
(function.constant extension/bundle.empty)
- ..program
+ ..lux_program
+ (reference.constant js/reference.system)
[(And Register Text) _.Expression _.Statement]
..extender
service