From c465702dbeb1ea63a356146403eee668fb59371d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 25 Jun 2009 19:21:31 +0000 Subject: Stubs for CPS conversion. git-svn-id: http://svn.drobilla.net/resp/tuplr@148 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr.hpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'tuplr.hpp') diff --git a/tuplr.hpp b/tuplr.hpp index 3c6bc81..fb16fe7 100644 --- a/tuplr.hpp +++ b/tuplr.hpp @@ -196,6 +196,7 @@ struct AST : public Object { virtual bool operator==(const AST& o) const = 0; virtual bool contains(const AST* child) const { return false; } virtual void constrain(TEnv& tenv, Constraints& c) const {} + virtual AST* cps(TEnv& tenv, AST* cont); virtual void lift(CEnv& cenv) {} virtual CValue compile(CEnv& cenv) = 0; string str() const { ostringstream ss; ss << this; return ss.str(); } @@ -254,7 +255,6 @@ struct ATuple : public AST, public vector { return false; return true; } - void lift(CEnv& cenv) { FOREACH(iterator, t, *this) (*t)->lift(cenv); } bool contains(AST* child) const { if (*this == *child) return true; FOREACH(const_iterator, p, *this) @@ -262,7 +262,10 @@ struct ATuple : public AST, public vector { return true; return false; } - void constrain(TEnv& tenv, Constraints& c) const; + void constrain(TEnv& tenv, Constraints& c) const; + AST* cps(TEnv& tenv, AST* cont); + void lift(CEnv& cenv) { FOREACH(iterator, t, *this) (*t)->lift(cenv); } + CValue compile(CEnv& cenv) { throw Error(loc, "tuple compiled"); } }; @@ -340,13 +343,13 @@ struct Subst : public map { } }; - -/// Closure (first-class function with captured lexical bindings) +/// Fn (first-class function with captured lexical bindings) struct AFn : public ATuple { AFn(Cursor c, ASymbol* fn, ATuple* p, const string& n="") : ATuple(c, fn, p, NULL), name(n) {} bool operator==(const AST& rhs) const { return this == &rhs; } void constrain(TEnv& tenv, Constraints& c) const; + AST* cps(TEnv& tenv, AST* cont); void lift(CEnv& cenv); void liftCall(CEnv& cenv, const AType& argsT); CValue compile(CEnv& cenv); @@ -368,7 +371,19 @@ struct AFn : public ATuple { /// Function call/application, e.g. "(func arg1 arg2)" struct ACall : public ATuple { ACall(const SExp& e, const ATuple& t) : ATuple(e.loc, t) {} + ACall(Cursor c, const ATuple& code) : ATuple(c, code) {} + ACall(Cursor c, AST* fn, AST* arg, ...) : ATuple(c) { + push_back(fn); + if (!arg) return; + va_list args; va_start(args, arg); + if (arg) + push_back(arg); + for (AST* a = va_arg(args, AST*); a; a = va_arg(args, AST*)) + push_back(a); + va_end(args); + } void constrain(TEnv& tenv, Constraints& c) const; + AST* cps(TEnv& tenv, AST* cont); void lift(CEnv& cenv); CValue compile(CEnv& cenv); }; @@ -376,6 +391,7 @@ struct ACall : public ATuple { /// Definition special form, e.g. "(def x 2)" struct ADef : public ACall { ADef(const SExp& e, const ATuple& t) : ACall(e, t) {} + ADef(Cursor c, const ATuple& code) : ACall(c, code) {} ASymbol* sym() const { ASymbol* sym = at(1)->to(); if (!sym) { @@ -386,6 +402,7 @@ struct ADef : public ACall { return sym; } void constrain(TEnv& tenv, Constraints& c) const; + AST* cps(TEnv& tenv, AST* cont); void lift(CEnv& cenv); CValue compile(CEnv& cenv); }; @@ -394,6 +411,7 @@ struct ADef : public ACall { struct AIf : public ACall { AIf(const SExp& e, const ATuple& t) : ACall(e, t) {} void constrain(TEnv& tenv, Constraints& c) const; + AST* cps(TEnv& tenv, AST* cont); CValue compile(CEnv& cenv); }; -- cgit v1.2.1