aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/constrain.cpp6
-rw-r--r--src/parse.cpp1
-rw-r--r--src/tuplr.hpp4
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)