diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-11-10 00:00:45 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-11-10 00:00:45 +0530 |
| commit | e7687ad8371977b827f8f3be8371e8beabee3d0c (patch) | |
| tree | d1154680de583f966ab0c0e66e4b516a727e08d5 /src/cljcc/analyzer.clj | |
| parent | 7140310b4cc538d12c1d1285ce96792aa619adcf (diff) | |
Add assembly emission for storage specifiers
Pass chapter 10, finish book part 1
Fixed bug by threading symbol map through all statements
Fixed emitting tacky instructions for variables which are supposed to be
initialized in static section
Diffstat (limited to 'src/cljcc/analyzer.clj')
| -rw-r--r-- | src/cljcc/analyzer.clj | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/cljcc/analyzer.clj b/src/cljcc/analyzer.clj index 31039db..0d8a763 100644 --- a/src/cljcc/analyzer.clj +++ b/src/cljcc/analyzer.clj @@ -525,7 +525,6 @@ (typecheck-declaration for-init ident->symbol) (typecheck-optional-expression for-init ident->symbol))) -;; TODO: typechecking must thread through all recursive typecheck statement (defn- typecheck-statement [{:keys [statement-type] :as s} ident->symbol] (condp = statement-type :return (do @@ -537,41 +536,40 @@ {:statement s :ident->symbol ident->symbol}) :if (if (:else-statement s) - (do - (typecheck-exp (:condition s) ident->symbol) - (typecheck-statement (:then-statement s) ident->symbol) - (typecheck-statement (:else-statement s) ident->symbol) + (let + [_ (typecheck-exp (:condition s) ident->symbol) + {i->s :ident->symbol} (typecheck-statement (:then-statement s) ident->symbol) + {i->s :ident->symbol} (typecheck-statement (:else-statement s) i->s)] {:statement s - :ident->symbol ident->symbol}) - (do - (typecheck-exp (:condition s) ident->symbol) - (typecheck-statement (:then-statement s) ident->symbol) + :ident->symbol i->s}) + (let + [_ (typecheck-exp (:condition s) ident->symbol) + {i->s :ident->symbol} (typecheck-statement (:then-statement s) ident->symbol)] {:statement s - :ident->symbol ident->symbol})) + :ident->symbol i->s})) :break {:statement s :ident->symbol ident->symbol} :continue {:statement s :ident->symbol ident->symbol} - :while (do - (typecheck-exp (:condition s) ident->symbol) - (typecheck-statement (:body s) ident->symbol) + :while (let + [_ (typecheck-exp (:condition s) ident->symbol) + {i->s :ident->symbol} (typecheck-statement (:body s) ident->symbol)] {:statement s - :ident->symbol ident->symbol}) - :do-while (do - (typecheck-exp (:condition s) ident->symbol) - (typecheck-statement (:body s) ident->symbol) + :ident->symbol i->s}) + :do-while (let + [_ (typecheck-exp (:condition s) ident->symbol) + {i->s :ident->symbol} (typecheck-statement (:body s) ident->symbol)] {:statement s - :ident->symbol ident->symbol}) + :ident->symbol i->s}) :for (let [f-init (typecheck-for-init (:init s) ident->symbol) updated-symbols (if (:declaration f-init) (:ident->symbol f-init) ident->symbol) _ (typecheck-optional-expression (:condition s) updated-symbols) _ (typecheck-optional-expression (:post s) updated-symbols) - _ (typecheck-statement (:body s) updated-symbols)] + {i->s :ident->symbol} (typecheck-statement (:body s) updated-symbols)] {:statement s - :ident->symbol ident->symbol}) - ;; TODO: Standardize returning map from statements + :ident->symbol i->s}) :compound (let [v (typecheck-block (:block s) ident->symbol)] {:statement s :ident->symbol (:ident->symbol v)}) @@ -637,6 +635,7 @@ int static y = 10; extern int x = 0; int main(void) { +int z = 100; return 2; } ") |
