aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-01 06:06:38 +0000
committerDavid Robillard <d@drobilla.net>2010-12-01 06:06:38 +0000
commit8972c175088b1cd083989ff9c07f59143a59fb69 (patch)
tree9135a433ddc72b429c420925787bc8c5d39469c7 /src/resp.hpp
parentea984b91ae477310ac7226fb56338a40531b07cb (diff)
downloadresp-8972c175088b1cd083989ff9c07f59143a59fb69.tar.gz
resp-8972c175088b1cd083989ff9c07f59143a59fb69.tar.bz2
resp-8972c175088b1cd083989ff9c07f59143a59fb69.zip
Add -T option to type-check and pretty-print with type annotations.
Rename -p to -P (all 'stage' options, i.e. -P -T -S are uppercase for consistency). Clean up main program. Decent pretty printing. git-svn-id: http://svn.drobilla.net/resp/resp@275 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/resp.hpp b/src/resp.hpp
index a972d48..3f73f2f 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -647,10 +647,6 @@ struct TEnv : public Env<const ASymbol*, const AType*> {
if (!ast)
return new AType(Cursor(), varID++);
- const ASymbol* sym = ast->to<const ASymbol*>();
- if (sym)
- return *ref(sym);
-
Vars::iterator v = vars.find(ast);
if (v != vars.end())
return v->second;
@@ -730,18 +726,20 @@ struct CEnv {
void lock(const AST* ast) {
Object::pool.addRoot(ast);
if (type(ast))
- Object::pool.addRoot(type(ast));
+ Object::pool.addRoot(type(ast));
}
const AType* type(const AST* ast, const Subst& subst = Subst()) const {
+ const AType* ret = NULL;
const ASymbol* sym = ast->to<const ASymbol*>();
if (sym) {
const AType** rec = tenv.ref(sym);
- return rec ? *rec : NULL;
- }
- const AType* var = tenv.vars[ast];
- if (var) {
- return tsubst.apply(subst.apply(var))->to<const AType*>();
+ if (rec)
+ ret = *rec;
}
+ if (!ret)
+ ret = tenv.vars[ast];
+ if (ret)
+ return tsubst.apply(subst.apply(ret))->to<const AType*>();
return NULL;
}
void def(const ASymbol* sym, const AST* c, const AType* t, CVal v) {
@@ -814,9 +812,9 @@ private:
* EVAL/REPL/MAIN *
***************************************************************************/
-void pprint(std::ostream& out, const AST* ast);
+void pprint(std::ostream& out, const AST* ast, CEnv* cenv, bool types);
void initLang(PEnv& penv, TEnv& tenv);
-int eval(CEnv& cenv, const string& name, istream& is, bool execute);
+int eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute);
int repl(CEnv& cenv);
#endif // RESP_HPP