aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2019-02-20 20:26:38 -0400
committerEduardo Julian2019-02-20 20:26:38 -0400
commitd751fd495380b3a54f295b2a3ea557eee24dadf4 (patch)
tree25202029faf4e193915dc10858c25f8185128b5e
parentbe3e93a0688d1fee7fcb6ee464642451b0e43fe0 (diff)
Moved expression machinery over.
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/lang/translation/js/expression.jvm.lux89
-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
-rw-r--r--stdlib/source/test/lux.lux3
8 files changed, 80 insertions, 110 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux b/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux
deleted file mode 100644
index 0adc4255c..000000000
--- a/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux
+++ /dev/null
@@ -1,89 +0,0 @@
-(.module:
- lux
- (lux (control [monad #+ do]
- ["ex" exception #+ exception:]
- ["p" parser])
- (data ["e" error]
- text/format)
- [macro]
- (macro ["s" syntax]))
- (luxc ["&" lang]
- (lang [".L" variable #+ Variable Register]
- [".L" extension]
- ["ls" synthesis]
- (host [js #+ JS Expression Statement])))
- [//]
- (// [".T" runtime]
- [".T" primitive]
- [".T" structure]
- [".T" reference]
- [".T" function]
- [".T" loop]
- [".T" case]
- [".T" procedure]))
-
-(do-template [<name>]
- [(exception: #export (<name> {message Text})
- message)]
-
- [Invalid-Function-Syntax]
- [Unrecognized-Synthesis]
- )
-
-(def: #export (translate synthesis)
- (-> ls.Synthesis (Meta Expression))
- (case synthesis
- (^code [])
- (:: macro.Monad<Meta> wrap runtimeT.unit)
-
- (^code [(~ singleton)])
- (translate singleton)
-
- (^template [<tag> <generator>]
- [_ (<tag> value)]
- (<generator> value))
- ([#.Bit primitiveT.translate-bit]
- [#.Nat primitiveT.translate-nat]
- [#.Int primitiveT.translate-int]
- [#.Rev primitiveT.translate-rev]
- [#.Frac primitiveT.translate-frac]
- [#.Text primitiveT.translate-text])
-
- (^code ((~ [_ (#.Nat tag)]) (~ [_ (#.Bit last?)]) (~ valueS)))
- (structureT.translate-variant translate tag last? valueS)
-
- (^code [(~+ members)])
- (structureT.translate-tuple translate members)
-
- (^ [_ (#.Form (list [_ (#.Int var)]))])
- (referenceT.translate-variable var)
-
- [_ (#.Identifier definition)]
- (referenceT.translate-definition definition)
-
- (^code ("lux let" (~ [_ (#.Nat register)]) (~ inputS) (~ exprS)))
- (caseT.translate-let translate register inputS exprS)
-
- (^code ("lux case" (~ inputS) (~ pathPS)))
- (caseT.translate-case translate inputS pathPS)
-
- (^code ("lux function" (~ [_ (#.Nat arity)]) [(~+ environment)] (~ bodyS)))
- (case (s.run environment (p.some s.int))
- (#e.Success environment)
- (functionT.translate-function translate environment arity bodyS)
-
- _
- (&.throw Invalid-Function-Syntax (%code synthesis)))
-
- (^code ("lux call" (~ functionS) (~+ argsS)))
- (functionT.translate-apply translate functionS argsS)
-
- (^code ((~ [_ (#.Text procedure)]) (~+ argsS)))
- (procedureT.translate-procedure translate procedure argsS)
- ## (do macro.Monad<Meta>
- ## [translation (extensionL.find-translation procedure)]
- ## (translation argsS))
-
- _
- (&.throw Unrecognized-Synthesis (%code synthesis))
- ))
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]
)
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:)]