Migrate declaration parsing to value semantics (#614)

* Use Expression by value in FunctionDefinition
* Migrate choice declarations to value semantics
* Migrate Declaration parsing to value semantics
This commit is contained in:
Geoff Romer
2021-06-30 13:09:12 -07:00
committed by GitHub
parent 7e70a0335e
commit fa5b9cd553
9 changed files with 90 additions and 81 deletions
@@ -314,9 +314,9 @@ void InitGlobals(std::list<Declaration>* fs) {
auto ChoiceDeclaration::InitGlobals(Env& globals) const -> void {
auto alts = new VarValues();
for (auto kv : alternatives) {
auto t = InterpExp(Env(), kv.second);
alts->push_back(make_pair(kv.first, t));
for (const auto& [name, signature] : alternatives) {
auto t = InterpExp(Env(), &signature);
alts->push_back(make_pair(name, t));
}
auto ct = Value::MakeChoiceTypeVal(name, alts);
auto a = state->heap.AllocateValue(ct);
@@ -342,10 +342,10 @@ auto StructDeclaration::InitGlobals(Env& globals) const -> void {
}
auto FunctionDeclaration::InitGlobals(Env& globals) const -> void {
auto pt = InterpExp(globals, definition->param_pattern);
auto f = Value::MakeFunVal(definition->name, pt, definition->body);
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);
globals.Set(definition.name, a);
}
// Adds an entry in `globals` mapping the variable's name to the