aboutsummaryrefslogtreecommitdiff
path: root/src/lux/analyser.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/lux/analyser.clj')
-rw-r--r--src/lux/analyser.clj115
1 files changed, 59 insertions, 56 deletions
diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj
index de6058f50..a9cd8670e 100644
--- a/src/lux/analyser.clj
+++ b/src/lux/analyser.clj
@@ -8,149 +8,150 @@
[type :as &type]
[macro :as &macro]
[host :as &host])
- (lux.analyser [base :as &]
+ (lux.analyser [base :as &&]
[lux :as &&lux]
[host :as &&host])))
;; [Utils]
(defn ^:private analyse-basic-ast [analyse-ast token]
+ (prn 'analyse-basic-ast token)
(match token
;; Standard special forms
- [::&parser/bool ?value]
- (return (list [::&/Expression [::bool ?value] [::&type/Data "java.lang.Boolean"]]))
+ [::&parser/Bool ?value]
+ (return (list [::&&/Expression [::&&/bool ?value] [::&type/Data "java.lang.Boolean"]]))
- [::&parser/int ?value]
- (return (list [::&/Expression [::int ?value] [::&type/Data "java.lang.Long"]]))
+ [::&parser/Int ?value]
+ (return (list [::&&/Expression [::&&/int ?value] [::&type/Data "java.lang.Long"]]))
- [::&parser/real ?value]
- (return (list [::&/Expression [::real ?value] [::&type/Data "java.lang.Double"]]))
+ [::&parser/Real ?value]
+ (return (list [::&&/Expression [::&&/real ?value] [::&type/Data "java.lang.Double"]]))
- [::&parser/char ?value]
- (return (list [::&/Expression [::char ?value] [::&type/Data "java.lang.Character"]]))
+ [::&parser/Char ?value]
+ (return (list [::&&/Expression [::&&/char ?value] [::&type/Data "java.lang.Character"]]))
- [::&parser/text ?value]
- (return (list [::&/Expression [::text ?value] [::&type/Data "java.lang.String"]]))
+ [::&parser/Text ?value]
+ (return (list [::&&/Expression [::&&/text ?value] [::&type/Data "java.lang.String"]]))
- [::&parser/tuple ?elems]
+ [::&parser/Tuple ?elems]
(&&lux/analyse-tuple analyse-ast ?elems)
- [::&parser/tag ?tag]
- (return (list [::&/Expression [::variant ?tag (list)] [::&type/Variant {?tag [::&type/Tuple (list)]}]]))
+ [::&parser/Tag ?tag]
+ (return (list [::&&/Expression [::&&/variant ?tag (list)] [::&type/Variant {?tag [::&type/Tuple (list)]}]]))
- [::&parser/ident ?ident]
+ [::&parser/Ident ?ident]
(&&lux/analyse-ident analyse-ast ?ident)
- [::&parser/form ([[::&parser/ident "case'"] ?variant & ?branches] :seq)]
+ [::&parser/Form ([[::&parser/Ident "case'"] ?variant & ?branches] :seq)]
(&&lux/analyse-case analyse-ast ?variant ?branches)
- [::&parser/form ([[::&parser/ident "lambda'"] [::&parser/ident ?self] [::&parser/ident ?arg] ?body] :seq)]
+ [::&parser/Form ([[::&parser/Ident "lambda'"] [::&parser/Ident ?self] [::&parser/Ident ?arg] ?body] :seq)]
(&&lux/analyse-lambda analyse-ast ?self ?arg ?body)
- [::&parser/form ([[::&parser/ident "def'"] [::&parser/ident ?name] ?value] :seq)]
+ [::&parser/Form ([[::&parser/Ident "def'"] [::&parser/Ident ?name] ?value] :seq)]
(&&lux/analyse-def analyse-ast ?name ?value)
- [::&parser/form ([[::&parser/ident "declare-macro"] [::&parser/ident ?ident]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "declare-macro"] [::&parser/Ident ?ident]] :seq)]
(&&lux/analyse-declare-macro ?ident)
- [::&parser/form ([[::&parser/ident "require"] [::&parser/text ?path]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "require"] [::&parser/Text ?path]] :seq)]
(&&lux/analyse-require analyse-ast ?path)
;; Host special forms
- [::&parser/form ([[::&parser/ident "exec"] & ?exprs] :seq)]
+ [::&parser/Form ([[::&parser/Ident "exec"] & ?exprs] :seq)]
(&&host/analyse-exec analyse-ast ?exprs)
;; Integer arithmetic
- [::&parser/form ([[::&parser/ident "jvm;iadd"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;iadd"] ?x ?y] :seq)]
(&&host/analyse-jvm-iadd analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;isub"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;isub"] ?x ?y] :seq)]
(&&host/analyse-jvm-isub analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;imul"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;imul"] ?x ?y] :seq)]
(&&host/analyse-jvm-imul analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;idiv"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;idiv"] ?x ?y] :seq)]
(&&host/analyse-jvm-idiv analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;irem"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;irem"] ?x ?y] :seq)]
(&&host/analyse-jvm-irem analyse-ast ?x ?y)
;; Long arithmetic
- [::&parser/form ([[::&parser/ident "jvm;ladd"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;ladd"] ?x ?y] :seq)]
(&&host/analyse-jvm-ladd analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;lsub"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;lsub"] ?x ?y] :seq)]
(&&host/analyse-jvm-lsub analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;lmul"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;lmul"] ?x ?y] :seq)]
(&&host/analyse-jvm-lmul analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;ldiv"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;ldiv"] ?x ?y] :seq)]
(&&host/analyse-jvm-ldiv analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;lrem"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;lrem"] ?x ?y] :seq)]
(&&host/analyse-jvm-lrem analyse-ast ?x ?y)
;; Float arithmetic
- [::&parser/form ([[::&parser/ident "jvm;fadd"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;fadd"] ?x ?y] :seq)]
(&&host/analyse-jvm-fadd analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;fsub"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;fsub"] ?x ?y] :seq)]
(&&host/analyse-jvm-fsub analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;fmul"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;fmul"] ?x ?y] :seq)]
(&&host/analyse-jvm-fmul analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;fdiv"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;fdiv"] ?x ?y] :seq)]
(&&host/analyse-jvm-fdiv analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;frem"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;frem"] ?x ?y] :seq)]
(&&host/analyse-jvm-frem analyse-ast ?x ?y)
;; Double arithmetic
- [::&parser/form ([[::&parser/ident "jvm;dadd"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;dadd"] ?x ?y] :seq)]
(&&host/analyse-jvm-dadd analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;dsub"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;dsub"] ?x ?y] :seq)]
(&&host/analyse-jvm-dsub analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;dmul"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;dmul"] ?x ?y] :seq)]
(&&host/analyse-jvm-dmul analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;ddiv"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;ddiv"] ?x ?y] :seq)]
(&&host/analyse-jvm-ddiv analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;drem"] ?x ?y] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;drem"] ?x ?y] :seq)]
(&&host/analyse-jvm-drem analyse-ast ?x ?y)
- [::&parser/form ([[::&parser/ident "jvm;getstatic"] [::&parser/ident ?class] [::&parser/ident ?field]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;getstatic"] [::&parser/Ident ?class] [::&parser/Ident ?field]] :seq)]
(&&host/analyse-jvm-getstatic analyse-ast ?class ?field)
- [::&parser/form ([[::&parser/ident "jvm;getfield"] [::&parser/ident ?class] [::&parser/ident ?field] ?object] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;getfield"] [::&parser/Ident ?class] [::&parser/Ident ?field] ?object] :seq)]
(&&host/analyse-jvm-getfield analyse-ast ?class ?field ?object)
- [::&parser/form ([[::&parser/ident "jvm;invokestatic"] [::&parser/ident ?class] [::&parser/text ?method] [::&parser/tuple ?classes] [::&parser/tuple ?args]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;invokestatic"] [::&parser/Ident ?class] [::&parser/Text ?method] [::&parser/Tuple ?classes] [::&parser/Tuple ?args]] :seq)]
(&&host/analyse-jvm-invokestatic analyse-ast ?class ?method ?classes ?args)
- [::&parser/form ([[::&parser/ident "jvm;invokevirtual"] [::&parser/ident ?class] [::&parser/text ?method] [::&parser/tuple ?classes] ?object [::&parser/tuple ?args]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;invokevirtual"] [::&parser/Ident ?class] [::&parser/Text ?method] [::&parser/Tuple ?classes] ?object [::&parser/Tuple ?args]] :seq)]
(&&host/analyse-jvm-invokevirtual analyse-ast ?class ?method ?classes ?object ?args)
- [::&parser/form ([[::&parser/ident "jvm;new"] [::&parser/ident ?class] [::&parser/tuple ?classes] [::&parser/tuple ?args]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;new"] [::&parser/Ident ?class] [::&parser/Tuple ?classes] [::&parser/Tuple ?args]] :seq)]
(&&host/analyse-jvm-new analyse-ast ?class ?classes ?args)
- [::&parser/form ([[::&parser/ident "jvm;new-array"] [::&parser/ident ?class] [::&parser/int ?length]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;new-array"] [::&parser/Ident ?class] [::&parser/Int ?length]] :seq)]
(&&host/analyse-jvm-new-array analyse-ast ?class ?length)
- [::&parser/form ([[::&parser/ident "jvm;aastore"] ?array [::&parser/int ?idx] ?elem] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;aastore"] ?array [::&parser/Int ?idx] ?elem] :seq)]
(&&host/analyse-jvm-aastore analyse-ast ?array ?idx ?elem)
- [::&parser/form ([[::&parser/ident "jvm;aaload"] ?array [::&parser/int ?idx]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;aaload"] ?array [::&parser/Int ?idx]] :seq)]
(&&host/analyse-jvm-aaload analyse-ast ?array ?idx)
- [::&parser/form ([[::&parser/ident "jvm;class"] [::&parser/ident ?name] [::&parser/ident ?super-class] [::&parser/tuple ?fields]] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;class"] [::&parser/Ident ?name] [::&parser/Ident ?super-class] [::&parser/Tuple ?fields]] :seq)]
(&&host/analyse-jvm-class analyse-ast ?name ?super-class ?fields)
- [::&parser/form ([[::&parser/ident "jvm;interface"] [::&parser/ident ?name] & ?members] :seq)]
+ [::&parser/Form ([[::&parser/Ident "jvm;interface"] [::&parser/Ident ?name] & ?members] :seq)]
(&&host/analyse-jvm-interface analyse-ast ?name ?members)
_
@@ -158,12 +159,13 @@
(defn ^:private analyse-ast [token]
(match token
- [::&parser/form ([[::&parser/tag ?tag] & ?data] :seq)]
+ [::&parser/Form ([[::&parser/Tag ?tag] & ?data] :seq)]
(exec [=data (mapcat-m analyse-ast ?data)
- =data-types (map-m &/expr-type =data)]
- (return (list [::&/Expression [::variant ?tag =data] [::&type/Variant {?tag [::&type/Tuple =data-types]}]])))
+ :let [_ (prn '=data =data)]
+ =data-types (map-m &&/expr-type =data)]
+ (return (list [::&&/Expression [::&&/variant ?tag =data] [::&type/Variant {?tag [::&type/Tuple =data-types]}]])))
- [::&parser/form ([?fn & ?args] :seq)]
+ [::&parser/Form ([?fn & ?args] :seq)]
(try-all-m [(&&lux/analyse-call analyse-ast ?fn ?args)
(analyse-basic-ast analyse-ast token)])
@@ -172,5 +174,6 @@
;; [Resources]
(def analyse
- (exec [asts &parser/parse]
+ (exec [asts &parser/parse
+ :let [_ (prn 'analyse/asts asts)]]
(mapcat-m analyse-ast asts)))