diff options
author | David Robillard <d@drobilla.net> | 2009-07-04 06:12:50 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-07-04 06:12:50 +0000 |
commit | d1f38c9f27ff1a0208884058d3c8450650703ee9 (patch) | |
tree | e0581b4047ad0bb5137e5a8389faf5c3ffb5b941 | |
parent | 24bacd4211b8c53e3eeee97fbc929a2f6c4a19e8 (diff) | |
download | resp-d1f38c9f27ff1a0208884058d3c8450650703ee9.tar.gz resp-d1f38c9f27ff1a0208884058d3c8450650703ee9.tar.bz2 resp-d1f38c9f27ff1a0208884058d3c8450650703ee9.zip |
Parse AString.
git-svn-id: http://svn.drobilla.net/resp/tuplr@186 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | src/constrain.cpp | 6 | ||||
-rw-r--r-- | src/parse.cpp | 1 | ||||
-rw-r--r-- | src/tuplr.hpp | 4 |
3 files changed, 10 insertions, 1 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp index f9a0e11..7db25fa 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -23,6 +23,12 @@ #include "tuplr.hpp" void +AString::constrain(TEnv& tenv, Constraints& c) const +{ + c.push_back(Constraint(tenv.var(this), tenv.named("String"), loc)); +} + +void ASymbol::constrain(TEnv& tenv, Constraints& c) const { addr = tenv.lookup(this); diff --git a/src/parse.cpp b/src/parse.cpp index d36a92a..9d26652 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -106,6 +106,7 @@ initLang(PEnv& penv, TEnv& tenv) tenv.def(penv.sym("Bool"), make_pair((AST*)0, new AType(penv.sym("Bool")))); tenv.def(penv.sym("Int"), make_pair((AST*)0, new AType(penv.sym("Int")))); tenv.def(penv.sym("Float"), make_pair((AST*)0, new AType(penv.sym("Float")))); + tenv.def(penv.sym("String"), make_pair((AST*)0, new AType(penv.sym("String")))); // Literals static bool trueVal = true; diff --git a/src/tuplr.hpp b/src/tuplr.hpp index da8eea5..1e64da1 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -237,7 +237,7 @@ struct ALiteral : public AST { struct AString : public AST, public std::string { AString(Cursor c, const string& s) : AST(c), std::string(s) {} bool operator==(const AST& rhs) const { return this == &rhs; } - void constrain(TEnv& tenv, Constraints& c) const {} + void constrain(TEnv& tenv, Constraints& c) const; CValue compile(CEnv& cenv) { return NULL; } }; @@ -535,6 +535,8 @@ struct PEnv : private map<const string, ASymbol*> { return new ALiteral<int32_t>(strtol(s.c_str(), NULL, 10), exp->loc); else return new ALiteral<float>(strtod(s.c_str(), NULL), exp->loc); + } else if ((*str)[0] == '\"') { + return new AString(exp->loc, str->substr(1, str->length() - 2)); } else { const PEnv::Handler* h = handler(false, *str); if (h) |