From d751fd495380b3a54f295b2a3ea557eee24dadf4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 20 Feb 2019 20:26:38 -0400 Subject: Moved expression machinery over. --- .../source/lux/tool/compiler/phase/extension.lux | 11 ++-- .../compiler/phase/translation/js/expression.lux | 59 ++++++++++++++++++++++ .../compiler/phase/translation/js/primitive.lux | 10 ++-- .../compiler/phase/translation/js/structure.lux | 6 +-- .../phase/translation/scheme/expression.jvm.lux | 4 +- .../phase/translation/scheme/primitive.jvm.lux | 8 +-- stdlib/source/test/lux.lux | 3 +- 7 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 stdlib/source/lux/tool/compiler/phase/translation/js/expression.lux (limited to 'stdlib') diff --git a/stdlib/source/lux/tool/compiler/phase/extension.lux b/stdlib/source/lux/tool/compiler/phase/extension.lux index 0d58cf37a..fd54d54b4 100644 --- a/stdlib/source/lux/tool/compiler/phase/extension.lux +++ b/stdlib/source/lux/tool/compiler/phase/extension.lux @@ -45,9 +45,8 @@ [invalid-syntax] ) -(exception: #export [s i o] (unknown {where Text} {name Name} {bundle (Bundle s i o)}) - (ex.report ["Where" (%t where)] - ["Extension" (%t name)] +(exception: #export [s i o] (unknown {name Name} {bundle (Bundle s i o)}) + (ex.report ["Extension" (%t name)] ["Available" (|> bundle dictionary.keys (list.sort text/<) @@ -71,9 +70,9 @@ _ (ex.throw cannot-overwrite name)))) -(def: #export (apply where phase [name parameters]) +(def: #export (apply phase [name parameters]) (All [s i o] - (-> Text (Phase s i o) (Extension i) (Operation s i o o))) + (-> (Phase s i o) (Extension i) (Operation s i o o))) (function (_ (^@ stateE [bundle state])) (case (dictionary.get name bundle) (#.Some handler) @@ -81,7 +80,7 @@ stateE) #.None - (ex.throw unknown [where name bundle])))) + (ex.throw unknown [name bundle])))) (def: #export (localized get set transform) (All [s s' i o v] diff --git a/stdlib/source/lux/tool/compiler/phase/translation/js/expression.lux b/stdlib/source/lux/tool/compiler/phase/translation/js/expression.lux new file mode 100644 index 000000000..76b206124 --- /dev/null +++ b/stdlib/source/lux/tool/compiler/phase/translation/js/expression.lux @@ -0,0 +1,59 @@ +(.module: + [lux #* + [control + [monad (#+ do)]]] + [// + [runtime (#+ Phase)] + ["." primitive] + ["." structure] + ["." reference] + ["." function] + ["." case] + ["." loop] + ["." /// + ["." synthesis] + ["." extension]]]) + +(def: #export (translate synthesis) + Phase + (case synthesis + (^template [ ] + (^ ( value)) + (:: ///.monad wrap ( value))) + ([synthesis.bit primitive.bit] + [synthesis.i64 primitive.i64] + [synthesis.f64 primitive.f64] + [synthesis.text primitive.text]) + + (^ (synthesis.variant variantS)) + (structure.variant translate variantS) + + (^ (synthesis.tuple members)) + (structure.tuple translate members) + + (#synthesis.Reference value) + (:: reference.system reference value) + + (^ (synthesis.branch/case case)) + (case.case translate case) + + (^ (synthesis.branch/let let)) + (case.let translate let) + + (^ (synthesis.branch/if if)) + (case.if translate if) + + (^ (synthesis.loop/scope scope)) + (loop.scope translate scope) + + (^ (synthesis.loop/recur updates)) + (loop.recur translate updates) + + (^ (synthesis.function/abstraction abstraction)) + (function.function translate abstraction) + + (^ (synthesis.function/apply application)) + (function.apply translate application) + + (#synthesis.Extension extension) + (extension.apply translate extension))) diff --git a/stdlib/source/lux/tool/compiler/phase/translation/js/primitive.lux b/stdlib/source/lux/tool/compiler/phase/translation/js/primitive.lux index 7b475c2e7..f2bee19c5 100644 --- a/stdlib/source/lux/tool/compiler/phase/translation/js/primitive.lux +++ b/stdlib/source/lux/tool/compiler/phase/translation/js/primitive.lux @@ -16,18 +16,18 @@ _.boolean) (def: high - (-> Int Int) + (-> (I64 Any) (I64 Any)) (i64.logic-right-shift 32)) (def: low - (-> Int Int) + (-> (I64 Any) (I64 Any)) (let [mask (dec (i64.left-shift 32 1))] (|>> (i64.and mask)))) (def: #export (i64 value) - (-> Int Expression) - (//runtime.i64//new (|> value ..high _.i32) - (|> value ..low _.i32))) + (-> (I64 Any) Expression) + (//runtime.i64//new (|> value ..high .int _.i32) + (|> value ..low .int _.i32))) (def: #export f64 (-> Frac Expression) diff --git a/stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux b/stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux index bac907bea..ec60f6292 100644 --- a/stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux +++ b/stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux @@ -27,6 +27,6 @@ (def: #export (variant translate [lefts right? valueS]) (-> Phase (Variant Synthesis) (Operation Expression)) - (do ////.monad - [valueT (translate valueS)] - (wrap (//runtime.variant (_.i32 (.int lefts)) (//runtime.flag right?) valueT)))) + (:: ////.monad map + (//runtime.variant (_.i32 (.int lefts)) (//runtime.flag right?)) + (translate valueS))) diff --git a/stdlib/source/lux/tool/compiler/phase/translation/scheme/expression.jvm.lux b/stdlib/source/lux/tool/compiler/phase/translation/scheme/expression.jvm.lux index c54311da0..76b206124 100644 --- a/stdlib/source/lux/tool/compiler/phase/translation/scheme/expression.jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/translation/scheme/expression.jvm.lux @@ -31,8 +31,8 @@ (^ (synthesis.tuple members)) (structure.tuple translate members) - (#synthesis.Reference reference) - (reference.reference reference) + (#synthesis.Reference value) + (:: reference.system reference value) (^ (synthesis.branch/case case)) (case.case translate case) diff --git a/stdlib/source/lux/tool/compiler/phase/translation/scheme/primitive.jvm.lux b/stdlib/source/lux/tool/compiler/phase/translation/scheme/primitive.jvm.lux index dff6cd644..d53a0691e 100644 --- a/stdlib/source/lux/tool/compiler/phase/translation/scheme/primitive.jvm.lux +++ b/stdlib/source/lux/tool/compiler/phase/translation/scheme/primitive.jvm.lux @@ -8,8 +8,8 @@ (-> Expression) )] - [bit Bit _.bool] - [i64 Int _.int] - [f64 Frac _.float] - [text Text _.string] + [bit Bit _.bool] + [i64 (I64 Any) (|>> .int _.int)] + [f64 Frac _.float] + [text Text _.string] ) diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index 4ed7ce96e..7a76cd53b 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -4,7 +4,8 @@ [reference (#+)] [case (#+)] [loop (#+)] - [function (#+)])] + [function (#+)] + [expression (#+)])] (.module: [lux #* [cli (#+ program:)] -- cgit v1.2.3