Type computation tests (#511)

* test of a little type computation

* another test and some bug fixes
This commit is contained in:
Jeremy G. Siek
2021-05-05 14:46:10 -04:00
committed by GitHub
parent 190fab9530
commit 56b47bcfa9
12 changed files with 54 additions and 11 deletions
@@ -333,8 +333,7 @@ auto StructDeclaration::InitGlobals(Env& globals) const -> void {
}
auto FunctionDeclaration::InitGlobals(Env& globals) const -> void {
Env values;
auto pt = InterpExp(values, definition->param_pattern);
auto pt = InterpExp(globals, definition->param_pattern);
auto f = Value::MakeFunVal(definition->name, pt, definition->body);
Address a = state->heap.AllocateValue(f);
globals.Set(definition->name, a);
@@ -391,15 +391,15 @@ auto TypeCheckExp(const Expression* e, TypeEnv types, Env values,
}
}
case ExpressionKind::IntT:
return TCResult(e, Value::MakeIntTypeVal(), types);
return TCResult(e, Value::MakeTypeTypeVal(), types);
case ExpressionKind::BoolT:
return TCResult(e, Value::MakeBoolTypeVal(), types);
return TCResult(e, Value::MakeTypeTypeVal(), types);
case ExpressionKind::TypeT:
return TCResult(e, Value::MakeTypeTypeVal(), types);
case ExpressionKind::AutoT:
return TCResult(e, Value::MakeAutoTypeVal(), types);
return TCResult(e, Value::MakeTypeTypeVal(), types);
case ExpressionKind::ContinuationT:
return TCResult(e, Value::MakeContinuationTypeVal(), types);
return TCResult(e, Value::MakeTypeTypeVal(), types);
}
}
@@ -734,6 +734,7 @@ auto TopLevel(std::list<Declaration>* fs) -> TypeCheckContext {
auto FunctionDeclaration::TopLevel(TypeCheckContext& tops) const -> void {
auto t = TypeOfFunDef(tops.types, tops.values, definition);
tops.types.Set(Name(), t);
InitGlobals(tops.values);
}
auto StructDeclaration::TopLevel(TypeCheckContext& tops) const -> void {
@@ -325,7 +325,6 @@ auto PrintValue(const Value* val, std::ostream& out) -> void {
out << element.name << " = ";
state->heap.PrintAddress(element.address, out);
out << "@" << element.address;
}
out << ")";
break;