diff options
author | Eduardo Julian | 2015-01-22 00:18:39 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-01-22 00:18:39 -0400 |
commit | 33aadce096a947300a2531940efc962c979542da (patch) | |
tree | 46c306177d19dae8eb4a9c65e43292dd3a95dd3e /source/lux.lux | |
parent | 117124707863ed7d89ef13db417f883a76da041c (diff) |
WARNING: Broken
[Enhancements]
- Restructured the lexer a bit.
- Restructured the parser a lot.
- Changed the syntax a bit.
- Module-names are now separated from def-names by a colon (e.g. module/submodule:var)
- i+ -> iadd, i- -> isub, i* -> imul, i/ -> idiv
- Added a (incomplete) way to annotate defs. Currently, only serves to mark defs as macros.
- Removed "import" and "use". "require" is meant to be the way to load modules.
- Did some major refactoring, cleaning and upgrading in the analyser. Though there is still some work pending.
Diffstat (limited to '')
-rw-r--r-- | source/lux.lux | 108 |
1 files changed, 55 insertions, 53 deletions
diff --git a/source/lux.lux b/source/lux.lux index 8f02c681d..2b008f95f 100644 --- a/source/lux.lux +++ b/source/lux.lux @@ -1,79 +1,96 @@ ## Base interfaces & classes -(jvm/definterface Function +(jvm:interface Function (: apply (-> [java.lang.Object] java.lang.Object))) -(jvm/defclass Tuple0 java.lang.Object +(jvm:class Tuple0 java.lang.Object []) -(jvm/defclass Tuple1 java.lang.Object +(jvm:class Tuple1 java.lang.Object [[java.lang.Object _1]]) -(jvm/defclass Tuple2 java.lang.Object +(jvm:class Tuple2 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2]]) -(jvm/defclass Tuple3 java.lang.Object +(jvm:class Tuple3 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3]]) -(jvm/defclass Tuple4 java.lang.Object +(jvm:class Tuple4 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4]]) -(jvm/defclass Tuple5 java.lang.Object +(jvm:class Tuple5 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5]]) -(jvm/defclass Tuple6 java.lang.Object +(jvm:class Tuple6 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6]]) -(jvm/defclass Tuple7 java.lang.Object +(jvm:class Tuple7 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6] [java.lang.Object _7]]) -(jvm/defclass Tuple8 java.lang.Object +(jvm:class Tuple8 java.lang.Object [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6] [java.lang.Object _7] [java.lang.Object _8]]) -(jvm/defclass Variant java.lang.Object +(jvm:class Variant java.lang.Object [[java.lang.String tag]]) -(jvm/defclass Variant0 lux.Variant +(jvm:class Variant0 lux.Variant []) -(jvm/defclass Variant1 lux.Variant +(jvm:class Variant1 lux.Variant [[java.lang.Object _1]]) -(jvm/defclass Variant2 lux.Variant +(jvm:class Variant2 lux.Variant [[java.lang.Object _1] [java.lang.Object _2]]) -(jvm/defclass Variant3 lux.Variant +(jvm:class Variant3 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3]]) -(jvm/defclass Variant4 lux.Variant +(jvm:class Variant4 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4]]) -(jvm/defclass Variant5 lux.Variant +(jvm:class Variant5 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5]]) -(jvm/defclass Variant6 lux.Variant +(jvm:class Variant6 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6]]) -(jvm/defclass Variant7 lux.Variant +(jvm:class Variant7 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6] [java.lang.Object _7]]) -(jvm/defclass Variant8 lux.Variant +(jvm:class Variant8 lux.Variant [[java.lang.Object _1] [java.lang.Object _2] [java.lang.Object _3] [java.lang.Object _4] [java.lang.Object _5] [java.lang.Object _6] [java.lang.Object _7] [java.lang.Object _8]]) ## Base functions & macros -(defmacro (list xs) - (case xs +(def (id x) + x) + +(def (fold f init values) + (case values #Nil - (#Tag "Nil") + init + (#Cons x xs) + (fold f (f init x) xs))) - (#Cons x xs*) - (#Form (#Cons (#Tag "Cons") (#Cons x (#Cons (list xs*) #Nil)))))) +(def (cons tail head) + (#Cons head tail)) + +(def (reverse list) + (fold cons #Nil list)) + +(annotate list Macro) +(def (list xs) + (fold (lambda [tail head] + (#Form (#Cons (#Tag "Cons") + (#Cons head + (#Cons tail #Nil))))) + (#Tag "Nil") + (reverse xs))) (def (++ xs ys) (case xs @@ -135,40 +152,31 @@ ## I/O (def (print x) - (jvm/invokevirtual java.io.PrintStream "print" [Object] - (jvm/getstatic System out) [x])) + (jvm:invokevirtual java.io.PrintStream "print" [Object] + (jvm:getstatic System out) [x])) (def (println x) - (jvm/invokevirtual java.io.PrintStream "println" [Object] - (jvm/getstatic System out) [x])) + (jvm:invokevirtual java.io.PrintStream "println" [Object] + (jvm:getstatic System out) [x])) -(defmacro (' form) +(annotate ' Macro) +(def (' form) (case form (#Cons token #Nil) (untemplate token))) (def (+ x y) - (jvm/i+ x y)) + (jvm:iadd x y)) (def inc (+ 1)) -(def (id x) - x) - -(def (fold f init values) - (case values - #Nil - init - (#Cons x xs) - (fold f (f init x) xs))) - (def length (fold (lambda [l x] (inc l)) 0)) (def (rem dividend divisor) - (jvm/irem dividend divisor)) + (jvm:irem dividend divisor)) (def (= x y) - (jvm/invokevirtual Object "equals" [Object] + (jvm:invokevirtual Object "equals" [Object] x [y])) (def (pairs list) @@ -180,11 +188,11 @@ #Nil)) (def (show x) - (jvm/invokevirtual Object "toString" [] + (jvm:invokevirtual Object "toString" [] x [])) (def (concat t1 t2) - (jvm/invokevirtual String "concat" [String] + (jvm:invokevirtual String "concat" [String] t1 [t2])) (def (range from to) @@ -193,19 +201,13 @@ (#Cons from (range (inc from) to)))) (def (text->list text) - (let length (jvm/invokevirtual String "length" [] + (let length (jvm:invokevirtual String "length" [] text []) (map (lambda [idx] - (jvm/invokevirtual String "charAt" [int] + (jvm:invokevirtual String "charAt" [int] text [idx])) (range 0 length)))) -(def (cons tail head) - (#Cons head tail)) - -(def (reverse list) - (fold cons #Nil list)) - (def (enumerate list) (case (fold (lambda [state x] (case state |