(.module: [lux #* [abstract ["." monad (#+ do)]] [control ["<>" parser ["" code (#+ Parser)]] pipe] [data [collection ["." array (#+ Array)] ["." dictionary]]] [type ["." check]] [target ["_" js]]] ["." // #_ ["/" lux (#+ custom)] ["/#" // ["#." bundle] ["/#" // ("#@." monad) [analysis [".A" type]] ["/#" // #_ ["#." analysis (#+ Analysis Operation Phase Handler Bundle)]]]]]) (def: array::new Handler (custom [.any (function (_ extension phase lengthC) (do ////.monad [lengthA (typeA.with-type Nat (phase lengthC)) [var-id varT] (typeA.with-env check.var) _ (typeA.infer (type (Array varT)))] (wrap (#/////analysis.Extension extension (list lengthA)))))])) (def: array::length Handler (custom [.any (function (_ extension phase arrayC) (do ////.monad [[var-id varT] (typeA.with-env check.var) arrayA (typeA.with-type (type (Array varT)) (phase arrayC)) _ (typeA.infer Nat)] (wrap (#/////analysis.Extension extension (list arrayA)))))])) (def: array::read Handler (custom [(<>.and .any .any) (function (_ extension phase [indexC arrayC]) (do ////.monad [indexA (typeA.with-type Nat (phase indexC)) [var-id varT] (typeA.with-env check.var) arrayA (typeA.with-type (type (Array varT)) (phase arrayC)) _ (typeA.infer varT)] (wrap (#/////analysis.Extension extension (list indexA arrayA)))))])) (def: array::write Handler (custom [($_ <>.and .any .any .any) (function (_ extension phase [indexC valueC arrayC]) (do ////.monad [indexA (typeA.with-type Nat (phase indexC)) [var-id varT] (typeA.with-env check.var) valueA (typeA.with-type varT (phase valueC)) arrayA (typeA.with-type (type (Array varT)) (phase arrayC)) _ (typeA.infer (type (Array varT)))] (wrap (#/////analysis.Extension extension (list indexA valueA arrayA)))))])) (def: array::delete Handler (custom [($_ <>.and .any .any) (function (_ extension phase [indexC arrayC]) (do ////.monad [indexA (typeA.with-type Nat (phase indexC)) [var-id varT] (typeA.with-env check.var) arrayA (typeA.with-type (type (Array varT)) (phase arrayC)) _ (typeA.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: object::new Handler (custom [($_ <>.and .any (.tuple (<>.some .any))) (function (_ extension phase [constructorC inputsC]) (do ////.monad [constructorA (typeA.with-type Any (phase constructorC)) inputsA (monad.map @ (|>> phase (typeA.with-type Any)) inputsC) _ (typeA.infer .Any)] (wrap (#/////analysis.Extension extension (list& constructorA inputsA)))))])) (def: object::get Handler (custom [($_ <>.and .text .any) (function (_ extension phase [fieldC objectC]) (do ////.monad [objectA (typeA.with-type Any (phase objectC)) _ (typeA.infer .Any)] (wrap (#/////analysis.Extension extension (list (/////analysis.text fieldC) objectA)))))])) (def: object::do Handler (custom [($_ <>.and .text .any (.tuple (<>.some .any))) (function (_ extension phase [methodC objectC inputsC]) (do ////.monad [objectA (typeA.with-type Any (phase objectC)) inputsA (monad.map @ (|>> phase (typeA.with-type Any)) inputsC) _ (typeA.infer .Any)] (wrap (#/////analysis.Extension extension (list& (/////analysis.text methodC) objectA inputsA)))))])) (def: bundle::object Bundle (<| (///bundle.prefix "object") (|> ///bundle.empty (///bundle.install "new" object::new) (///bundle.install "get" object::get) (///bundle.install "do" object::do) (///bundle.install "null" (/.nullary Any)) (///bundle.install "null?" (/.unary Any Bit)) (///bundle.install "undefined" (/.nullary Any)) (///bundle.install "undefined?" (/.unary Any Bit)) ))) (def: js::constant Handler (custom [.text (function (_ extension phase name) (do ////.monad [_ (typeA.infer Any)] (wrap (#/////analysis.Extension extension (list (/////analysis.text name))))))])) (def: js::apply Handler (custom [($_ <>.and .any (<>.some .any)) (function (_ extension phase [abstractionC inputsC]) (do ////.monad [abstractionA (typeA.with-type Any (phase abstractionC)) inputsA (monad.map @ (|>> phase (typeA.with-type Any)) inputsC) _ (typeA.infer Any)] (wrap (#/////analysis.Extension extension (list& abstractionA inputsA)))))])) (def: js::type-of Handler (custom [.any (function (_ extension phase objectC) (do ////.monad [objectA (typeA.with-type Any (phase objectC)) _ (typeA.infer .Text)] (wrap (#/////analysis.Extension extension (list objectA)))))])) (def: #export bundle Bundle (<| (///bundle.prefix "js") (|> ///bundle.empty (///bundle.install "constant" js::constant) (///bundle.install "apply" js::apply) (///bundle.install "type-of" js::type-of) (dictionary.merge bundle::array) (dictionary.merge bundle::object) )))