aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-27 22:48:00 +0000
committerDavid Robillard <d@drobilla.net>2010-12-27 22:48:00 +0000
commitcce4f16e87870eae8a1c3f430c9617cefd55fe54 (patch)
tree79dbeec5b3368045b36719b63d24ea1bc9ef150f /src
parent1a8107c0156e1615fbdbe009f30d8e66cb280c03 (diff)
downloadresp-cce4f16e87870eae8a1c3f430c9617cefd55fe54.tar.gz
resp-cce4f16e87870eae8a1c3f430c9617cefd55fe54.tar.bz2
resp-cce4f16e87870eae8a1c3f430c9617cefd55fe54.zip
Remove weird __tag_is form by adding a T_LITSYM type and using = operator.
Step towards having first class symbols... git-svn-id: http://svn.drobilla.net/resp/resp@362 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src')
-rw-r--r--src/c.cpp7
-rw-r--r--src/compile.cpp29
-rw-r--r--src/constrain.cpp1
-rw-r--r--src/expand.cpp2
-rw-r--r--src/lift.cpp2
-rw-r--r--src/llvm.cpp10
-rw-r--r--src/pprint.cpp1
-rw-r--r--src/resp.hpp9
-rw-r--r--src/simplify.cpp14
9 files changed, 30 insertions, 45 deletions
diff --git a/src/c.cpp b/src/c.cpp
index d139c35..66a4963 100644
--- a/src/c.cpp
+++ b/src/c.cpp
@@ -52,7 +52,6 @@ struct CEngine : public Engine {
CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t);
CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v);
CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse);
- CVal compileIsA(CEnv& cenv, CVal rtti, CVal tag);
CVal compileLiteral(CEnv& cenv, const AST* lit);
CVal compilePrimitive(CEnv& cenv, const ATuple* prim);
CVal compileString(CEnv& cenv, const char* str);
@@ -265,12 +264,6 @@ CEngine::compileIf(CEnv& cenv, const ATuple* aif)
#endif
CVal
-CEngine::compileIsA(CEnv& cenv, CVal rtti, CVal tag)
-{
- return NULL;
-}
-
-CVal
CEngine::compilePrimitive(CEnv& cenv, const ATuple* prim)
{
ATuple::const_iterator i = prim->begin();
diff --git a/src/compile.cpp b/src/compile.cpp
index 4fed182..393084e 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -37,18 +37,23 @@ compile_symbol(CEnv& cenv, const ASymbol* sym) throw()
}
static CVal
-compile_type(CEnv& cenv, const AST* type) throw()
+compile_literal_symbol(CEnv& cenv, const ASymbol* sym) throw()
{
- const ASymbol* sym = type->as_tuple()->head()->as_symbol();
- CVal* existing = cenv.vals.ref(sym);
+ CVal* existing = cenv.vals.ref(sym);
if (existing) {
return *existing;
} else {
- CVal compiled = cenv.engine()->compileString(
- cenv, (string("__T_") + type->as_tuple()->head()->str()).c_str());
+ CVal compiled = cenv.engine()->compileString(cenv, (string("__T_") + sym->sym()).c_str());
cenv.vals.def(sym, compiled);
return compiled;
}
+
+}
+
+static CVal
+compile_type(CEnv& cenv, const AST* type) throw()
+{
+ return compile_literal_symbol(cenv, type->as_tuple()->head()->as_symbol());
}
static CVal
@@ -142,16 +147,6 @@ compile_if(CEnv& cenv, const ATuple* aif) throw()
}
static CVal
-compile_tag_is(CEnv& cenv, const ATuple* call) throw()
-{
- const AST* lhs = call->list_ref(1);
- const ASymbol* tag = call->list_ref(2)->as_symbol();
- const ATuple* patT = new ATuple(tag, 0, Cursor());
-
- return cenv.engine()->compileIsA(cenv, resp_compile(cenv, lhs), compile_type(cenv, patT));
-}
-
-static CVal
compile_call(CEnv& cenv, const ATuple* call) throw()
{
CFunc f = resp_compile(cenv, call->head());
@@ -181,6 +176,8 @@ resp_compile(CEnv& cenv, const AST* ast) throw()
return cenv.engine()->compileString(cenv, ((AString*)ast)->cppstr.c_str());
case T_SYMBOL:
return compile_symbol(cenv, ast->as_symbol());
+ case T_LITSYM:
+ return compile_literal_symbol(cenv, (ASymbol*)ast);
case T_TUPLE:
{
const ATuple* const call = ast->as_tuple();
@@ -202,8 +199,6 @@ resp_compile(CEnv& cenv, const AST* ast) throw()
return compile_fn(cenv, call);
else if (form == "if")
return compile_if(cenv, call);
- else if (form == "__tag_is")
- return compile_tag_is(cenv, call);
else
return compile_call(cenv, call);
}
diff --git a/src/constrain.cpp b/src/constrain.cpp
index 39a0287..4bd6c08 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -394,6 +394,7 @@ resp_constrain(TEnv& tenv, Constraints& c, const AST* ast) throw(Error)
c.constrain(tenv, ast, tenv.named("String"));
break;
case T_SYMBOL:
+ case T_LITSYM:
constrain_symbol(tenv, c, ast->as_symbol());
break;
case T_TUPLE:
diff --git a/src/expand.cpp b/src/expand.cpp
index 020410e..eb508f1 100644
--- a/src/expand.cpp
+++ b/src/expand.cpp
@@ -113,7 +113,7 @@ initLang(PEnv& penv, TEnv& tenv)
{
// Types
const char* types[] = {
- "Bool", "Float", "Int", "Nothing", "Quote", "String", 0 };
+ "Bool", "Float", "Int", "Nothing", "Quote", "String", "Symbol", 0 };
for (const char** t = types; *t; ++t) {
const ASymbol* sym = penv.sym(*t);
tenv.def(sym, sym); // FIXME: define to NULL?
diff --git a/src/lift.cpp b/src/lift.cpp
index 222cd09..201d40f 100644
--- a/src/lift.cpp
+++ b/src/lift.cpp
@@ -271,8 +271,6 @@ resp_lift(CEnv& cenv, Code& code, const AST* ast) throw()
return lift_fn(cenv, code, call);
else if (form == "if")
return lift_args(cenv, code, call);
- else if (form == "__tag_is")
- return call;
else
return lift_call(cenv, code, call);
}
diff --git a/src/llvm.cpp b/src/llvm.cpp
index 6ef25bb..f6874d7 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -67,7 +67,6 @@ struct LLVMEngine : public Engine {
CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t);
CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v);
CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse);
- CVal compileIsA(CEnv& cenv, CVal rtti, CVal tag);
CVal compileLiteral(CEnv& cenv, const AST* lit);
CVal compilePrimitive(CEnv& cenv, const ATuple* prim);
CVal compileString(CEnv& cenv, const char* str);
@@ -365,15 +364,6 @@ LLVMEngine::compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* a
}
CVal
-LLVMEngine::compileIsA(CEnv& cenv, CVal rtti, CVal tag)
-{
- LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
- Value* typeV = llVal(tag);
-
- return engine->builder.CreateICmp(CmpInst::ICMP_EQ, llVal(rtti), typeV);
-}
-
-CVal
LLVMEngine::compilePrimitive(CEnv& cenv, const ATuple* prim)
{
ATuple::const_iterator i = prim->iter_at(1);
diff --git a/src/pprint.cpp b/src/pprint.cpp
index a932065..ca2ee92 100644
--- a/src/pprint.cpp
+++ b/src/pprint.cpp
@@ -186,6 +186,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types)
case T_STRING:
return out << '"' << ((const AString*)ast)->cppstr << '"';
case T_SYMBOL:
+ case T_LITSYM:
return out << ((const ASymbol*)ast)->sym();
}
diff --git a/src/resp.hpp b/src/resp.hpp
index f6e65ea..3c949a0 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -89,8 +89,9 @@ enum Tag {
T_INT32 = 8,
T_STRING = 10,
T_SYMBOL = 12,
- T_TUPLE = 14,
- T_TVAR = 16
+ T_LITSYM = 14,
+ T_TUPLE = 16,
+ T_TVAR = 18
};
/// Garbage collector
@@ -409,6 +410,7 @@ AST::operator==(const AST& rhs) const
case T_STRING:
return ((AString*)this)->cppstr == ((AString*)&rhs)->cppstr;
case T_SYMBOL:
+ case T_LITSYM:
return ((ASymbol*)this)->sym() == ((ASymbol*)&rhs)->sym(); // interned
case T_UNKNOWN:
return this == &rhs;
@@ -658,7 +660,6 @@ struct Engine {
virtual CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t) = 0;
virtual CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v) = 0;
virtual CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse) = 0;
- virtual CVal compileIsA(CEnv& cenv, CVal rtti, CVal tag) = 0;
virtual CVal compileLiteral(CEnv& cenv, const AST* lit) = 0;
virtual CVal compilePrimitive(CEnv& cenv, const ATuple* prim) = 0;
virtual CVal compileString(CEnv& cenv, const char* str) = 0;
@@ -721,7 +722,7 @@ struct CEnv {
return rec ? *rec : ast;
}
void setType(const AST* ast, const AST* type) {
- assert(!ast->to_symbol());
+ //assert(!ast->to_symbol());
const AST* tvar = tenv.var();
tenv.vars.insert(make_pair(ast, tvar));
tsubst.add(tvar, type);
diff --git a/src/simplify.cpp b/src/simplify.cpp
index 715202a..397c2b7 100644
--- a/src/simplify.cpp
+++ b/src/simplify.cpp
@@ -63,10 +63,10 @@ simplify_match(CEnv& cenv, const ATuple* match) throw()
tval.push_back(resp_simplify(cenv, match->list_ref(1)));
tval.push_back(new ALiteral<int32_t>(T_INT32, -1, Cursor()));
- const ASymbol* tsym = cenv.penv.gensym("_matchT");
+ const ASymbol* tsym = cenv.penv.gensym("__tag");
List def(match->loc, cenv.penv.sym("def"), tsym, tval.head, NULL);
- cenv.setType(tval.head, cenv.tenv.named("String"));
+ cenv.setType(tval.head, cenv.tenv.named("Symbol"));
List copyIf;
copyIf.push_back(cenv.penv.sym("if"));
@@ -74,10 +74,16 @@ simplify_match(CEnv& cenv, const ATuple* match) throw()
const ATuple* pat = (*i++)->as_tuple();
const AST* body = *i++;
+ const ASymbol* consTag = cenv.penv.sym(pat->head()->str(), pat->head()->loc);
+ const_cast<ASymbol*>(consTag)->tag(T_LITSYM);
+ cenv.setType(consTag, cenv.tenv.named("Symbol"));
+
List cond;
- cond.push_back(cenv.penv.sym("__tag_is"));
+ cond.push_back(cenv.penv.sym("="));
cond.push_back(tsym);
- cond.push_back(pat->head());
+ cond.push_back(consTag);
+
+ cenv.setType(cond, cenv.tenv.named("Bool"));
copyIf.push_back(cond);
copyIf.push_back(resp_simplify(cenv, body));