aboutsummaryrefslogtreecommitdiffstats
path: root/src/lift.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lift.cpp')
-rw-r--r--src/lift.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/lift.cpp b/src/lift.cpp
index df34d7a..04bf61b 100644
--- a/src/lift.cpp
+++ b/src/lift.cpp
@@ -28,7 +28,7 @@
using namespace std;
static AST*
-lift_symbol(CEnv& cenv, Code& code, ASymbol* sym) throw()
+lift_symbol(CEnv& cenv, Code& code, const ASymbol* sym) throw()
{
const std::string& cppstr = sym->cppstr;
if (!cenv.liftStack.empty() && cppstr == cenv.name(cenv.liftStack.top().fn)) {
@@ -45,7 +45,7 @@ lift_symbol(CEnv& cenv, Code& code, ASymbol* sym) throw()
new ALiteral<int32_t>(T_INT32, index, Cursor()),
NULL);
} else {
- return sym;
+ return const_cast<ASymbol*>(sym);
}
}
@@ -64,16 +64,18 @@ lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw()
cenv.push();
const AType* type = cenv.type(fn);
AType::const_iterator tp = type->prot()->begin();
- AType* implProtT = new AType(*type->prot()->as<const AType*>());
+ AType* implProtT = new AType(*type->prot()->as_type());
ATuple::iterator ip = implProtT->begin();
for (ATuple::const_iterator p = fn->prot()->begin(); p != fn->prot()->end(); ++p) {
- const AType* paramType = (*tp++)->as<const AType*>();
+ const AType* paramType = (*tp++)->as_type();
if (paramType->kind == AType::EXPR && *paramType->head() == *cenv.tenv.Fn) {
AType* fnType = new AType(*paramType);
- fnType->set_prot(new AType(const_cast<AType*>(cenv.tenv.var()), fnType->prot()->as<AType*>(), Cursor()));
+ fnType->set_prot(new AType(const_cast<AType*>(cenv.tenv.var()),
+ const_cast<AType*>(fnType->prot()->as_type()),
+ Cursor()));
paramType = tup<const AType>((*p)->loc, cenv.tenv.Tup, fnType, NULL);
}
- cenv.def((*p)->as<const ASymbol*>(), *p, paramType, NULL);
+ cenv.def((*p)->as_symbol(), *p, paramType, NULL);
*ip++ = new AType(*paramType);
}
@@ -111,7 +113,7 @@ lift_fn(CEnv& cenv, Code& code, ATuple* fn) throw()
const CEnv::FreeVars& freeVars = cenv.liftStack.top();
for (CEnv::FreeVars::const_iterator i = freeVars.begin(); i != freeVars.end(); ++i) {
- cons.push_back(*i);
+ cons.push_back(const_cast<ASymbol*>(*i));
tupT.push_back(const_cast<AType*>(cenv.type(*i)));
consT.push_back(const_cast<AType*>(cenv.type(*i)));
}
@@ -143,7 +145,7 @@ lift_call(CEnv& cenv, Code& code, ATuple* call) throw()
const AType* copyT = NULL;
- ASymbol* sym = call->head()->to<ASymbol*>();
+ const ASymbol* sym = call->head()->to_symbol();
if (sym && !cenv.liftStack.empty() && sym->cppstr == cenv.name(cenv.liftStack.top().fn)) {
/* Recursive call to innermost function, call implementation directly,
* reusing the current "_me" closure parameter (no cons or .).
@@ -157,11 +159,11 @@ lift_call(CEnv& cenv, Code& code, ATuple* call) throw()
* closure as the first parameter:
* (_impl (Fn _impl ...) ...)
*/
- ATuple* closure = copy.head->list_ref(0)->as<ATuple*>();
- ASymbol* implSym = closure->list_ref(1)->as<ASymbol*>();
+ ATuple* closure = copy.head->list_ref(0)->as_tuple();
+ ASymbol* implSym = const_cast<ASymbol*>(closure->list_ref(1)->as_symbol());
const AType* implT = cenv.type(cenv.resolve(implSym));
copy.push_front(implSym);
- copyT = implT->list_ref(2)->as<const AType*>();
+ copyT = implT->list_ref(2)->as_type();
} else {
// Call to a closure, prepend code to access implementation function
ATuple* getFn = tup<ATuple>(call->loc, cenv.penv.sym("."),
@@ -169,10 +171,10 @@ lift_call(CEnv& cenv, Code& code, ATuple* call) throw()
new ALiteral<int32_t>(T_INT32, 0, Cursor()), NULL);
const AType* calleeT = cenv.type(copy.head->head());
assert(**calleeT->begin() == *cenv.tenv.Tup);
- const AType* implT = calleeT->list_ref(1)->as<const AType*>();
+ const AType* implT = calleeT->list_ref(1)->as_type();
copy.push_front(getFn);
cenv.setType(getFn, implT);
- copyT = implT->list_ref(2)->as<const AType*>();
+ copyT = implT->list_ref(2)->as_type();
}
cenv.setType(copy, copyT);
@@ -183,13 +185,13 @@ static AST*
lift_def(CEnv& cenv, Code& code, ATuple* def) throw()
{
// Define stub first for recursion
- const ASymbol* const sym = def->list_ref(1)->as<const ASymbol*>();
+ const ASymbol* const sym = def->list_ref(1)->as_symbol();
AST* const body = def->list_ref(2);
cenv.def(sym, body, cenv.type(body), NULL);
if (is_form(body, "fn"))
- cenv.setName(body->as<const ATuple*>(), sym->str());
+ cenv.setName(body->as_tuple(), sym->str());
- assert(def->list_ref(1)->to<const ASymbol*>());
+ assert(def->list_ref(1)->to_symbol());
List<ATuple, AST> copy;
copy.push_back(def->head());
copy.push_back(resp_lift(cenv, code, def->list_ref(1)));
@@ -201,7 +203,7 @@ lift_def(CEnv& cenv, Code& code, ATuple* def) throw()
if (copy.head->list_ref(1) == copy.head->list_ref(2))
return NULL; // Definition created by lift_fn when body was lifted
- cenv.def(copy.head->list_ref(1)->as<const ASymbol*>(),
+ cenv.def(copy.head->list_ref(1)->as_symbol(),
copy.head->list_ref(2),
cenv.type(copy.head->list_ref(2)),
NULL);
@@ -225,13 +227,13 @@ lift_builtin_call(CEnv& cenv, Code& code, ATuple* call) throw()
AST*
resp_lift(CEnv& cenv, Code& code, AST* ast) throw()
{
- ASymbol* const sym = ast->to<ASymbol*>();
+ const ASymbol* const sym = ast->to_symbol();
if (sym)
return lift_symbol(cenv, code, sym);
- ATuple* const call = ast->to<ATuple*>();
+ ATuple* const call = ast->to_tuple();
if (call) {
- const ASymbol* const sym = call->head()->to<const ASymbol*>();
+ const ASymbol* const sym = call->head()->to_symbol();
const std::string form = sym ? sym->cppstr : "";
if (is_primitive(cenv.penv, call))
return lift_builtin_call(cenv, code, call);