aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool
diff options
context:
space:
mode:
authorEduardo Julian2019-02-20 20:26:38 -0400
committerEduardo Julian2019-02-20 20:26:38 -0400
commitd751fd495380b3a54f295b2a3ea557eee24dadf4 (patch)
tree25202029faf4e193915dc10858c25f8185128b5e /stdlib/source/lux/tool
parentbe3e93a0688d1fee7fcb6ee464642451b0e43fe0 (diff)
Moved expression machinery over.
Diffstat (limited to 'stdlib/source/lux/tool')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/extension.lux11
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/js/expression.lux59
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/js/primitive.lux10
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/js/structure.lux6
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/scheme/expression.jvm.lux4
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/scheme/primitive.jvm.lux8
6 files changed, 78 insertions, 20 deletions
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 [<tag> <generator>]
+ (^ (<tag> value))
+ (:: ///.monad wrap (<generator> 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 @@
(-> <type> Expression)
<code>)]
- [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]
)