diff options
| author | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-04 22:20:38 +0530 |
|---|---|---|
| committer | Shagun Agrawal <agrawalshagun07@gmail.com> | 2024-08-04 22:20:38 +0530 |
| commit | c3fdb442e642ca50ad4dc6c942e4ebcb9cbaad3b (patch) | |
| tree | 5f6d826ee4ef4f492bc1fe88163000b52497b7e1 /src/cljcc/tacky.clj | |
| parent | e0de6ddf16a37435966e31a73b4425a0300dc1e6 (diff) | |
Add assembly generation for unary operators
Adding assembly generation
New opcodes, operands
Diffstat (limited to 'src/cljcc/tacky.clj')
| -rw-r--r-- | src/cljcc/tacky.clj | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/cljcc/tacky.clj b/src/cljcc/tacky.clj index e25c87f..4772766 100644 --- a/src/cljcc/tacky.clj +++ b/src/cljcc/tacky.clj @@ -61,9 +61,10 @@ (conj instructions (return-instruction val)))) (defn statement-transform [_ret-keyword exp] - (reverse (ret-instructions exp))) + {:instructions (reverse (ret-instructions exp))}) (defn tacky-generate [ast] + (reset! counter 0) (insta/transform {:statement statement-transform} ast)) (comment @@ -106,13 +107,11 @@ (pp/pprint (ret-instructions ex-ret)) - (def exprg - "int main(void) { + (def exprg + "int main(void) { return -(~(-8)); }") - (pp/pprint (parse "int main(void) {return 2;}")) - - (pp/pprint (parse exprg)) + (pp/pprint (parse "int main(void) {return 2;}")) - ,) + (pp/pprint (parse exprg))) |
