aboutsummaryrefslogtreecommitdiffstats
path: root/cps.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-25 19:21:31 +0000
committerDavid Robillard <d@drobilla.net>2009-06-25 19:21:31 +0000
commitc465702dbeb1ea63a356146403eee668fb59371d (patch)
tree55b4b2e4f56634fd3fae61057472768cc629be2b /cps.cpp
parent29b44e4e428a4b036ba6ffd3a79c65c7da24324e (diff)
downloadresp-c465702dbeb1ea63a356146403eee668fb59371d.tar.gz
resp-c465702dbeb1ea63a356146403eee668fb59371d.tar.bz2
resp-c465702dbeb1ea63a356146403eee668fb59371d.zip
Stubs for CPS conversion.
git-svn-id: http://svn.drobilla.net/resp/tuplr@148 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'cps.cpp')
-rw-r--r--cps.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/cps.cpp b/cps.cpp
new file mode 100644
index 0000000..60f500d
--- /dev/null
+++ b/cps.cpp
@@ -0,0 +1,86 @@
+/* Tuplr Type Inferencing
+ * Copyright (C) 2008-2009 David Robillard <dave@drobilla.net>
+ *
+ * Tuplr is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Affero General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * Tuplr is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
+ * Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Tuplr. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <set>
+#include "tuplr.hpp"
+
+/***************************************************************************
+ * CPS Conversion *
+ ***************************************************************************/
+
+/** (cps x) => (cont x) */
+AST*
+AST::cps(TEnv& tenv, AST* cont)
+{
+ return new ACall(loc, cont, this, 0);
+}
+
+AST*
+ATuple::cps(TEnv& tenv, AST* cont)
+{
+ ATuple* copy = new ATuple(loc, NULL);
+ FOREACH(const_iterator, p, *this)
+ copy->push_back((*p)->cps(tenv, cont));
+ return copy;
+}
+
+/** (cps (fn (a ...) body ...)) => */
+AST*
+AFn::cps(TEnv& tenv, AST* cont)
+{
+ AFn* copy = new AFn(loc, tenv.penv.sym("fn"), prot());
+ const_iterator p = begin();
+ ++(++p);
+ for (; p != end(); ++p)
+ copy->push_back((*p)->cps(tenv, cont));
+ return copy;
+ return ATuple::cps(tenv, cont);
+}
+
+/** (cps (f a b ...)) => (a (fn (x) (b (fn (y) ... (cont (f x y ...)) */
+AST*
+ACall::cps(TEnv& tenv, AST* cont)
+{
+ return new ACall(loc, cont, this, 0);
+}
+
+/** (cps (def x y)) => (y (fn (x) (cont))) */
+AST*
+ADef::cps(TEnv& tenv, AST* cont)
+{
+ ADef* copy = new ADef(loc,
+ ATuple(loc, tenv.penv.sym("def"), sym(), at(2)->cps(tenv, cont), 0));
+ return copy;
+ /*
+ ASymbol* fnSym = tenv.penv.sym("deff");
+ AFn* defFn = new AFn(loc, tenv.penv.sym("def"),
+ new ATuple(at(1)->loc, sym(), new ACall(loc, cont, this)));
+ ACall* defCall = new ACall(loc, at(2)->cps(tenv, defFn), 0);
+ */
+}
+
+/** (cps (if c t ... e)) => */
+AST*
+AIf::cps(TEnv& tenv, AST* cont)
+{
+ AFn* contFn = new AFn(loc, tenv.penv.sym("if0"),
+ new ATuple(at(1)->loc, cont, 0));
+ //ACall* contCall = new ACall(loc, cont, this, 0);
+ ACall* condCall = new ACall(loc, contFn, 0);
+ return condCall;
+}
+