aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2017-10-17 02:01:41 -0400
committerEduardo Julian2017-10-17 02:01:41 -0400
commit14e381de130f0c8d3e333cf0523c6c98b9aa84b1 (patch)
tree104e98ded63d6d06c894df646d33d6097cf7be34 /stdlib
parent98bfe062d911163a063f7139a840410964f12878 (diff)
- Added "for" macro to specify platform-dependent code.
- Some refactoring/re-naming.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux.lux75
-rw-r--r--stdlib/test/test/lux.lux18
2 files changed, 71 insertions, 22 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index e31e96e7c..205f1a543 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -662,12 +662,12 @@
#Nil))))]
default-def-meta-exported)))
-## (type: Compiler-Mode
+## (type: Mode
## #Build
## #Eval
## #REPL)
-(_lux_def Compiler-Mode
- (#Named ["lux" "Compiler-Mode"]
+(_lux_def Mode
+ (#Named ["lux" "Mode"]
(#Sum ## Build
#Unit
(#Sum ## Eval
@@ -683,31 +683,31 @@
(text$ "A sign that shows the conditions under which the compiler is running.")]
default-def-meta-exported))))
-## (type: Compiler-Info
-## {#compiler-name Text
-## #compiler-version Text
-## #compiler-mode Compiler-Mode})
-(_lux_def Compiler-Info
- (#Named ["lux" "Compiler-Info"]
+## (type: Info
+## {#target Text
+## #version Text
+## #mode Mode})
+(_lux_def Info
+ (#Named ["lux" "Info"]
(#Product
- ## compiler-name
+ ## target
Text
(#Product
- ## compiler-version
+ ## version
Text
- ## compiler-mode
- Compiler-Mode)))
+ ## mode
+ Mode)))
(record$ (#Cons [(tag$ ["lux" "tags"])
- (tuple$ (#Cons (text$ "compiler-name")
- (#Cons (text$ "compiler-version")
- (#Cons (text$ "compiler-mode")
+ (tuple$ (#Cons (text$ "target")
+ (#Cons (text$ "version")
+ (#Cons (text$ "mode")
#Nil))))]
(#Cons [(tag$ ["lux" "doc"])
(text$ "Information about the current version and type of compiler that is running.")]
default-def-meta-exported))))
## (type: Compiler
-## {#info Compiler-Info
+## {#info Info
## #source Source
## #cursor Cursor
## #modules (List [Text Module])
@@ -720,7 +720,7 @@
(_lux_def Compiler
(#Named ["lux" "Compiler"]
(#Product ## "lux;info"
- Compiler-Info
+ Info
(#Product ## "lux;source"
Source
(#Product ## "lux;cursor"
@@ -5867,3 +5867,42 @@
(type: #export (Array a)
{#;doc "Mutable arrays."}
(#;Host "#Array" (#;Cons a #;Nil)))
+
+(def: target
+ (Meta Text)
+ (function [compiler]
+ (#;Right [compiler (get@ [#info #target] compiler)])))
+
+(def: (pick-for-target target options)
+ (-> Text (List [Code Code]) (Maybe Code))
+ (case options
+ #;Nil
+ #;None
+
+ (#;Cons [key value] options')
+ (case key
+ (^multi [_ (#Text platform)]
+ (text/= target platform))
+ (#;Some value)
+
+ _
+ (pick-for-target target options'))
+ ))
+
+(macro: #export (for tokens)
+ (do Monad<Meta>
+ [target target]
+ (case tokens
+ (^ (list [_ (#Record options)]))
+ (case (pick-for-target target options)
+ (#;Some pick)
+ (wrap (list pick))
+
+ #;None
+ (wrap (list)))
+
+ (^ (list [_ (#Record options)] default))
+ (wrap (list (;;default default (pick-for-target target options))))
+
+ _
+ (fail "Wrong syntax for 'for'"))))
diff --git a/stdlib/test/test/lux.lux b/stdlib/test/test/lux.lux
index 88f8c6f79..f44430c6c 100644
--- a/stdlib/test/test/lux.lux
+++ b/stdlib/test/test/lux.lux
@@ -6,7 +6,7 @@
[math]
["r" math/random]
(data [maybe]
- [text "T/" Eq<Text>]
+ [text "text/" Eq<Text>]
text/format)
[meta]
(meta ["s" syntax #+ syntax:])))
@@ -96,7 +96,7 @@
## Skip this test for Deg
## because Deg division loses the last
## 32 bits of precision.
- (or (T/= "Deg" category)
+ (or (text/= "Deg" category)
(and (|> x (* <1>) (= x))
(|> x (/ <1>) (= x))))))
@@ -111,7 +111,7 @@
## Skip this test for Deg
## because Deg division loses the last
## 32 bits of precision.
- (or (T/= "Deg" category)
+ (or (text/= "Deg" category)
(or (> x' y)
(|> x' (/ y) (* y) (= x'))))
))]
@@ -172,9 +172,19 @@
(template: (hypotenuse x y)
(i.+ (i.* x x) (i.* y y)))
-(context: "Templates"
+(context: "Templates."
[x r;int
y r;int]
(test "Template application is a stand-in for the templated code."
(i.= (i.+ (i.* x x) (i.* y y))
(hypotenuse x y))))
+
+(context: "Cross-platform support."
+ ($_ seq
+ (test "Can provide default in case there is no particular platform support."
+ (for {"" false}
+ true))
+ (test "Can pick code depending on the platform being targeted."
+ (for {"JVM" true
+ "JS" true}
+ false))))