diff options
author | Eduardo Julian | 2021-02-22 01:46:40 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-02-22 01:46:40 -0400 |
commit | 565e7fae85379e4d2e4daacc51eb1f8796c738c1 (patch) | |
tree | a306f40f45be76359481a30cc7dc83f405c12716 /lux-php | |
parent | cfa75870e67e7759bba47f25b3fd7dd252f9341e (diff) |
Updates for PHP compiler.
Diffstat (limited to 'lux-php')
-rw-r--r-- | lux-php/source/program.lux | 671 |
1 files changed, 398 insertions, 273 deletions
diff --git a/lux-php/source/program.lux b/lux-php/source/program.lux index a65999526..ae41496a2 100644 --- a/lux-php/source/program.lux +++ b/lux-php/source/program.lux @@ -1,259 +1,300 @@ (.module: [lux #* + [program (#+ program:)] + ["." host] + ["." debug] [abstract ["." monad (#+ do)]] [control - pipe + ["." try (#+ Try)] ["." exception (#+ exception:)] ["." io (#+ IO io)] - ["p" parser - [cli (#+ program:)]]] + [concurrency + ["." promise (#+ Promise)]]] [data ["." maybe] - ["." error (#+ Error)] - [number - ["." i64]] - ["." text ("#@." hash) - format] + ["." text ("#\." hash) + ["%" format (#+ format)] + ["." encoding]] [collection - ["." array (#+ Array)] - ["." list ("#@." functor)]]] + ["." array (#+ Array)]]] [macro ["." template]] - [world - ["." file]] - ["." host (#+ import: interface: do-to object) + [math + [number (#+ hex) + ["n" nat] + ["." i64]]] + ["." world #_ + ["." file] + ["#/." program]] + ["@" target ["_" php]] [tool [compiler - ["." name] - ["." synthesis] - [phase - [macro (#+ Expander)] - ["." generation - ["." php - ["." runtime] - ["." extension]]]] + [phase (#+ Operation Phase)] + [reference + [variable (#+ Register)]] + [language + [lux + [program (#+ Program)] + [generation (#+ Context Host)] + ["." synthesis] + [analysis + [macro (#+ Expander)]] + [phase + ["." extension (#+ Extender Handler) + ["#/." bundle] + ["." analysis #_ + ["#" php]] + ["." generation #_ + ["#" php]]] + [generation + ["." reference] + ["." php + ["." runtime]]]]]] [default - ["." platform (#+ Platform)]]]] - ["." debug]] + ["." platform (#+ Platform)]] + [meta + ["." packager #_ + ["#" script]]]]]] [program ["/" compositor - ["/." cli]]]) + ["#." cli] + ["#." static]]]) -(import: #long java/lang/String) +(host.import: java/lang/String) -(import: #long (java/lang/Class a)) +(host.import: (java/lang/Class a)) -(import: #long java/lang/Object - (toString [] java/lang/String) - (getClass [] (java/lang/Class java/lang/Object))) +(host.import: java/lang/Object + ["#::." + (toString [] java/lang/String) + (getClass [] (java/lang/Class java/lang/Object))]) -(import: #long java/lang/Integer) +(host.import: java/lang/Integer) -(import: #long java/lang/Long - (intValue [] java/lang/Integer)) +(host.import: java/lang/Long + ["#::." + (intValue [] java/lang/Integer)]) -(import: #long php/runtime/Memory) +(host.import: php/runtime/Memory) -(import: #long php/runtime/Memory$Type - (#enum ARRAY)) +(host.import: php/runtime/Memory$Type + ["#::." + (#enum ARRAY)]) -(import: #long php/runtime/memory/NullMemory) +(host.import: php/runtime/memory/NullMemory) -(import: #long php/runtime/memory/FalseMemory) -(import: #long php/runtime/memory/TrueMemory) +(host.import: php/runtime/memory/FalseMemory) +(host.import: php/runtime/memory/TrueMemory) -(import: #long php/runtime/memory/LongMemory - (new [long]) - (toLong [] long)) +(host.import: php/runtime/memory/LongMemory + ["#::." + (new [long]) + (toLong [] long)]) -(import: #long php/runtime/memory/DoubleMemory - (toDouble [] double)) +(host.import: php/runtime/memory/DoubleMemory + ["#::." + (toDouble [] double)]) -(import: #long php/runtime/memory/StringMemory - (new [java/lang/String]) - (toString [] java/lang/String)) +(host.import: php/runtime/memory/StringMemory + ["#::." + (new [java/lang/String]) + (toString [] java/lang/String)]) -(import: #long php/runtime/memory/ReferenceMemory - (getValue [] php/runtime/Memory)) +(host.import: php/runtime/memory/ReferenceMemory + ["#::." + (getValue [] php/runtime/Memory)]) -(import: #long php/runtime/memory/ArrayMemory - (new [[java/lang/Object]]) - (size [] int) - (isMap [] boolean) - (get [php/runtime/Memory] php/runtime/Memory)) +(host.import: php/runtime/memory/ArrayMemory + ["#::." + (new [[java/lang/Object]]) + (size [] int) + (isMap [] boolean) + (get [php/runtime/Memory] php/runtime/Memory)]) -(import: #long php/runtime/lang/IObject) +(host.import: php/runtime/lang/IObject) -(import: #long php/runtime/memory/ObjectMemory - (value php/runtime/lang/IObject)) +(host.import: php/runtime/memory/ObjectMemory + ["#::." + (value php/runtime/lang/IObject)]) -(import: #long php/runtime/env/Environment - (#static current [] php/runtime/env/Environment)) +(host.import: php/runtime/env/Environment + ["#::." + (#static current [] php/runtime/env/Environment)]) -(import: #long php/runtime/env/TraceInfo - (new [java/lang/String int int])) +(host.import: php/runtime/env/TraceInfo + ["#::." + (new [java/lang/String int int])]) -(import: #long php/runtime/reflection/FunctionEntity) +(host.import: php/runtime/reflection/FunctionEntity) -(import: #long php/runtime/invoke/InvokeHelper - (#static callAny [php/runtime/Memory [php/runtime/Memory] php/runtime/env/Environment php/runtime/env/TraceInfo] - #try php/runtime/Memory)) +(host.import: php/runtime/invoke/InvokeHelper + ["#::." + (#static callAny [php/runtime/Memory [php/runtime/Memory] php/runtime/env/Environment php/runtime/env/TraceInfo] + #try php/runtime/Memory)]) -(import: #long php/runtime/lang/Closure - (call [php/runtime/env/Environment [php/runtime/Memory]] #try php/runtime/Memory)) +(host.import: php/runtime/lang/Closure + ["#::." + (call [php/runtime/env/Environment [php/runtime/Memory]] #try php/runtime/Memory)]) (template [<name>] - [(interface: <name> + [(host.interface: <name> (getValue [] java/lang/Object)) - (`` (import: (~~ (template.identifier ["program/" <name>])) - (getValue [] java/lang/Object)))] + (`` (host.import: (~~ (template.identifier ["program/" <name>])) + ["#::." + (getValue [] java/lang/Object)]))] [StructureValue] ) (type: Reader - (-> java/lang/Object (Error Any))) + (-> java/lang/Object (Try Any))) -(exception: (unknown-kind-of-object {object java/lang/Object}) +(exception: (unknown_kind_of_object {object java/lang/Object}) (exception.report ["Class" (java/lang/Object::toString (java/lang/Object::getClass object))] ["Object" (java/lang/Object::toString object)])) -(def: (lux-structure value) +(def: (lux_structure value) (-> (Array java/lang/Object) - ## php/runtime/memory/ArrayMemory - php/runtime/Memory) - (`` (object [] php/runtime/Memory ## php/runtime/memory/ArrayMemory + php/runtime/memory/ArrayMemory + ## php/runtime/Memory + ) + (`` (host.object [] ## php/runtime/Memory + php/runtime/memory/ArrayMemory [program/StructureValue] - [{php/runtime/Memory$Type php/runtime/Memory$Type::ARRAY}] + [## {php/runtime/Memory$Type php/runtime/Memory$Type::ARRAY} + ] ## Methods (program/StructureValue - (getValue) - java/lang/Object + [] (getValue self) java/lang/Object (:assume value)) - ## (php/runtime/memory/ArrayMemory - ## (size) - ## int - ## (exec - ## (log! "{lux-structure#size}") - ## (:assume (array.size value)))) + (php/runtime/memory/ArrayMemory + [] (size self) + int + (exec + (debug.log! "{lux_structure#size}") + (:assume (array.size value)))) - ## (php/runtime/memory/ArrayMemory - ## (get {key php/runtime/Memory}) - ## php/runtime/Memory - ## (exec - ## (log! (format "{lux-structure#get}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) - - ## (php/runtime/memory/ArrayMemory - ## (getOrCreate {key php/runtime/Memory}) - ## php/runtime/memory/ReferenceMemory - ## (exec - ## (log! (format "{lux-structure#getOrCreate}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) - - ## (php/runtime/memory/ArrayMemory - ## (getOrCreateAsShortcut {key php/runtime/Memory}) - ## php/runtime/memory/ReferenceMemory - ## (exec - ## (log! (format "{lux-structure#getOrCreateAsShortcut}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) - - ## (php/runtime/memory/ArrayMemory - ## (getByScalarOrCreateAsShortcut {key java/lang/Object}) - ## php/runtime/memory/ReferenceMemory - ## (exec - ## (log! (format "{lux-structure#getByScalarOrCreateAsShortcut}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) - - ## (php/runtime/memory/ArrayMemory - ## (getByScalarOrCreate {key java/lang/Object}) - ## php/runtime/memory/ReferenceMemory - ## (exec - ## (log! (format "{lux-structure#getByScalarOrCreate}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) + (php/runtime/memory/ArrayMemory + [] (get self {key php/runtime/Memory}) + php/runtime/Memory + (exec + (debug.log! (format "{lux_structure#get}" text.new_line + (exception.construct unknown_kind_of_object key))) + (error! "OOPS!"))) - ## (php/runtime/memory/ArrayMemory - ## (getByScalar {key java/lang/Object}) - ## php/runtime/memory/ReferenceMemory - ## (exec - ## (log! (format "{lux-structure#getByScalar}" text.new-line - ## (exception.construct unknown-kind-of-object key))) - ## (error! "OOPS!"))) + (php/runtime/memory/ArrayMemory + [] (getOrCreate self {key php/runtime/Memory}) + php/runtime/memory/ReferenceMemory + (exec + (debug.log! (format "{lux_structure#getOrCreate}" text.new_line + (exception.construct unknown_kind_of_object key))) + (error! "OOPS!"))) - (php/runtime/Memory - (refOfIndex {trace php/runtime/env/TraceInfo} - {index php/runtime/Memory}) - php/runtime/Memory + (php/runtime/memory/ArrayMemory + [] (getOrCreateAsShortcut self {key php/runtime/Memory}) + php/runtime/memory/ReferenceMemory (exec - (log! (format "{lux-structure#refOfIndex}" text.new-line - (exception.construct unknown-kind-of-object index))) + (debug.log! (format "{lux_structure#getOrCreateAsShortcut}" text.new_line + (exception.construct unknown_kind_of_object key))) (error! "OOPS!"))) - (php/runtime/Memory - (refOfIndexAsShortcut {trace php/runtime/env/TraceInfo} - {index php/runtime/Memory}) - php/runtime/Memory + (php/runtime/memory/ArrayMemory + [] (getByScalarOrCreateAsShortcut self {key java/lang/Object}) + php/runtime/memory/ReferenceMemory (exec - (log! (format "{lux-structure#refOfIndexAsShortcut}" text.new-line - (exception.construct unknown-kind-of-object index))) + (debug.log! (format "{lux_structure#getByScalarOrCreateAsShortcut}" text.new_line + (exception.construct unknown_kind_of_object key))) (error! "OOPS!"))) - (php/runtime/Memory - (refOfIndex {trace php/runtime/env/TraceInfo} - {index long}) - php/runtime/Memory + (php/runtime/memory/ArrayMemory + [] (getByScalarOrCreate self {key java/lang/Object}) + php/runtime/memory/ReferenceMemory (exec - (log! (format "{lux-structure#refOfIndex long}" text.new-line - (exception.construct unknown-kind-of-object index))) + (debug.log! (format "{lux_structure#getByScalarOrCreate}" text.new_line + (exception.construct unknown_kind_of_object key))) (error! "OOPS!"))) - (php/runtime/Memory - (refOfIndex {trace php/runtime/env/TraceInfo} - {index java/lang/String}) - php/runtime/Memory + (php/runtime/memory/ArrayMemory + [] (getByScalar self {key java/lang/Object}) + php/runtime/memory/ReferenceMemory (exec - (log! (format "{lux-structure#refOfIndex java/lang/String}" text.new-line - (exception.construct unknown-kind-of-object index))) + (debug.log! (format "{lux_structure#getByScalar}" text.new_line + (exception.construct unknown_kind_of_object key))) (error! "OOPS!"))) - (~~ (template [<name>] - [(php/runtime/Memory (<name>) php/runtime/Memory (undefined))] + ## (php/runtime/Memory + ## [] (refOfIndex self + ## {trace php/runtime/env/TraceInfo} + ## {index php/runtime/Memory}) + ## php/runtime/Memory + ## (exec + ## (log! (format "{lux_structure#refOfIndex}" text.new_line + ## (exception.construct unknown_kind_of_object index))) + ## (error! "OOPS!"))) - [inc] [dec] [negative] [toNumeric] - )) + ## (php/runtime/Memory + ## [] (refOfIndexAsShortcut self + ## {trace php/runtime/env/TraceInfo} + ## {index php/runtime/Memory}) + ## php/runtime/Memory + ## (exec + ## (log! (format "{lux_structure#refOfIndexAsShortcut}" text.new_line + ## (exception.construct unknown_kind_of_object index))) + ## (error! "OOPS!"))) - (~~ (template [<name>] - [(php/runtime/Memory (<name> {other php/runtime/Memory}) php/runtime/Memory (undefined))] + ## (php/runtime/Memory + ## [] (refOfIndex self + ## {trace php/runtime/env/TraceInfo} + ## {index long}) + ## php/runtime/Memory + ## (exec + ## (log! (format "{lux_structure#refOfIndex long}" text.new_line + ## (exception.construct unknown_kind_of_object index))) + ## (error! "OOPS!"))) - [plus] [minus] [mul] [pow] [div] - [identical] [equal] [notEqual] - [smaller] [smallerEq] [greater] [greaterEq] - )) + ## (php/runtime/Memory + ## [] (refOfIndex self + ## {trace php/runtime/env/TraceInfo} + ## {index java/lang/String}) + ## php/runtime/Memory + ## (exec + ## (log! (format "{lux_structure#refOfIndex java/lang/String}" text.new_line + ## (exception.construct unknown_kind_of_object index))) + ## (error! "OOPS!"))) + + ## (~~ (template [<name>] + ## [(php/runtime/Memory [] (<name> self) php/runtime/Memory (undefined))] + + ## [inc] [dec] [negative] [toNumeric] + ## )) - (php/runtime/Memory (toLong) long (undefined)) - (php/runtime/Memory (toDouble) double (undefined)) - (php/runtime/Memory (toBoolean) boolean (undefined)) - (php/runtime/Memory (toString) java/lang/String (undefined)) - (php/runtime/Memory (getBinaryBytes {input java/nio/charset/Charset}) ByteArray (undefined)) + ## (~~ (template [<name>] + ## [(php/runtime/Memory [] (<name> self {other php/runtime/Memory}) php/runtime/Memory (undefined))] + + ## [plus] [minus] [mul] [pow] [div] + ## [identical] [equal] [notEqual] + ## [smaller] [smallerEq] [greater] [greaterEq] + ## )) + + ## (php/runtime/Memory [] (toLong self) long (undefined)) + ## (php/runtime/Memory [] (toDouble self) double (undefined)) + ## (php/runtime/Memory [] (toBoolean self) boolean (undefined)) + ## (php/runtime/Memory [] (toString self) java/lang/String (undefined)) + ## (php/runtime/Memory [] (getBinaryBytes self {input java/nio/charset/Charset}) ByteArray (undefined)) ))) -(def: (read-tuple read host-object) - (-> Reader php/runtime/memory/ArrayMemory (Error Any)) - (let [size (:coerce Nat (php/runtime/memory/ArrayMemory::size host-object))] +(def: (read_tuple read host_object) + (-> Reader php/runtime/memory/ArrayMemory (Try Any)) + (let [size (:coerce Nat (php/runtime/memory/ArrayMemory::size host_object))] (loop [idx 0 output (:coerce (Array Any) (array.new size))] - (if (n/< size idx) - (let [value (|> host-object + (if (n.< size idx) + (let [value (|> host_object (php/runtime/memory/ArrayMemory::get (php/runtime/memory/LongMemory::new (.int idx))) (:coerce php/runtime/memory/ReferenceMemory) php/runtime/memory/ReferenceMemory::getValue)] @@ -263,47 +304,47 @@ #.None (case (read value) - (#error.Failure error) - (#error.Failure error) + (#try.Failure error) + (#try.Failure error) - (#error.Success lux-value) - (recur (inc idx) (array.write idx lux-value output))))) - (#error.Success output))))) + (#try.Success lux_value) + (recur (inc idx) (array.write! idx lux_value output))))) + (#try.Success output))))) -(def: (read-variant read host-object) - (-> Reader php/runtime/memory/ArrayMemory (Error Any)) - (case [(|> host-object - (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant-tag-field)) +(def: (read_variant read host_object) + (-> Reader php/runtime/memory/ArrayMemory (Try Any)) + (case [(|> host_object + (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant_tag_field)) read) - (|> host-object - (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant-value-field)) + (|> host_object + (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant_value_field)) read)] - [(#error.Success tag) (#error.Success value)] - (#error.Success [(java/lang/Long::intValue (:coerce java/lang/Long tag)) - (: Any - (case (|> host-object - (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant-flag-field)) - (:coerce php/runtime/memory/ReferenceMemory) - php/runtime/memory/ReferenceMemory::getValue - (host.check php/runtime/memory/NullMemory)) - (#.Some _) - (host.null) - - #.None - synthesis.unit)) - value]) + [(#try.Success tag) (#try.Success value)] + (#try.Success [(java/lang/Long::intValue (:coerce java/lang/Long tag)) + (: Any + (case (|> host_object + (php/runtime/memory/ArrayMemory::get (php/runtime/memory/StringMemory::new runtime.variant_flag_field)) + (:coerce php/runtime/memory/ReferenceMemory) + php/runtime/memory/ReferenceMemory::getValue + (host.check php/runtime/memory/NullMemory)) + (#.Some _) + (host.null) + + #.None + synthesis.unit)) + value]) _ - (exception.throw ..unknown-kind-of-object host-object))) + (exception.throw ..unknown_kind_of_object host_object))) -(exception: #export nulll-has-no-lux-representation) +(exception: #export nulll_has_no_lux_representation) -(def: (read host-object) +(def: (read host_object) Reader (`` (<| (~~ (template [<class> <constant>] - [(case (host.check <class> host-object) + [(case (host.check <class> host_object) (#.Some _) - (#error.Success <constant>) + (#try.Success <constant>) #.None)] @@ -311,46 +352,48 @@ [php/runtime/memory/TrueMemory true] )) (~~ (template [<class> <post>] - [(case (host.check <class> host-object) + [(case (host.check <class> host_object) (#.Some value) (`` (|> value (~~ (template.splice <post>)))) #.None)] - [php/runtime/memory/LongMemory [php/runtime/memory/LongMemory::toLong #error.Success]] - [php/runtime/memory/DoubleMemory [php/runtime/memory/DoubleMemory::toDouble #error.Success]] - [php/runtime/memory/StringMemory [php/runtime/memory/StringMemory::toString #error.Success]] + [php/runtime/memory/LongMemory [php/runtime/memory/LongMemory::toLong #try.Success]] + [php/runtime/memory/DoubleMemory [php/runtime/memory/DoubleMemory::toDouble #try.Success]] + [php/runtime/memory/StringMemory [php/runtime/memory/StringMemory::toString #try.Success]] [php/runtime/memory/ReferenceMemory [php/runtime/memory/ReferenceMemory::getValue read]] - [php/runtime/memory/ObjectMemory [#error.Success]] + [php/runtime/memory/ObjectMemory [#try.Success]] )) - (case (host.check php/runtime/memory/ArrayMemory host-object) + (case (host.check php/runtime/memory/ArrayMemory host_object) (#.Some value) (if (php/runtime/memory/ArrayMemory::isMap value) - (read-variant read value) - (read-tuple read value)) + (read_variant read value) + (read_tuple read value)) #.None) - (exception.throw ..unknown-kind-of-object host-object) + (exception.throw ..unknown_kind_of_object host_object) ))) -(exception: (cannot-apply-a-non-function {object java/lang/Object}) +(exception: (cannot_apply_a_non_function {object java/lang/Object}) (exception.report ["Class" (java/lang/Object::toString (java/lang/Object::getClass object))] ["Non-function" (java/lang/Object::toString object)])) -(import: #long javax/script/ScriptEngine - (eval [String] #try Object)) +(host.import: javax/script/ScriptEngine + ["#::." + (eval [java/lang/String] #try Object)]) -(import: #long org/develnext/jphp/scripting/JPHPScriptEngine - (new [])) +(host.import: org/develnext/jphp/scripting/JPHPScriptEngine + ["#::." + (new [])]) -(def: (ensure-macro macro) +(def: (ensure_macro macro) ## (-> Macro (Maybe php/runtime/lang/Closure)) ## (do maybe.monad - ## [object-memory (|> macro + ## [object_memory (|> macro ## (:coerce java/lang/Object) ## (host.check php/runtime/memory/ObjectMemory))] - ## (|> object-memory + ## (|> object_memory ## php/runtime/memory/ObjectMemory::value ## (host.check php/runtime/lang/Closure))) (-> Macro (Maybe php/runtime/memory/ObjectMemory)) @@ -358,103 +401,185 @@ (:coerce java/lang/Object) (host.check php/runtime/memory/ObjectMemory))) -(def: (call-macro inputs lux macro) +(def: (call_macro inputs lux macro) (-> (List Code) Lux php/runtime/memory/ObjectMemory ## php/runtime/lang/Closure - (Error (Error [Lux (List Code)]))) + (Try (Try [Lux (List Code)]))) (<| :assume - (do error.monad - [#let [_ (log! (format "{call-macro 0} " (exception.construct ..unknown-kind-of-object (:coerce java/lang/Object (php/runtime/memory/ObjectMemory::value macro)))))] + (do try.monad + [#let [_ (debug.log! (format "{call_macro 0} " (exception.construct ..unknown_kind_of_object (:coerce java/lang/Object (php/runtime/memory/ObjectMemory::value macro)))))] output (php/runtime/lang/Closure::call (php/runtime/env/Environment::current) (|> (host.array php/runtime/Memory 3) - (host.array-write 0 macro) - (host.array-write 1 + (host.array_write 0 macro) + (host.array_write 1 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) inputs)) - (lux-structure (:coerce (Array java/lang/Object) inputs)) + (lux_structure (:coerce (Array java/lang/Object) inputs)) ) - (host.array-write 2 + (host.array_write 2 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) lux)) - (lux-structure (:coerce (Array java/lang/Object) lux)) + (lux_structure (:coerce (Array java/lang/Object) lux)) )) (:coerce php/runtime/lang/Closure (php/runtime/memory/ObjectMemory::value macro))) ## output (php/runtime/invoke/InvokeHelper::callAny macro ## (|> (host.array php/runtime/Memory 2) - ## ## (host.array-write 0 macro) - ## ## (host.array-write 1 macro) - ## (host.array-write 0 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) inputs)) - ## (lux-structure (:coerce (Array java/lang/Object) inputs)) + ## ## (host.array_write 0 macro) + ## ## (host.array_write 1 macro) + ## (host.array_write 0 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) inputs)) + ## (lux_structure (:coerce (Array java/lang/Object) inputs)) ## ) - ## (host.array-write 1 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) lux)) - ## (lux-structure (:coerce (Array java/lang/Object) lux)) + ## (host.array_write 1 ## (php/runtime/memory/ArrayMemory::new (:coerce (Array java/lang/Object) lux)) + ## (lux_structure (:coerce (Array java/lang/Object) lux)) ## )) ## (php/runtime/env/Environment::current) ## (php/runtime/env/TraceInfo::new "" +0 +0)) - #let [_ (log! (format "{call-macro 1} " (debug.inspect output))) - _ (log! (format "{call-macro 2} " (exception.construct ..unknown-kind-of-object (:coerce java/lang/Object output))))]] + #let [_ (debug.log! (format "{call_macro 1} " (debug.inspect output))) + _ (debug.log! (format "{call_macro 2} " (exception.construct ..unknown_kind_of_object (:coerce java/lang/Object output))))]] (..read (:coerce java/lang/Object output))))) (def: (expander macro inputs lux) Expander - (case (ensure-macro macro) + (case (ensure_macro macro) (#.Some macro) - (call-macro inputs lux macro) + (call_macro inputs lux macro) #.None - (exception.throw cannot-apply-a-non-function (:coerce java/lang/Object macro))) - ) + (exception.throw ..cannot_apply_a_non_function (:coerce java/lang/Object macro)))) (def: separator "___") -(type: Host - (generation.Host (_.Expression Any) _.Statement)) - (def: host - (IO Host) + (IO (Host _.Expression _.Statement)) (io (let [interpreter (org/develnext/jphp/scripting/JPHPScriptEngine::new) - run! (: (-> Text (_.Code Any) (Error Any)) - (function (_ dummy-name code) - (do error.monad + run! (: (-> (_.Code Any) (Try Any)) + (function (_ code) + (do try.monad [output (javax/script/ScriptEngine::eval (format "<?php " (_.code code)) interpreter)] (..read output))))] - (: Host + (: (Host _.Expression _.Statement) (structure - (def: (evaluate! dummy-name code) - (run! dummy-name (_.return code))) + (def: (evaluate! context code) + (run! (_.return code))) (def: execute! run!) - (def: (define! [module name] input) - (let [global (format (text.replace-all .module-separator ..separator module) - ..separator (name.normalize name) - "___" (%n (text@hash name))) + (def: (define! context input) + (let [global (reference.artifact context) @global (_.global global)] - (do error.monad + (do try.monad [#let [definition (_.; (_.set @global input))] - _ (run! global definition) - value (run! global (_.return @global))] - (wrap [global value definition]))))))))) + _ (run! definition) + value (run! (_.return @global))] + (wrap [global value definition])))) + + (def: (ingest context content) + (|> content (\ encoding.utf8 decode) try.assume (:coerce _.Statement))) + + (def: (re_learn context content) + (run! content)) + + (def: (re_load context content) + (do try.monad + [_ (run! content)] + (run! (_.return (_.var (reference.artifact context))))))))))) (def: platform - (IO (Platform IO _.Var (_.Expression Any) _.Statement)) + (IO (Platform _.Var _.Expression _.Statement)) (do io.monad [host ..host] - (wrap {#platform.&monad io.monad - #platform.&file-system file.system + (wrap {#platform.&file_system (file.async file.default) #platform.host host #platform.phase php.generate - #platform.runtime runtime.generate}))) + #platform.runtime runtime.generate + #platform.write (|>> _.code (\ encoding.utf8 encode))}))) -(def: (program program) - (-> (_.Expression Any) _.Statement) - (_.; (_.apply/2 [(runtime.lux//program-args _.command-line-arguments) +(def: (program context program) + (Program _.Expression _.Statement) + (_.; (_.apply/2 [(runtime.lux//program_args _.command_line_arguments) _.null] program))) -(program: [{service /cli.service}] - (/.compiler ..expander - ..platform - extension.bundle - ..program - service)) +(for {@.old + (def: extender + Extender + ## TODO: Stop relying on coercions ASAP. + (<| (:coerce Extender) + (function (@self handler)) + (:coerce Handler) + (function (@self name phase)) + (:coerce Phase) + (function (@self archive parameters)) + (:coerce Operation) + (function (@self state)) + (:coerce Try) + try.assume + (:coerce Try) + (do try.monad + [handler (try.from_maybe (..ensure_macro handler)) + #let [to_php (: (-> Any php/runtime/Memory) + (|>> (:coerce (Array java/lang/Object)) lux_structure (:coerce php/runtime/Memory)))] + output (php/runtime/lang/Closure::call (php/runtime/env/Environment::current) + (|> (host.array php/runtime/Memory 6) + (host.array_write 0 handler) + (host.array_write 1 (php/runtime/memory/StringMemory::new name)) + (host.array_write 2 (to_php phase)) + (host.array_write 3 (to_php archive)) + (host.array_write 4 (to_php parameters)) + (host.array_write 5 (to_php state))) + (:coerce php/runtime/lang/Closure + (php/runtime/memory/ObjectMemory::value handler)))] + (..read output)))) + + @.php + (def: (extender handler) + Extender + (:assume handler))}) + +(def: (declare_success! _) + (-> Any (Promise Any)) + (promise.future (\ world/program.default exit +0))) + +(def: (scope body) + (-> _.Statement _.Statement) + (let [@program (_.constant "lux_program")] + ($_ _.then + (_.define_function @program (list) body) + (_.; (_.apply/* (list) @program)) + ))) + +## (program: [{service /cli.service}] +## (/.compiler ..expander +## ..platform +## extension.bundle +## ..program +## service)) + +(`` (program: [{service /cli.service}] + (let [extension ".php"] + (do io.monad + [platform ..platform] + (exec (do promise.monad + [_ (/.compiler {#/static.host @.php + #/static.host_module_extension extension + #/static.target (/cli.target service) + #/static.artifact_extension extension} + ..expander + analysis.bundle + (io.io platform) + generation.bundle + extension/bundle.empty + ..program + [_.Var _.Expression _.Statement] + ..extender + service + [(packager.package (_.manual "") + _.code + _.then + ..scope) + (format (/cli.target service) + (\ file.default separator) + "program" + extension)])] + (..declare_success! [])) + (io.io [])))))) |