aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lux-mode/lux-mode.el3
-rw-r--r--luxc/src/lux/base.clj36
-rw-r--r--luxc/src/lux/compiler/cache.clj2
-rw-r--r--luxc/src/lux/compiler/core.clj2
-rw-r--r--luxc/src/lux/compiler/js.clj2
-rw-r--r--luxc/src/lux/compiler/jvm.clj2
-rw-r--r--stdlib/source/lux.lux75
-rw-r--r--stdlib/test/test/lux.lux18
8 files changed, 95 insertions, 45 deletions
diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el
index 5342a8495..633c42244 100644
--- a/lux-mode/lux-mode.el
+++ b/lux-mode/lux-mode.el
@@ -227,7 +227,8 @@ Called by `imenu--generic-function'."
"function" "case" ":" ":!" ":!!" "undefined" "ident-for"
"and" "or"
"char"
- "exec" "let" "with-expansions" "if" "cond" "do" "be" "open" "loop" "recur" "comment" "list" "list&" "io" "vector" "tree"
+ "exec" "let" "with-expansions" "if" "cond" "do" "be" "open" "loop" "recur" "comment" "for"
+ "list" "list&" "io" "sequence" "tree"
"get@" "set@" "update@" "|>" "|>." "<|" "<|." "_$" "$_" "~" "~@" "~'" "::" ":::"
"|" "&" "->" "All" "Ex" "Rec" "host" "$" "type"
"^" "^or" "^slots" "^multi" "^~" "^@" "^template" "^open" "^|>" "^stream&" "^regex"
diff --git a/luxc/src/lux/base.clj b/luxc/src/lux/base.clj
index 7207b2cca..1281df4e6 100644
--- a/luxc/src/lux/base.clj
+++ b/luxc/src/lux/base.clj
@@ -138,9 +138,9 @@
("REPL" 0))
(deftuple
- ["compiler-name"
- "compiler-version"
- "compiler-mode"])
+ ["target"
+ "version"
+ "mode"])
;; Hosts
(defvariant
@@ -220,7 +220,7 @@
(def ^:const module-class-name "_")
(def ^:const +name-separator+ ";")
-(def ^:const ^String compiler-version "0.6.0")
+(def ^:const ^String version "0.6.0")
;; Constructors
(def empty-cursor (T ["" -1 -1]))
@@ -803,18 +803,18 @@
_
class-name))))
-(defn default-compiler-info [name mode]
- (T [;; compiler-name
- name
- ;; compiler-version
- compiler-version
- ;; compiler-mode
+(defn default-info [target mode]
+ (T [;; target
+ target
+ ;; version
+ version
+ ;; mode
mode]
))
(defn init-state [name mode host-data]
(T [;; "lux;info"
- (default-compiler-info name mode)
+ (default-info name mode)
;; "lux;source"
$Nil
;; "lux;cursor"
@@ -861,21 +861,21 @@
(defn with-eval [body]
(fn [state]
- (let [old-mode (->> state (get$ $info) (get$ $compiler-mode))]
- (|case (body (update$ $info #(set$ $compiler-mode $Eval %) state))
+ (let [old-mode (->> state (get$ $info) (get$ $mode))]
+ (|case (body (update$ $info #(set$ $mode $Eval %) state))
($Right state* output)
- (return* (update$ $info #(set$ $compiler-mode old-mode %) state*) output)
+ (return* (update$ $info #(set$ $mode old-mode %) state*) output)
($Left msg)
(fail* msg)))))
(def get-eval
(fn [state]
- (return* state (->> state (get$ $info) (get$ $compiler-mode) in-eval?))))
+ (return* state (->> state (get$ $info) (get$ $mode) in-eval?))))
(def get-mode
(fn [state]
- (return* state (->> state (get$ $info) (get$ $compiler-mode)))))
+ (return* state (->> state (get$ $info) (get$ $mode)))))
(def get-top-local-env
(fn [state]
@@ -994,11 +994,11 @@
(|do [_mode get-mode]
(fn [state]
(let [output (body (if (in-repl? _mode)
- (update$ $info #(set$ $compiler-mode $Build %) state)
+ (update$ $info #(set$ $mode $Build %) state)
state))]
(|case output
($Right state* datum)
- (return* (update$ $info #(set$ $compiler-mode _mode %) state*) datum)
+ (return* (update$ $info #(set$ $mode _mode %) state*) datum)
_
output)))))
diff --git a/luxc/src/lux/compiler/cache.clj b/luxc/src/lux/compiler/cache.clj
index e017e08e2..4c3b1a436 100644
--- a/luxc/src/lux/compiler/cache.clj
+++ b/luxc/src/lux/compiler/cache.clj
@@ -193,7 +193,7 @@
_ (uninstall-all-defs-in-module module-name)]
(return cache-table))]]
(if (and (= module-hash (Long/parseUnsignedLong ^String _hash))
- (= &/compiler-version _compiler))
+ (= &/version _compiler))
(|do [[success? cache-table*] (process-module pre-load! source-dirs cache-table module-name module-hash
_imports-section _tags-section _module-anns-section _defs-section
load-def-value install-all-defs-in-module uninstall-all-defs-in-module)
diff --git a/luxc/src/lux/compiler/core.clj b/luxc/src/lux/compiler/core.clj
index 3f8532e94..8367678c3 100644
--- a/luxc/src/lux/compiler/core.clj
+++ b/luxc/src/lux/compiler/core.clj
@@ -71,7 +71,7 @@
(str type datum-separator)))))
(&/|interpose entry-separator)
(&/fold str ""))
- module-descriptor (->> (&/|list &/compiler-version
+ module-descriptor (->> (&/|list &/version
(Long/toUnsignedString file-hash)
import-entries
tag-entries
diff --git a/luxc/src/lux/compiler/js.clj b/luxc/src/lux/compiler/js.clj
index 6eff83688..dbf229fe5 100644
--- a/luxc/src/lux/compiler/js.clj
+++ b/luxc/src/lux/compiler/js.clj
@@ -173,7 +173,7 @@
:let [full-program-file (str @&&core/!output-dir java.io.File/separator "program.js")
_ (&&core/write-file full-program-file (.getBytes (.toString total-buffer)))]]
(return nil))]
- (|case (m-action (&/init-state "Lux/JS" mode (&&/js-host)))
+ (|case (m-action (&/init-state "JS" mode (&&/js-host)))
(&/$Right ?state _)
(do (println "Compilation complete!")
(&&cache/clean ?state))
diff --git a/luxc/src/lux/compiler/jvm.clj b/luxc/src/lux/compiler/jvm.clj
index e54f92d91..ff728ae81 100644
--- a/luxc/src/lux/compiler/jvm.clj
+++ b/luxc/src/lux/compiler/jvm.clj
@@ -245,7 +245,7 @@
&&jvm-cache/uninstall-all-defs-in-module)
_ (compile-module source-dirs "lux")]
(compile-module source-dirs program-module))]
- (|case (m-action (&/init-state "Lux/JVM" mode (jvm-host)))
+ (|case (m-action (&/init-state "JVM" mode (jvm-host)))
(&/$Right ?state _)
(do (println "Compilation complete!")
(&&cache/clean ?state))
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))))