aboutsummaryrefslogtreecommitdiff
path: root/src/cljcc/tacky.clj
diff options
context:
space:
mode:
authorShagun Agrawal <agrawalshagun07@gmail.com>2024-10-28 23:50:46 +0530
committerShagun Agrawal <agrawalshagun07@gmail.com>2024-10-28 23:50:46 +0530
commit40da421300b14e4766718984e0787550aadb9319 (patch)
treef03f048efcf21edce531b6b4b3eadc1896fa5d23 /src/cljcc/tacky.clj
parentdf99cd726207679be89917d7888537c6bb84665e (diff)
Add assembly instruction step for functions
Diffstat (limited to 'src/cljcc/tacky.clj')
-rw-r--r--src/cljcc/tacky.clj15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/cljcc/tacky.clj b/src/cljcc/tacky.clj
index 0741fe2..5451f78 100644
--- a/src/cljcc/tacky.clj
+++ b/src/cljcc/tacky.clj
@@ -13,7 +13,7 @@
{:type :variable
:value (u/create-identifier! (str identifier))}))
-(defn- parsed-var->tacky-var [v]
+(defn parsed-var->tacky-var [v]
{:type :variable
:value (:identifier v)})
@@ -366,14 +366,6 @@
:declaration (declaration->tacky-instruction item)
(throw (ex-info "Tacky error. Invalid block item." {:item item}))))
-(defn- function-body->tacky-instructions [body]
- (let [v (->> body
- (remove nil?)
- (map block-item->tacky-instruction)
- flatten
- (remove nil?))]
- (conj (vec v) (return-instruction (constant 0)))))
-
(defn- function-definition->tacky-function [function-definition]
(let [add-return (fn [xs] (conj (vec xs) (return-instruction (constant 0))))
instructions (->> function-definition
@@ -402,7 +394,6 @@
(comment
- (pp/pprint
(tacky-from-src
"
int foo(int a) {
@@ -411,10 +402,10 @@ return a + 1;
int main (void) {
int y = 5;
-int x = foo(y + 10);
+int x = foo(10);
return x;
-}"))
+}")
(pp/pprint
(tacky-generate