aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/analyze
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-12-02 20:58:31 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-12-02 20:58:31 +0530
commitfa049cc22c6c7b64b51e6e10b33a259fa58945d7 (patch)
tree20806700ac0e751fa154df249be0ee87cbb4bb76 /src/cljcc/analyze
parent70314ca6f691ea1f547f09d3044a7f2b2a684289 (diff)
Refactor schema to separate file
Diffstat (limited to 'src/cljcc/analyze')
-rw-r--r--src/cljcc/analyze/resolve.clj7
-rw-r--r--src/cljcc/analyze/typecheck.clj71
2 files changed, 8 insertions, 70 deletions
diff --git a/src/cljcc/analyze/resolve.clj b/src/cljcc/analyze/resolve.clj
index b633405..9250e49 100644
--- a/src/cljcc/analyze/resolve.clj
+++ b/src/cljcc/analyze/resolve.clj
@@ -2,6 +2,7 @@
(:require [cljcc.exception :as exc]
[cljcc.parser :as p]
[malli.dev.pretty :as pretty]
+ [cljcc.schema :as s]
[cljcc.util :as util]
[malli.core :as m]))
@@ -271,8 +272,8 @@
;; Program is list of block items, which are themselves just blocks.
(defn resolve-program [program]
(let [res (:block (resolve-block program))
- _ (m/coerce p/Program res)]
- res))
+ _ (m/coerce s/Program res)]
+ res))
(comment
@@ -290,7 +291,7 @@
resolve-program)
(pretty/explain
- p/Program
+ s/Program
(-> file-path
slurp
p/parse-from-src
diff --git a/src/cljcc/analyze/typecheck.clj b/src/cljcc/analyze/typecheck.clj
index 001c618..7f8134a 100644
--- a/src/cljcc/analyze/typecheck.clj
+++ b/src/cljcc/analyze/typecheck.clj
@@ -3,76 +3,13 @@
[malli.dev.pretty :as pretty]
[cljcc.parser :as p]
[cljcc.token :as t]
+ [cljcc.schema :as s]
[cljcc.analyze.resolve :as r]
[cljcc.analyze.label-loops :as l]
[cljcc.exception :as exc]))
(declare typecheck-block typecheck-declaration to-static-init)
-(def FunAttribute
- [:map
- [:type [:= :fun]]
- [:defined? boolean?]
- [:global? boolean?]])
-
-(def LocalAttribute
- [:map
- [:type [:= :local]]])
-
-(def NoInitializer
- [:map
- [:type [:= :no-initializer]]])
-
-(def Tentative
- [:map
- [:type [:= :tentative]]])
-
-(def IntInit
- [:map
- [:type [:= :int-init]]
- [:value int?]])
-
-(def LongInit
- [:map
- [:type [:= :long-init]]
- [:value int?]])
-
-(def Initial
- [:map
- [:type [:= :initial]]
- [:static-init [:or IntInit LongInit]]])
-
-(def InitialValue
- [:or
- NoInitializer
- Tentative
- Initial])
-
-(def StaticAttribute
- [:map
- [:type [:= :static]]
- [:global? boolean?]
- [:initial-value #'InitialValue]])
-
-(def Attribute
- [:multi {:dispatch :type}
- [:fun #'FunAttribute]
- [:static #'StaticAttribute]
- [:local #'LocalAttribute]])
-
-(def Symbol
- [:map
- [:type #'p/Type]
- [:attribute #'Attribute]])
-
-(def SymbolMap
- [:map-of string? #'Symbol])
-
-(def TypecheckedOut
- [:map
- [:ident->symbol #'SymbolMap]
- [:program p/Program]])
-
(defn- create-symbol [type attribute]
{:type type
:attribute attribute})
@@ -535,8 +472,8 @@
(let [v (typecheck-program program)
program (:program v)
m (dissoc (:ident->symbol v) :at-top-level)
- _ (m/coerce p/Program program)
- _ (m/coerce SymbolMap m)]
+ _ (m/coerce s/Program program)
+ _ (m/coerce s/SymbolMap m)]
{:program program
:ident->symbol m}))
@@ -558,7 +495,7 @@
typecheck)
(pretty/explain
- #'TypecheckedOut
+ s/TypecheckedOut
(-> file-path
slurp
p/parse-from-src