From ddc471806fba8fe179d52b4781f0a66d871b5e99 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 3 Aug 2015 19:54:53 -0400 Subject: - Type definitions inside the compiler data now hold the type itself. - Value definitions inside the compiler data now hold the value itself. - Fixed a few bugs. --- source/lux.lux | 24 +++++++++++++++++------- source/lux/data/list.lux | 20 +++++++++++++++++++- source/lux/data/text.lux | 18 ++++++++---------- source/lux/meta/lux.lux | 8 ++++---- 4 files changed, 48 insertions(+), 22 deletions(-) (limited to 'source') diff --git a/source/lux.lux b/source/lux.lux index 3670a9e52..d3dd374d5 100644 --- a/source/lux.lux +++ b/source/lux.lux @@ -220,14 +220,16 @@ #Nil])])]))) ## (deftype (DefData' m) -## (| #TypeD -## (#ValueD Type) +## (| (#TypeD Type) +## (#ValueD (, Type Unit)) ## (#MacroD m) ## (#AliasD Ident))) (_lux_def DefData' (#AllT [(#Some #Nil) "lux;DefData'" "" - (#VariantT (#Cons [["lux;TypeD" (#TupleT #Nil)] - (#Cons [["lux;ValueD" Type] + (#VariantT (#Cons [["lux;TypeD" Type] + (#Cons [["lux;ValueD" (#TupleT (#Cons [Type + (#Cons [Unit + #Nil])]))] (#Cons [["lux;MacroD" (#BoundT "")] (#Cons [["lux;AliasD" Ident] #Nil])])])]))])) @@ -1710,7 +1712,7 @@ (_lux_case pattern (#Meta _ (#FormS (#Cons (#Meta _ (#SymbolS macro-name)) macro-args))) (do Lux/Monad - [expansion (macro-expand-all (form$ (list& (symbol$ macro-name) body macro-args))) + [expansion (macro-expand (form$ (list& (symbol$ macro-name) body macro-args))) expansions (map% Lux/Monad expander (as-pairs expansion))] (;return (list:join expansions))) @@ -2621,8 +2623,8 @@ (#Some _ def-data) (case def-data - #TypeD (#Some Type) - (#ValueD type) (#Some type) + (#TypeD _) (#Some Type) + (#ValueD [type _]) (#Some type) (#MacroD m) (#Some Macro) (#AliasD name') (find-in-defs name' state)))))) ## (def (find-in-defs name state) @@ -3048,3 +3050,11 @@ _ (fail "Wrong syntax for loop"))) + +## (defmacro #export (extend tokens) +## (case tokens +## (\ (list (#Meta _ (#SymbolS name)))) + + +## _ +## (fail "Wrong syntax for extend"))) diff --git a/source/lux/data/list.lux b/source/lux/data/list.lux index 2bbbe66cc..f840688fd 100644 --- a/source/lux/data/list.lux +++ b/source/lux/data/list.lux @@ -11,7 +11,8 @@ (functor #as F #refer #all) (monad #as M #refer #all) (eq #as E) - (dict #as D #refer #all)) + (dict #as D #refer #all) + (stack #as S)) (data (number (int #open ("i" Int/Number Int/Ord Int/Eq))) bool) meta/macro)) @@ -312,3 +313,20 @@ (if (:: eq (E;= k k')) kvs' (#;Cons [[k' v'] (recur kvs')]))))]))) + +(defstruct #export List/Stack (S;Stack List) + (def S;empty (list)) + (def (S;empty? xs) + (case xs + #;Nil true + _ false)) + (def (S;push x xs) + (#;Cons x xs)) + (def (S;pop xs) + (case xs + #;Nil #;None + (#;Cons x xs') (#;Some xs'))) + (def (S;top xs) + (case xs + #;Nil #;None + (#;Cons x xs') (#;Some x)))) diff --git a/source/lux/data/text.lux b/source/lux/data/text.lux index ae4f9974f..1d582c1d5 100644 --- a/source/lux/data/text.lux +++ b/source/lux/data/text.lux @@ -147,16 +147,14 @@ ## [Syntax] (def (extract-var template) (-> Text (Maybe (, Text Text Text))) - (exec (_jvm_invokevirtual "java.io.PrintStream" "println" ["java.lang.Object"] - (_jvm_getstatic "java.lang.System" "out") [(:: Text/Monoid (m;++ "Template: " template))]) - (do Maybe/Monad - [pre-idx (index-of "#{" template) - [pre in] (split pre-idx template) - [_ in] (split 2 in) - post-idx (index-of "}" in) - [var post] (split post-idx in) - [_ post] (split 1 post)] - (M;wrap [pre var post])))) + (do Maybe/Monad + [pre-idx (index-of "#{" template) + [pre in] (split pre-idx template) + [_ in] (split 2 in) + post-idx (index-of "}" in) + [var post] (split post-idx in) + [_ post] (split 1 post)] + (M;wrap [pre var post]))) (def (unravel-template template) (-> Text (List Syntax)) diff --git a/source/lux/meta/lux.lux b/source/lux/meta/lux.lux index 66e4cc341..cdbade999 100644 --- a/source/lux/meta/lux.lux +++ b/source/lux/meta/lux.lux @@ -286,10 +286,10 @@ (#;Some [_ def-data]) (case def-data - #;TypeD (#;Some Type) - (#;ValueD type) (#;Some type) - (#;MacroD m) (#;Some Macro) - (#;AliasD name') (find-in-defs name' state)))))) + (#;TypeD value) (#;Some Type) + (#;ValueD type _) (#;Some type) + (#;MacroD m) (#;Some Macro) + (#;AliasD name') (find-in-defs name' state)))))) (def #export (find-var-type name) (-> Ident (Lux Type)) -- cgit v1.2.3