Skip to content
Permalink
Browse files

Rework codegen to put all definitions in #main

  • Loading branch information
jeaye committed Dec 28, 2015
1 parent dc42bf8 commit fcdf4de0da307808da24df29b50d7c1fb31a437f
Showing with 16 additions and 27 deletions.
  1. +1 −4 .color_coded
  2. +2 −1 bin/jank
  3. +13 −22 src/jank/codegen/c++.clj
@@ -1,5 +1,2 @@
-std=c++1y
-Itest/include
-Iinclude
-Ilib/jtl/include
-Ilib/jest/include
-Ibackend/c++/include
@@ -10,8 +10,9 @@ lein run $@ > $tmp/jank-generated.hpp 2>&1
ret=$?
if [ $ret -eq 0 ];
then
set -e
g++ -std=c++14 -I$here/../backend/c++/include -I$tmp $here/../backend/c++/src/main.cpp
ret=$?
set +e
else
cat $tmp/jank-generated.hpp
fi
@@ -33,13 +33,10 @@
"}"))

(defmethod codegen-impl :binding-definition [current]
; Special case for function definitions
(if (= (first (nth current 2)) :lambda-definition)
(codegen-impl (update-in current [0] (fn [x] :function-definition)))
(str "auto "
(codegen-impl (second current))
"="
(codegen-impl (nth current 2)))))
(str "auto "
(codegen-impl (second current))
"="
(codegen-impl (nth current 2))))

(defmethod codegen-impl :function-call [current]
(str (codegen-impl (second current)) ; Name
@@ -110,18 +107,12 @@
(codegen-assert false (str "no codegen for '" current "'")))

(defn codegen [ast]
(let [[definitions expressions] (util/partition-definitions (:cells ast))]
; Generate all top-level definitions
(doseq [current definitions]
(util/print-statement (util/end-statement (codegen-impl current))))

; Build the main function
(util/print-statement
(codegen-impl
[:binding-definition
[:identifier "#main"]
(apply (partial vector
:lambda-definition
[:argument-list]
[:return-list])
expressions)]))))
(util/print-statement
(codegen-impl
[:function-definition
[:identifier "#main"]
(apply (partial vector
:lambda-definition
[:argument-list]
[:return-list])
(:cells ast))])))

0 comments on commit fcdf4de

Please sign in to comment.
You can’t perform that action at this time.