aboutsummaryrefslogtreecommitdiff
path: root/source/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2015-01-19 19:38:38 -0400
committerEduardo Julian2015-01-19 19:38:38 -0400
commit2103b30f37db2aaed472981d2642f4c32c25869c (patch)
tree5ffc6b311881f02b6c2fb95f9c6d80a2e11875df /source/lux.lux
parenta14d86d958af652f7bc4ce669dffcc100d2a084c (diff)
[Bugs]
- Removed the issue that was causing the compiler to never display the true source of errors. [Enhancements] - Separated the prelude (lux.lux) and utils (util.lux) from the code at test2.lux - The compiler now handles module-separation a bit better [Cleanup] - Removed the unnecessary another.lux [Temporary] - The base classes/interfaces are now assumed to be in the "lux" module, but they must be moved to "lux/host"
Diffstat (limited to 'source/lux.lux')
-rw-r--r--source/lux.lux259
1 files changed, 259 insertions, 0 deletions
diff --git a/source/lux.lux b/source/lux.lux
new file mode 100644
index 000000000..8f02c681d
--- /dev/null
+++ b/source/lux.lux
@@ -0,0 +1,259 @@
+## Base interfaces & classes
+(jvm/definterface Function
+ (: apply (-> [java.lang.Object] java.lang.Object)))
+
+(jvm/defclass Tuple0 java.lang.Object
+ [])
+(jvm/defclass Tuple1 java.lang.Object
+ [[java.lang.Object _1]])
+(jvm/defclass Tuple2 java.lang.Object
+ [[java.lang.Object _1] [java.lang.Object _2]])
+(jvm/defclass Tuple3 java.lang.Object
+ [[java.lang.Object _1] [java.lang.Object _2]
+ [java.lang.Object _3]])
+(jvm/defclass 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
+ [[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
+ [[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
+ [[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
+ [[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
+ [[java.lang.String tag]])
+(jvm/defclass Variant0 lux.Variant
+ [])
+(jvm/defclass Variant1 lux.Variant
+ [[java.lang.Object _1]])
+(jvm/defclass Variant2 lux.Variant
+ [[java.lang.Object _1] [java.lang.Object _2]])
+(jvm/defclass Variant3 lux.Variant
+ [[java.lang.Object _1] [java.lang.Object _2]
+ [java.lang.Object _3]])
+(jvm/defclass Variant4 lux.Variant
+ [[java.lang.Object _1] [java.lang.Object _2]
+ [java.lang.Object _3] [java.lang.Object _4]])
+(jvm/defclass 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
+ [[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
+ [[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
+ [[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
+ #Nil
+ (#Tag "Nil")
+
+ (#Cons x xs*)
+ (#Form (#Cons (#Tag "Cons") (#Cons x (#Cons (list xs*) #Nil))))))
+
+(def (++ xs ys)
+ (case xs
+ #Nil
+ ys
+
+ (#Cons x xs*)
+ (#Cons x (++ xs* ys))))
+
+(def (map f xs)
+ (case xs
+ #Nil
+ #Nil
+
+ (#Cons x xs*)
+ (#Cons (f x) (map f xs*))))
+
+(def (untemplate-list untemplate tokens)
+ (case tokens
+ #Nil
+ (#Tag "Nil")
+
+ (#Cons token tokens')
+ (#Form (list (#Tag "Cons") (untemplate token) (untemplate-list untemplate tokens')))))
+
+(def (untemplate token)
+ (case token
+ (#Bool elem)
+ (#Form (list (#Tag "Bool") (#Bool elem)))
+
+ (#Int elem)
+ (#Form (list (#Tag "Int") (#Int elem)))
+
+ (#Real elem)
+ (#Form (list (#Tag "Real") (#Real elem)))
+
+ (#Char elem)
+ (#Form (list (#Tag "Char") (#Char elem)))
+
+ (#Text elem)
+ (#Form (list (#Tag "Text") (#Text elem)))
+
+ (#Tag elem)
+ (#Form (list (#Tag "Tag") (#Text elem)))
+
+ (#Ident elem)
+ (#Form (list (#Tag "Ident") (#Text elem)))
+
+ (#Form (#Cons (#Ident "~") (#Cons unquoted #Nil)))
+ unquoted
+
+ (#Tuple elems)
+ (#Form (list (#Tag "Tuple") (untemplate-list untemplate elems)))
+
+ (#Form elems)
+ (#Form (list (#Tag "Form") (untemplate-list untemplate elems)))
+ ))
+
+
+## I/O
+(def (print 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]))
+
+(defmacro (' form)
+ (case form
+ (#Cons token #Nil)
+ (untemplate token)))
+
+(def (+ x y)
+ (jvm/i+ 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))
+
+(def (= x y)
+ (jvm/invokevirtual Object "equals" [Object]
+ x [y]))
+
+(def (pairs list)
+ (case list
+ (#Cons x (#Cons y list*))
+ (#Cons [x y] (pairs list*))
+
+ _
+ #Nil))
+
+(def (show x)
+ (jvm/invokevirtual Object "toString" []
+ x []))
+
+(def (concat t1 t2)
+ (jvm/invokevirtual String "concat" [String]
+ t1 [t2]))
+
+(def (range from to)
+ (if (= from to)
+ #Nil
+ (#Cons from (range (inc from) to))))
+
+(def (text->list text)
+ (let length (jvm/invokevirtual String "length" []
+ text [])
+ (map (lambda [idx]
+ (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
+ [idx list']
+ [(inc idx) (#Cons [idx x] list')]))
+ [0 #Nil]
+ list)
+ [_ list']
+ (reverse list')))
+
+(def list-map #Nil)
+
+(def (put key val map)
+ (case map
+ #Nil
+ (#Cons [key val] map)
+
+ (#Cons [?key ?val] map')
+ (if (= key ?key)
+ (#Cons [?key val] map')
+ (#Cons [?key ?val] (put key val map')))))
+
+(def (get key map)
+ (case map
+ #Nil
+ #None
+
+ (#Cons [?key ?val] map')
+ (if (= key ?key)
+ (#Some ?val)
+ (get key map'))))
+
+(def (show-kv kv)
+ (case kv
+ [?key ?val]
+ (fold concat "" (list "#" ?key " " (show ?val)))))
+
+(def (interpose elem list)
+ (case list
+ (#Cons x (#Cons y list'))
+ (#Cons x (#Cons elem (#Cons y list')))
+
+ _
+ list))
+
+(def (show-list xs)
+ (case xs
+ #Nil
+ "#Nil"
+ (#Cons x xs')
+ (fold concat "" (list "(#Cons " (show x) " " (show-list xs') ")"))))