aboutsummaryrefslogtreecommitdiffstats
path: root/src/constrain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/constrain.cpp')
-rw-r--r--src/constrain.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/constrain.cpp b/src/constrain.cpp
index b7d7a0d..36a82d1 100644
--- a/src/constrain.cpp
+++ b/src/constrain.cpp
@@ -185,6 +185,27 @@ ACons::constrain(TEnv& tenv, Constraints& c) const
}
void
+ADot::constrain(TEnv& tenv, Constraints& c) const
+{
+ THROW_IF(size() != 3, loc, "`.' requires exactly 2 arguments");
+ const_iterator i = begin();
+ AST* obj = *++i;
+ ALiteral<int32_t>* idx = (*++i)->to<ALiteral<int32_t>*>();
+ THROW_IF(!idx, loc, "the 2nd argument to `.' must be a literal integer");
+ obj->constrain(tenv, c);
+
+ AType* retT = tenv.var(this);
+ c.constrain(tenv, this, retT);
+
+ AType* objT = tup<AType>(loc, tenv.Tup, 0);
+ for (int i = 0; i < idx->val; ++i)
+ objT->push_back(tenv.var());
+ objT->push_back(retT);
+ objT->push_back(tenv.ellipses);
+ c.constrain(tenv, obj, objT);
+}
+
+void
APrimitive::constrain(TEnv& tenv, Constraints& c) const
{
const string n = head()->to<const ASymbol*>()->str();