aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool
diff options
context:
space:
mode:
authorEduardo Julian2021-03-12 05:45:44 -0400
committerEduardo Julian2021-03-12 05:45:44 -0400
commitdff34f01e838475b817803ec856661fe8940e5c0 (patch)
treed8ddb3b6fd5963fdbdda64a13f2a430242fd7b26 /stdlib/source/lux/tool
parent0c75fd67e3fcfbfb09d8c11b6cf396084ce40a15 (diff)
Almost done with PHP.
Diffstat (limited to 'stdlib/source/lux/tool')
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux168
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux103
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux256
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php.lux86
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/case.lux88
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/function.lux32
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/loop.lux92
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux121
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/structure.lux13
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux12
10 files changed, 619 insertions, 352 deletions
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux
index 466c8daea..70437ea89 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/php.lux
@@ -27,8 +27,176 @@
[///
["." phase]]]]]])
+(def: array::new
+ Handler
+ (custom
+ [<c>.any
+ (function (_ extension phase archive lengthC)
+ (do phase.monad
+ [lengthA (analysis/type.with_type Nat
+ (phase archive lengthC))
+ [var_id varT] (analysis/type.with_env check.var)
+ _ (analysis/type.infer (type (Array varT)))]
+ (wrap (#analysis.Extension extension (list lengthA)))))]))
+
+(def: array::length
+ Handler
+ (custom
+ [<c>.any
+ (function (_ extension phase archive arrayC)
+ (do phase.monad
+ [[var_id varT] (analysis/type.with_env check.var)
+ arrayA (analysis/type.with_type (type (Array varT))
+ (phase archive arrayC))
+ _ (analysis/type.infer Nat)]
+ (wrap (#analysis.Extension extension (list arrayA)))))]))
+
+(def: array::read
+ Handler
+ (custom
+ [(<>.and <c>.any <c>.any)
+ (function (_ extension phase archive [indexC arrayC])
+ (do phase.monad
+ [indexA (analysis/type.with_type Nat
+ (phase archive indexC))
+ [var_id varT] (analysis/type.with_env check.var)
+ arrayA (analysis/type.with_type (type (Array varT))
+ (phase archive arrayC))
+ _ (analysis/type.infer varT)]
+ (wrap (#analysis.Extension extension (list indexA arrayA)))))]))
+
+(def: array::write
+ Handler
+ (custom
+ [($_ <>.and <c>.any <c>.any <c>.any)
+ (function (_ extension phase archive [indexC valueC arrayC])
+ (do phase.monad
+ [indexA (analysis/type.with_type Nat
+ (phase archive indexC))
+ [var_id varT] (analysis/type.with_env check.var)
+ valueA (analysis/type.with_type varT
+ (phase archive valueC))
+ arrayA (analysis/type.with_type (type (Array varT))
+ (phase archive arrayC))
+ _ (analysis/type.infer (type (Array varT)))]
+ (wrap (#analysis.Extension extension (list indexA valueA arrayA)))))]))
+
+(def: array::delete
+ Handler
+ (custom
+ [($_ <>.and <c>.any <c>.any)
+ (function (_ extension phase archive [indexC arrayC])
+ (do phase.monad
+ [indexA (analysis/type.with_type Nat
+ (phase archive indexC))
+ [var_id varT] (analysis/type.with_env check.var)
+ arrayA (analysis/type.with_type (type (Array varT))
+ (phase archive arrayC))
+ _ (analysis/type.infer (type (Array varT)))]
+ (wrap (#analysis.Extension extension (list indexA arrayA)))))]))
+
+(def: bundle::array
+ Bundle
+ (<| (bundle.prefix "array")
+ (|> bundle.empty
+ (bundle.install "new" array::new)
+ (bundle.install "length" array::length)
+ (bundle.install "read" array::read)
+ (bundle.install "write" array::write)
+ (bundle.install "delete" array::delete)
+ )))
+
+(def: Null
+ (for {@.php host.Null}
+ Any))
+
+(def: Object
+ (for {@.php (type (host.Object Any))}
+ Any))
+
+(def: Function
+ (for {@.php host.Function}
+ Any))
+
+(def: object::get
+ Handler
+ (custom
+ [($_ <>.and <c>.text <c>.any)
+ (function (_ extension phase archive [fieldC objectC])
+ (do phase.monad
+ [objectA (analysis/type.with_type ..Object
+ (phase archive objectC))
+ _ (analysis/type.infer .Any)]
+ (wrap (#analysis.Extension extension (list (analysis.text fieldC)
+ objectA)))))]))
+
+(def: object::do
+ Handler
+ (custom
+ [($_ <>.and <c>.text <c>.any (<>.some <c>.any))
+ (function (_ extension phase archive [methodC objectC inputsC])
+ (do {! phase.monad}
+ [objectA (analysis/type.with_type ..Object
+ (phase archive objectC))
+ inputsA (monad.map ! (|>> (phase archive) (analysis/type.with_type Any)) inputsC)
+ _ (analysis/type.infer .Any)]
+ (wrap (#analysis.Extension extension (list& (analysis.text methodC)
+ objectA
+ inputsA)))))]))
+
+(def: bundle::object
+ Bundle
+ (<| (bundle.prefix "object")
+ (|> bundle.empty
+ (bundle.install "get" object::get)
+ (bundle.install "do" object::do)
+ (bundle.install "null" (/.nullary ..Null))
+ (bundle.install "null?" (/.unary Any Bit))
+ )))
+
+(def: php::constant
+ Handler
+ (custom
+ [<c>.text
+ (function (_ extension phase archive name)
+ (do phase.monad
+ [_ (analysis/type.infer Any)]
+ (wrap (#analysis.Extension extension (list (analysis.text name))))))]))
+
+(def: php::apply
+ Handler
+ (custom
+ [($_ <>.and <c>.any (<>.some <c>.any))
+ (function (_ extension phase archive [abstractionC inputsC])
+ (do {! phase.monad}
+ [abstractionA (analysis/type.with_type ..Function
+ (phase archive abstractionC))
+ inputsA (monad.map ! (|>> (phase archive) (analysis/type.with_type Any)) inputsC)
+ _ (analysis/type.infer Any)]
+ (wrap (#analysis.Extension extension (list& abstractionA inputsA)))))]))
+
+(def: php::pack
+ Handler
+ (custom
+ [($_ <>.and <c>.any <c>.any)
+ (function (_ extension phase archive [formatC dataC])
+ (do {! phase.monad}
+ [formatA (analysis/type.with_type Text
+ (phase archive formatC))
+ dataA (analysis/type.with_type (type (Array (I64 Any)))
+ (phase archive dataC))
+ _ (analysis/type.infer Text)]
+ (wrap (#analysis.Extension extension (list formatA dataA)))))]))
+
(def: #export bundle
Bundle
(<| (bundle.prefix "php")
(|> bundle.empty
+ (dictionary.merge bundle::array)
+ (dictionary.merge bundle::object)
+
+ (bundle.install "constant" php::constant)
+ (bundle.install "apply" php::apply)
+ (bundle.install "pack" php::pack)
+ (bundle.install "script universe" (/.nullary .Bit))
)))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux
index 572f1f2a8..7dbc8bacc 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux
@@ -13,6 +13,7 @@
["%" format (#+ format)]]
[collection
["." dictionary]
+ ["." set]
["." list ("#\." functor fold)]]]
[math
[number
@@ -26,10 +27,12 @@
[generation
[extension (#+ Nullary Unary Binary Trinary
nullary unary binary trinary)]
+ ["." reference]
["//" php #_
- ["#." runtime (#+ Operation Phase Handler Bundle Generator)]]]
+ ["#." runtime (#+ Operation Phase Handler Bundle Generator)]
+ ["#." case]]]
[//
- [synthesis (#+ %synthesis)]
+ ["." synthesis (#+ %synthesis)]
["." generation]
[///
["#" phase]]]]])
@@ -50,45 +53,55 @@
(template: (!unary function)
(|>> list _.apply/* (|> (_.constant function))))
-## ## TODO: Get rid of this ASAP
-## (def: lux::syntax_char_case!
-## (..custom [($_ <>.and
-## <s>.any
-## <s>.any
-## (<>.some (<s>.tuple ($_ <>.and
-## (<s>.tuple (<>.many <s>.i64))
-## <s>.any))))
-## (function (_ extension_name phase archive [input else conditionals])
-## (do {! /////.monad}
-## [inputG (phase archive input)
-## elseG (phase archive else)
-## @input (\ ! map _.var (generation.gensym "input"))
-## conditionalsG (: (Operation (List [Expression Expression]))
-## (monad.map ! (function (_ [chars branch])
-## (do !
-## [branchG (phase archive branch)]
-## (wrap [(|> chars
-## (list\map (|>> .int _.int (_.= @input)))
-## (list\fold (function (_ clause total)
-## (if (is? _.nil total)
-## clause
-## (_.or clause total)))
-## _.nil))
-## branchG])))
-## conditionals))
-## #let [closure (_.closure (list @input)
-## (list\fold (function (_ [test then] else)
-## (_.if test (_.return then) else))
-## (_.return elseG)
-## conditionalsG))]]
-## (wrap (_.apply/1 closure inputG))))]))
+## TODO: Get rid of this ASAP
+(def: lux::syntax_char_case!
+ (..custom [($_ <>.and
+ <s>.any
+ <s>.any
+ (<>.some (<s>.tuple ($_ <>.and
+ (<s>.tuple (<>.many <s>.i64))
+ <s>.any))))
+ (function (_ extension_name phase archive [input else conditionals])
+ (do {! /////.monad}
+ [inputG (phase archive input)
+ [[context_module context_artifact] elseG] (generation.with_new_context archive
+ (phase archive else))
+ @input (\ ! map _.var (generation.gensym "input"))
+ conditionalsG (: (Operation (List [Expression Expression]))
+ (monad.map ! (function (_ [chars branch])
+ (do !
+ [branchG (phase archive branch)]
+ (wrap [(|> chars
+ (list\map (|>> .int _.int (_.=== @input)))
+ (list\fold (function (_ clause total)
+ (if (is? _.null total)
+ clause
+ (_.or clause total)))
+ _.null))
+ branchG])))
+ conditionals))
+ #let [foreigns (|> conditionals
+ (list\map (|>> product.right synthesis.path/then //case.dependencies))
+ (list& (//case.dependencies (synthesis.path/then else)))
+ list.concat
+ (set.from_list _.hash)
+ set.to_list)
+ @expression (_.constant (reference.artifact [context_module context_artifact]))
+ directive (_.define_function @expression (list& (_.parameter @input) (list\map _.reference foreigns))
+ (list\fold (function (_ [test then] else)
+ (_.if test (_.return then) else))
+ (_.return elseG)
+ conditionalsG))]
+ _ (generation.execute! directive)
+ _ (generation.save! (%.nat context_artifact) directive)]
+ (wrap (_.apply/* (list& inputG foreigns) @expression))))]))
(def: lux_procs
Bundle
(|> /.empty
- ## (/.install "syntax char case!" lux::syntax_char_case!)
- (/.install "is" (binary (product.uncurry _.=)))
- ## (/.install "try" (unary //runtime.lux//try))
+ (/.install "syntax char case!" lux::syntax_char_case!)
+ (/.install "is" (binary (product.uncurry _.===)))
+ (/.install "try" (unary //runtime.lux//try))
))
(def: i64_procs
@@ -100,12 +113,13 @@
(/.install "xor" (binary (product.uncurry _.bit_xor)))
(/.install "left-shift" (binary (product.uncurry _.bit_shl)))
(/.install "right-shift" (binary (product.uncurry //runtime.i64//right_shift)))
- (/.install "=" (binary (product.uncurry _.=)))
+ (/.install "=" (binary (product.uncurry _.==)))
(/.install "+" (binary (product.uncurry _.+)))
(/.install "-" (binary (product.uncurry _.-)))
(/.install "<" (binary (product.uncurry _.<)))
(/.install "*" (binary (product.uncurry _.*)))
- (/.install "/" (binary (product.uncurry _./)))
+ (/.install "/" (binary (function (_ [parameter subject])
+ (_.intdiv/2 [subject parameter]))))
(/.install "%" (binary (product.uncurry _.%)))
(/.install "f64" (unary (_./ (_.float +1.0))))
(/.install "char" (unary //runtime.i64//char))
@@ -124,7 +138,7 @@
(/.install "*" (binary (product.uncurry _.*)))
(/.install "/" (binary (product.uncurry _./)))
(/.install "%" (binary ..f64//%))
- (/.install "=" (binary (product.uncurry _.=)))
+ (/.install "=" (binary (product.uncurry _.==)))
(/.install "<" (binary (product.uncurry _.<)))
(/.install "i64" (unary _.intval/1))
(/.install "encode" (unary _.strval/1))
@@ -142,7 +156,7 @@
Bundle
(<| (/.prefix "text")
(|> /.empty
- (/.install "=" (binary (product.uncurry _.=)))
+ (/.install "=" (binary (product.uncurry _.==)))
(/.install "<" (binary (product.uncurry _.<)))
(/.install "concat" (binary (product.uncurry (function.flip _.concat))))
(/.install "index" (trinary ..text//index))
@@ -151,11 +165,6 @@
(/.install "clip" (trinary ..text//clip))
)))
-(def: io//log!
- (Unary Expression)
- (|>> _.print/1
- (_.or //runtime.unit)))
-
(def: io//current-time
(Nullary Expression)
(|>> _.time/0
@@ -165,7 +174,7 @@
Bundle
(<| (/.prefix "io")
(|> /.empty
- (/.install "log" (unary ..io//log!))
+ (/.install "log" (unary //runtime.io//log!))
(/.install "error" (unary //runtime.io//throw!))
(/.install "current-time" (nullary ..io//current-time)))))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux
index fef37539e..f523f1647 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/generation/php/host.lux
@@ -32,168 +32,106 @@
["//#" /// #_
["#." phase]]]]]])
-## (def: array::new
-## (Unary Expression)
-## (|>> ["n"] list _.table))
-
-## (def: array::length
-## (Unary Expression)
-## (_.the "n"))
-
-## (def: (array::read [indexG arrayG])
-## (Binary Expression)
-## (_.nth (_.+ (_.int +1) indexG) arrayG))
-
-## (def: (array::write [indexG valueG arrayG])
-## (Trinary Expression)
-## (//runtime.array//write indexG valueG arrayG))
-
-## (def: (array::delete [indexG arrayG])
-## (Binary Expression)
-## (//runtime.array//write indexG _.nil arrayG))
-
-## (def: array
-## Bundle
-## (<| (/.prefix "array")
-## (|> /.empty
-## (/.install "new" (unary array::new))
-## (/.install "length" (unary array::length))
-## (/.install "read" (binary array::read))
-## (/.install "write" (trinary array::write))
-## (/.install "delete" (binary array::delete))
-## )))
-
-## (def: object::get
-## Handler
-## (custom
-## [($_ <>.and <s>.text <s>.any)
-## (function (_ extension phase archive [fieldS objectS])
-## (do ////////phase.monad
-## [objectG (phase archive objectS)]
-## (wrap (_.the fieldS objectG))))]))
-
-## (def: object::do
-## Handler
-## (custom
-## [($_ <>.and <s>.text <s>.any (<>.some <s>.any))
-## (function (_ extension phase archive [methodS objectS inputsS])
-## (do {! ////////phase.monad}
-## [objectG (phase archive objectS)
-## inputsG (monad.map ! (phase archive) inputsS)]
-## (wrap (_.do methodS inputsG objectG))))]))
-
-## (template [<!> <?> <unit>]
-## [(def: <!> (Nullary Expression) (function.constant <unit>))
-## (def: <?> (Unary Expression) (_.= <unit>))]
-
-## [object::nil object::nil? _.nil]
-## )
-
-## (def: object
-## Bundle
-## (<| (/.prefix "object")
-## (|> /.empty
-## (/.install "get" object::get)
-## (/.install "do" object::do)
-## (/.install "nil" (nullary object::nil))
-## (/.install "nil?" (unary object::nil?))
-## )))
-
-## (def: $input
-## (_.var "input"))
-
-## (def: utf8::encode
-## (custom
-## [<s>.any
-## (function (_ extension phase archive inputS)
-## (do {! ////////phase.monad}
-## [inputG (phase archive inputS)]
-## (wrap (_.apply/1 (<| (_.closure (list $input))
-## (_.return (|> (_.var "string.byte")
-## (_.apply/* (list $input (_.int +1) (_.length $input)))
-## (_.apply/1 (_.var "table.pack")))))
-## inputG))))]))
-
-## (def: utf8::decode
-## (custom
-## [<s>.any
-## (function (_ extension phase archive inputS)
-## (do {! ////////phase.monad}
-## [inputG (phase archive inputS)]
-## (wrap (|> inputG
-## (_.apply/1 (_.var "table.unpack"))
-## (_.apply/1 (_.var "string.char"))))))]))
-
-## (def: utf8
-## Bundle
-## (<| (/.prefix "utf8")
-## (|> /.empty
-## (/.install "encode" utf8::encode)
-## (/.install "decode" utf8::decode)
-## )))
-
-## (def: lua::constant
-## (custom
-## [<s>.text
-## (function (_ extension phase archive name)
-## (\ ////////phase.monad wrap (_.var name)))]))
-
-## (def: lua::apply
-## (custom
-## [($_ <>.and <s>.any (<>.some <s>.any))
-## (function (_ extension phase archive [abstractionS inputsS])
-## (do {! ////////phase.monad}
-## [abstractionG (phase archive abstractionS)
-## inputsG (monad.map ! (phase archive) inputsS)]
-## (wrap (_.apply/* inputsG abstractionG))))]))
-
-## (def: lua::power
-## (custom
-## [($_ <>.and <s>.any <s>.any)
-## (function (_ extension phase archive [powerS baseS])
-## (do {! ////////phase.monad}
-## [powerG (phase archive powerS)
-## baseG (phase archive baseS)]
-## (wrap (_.^ powerG baseG))))]))
-
-## (def: lua::import
-## (custom
-## [<s>.text
-## (function (_ extension phase archive module)
-## (\ ////////phase.monad wrap
-## (_.require/1 (_.string module))))]))
-
-## (def: lua::function
-## (custom
-## [($_ <>.and <s>.i64 <s>.any)
-## (function (_ extension phase archive [arity abstractionS])
-## (do {! ////////phase.monad}
-## [abstractionG (phase archive abstractionS)
-## #let [variable (: (-> Text (Operation Var))
-## (|>> generation.gensym
-## (\ ! map _.var)))]
-## g!inputs (monad.map ! (function (_ _)
-## (variable "input"))
-## (list.repeat (.nat arity) []))]
-## (wrap (<| (_.closure g!inputs)
-## _.statement
-## (case (.nat arity)
-## 0 (_.apply/1 abstractionG //runtime.unit)
-## 1 (_.apply/* g!inputs abstractionG)
-## _ (_.apply/1 abstractionG (_.array g!inputs)))))))]))
+(def: (array::new size)
+ (Unary Expression)
+ (//runtime.tuple//make size (_.array_fill/3 [(_.int +0) size _.null])))
+
+(def: array::length
+ (Unary Expression)
+ //runtime.array//length)
+
+(def: (array::read [indexG arrayG])
+ (Binary Expression)
+ (_.nth indexG arrayG))
+
+(def: (array::write [indexG valueG arrayG])
+ (Trinary Expression)
+ (//runtime.array//write indexG valueG arrayG))
+
+(def: (array::delete [indexG arrayG])
+ (Binary Expression)
+ (//runtime.array//write indexG _.null arrayG))
+
+(def: array
+ Bundle
+ (<| (/.prefix "array")
+ (|> /.empty
+ (/.install "new" (unary array::new))
+ (/.install "length" (unary array::length))
+ (/.install "read" (binary array::read))
+ (/.install "write" (trinary array::write))
+ (/.install "delete" (binary array::delete))
+ )))
+
+(def: object::get
+ Handler
+ (custom
+ [($_ <>.and <s>.text <s>.any)
+ (function (_ extension phase archive [fieldS objectS])
+ (do ////////phase.monad
+ [objectG (phase archive objectS)]
+ (wrap (_.the fieldS objectG))))]))
+
+(def: object::do
+ Handler
+ (custom
+ [($_ <>.and <s>.text <s>.any (<>.some <s>.any))
+ (function (_ extension phase archive [methodS objectS inputsS])
+ (do {! ////////phase.monad}
+ [objectG (phase archive objectS)
+ inputsG (monad.map ! (phase archive) inputsS)]
+ (wrap (_.do methodS inputsG objectG))))]))
+
+(template [<!> <?> <unit>]
+ [(def: <!> (Nullary Expression) (function.constant <unit>))
+ (def: <?> (Unary Expression) (_.=== <unit>))]
+
+ [object::null object::null? _.null]
+ )
+
+(def: object
+ Bundle
+ (<| (/.prefix "object")
+ (|> /.empty
+ (/.install "get" object::get)
+ (/.install "do" object::do)
+ (/.install "null" (nullary object::null))
+ (/.install "null?" (unary object::null?))
+ )))
+
+(def: php::constant
+ (custom
+ [<s>.text
+ (function (_ extension phase archive name)
+ (\ ////////phase.monad wrap (_.constant name)))]))
+
+(def: php::apply
+ (custom
+ [($_ <>.and <s>.any (<>.some <s>.any))
+ (function (_ extension phase archive [abstractionS inputsS])
+ (do {! ////////phase.monad}
+ [abstractionG (phase archive abstractionS)
+ inputsG (monad.map ! (phase archive) inputsS)]
+ (wrap (_.apply/* inputsG abstractionG))))]))
+
+(def: php::pack
+ (custom
+ [($_ <>.and <s>.any <s>.any)
+ (function (_ extension phase archive [formatS dataS])
+ (do {! ////////phase.monad}
+ [formatG (phase archive formatS)
+ dataG (phase archive dataS)]
+ (wrap (_.pack/2 [formatG (_.splat dataG)]))))]))
(def: #export bundle
Bundle
(<| (/.prefix "php")
(|> /.empty
- ## (dictionary.merge ..array)
- ## (dictionary.merge ..object)
- ## (dictionary.merge ..utf8)
-
- ## (/.install "constant" lua::constant)
- ## (/.install "apply" lua::apply)
- ## (/.install "power" lua::power)
- ## (/.install "import" lua::import)
- ## (/.install "function" lua::function)
- ## (/.install "script universe" (nullary (function.constant (_.bool reference.universe))))
+ (dictionary.merge ..array)
+ (dictionary.merge ..object)
+
+ (/.install "constant" php::constant)
+ (/.install "apply" php::apply)
+ (/.install "pack" php::pack)
+ (/.install "script universe" (nullary (function.constant (_.bool reference.universe))))
)))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php.lux
index c310de4a9..654c07bdf 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php.lux
@@ -20,39 +20,83 @@
["#." extension]
["/#" // #_
[analysis (#+)]
- ["." synthesis]
+ ["#." synthesis]
["//#" /// #_
["#." phase ("#\." monad)]
[reference (#+)
[variable (#+)]]]]]]])
-(def: #export (generate archive synthesis)
+(def: (statement expression archive synthesis)
+ Phase!
+ (case synthesis
+ (^template [<tag>]
+ [(^ (<tag> value))
+ (//////phase\map _.return (expression archive synthesis))])
+ ([////synthesis.bit]
+ [////synthesis.i64]
+ [////synthesis.f64]
+ [////synthesis.text]
+ [////synthesis.variant]
+ [////synthesis.tuple]
+ [#////synthesis.Reference]
+ [////synthesis.branch/get]
+ [////synthesis.function/apply]
+ [#////synthesis.Extension])
+
+ (^ (////synthesis.branch/case case))
+ (/case.case! statement expression archive case)
+
+ (^template [<tag> <generator>]
+ [(^ (<tag> value))
+ (<generator> statement expression archive value)])
+ ([////synthesis.branch/let /case.let!]
+ [////synthesis.branch/if /case.if!]
+ [////synthesis.loop/scope /loop.scope!]
+ [////synthesis.loop/recur /loop.recur!])
+
+ (^ (////synthesis.function/abstraction abstraction))
+ (//////phase\map _.return (/function.function statement expression archive abstraction))
+ ))
+
+(exception: #export cannot-recur-as-an-expression)
+
+(def: #export (expression archive synthesis)
Phase
(case synthesis
(^template [<tag> <generator>]
[(^ (<tag> value))
(//////phase\wrap (<generator> value))])
- ([synthesis.bit /primitive.bit]
- [synthesis.i64 /primitive.i64]
- [synthesis.f64 /primitive.f64]
- [synthesis.text /primitive.text])
+ ([////synthesis.bit /primitive.bit]
+ [////synthesis.i64 /primitive.i64]
+ [////synthesis.f64 /primitive.f64]
+ [////synthesis.text /primitive.text])
- (#synthesis.Reference value)
+ (#////synthesis.Reference value)
(//reference.reference /reference.system archive value)
(^template [<tag> <generator>]
[(^ (<tag> value))
- (<generator> generate archive value)])
- ([synthesis.variant /structure.variant]
- [synthesis.tuple /structure.tuple]
- [synthesis.branch/case /case.case]
- [synthesis.branch/let /case.let]
- [synthesis.branch/if /case.if]
- [synthesis.branch/get /case.get]
- [synthesis.loop/scope /loop.scope]
- [synthesis.loop/recur /loop.recur]
- [synthesis.function/apply /function.apply]
- [synthesis.function/abstraction /function.function])
-
- (#synthesis.Extension extension)
- (///extension.apply archive generate extension)))
+ (<generator> expression archive value)])
+ ([////synthesis.variant /structure.variant]
+ [////synthesis.tuple /structure.tuple]
+ [////synthesis.branch/let /case.let]
+ [////synthesis.branch/if /case.if]
+ [////synthesis.branch/get /case.get]
+ [////synthesis.function/apply /function.apply])
+
+ (^template [<tag> <generator>]
+ [(^ (<tag> value))
+ (<generator> statement expression archive value)])
+ ([////synthesis.branch/case /case.case]
+ [////synthesis.loop/scope /loop.scope]
+ [////synthesis.function/abstraction /function.function])
+
+ (^ (////synthesis.loop/recur _))
+ (//////phase.throw ..cannot-recur-as-an-expression [])
+
+ (#////synthesis.Extension extension)
+ (///extension.apply archive expression extension)))
+
+(def: #export generate
+ Phase
+ ..expression)
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/case.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/case.lux
index b04d8e766..419c0ed2f 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/case.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/case.lux
@@ -41,20 +41,47 @@
(-> Register Var)
(|>> (///reference.foreign //reference.system) :assume))
-(def: #export (let generate archive [valueS register bodyS])
+(def: #export (let expression archive [valueS register bodyS])
(Generator [Synthesis Register Synthesis])
(do ///////phase.monad
- [valueG (generate archive valueS)
- bodyG (generate archive bodyS)]
+ [valueG (expression archive valueS)
+ bodyG (expression archive bodyS)]
(wrap (|> bodyG
(list (_.set (..register register) valueG))
_.array/*
(_.nth (_.int +1))))))
-(def: #export (get generate archive [pathP valueS])
+(def: #export (let! statement expression archive [valueS register bodyS])
+ (Generator! [Synthesis Register Synthesis])
+ (do ///////phase.monad
+ [valueO (expression archive valueS)
+ body! (statement expression archive bodyS)]
+ (wrap ($_ _.then
+ (_.; (_.set (..register register) valueO))
+ body!))))
+
+(def: #export (if expression archive [testS thenS elseS])
+ (Generator [Synthesis Synthesis Synthesis])
+ (do ///////phase.monad
+ [testG (expression archive testS)
+ thenG (expression archive thenS)
+ elseG (expression archive elseS)]
+ (wrap (_.? testG thenG elseG))))
+
+(def: #export (if! statement expression archive [testS thenS elseS])
+ (Generator! [Synthesis Synthesis Synthesis])
+ (do ///////phase.monad
+ [test! (expression archive testS)
+ then! (statement expression archive thenS)
+ else! (statement expression archive elseS)]
+ (wrap (_.if test!
+ then!
+ else!))))
+
+(def: #export (get expression archive [pathP valueS])
(Generator [(List Member) Synthesis])
(do ///////phase.monad
- [valueG (generate archive valueS)]
+ [valueG (expression archive valueS)]
(wrap (list\fold (function (_ side source)
(.let [method (.case side
(^template [<side> <accessor>]
@@ -64,15 +91,7 @@
[#.Right //runtime.tuple//right]))]
(method source)))
valueG
- pathP))))
-
-(def: #export (if generate archive [testS thenS elseS])
- (Generator [Synthesis Synthesis Synthesis])
- (do ///////phase.monad
- [testG (generate archive testS)
- thenG (generate archive thenS)
- elseG (generate archive elseS)]
- (wrap (_.? testG thenG elseG))))
+ (list.reverse pathP)))))
(def: @savepoint (_.var "lux_pm_savepoint"))
(def: @cursor (_.var "lux_pm_cursor"))
@@ -139,12 +158,12 @@
..restore!
post!)))
-(def: (pattern_matching' generate archive)
- (-> Phase Archive Path (Operation Statement))
+(def: (pattern_matching' statement expression archive)
+ (Generator! Path)
(function (recur pathP)
(.case pathP
(#/////synthesis.Then bodyS)
- (\ ///////phase.monad map _.return (generate archive bodyS))
+ (statement expression archive bodyS)
#/////synthesis.Pop
(///////phase\wrap ..pop!)
@@ -175,8 +194,8 @@
[clauses (monad.map ! (function (_ [match then])
(do !
[then! (recur then)]
- (wrap [(_.= (|> match <format>)
- ..peek)
+ (wrap [(_.=== (|> match <format>)
+ ..peek)
then!])))
(#.Cons cons))]
(wrap (_.cond clauses ..fail!)))])
@@ -228,10 +247,10 @@
([/////synthesis.path/seq _.then]
[/////synthesis.path/alt ..alternation]))))
-(def: (pattern_matching generate archive pathP)
- (-> Phase Archive Path (Operation Statement))
+(def: (pattern_matching statement expression archive pathP)
+ (Generator! Path)
(do ///////phase.monad
- [iteration! (pattern_matching' generate archive pathP)]
+ [iteration! (pattern_matching' statement expression archive pathP)]
(wrap ($_ _.then
(_.do_while (_.bool false)
iteration!)
@@ -254,20 +273,25 @@
(#///////variable.Foreign register)
(..capture register))))))
-(def: #export (case generate archive [valueS pathP])
- (Generator [Synthesis Path])
+(def: #export (case! statement expression archive [valueS pathP])
+ (Generator! [Synthesis Path])
+ (do ///////phase.monad
+ [stack_init (expression archive valueS)
+ pattern_matching! (pattern_matching statement expression archive pathP)]
+ (wrap ($_ _.then
+ (_.; (_.set @cursor (_.array/* (list stack_init))))
+ (_.; (_.set @savepoint (_.array/* (list))))
+ pattern_matching!))))
+
+(def: #export (case statement expression archive [valueS pathP])
+ (-> Phase! (Generator [Synthesis Path]))
(do {! ///////phase.monad}
- [initG (generate archive valueS)
- [[case_module case_artifact] pattern_matching!] (/////generation.with_new_context archive
- (pattern_matching generate archive pathP))
+ [[[case_module case_artifact] case!] (/////generation.with_new_context archive
+ (case! statement expression archive [valueS pathP]))
#let [@case (_.constant (///reference.artifact [case_module case_artifact]))
@dependencies+ (..dependencies (/////synthesis.path/seq (/////synthesis.path/then valueS)
pathP))
- directive (<| (_.define_function @case (list\map _.parameter @dependencies+))
- ($_ _.then
- (_.; (_.set @cursor (_.array/* (list initG))))
- (_.; (_.set @savepoint (_.array/* (list))))
- pattern_matching!))]
+ directive (_.define_function @case (list\map _.parameter @dependencies+) case!)]
_ (/////generation.execute! directive)
_ (/////generation.save! (%.nat case_artifact) directive)]
(wrap (_.apply/* @dependencies+ @case))))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/function.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/function.lux
index 66d9eb37d..c6fa5687c 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/function.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/function.lux
@@ -11,7 +11,7 @@
[collection
["." list ("#\." functor fold)]]]
[target
- ["_" php (#+ Var Global Expression Argument Statement)]]]
+ ["_" php (#+ Var Global Expression Argument Label Statement)]]]
["." // #_
["#." runtime (#+ Operation Phase Phase! Generator)]
["#." reference]
@@ -42,6 +42,10 @@
(def: input
(|>> inc //case.register))
+(def: (@scope function_name)
+ (-> Context Label)
+ (_.label (format (///reference.artifact function_name) "_scope")))
+
(def: (with_closure inits @selfG @selfL body!)
(-> (List Expression) Global Var Statement [Statement Expression])
(case inits
@@ -53,28 +57,29 @@
_
(let [@inits (|> (list.enumeration inits)
- (list\map (|>> product.left ..capture _.reference)))]
- [(_.; (_.set @selfG (_.closure (list) @inits
+ (list\map (|>> product.left ..capture)))]
+ [(_.; (_.set @selfG (_.closure (list) (list\map _.parameter @inits)
($_ _.then
- (_.; (_.set @selfL (_.closure (list& (_.reference @selfL) @inits)
+ (_.; (_.set @selfL (_.closure (list& (_.reference @selfL) (list\map _.reference @inits))
(list)
body!)))
(_.return @selfL)))))
(_.apply/* inits @selfG)])))
-(def: #export (function expression archive [environment arity bodyS])
- (Generator (Abstraction Synthesis))
+(def: #export (function statement expression archive [environment arity bodyS])
+ (-> Phase! (Generator (Abstraction Synthesis)))
(do {! ///////phase.monad}
- [[function_name bodyG] (/////generation.with_new_context archive
+ [[function_name body!] (/////generation.with_new_context archive
(do !
- [function_name (\ ! map ///reference.artifact
- (/////generation.context archive))]
- (/////generation.with_anchor (_.global function_name)
- (expression archive bodyS))))
+ [@scope (\ ! map ..@scope
+ (/////generation.context archive))]
+ (/////generation.with_anchor [1 @scope]
+ (statement expression archive bodyS))))
closureG+ (monad.map ! (expression archive) environment)
#let [@curried (_.var "curried")
arityG (|> arity .int _.int)
@num_args (_.var "num_args")
+ @scope (..@scope function_name)
@selfG (_.global (///reference.artifact function_name))
@selfL (_.var (///reference.artifact function_name))
initialize_self! (_.; (_.set (//case.register 0) @selfL))
@@ -88,10 +93,11 @@
($_ _.then
(_.; (_.set @num_args (_.func_num_args/0 [])))
(_.; (_.set @curried (_.func_get_args/0 [])))
- (_.cond (list [(|> @num_args (_.= arityG))
+ (_.cond (list [(|> @num_args (_.=== arityG))
($_ _.then
initialize!
- (_.return bodyG))]
+ (_.set_label @scope)
+ body!)]
[(|> @num_args (_.> arityG))
(let [arity_inputs (_.array_slice/3 [@curried (_.int +0) arityG])
extra_inputs (_.array_slice/2 [@curried arityG])
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/loop.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/loop.lux
index cdac65275..30e325363 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/loop.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/loop.lux
@@ -4,16 +4,16 @@
["." monad (#+ do)]]
[data
["." product]
- [text
+ ["." text
["%" format (#+ format)]]
[collection
- ["." list ("#\." functor)]
+ ["." list ("#\." functor fold)]
["." set]]]
[math
[number
["n" nat]]]
[target
- ["_" php (#+ Var Expression Statement)]]]
+ ["_" php (#+ Var Expression Label Statement)]]]
["." // #_
[runtime (#+ Operation Phase Phase! Generator Generator!)]
["#." case]
@@ -32,8 +32,41 @@
[reference
[variable (#+ Register)]]]]]]])
-(def: #export (scope expression archive [start initsS+ bodyS])
- (Generator (Scope Synthesis))
+(def: @scope
+ (-> Nat Label)
+ (|>> %.nat (format "scope") _.label))
+
+(def: (setup offset bindings body)
+ (-> Register (List Expression) Statement Statement)
+ (|> bindings
+ list.enumeration
+ (list\map (function (_ [register value])
+ (let [variable (//case.register (n.+ offset register))]
+ (_.; (_.set variable value)))))
+ list.reverse
+ (list\fold _.then body)))
+
+(def: #export (scope! statement expression archive [start initsS+ bodyS])
+ (Generator! (Scope Synthesis))
+ (case initsS+
+ ## function/false/non-independent loop
+ #.Nil
+ (statement expression archive bodyS)
+
+ ## true loop
+ _
+ (do {! ///////phase.monad}
+ [@scope (\ ! map ..@scope /////generation.next)
+ initsO+ (monad.map ! (expression archive) initsS+)
+ body! (/////generation.with_anchor [start @scope]
+ (statement expression archive bodyS))]
+ (wrap (..setup start initsO+
+ ($_ _.then
+ (_.set_label @scope)
+ body!))))))
+
+(def: #export (scope statement expression archive [start initsS+ bodyS])
+ (-> Phase! (Generator (Scope Synthesis)))
(case initsS+
## function/false/non-independent loop
#.Nil
@@ -42,15 +75,12 @@
## true loop
_
(do {! ///////phase.monad}
- [initsO+ (monad.map ! (expression archive) initsS+)
- [[loop_module loop_artifact] bodyO] (/////generation.with_new_context archive
- (do !
- [loop_context (/////generation.context archive)]
- (/////generation.with_anchor (_.var (///reference.artifact loop_context))
- (expression archive bodyS))))
+ [[[loop_module loop_artifact] scope!] (/////generation.with_new_context archive
+ (..scope! statement expression archive [start initsS+ bodyS]))
#let [locals (|> initsS+
list.enumeration
(list\map (|>> product.left (n.+ start) //case.register _.parameter)))
+ @loop (_.constant (///reference.artifact [loop_module loop_artifact]))
[directive instantiation] (: [Statement Expression]
(case (|> (synthesis.path/then bodyS)
//case.dependencies
@@ -58,30 +88,30 @@
(set.difference (set.from_list _.hash (list\map product.right locals)))
set.to_list)
#.Nil
- (let [@loop (_.var (///reference.artifact [loop_module loop_artifact]))]
- [(_.; (_.set @loop
- (_.closure (list (_.reference @loop))
- locals
- (_.return bodyO))))
- @loop])
+ [(_.define_function @loop (list) scope!)
+ @loop]
foreigns
- (let [@loop (_.constant (///reference.artifact [loop_module loop_artifact]))]
- [(<| (_.define_function @loop (list\map _.parameter foreigns))
- (let [@loop (_.var (///reference.artifact [loop_module loop_artifact]))]
- (_.return (_.set @loop
- (_.closure (list& (_.reference @loop)
- (list\map _.reference foreigns))
- locals
- (_.return bodyO))))))
- (_.apply/* foreigns @loop)])))]
+ [(<| (_.define_function @loop (list\map _.parameter foreigns))
+ (_.return (_.closure (list\map _.parameter foreigns) (list) scope!)))
+ (_.apply/* foreigns @loop)]))]
_ (/////generation.execute! directive)
_ (/////generation.save! (%.nat loop_artifact) directive)]
- (wrap (_.apply/* initsO+ instantiation)))))
+ (wrap (_.apply/* (list) instantiation)))))
+
+(def: @temp
+ (_.var "lux_recur_values"))
-(def: #export (recur expression archive argsS+)
- (Generator (List Synthesis))
+(def: #export (recur! statement expression archive argsS+)
+ (Generator! (List Synthesis))
(do {! ///////phase.monad}
- [@scope /////generation.anchor
+ [[offset @scope] /////generation.anchor
argsO+ (monad.map ! (expression archive) argsS+)]
- (wrap (_.apply/* argsO+ @scope))))
+ (wrap ($_ _.then
+ (_.; (_.set @temp (_.array/* argsO+)))
+ (..setup offset
+ (|> argsO+
+ list.enumeration
+ (list\map (function (_ [idx _])
+ (_.nth (_.int (.int idx)) @temp))))
+ (_.go_to @scope))))))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux
index 7b3e55481..5e1c36112 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/runtime.lux
@@ -22,7 +22,7 @@
[number (#+ hex)
["." i64]]]
["@" target
- ["_" php (#+ Expression Location Constant Var Computation Literal Statement)]]]
+ ["_" php (#+ Expression Label Constant Var Computation Literal Statement)]]]
["." /// #_
["#." reference]
["//#" /// #_
@@ -38,7 +38,7 @@
(template [<name> <base>]
[(type: #export <name>
- (<base> Location Expression Statement))]
+ (<base> [Nat Label] Expression Statement))]
[Operation /////generation.Operation]
[Phase /////generation.Phase]
@@ -128,6 +128,12 @@
(list (~+ (list\map (|>> (~) [false] (`)) inputsC)))
(~ code))))))))))))))))
+(runtime: (io//log! message)
+ ($_ _.then
+ (_.echo message)
+ (_.echo (_.string text.new_line))
+ (_.return ..unit)))
+
(runtime: (io//throw! message)
($_ _.then
(_.throw (_.new (_.constant "Exception") (list message)))
@@ -136,15 +142,39 @@
(def: runtime//io
Statement
($_ _.then
+ @io//log!
@io//throw!
))
(def: #export tuple_size_field
"_lux_size")
-(def: tuple_size
+(def: #export tuple_size
(_.nth (_.string ..tuple_size_field)))
+(def: jphp?
+ (_.=== (_.string "5.6.99") (_.phpversion/0 [])))
+
+(runtime: (array//length array)
+ ## TODO: Get rid of this as soon as JPHP is no longer necessary.
+ (_.if ..jphp?
+ (_.if (..tuple_size array)
+ (_.return (..tuple_size array))
+ (_.return (_.count/1 array)))
+ (_.return (_.count/1 array))))
+
+(runtime: (array//write idx value array)
+ ($_ _.then
+ (_.; (_.set (_.nth idx array) value))
+ (_.return array)))
+
+(def: runtime//array
+ Statement
+ ($_ _.then
+ @array//length
+ @array//write
+ ))
+
(def: last_index
(|>> ..tuple_size (_.- (_.int +1))))
@@ -167,20 +197,37 @@
## Needs recursion
<recur>)))))
+ ## TODO: Get rid of this as soon as JPHP is no longer necessary.
+ (runtime: (tuple//slice offset input)
+ (with_vars [size index output]
+ ($_ _.then
+ (_.; (_.set size (..array//length input)))
+ (_.; (_.set index (_.int +0)))
+ (_.; (_.set output (_.array/* (list))))
+ (<| (_.while (|> index (_.+ offset) (_.< size)))
+ ($_ _.then
+ (_.; (_.set (_.nth index output) (_.nth (_.+ offset index) input)))
+ (_.; (_.set index (_.+ (_.int +1) index)))
+ ))
+ (_.return (..tuple//make (_.- offset size) output))
+ )))
+
(runtime: (tuple//right lefts tuple)
(with_vars [last_index_right right_index]
(<| (_.while (_.bool true))
($_ _.then
(_.; (_.set last_index_right (..last_index tuple)))
(_.; (_.set right_index (_.+ (_.int +1) lefts)))
- (_.cond (list [(_.= last_index_right right_index)
+ (_.cond (list [(_.=== last_index_right right_index)
(_.return (_.nth right_index tuple))]
[(_.> last_index_right right_index)
## Needs recursion.
<recur>])
- ($_ _.then
- (_.echo (_.string (format "[tuple//right] _.array_slice/2" text.new_line)))
- (_.return (_.array_slice/2 [tuple right_index]))))
+ (_.if ..jphp?
+ (_.return (..tuple//make (_.- right_index (..tuple_size tuple))
+ (..tuple//slice right_index tuple)))
+ (_.return (..tuple//make (_.- right_index (..tuple_size tuple))
+ (_.array_slice/2 [tuple right_index])))))
)))))
(def: #export variant_tag_field "_lux_tag")
@@ -222,7 +269,7 @@
## sum_flag (_.nth (_.int +1) sum)
sum_value (_.nth (_.string ..variant_value_field) sum)
## sum_value (_.nth (_.int +2) sum)
- is_last? (_.= ..unit sum_flag)
+ is_last? (_.=== ..unit sum_flag)
test_recursion! (_.if is_last?
## Must recurse.
($_ _.then
@@ -230,15 +277,15 @@
(_.; (_.set sum sum_value)))
no_match!)]
(<| (_.while (_.bool true))
- (_.cond (list [(_.= sum_tag wantedTag)
- (_.if (_.= wantsLast sum_flag)
+ (_.cond (list [(_.=== sum_tag wantedTag)
+ (_.if (_.=== wantsLast sum_flag)
(_.return sum_value)
test_recursion!)]
[(_.< wantedTag sum_tag)
test_recursion!]
- [(_.= ..unit wantsLast)
+ [(_.=== ..unit wantsLast)
(_.return (sum//make (_.- wantedTag sum_tag) sum_flag sum_value))])
no_match!))))
@@ -247,6 +294,7 @@
($_ _.then
@tuple//make
@tuple//left
+ @tuple//slice
@tuple//right
@sum//make
@sum//get
@@ -281,12 +329,13 @@
(let [mask (|> (_.int +1)
(_.bit_shl (_.- param (_.int +64)))
(_.- (_.int +1)))]
- (_.return (|> subject
- (_.bit_and mask)
- (_.bit_shr param)))))
-
-(def: jphp?
- (_.= (_.string "5.6.99") (_.phpversion/0 [])))
+ ($_ _.then
+ (_.; (_.set param (_.bit_and (_.int +63) param)))
+ (_.if (_.=== (_.int +0) param)
+ (_.return subject)
+ (_.return (|> subject
+ (_.bit_and mask)
+ (_.bit_shr param)))))))
(runtime: (i64//char code)
(_.if ..jphp?
@@ -314,12 +363,12 @@
(_.if ..jphp?
($_ _.then
(_.; (_.set idx (_.strpos/3 [subject param start])))
- (_.if (_.= (_.bool false) idx)
+ (_.if (_.=== (_.bool false) idx)
(_.return ..none)
(_.return (..some idx))))
($_ _.then
(_.; (_.set idx (_.iconv_strpos/3 [subject param start])))
- (_.if (_.= (_.bool false) idx)
+ (_.if (_.=== (_.bool false) idx)
(_.return ..none)
(_.return (..some idx)))))))
@@ -335,15 +384,14 @@
(runtime: (text//char idx text)
(_.if (|> idx (within? (text//size text)))
- (let [code_point (: (-> Expression Computation)
- (|>> [(_.string "UTF-8") (_.string "UTF-32LE")]
- _.iconv/3
- [(_.string "V")]
- _.unpack/2
- (_.nth (_.int +1))))]
- (_.if ..jphp?
- (_.return (code_point (_.substr/3 [text idx (_.int +1)])))
- (_.return (code_point (_.iconv_substr/3 [text idx (_.int +1)])))))
+ (_.if ..jphp?
+ (_.return (_.ord/1 (_.substr/3 [text idx (_.int +1)])))
+ (_.return (|> (_.iconv_substr/3 [text idx (_.int +1)])
+ [(_.string "UTF-8") (_.string "UTF-32LE")]
+ _.iconv/3
+ [(_.string "V")]
+ _.unpack/2
+ (_.nth (_.int +1)))))
(_.throw (_.new (_.constant "Exception") (list (_.string "[Lux Error] Cannot get char from text."))))))
(def: runtime//text
@@ -359,14 +407,14 @@
(with_vars [output]
($_ _.then
(_.; (_.set output (_.floatval/1 value)))
- (_.if (_.= (_.float +0.0) output)
+ (_.if (_.=== (_.float +0.0) output)
(_.if ($_ _.or
- (_.= (_.string "0.0") output)
- (_.= (_.string "+0.0") output)
- (_.= (_.string "-0.0") output)
- (_.= (_.string "0") output)
- (_.= (_.string "+0") output)
- (_.= (_.string "-0") output))
+ (_.=== (_.string "0.0") output)
+ (_.=== (_.string "+0.0") output)
+ (_.=== (_.string "-0.0") output)
+ (_.=== (_.string "0") output)
+ (_.=== (_.string "+0") output)
+ (_.=== (_.string "-0") output))
(_.return (..some output))
(_.return ..none))
(_.return (..some output)))
@@ -380,7 +428,7 @@
(def: check_necessary_conditions!
Statement
- (let [i64_support? (_.= (_.int +8) (_.constant "PHP_INT_SIZE"))
+ (let [i64_support? (_.=== (_.int +8) (_.constant "PHP_INT_SIZE"))
i64_error (_.string (format "Cannot run program!" text.new_line
"Lux/PHP programs require 64-bit PHP builds!"))]
(_.when (_.not i64_support?)
@@ -390,6 +438,7 @@
Statement
($_ _.then
check_necessary_conditions!
+ runtime//array
runtime//adt
runtime//lux
runtime//i64
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/structure.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/structure.lux
index 307417c6c..ed4fe4ae1 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/structure.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/php/structure.lux
@@ -2,6 +2,9 @@
[lux #*
[abstract
["." monad (#+ do)]]
+ [data
+ [collection
+ ["." list]]]
[target
["_" php (#+ Expression)]]]
["." // #_
@@ -23,9 +26,13 @@
(generate archive singletonS)
_
- (|> elemsS+
- (monad.map ///////phase.monad (generate archive))
- (///////phase\map _.array/*))))
+ (let [size (_.int (.int (list.size elemsS+)))]
+ (|> elemsS+
+ (monad.map ///////phase.monad (generate archive))
+ ## (///////phase\map (|>> (list& (_.key_value (_.string //runtime.tuple_size_field) size))
+ ## _.array/*))
+ (///////phase\map (|>> _.array/*
+ (//runtime.tuple//make size)))))))
(def: #export (variant generate archive [lefts right? valueS])
(Generator (Variant Synthesis))
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux
index e21957afe..2249874b5 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/ruby/case.lux
@@ -129,13 +129,7 @@
Statement
(_.set (list @cursor) (|> @savepoint (_.do "pop" (list)))))
-(def: #export symbol
- (_.symbol "lux_break"))
-
-(def: fail!
- _.break
- ## (_.throw/1 ..symbol)
- )
+(def: fail! _.break)
(def: (multi_pop! pops)
(-> Nat Statement)
@@ -161,7 +155,6 @@
(def: (with_looping in_closure? g!once g!continue? body!)
(-> Bit LVar LVar Statement Statement)
- ## (_.catch ..symbol body!)
(.if in_closure?
($_ _.then
(_.while (_.bool true)
@@ -178,8 +171,7 @@
(_.set (list g!continue?) (_.bool true))
_.break)))
(_.when g!continue?
- _.next)))
- )
+ _.next))))
(def: (alternation in_closure? g!once g!continue? pre! post!)
(-> Bit LVar LVar Statement Statement Statement)