From 14e381de130f0c8d3e333cf0523c6c98b9aa84b1 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 17 Oct 2017 02:01:41 -0400 Subject: - Added "for" macro to specify platform-dependent code. - Some refactoring/re-naming. --- stdlib/source/lux.lux | 75 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 18 deletions(-) (limited to 'stdlib/source') 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 + [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'")))) -- cgit v1.2.3