aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/lux.lux43
-rw-r--r--src/lux/analyser.clj19
2 files changed, 51 insertions, 11 deletions
diff --git a/source/lux.lux b/source/lux.lux
index 1a5317991..c40c26589 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -84,6 +84,37 @@
(fold f (f init x) xs)
)))))
+(annotate lambda Macro)
+(def' lambda
+ (lambda' _ tokens
+ (case tokens
+ (#Cons self (#Cons (#Tuple (#Cons arg args')) (#Cons body #Nil)))
+ (#Form (#Cons (#Ident "lambda'")
+ (#Cons self
+ (#Cons arg
+ (case args'
+ #Nil
+ (#Cons body #Nil)
+
+ _
+ (#Cons (#Ident "lux:lambda")
+ (#Cons (#Tuple args')
+ (#Cons body #Nil))))))))
+
+ (#Cons (#Tuple (#Cons arg args')) (#Cons body #Nil))
+ (#Form (#Cons (#Ident "lambda'")
+ (#Cons (#Ident "_")
+ (#Cons arg
+ (case args'
+ #Nil
+ (#Cons body #Nil)
+
+ _
+ (#Cons (#Ident "lux:lambda")
+ (#Cons (#Tuple args')
+ (#Cons body #Nil))))))))
+ )))
+
#(
(defmacro (lambda tokens)
(case tokens
@@ -232,16 +263,16 @@
(let length (jvm:invokevirtual String "length" []
text [])
(map (lambda' idx
- (jvm:invokevirtual String "charAt" [int]
- text [idx]))
+ (jvm:invokevirtual String "charAt" [int]
+ text [idx]))
(range 0 length))))
(def (enumerate list)
(case (fold (lambda' state
- (lambda' x
- (case state
- [idx list']
- [(inc idx) (#Cons [idx x] list')])))
+ (lambda' x
+ (case state
+ [idx list']
+ [(inc idx) (#Cons [idx x] list')])))
[0 #Nil]
list)
[_ list']
diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj
index 5fe13b91d..14bb533dc 100644
--- a/src/lux/analyser.clj
+++ b/src/lux/analyser.clj
@@ -746,6 +746,13 @@
(defn ^:private ->def-lambda [old-scope new-scope syntax]
(match (:form syntax)
+ [::literal _]
+ syntax
+
+ [::variant ?tag ?elems]
+ {:form [::variant ?tag (map (partial ->def-lambda old-scope new-scope) ?elems)]
+ :type (:type syntax)}
+
[::local ?local-scope ?idx]
{:form [::local new-scope (inc ?idx)]
:type (:type syntax)}
@@ -914,11 +921,8 @@
(return (list (annotated [::literal ?value] [::&type/object "java.lang.String" []])))
[::&parser/tag ?tag]
- (return (list (annotated [::variant ?tag '()] [::&type/variant ?tag '()])))
-
- [::&parser/form ([[::&parser/tag ?tag] & ?data] :seq)]
- (exec [=data (do-all-m* (map analyse-ast ?data))]
- (return (list (annotated [::variant ?tag =data] [::&type/variant ?tag (map :type =data)]))))
+ (do (prn 'analyse-basic-ast/variant0 ?tag)
+ (return (list (annotated [::variant ?tag '()] [::&type/variant ?tag '()]))))
[::&parser/tuple ?elems]
(analyse-tuple analyse-ast ?elems)
@@ -996,6 +1000,11 @@
(defn analyse-ast [token]
;; (prn 'analyse-ast token)
(match token
+ [::&parser/form ([[::&parser/tag ?tag] & ?data] :seq)]
+ (exec [=data (do-all-m* (map analyse-ast ?data))
+ :let [_ (prn 'analyse-ast/variant+ ?tag '=data =data)]]
+ (return (list (annotated [::variant ?tag =data] [::&type/variant ?tag (map :type =data)]))))
+
[::&parser/form ([?fn & ?args] :seq)]
(try-all-m [(analyse-call analyse-ast ?fn ?args)
(analyse-basic-ast analyse-ast token)])