Skip to content

Commit

Permalink
WIP: more work on instantiator
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Oct 10, 2023
1 parent 55df9dd commit 40399d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
14 changes: 0 additions & 14 deletions src/engine/Instantiator.v3
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,6 @@ class Instantiator(extensions: Extension.set, module: Module, var imports: Array
def mapArray(decl: ArrayDecl) -> ArrayDecl {
return decl; // TODO: substitute and canonicalize
}
def mapHeapTypeDecl(t: HeapTypeDecl) -> HeapTypeDecl {
match (t) {
x: SigDecl => {
var p = Arrays.map(x.params, mapType);
var r = Arrays.map(x.results, mapType);
return SigDecl.new(x.final, Arrays.map(x.supertypes, mapHeapType), p, r); // TODO: map super decls
}
x: StructDecl => {
}
x: ArrayDecl => {
}
_ => return t;
}
}
def mapType(t: ValueType) -> ValueType {
if (!module.isAbstract()) return t;
// TODO: memoize results of previous type mappings
Expand Down
25 changes: 23 additions & 2 deletions src/engine/Type.v3
Original file line number Diff line number Diff line change
Expand Up @@ -579,22 +579,43 @@ class TypeSubst {
Func(sig) => {
var nsig = outputs[sig.heaptype_index];
if (nsig == sig) return t;
return ValueType.Ref(nullable, HeapType.Func(SigDecl.!(nsig)));
}
Struct(decl) => {
var ndecl = outputs[decl.heaptype_index];
if (ndecl == decl) return t;
return ValueType.Ref(nullable, HeapType.Struct(StructDecl.!(ndecl)));
}
Array(decl) => {
var ndecl = outputs[decl.heaptype_index];
if (ndecl == decl) return t;
return ValueType.Ref(nullable, HeapType.Array(ArrayDecl.!(ndecl)));
}
_ => return t;
}
Abstract(it) => return args[it.abstype_index];
_ => return t;
}
// TODO: memoize results of previous type mappings
return ValueTypes.map(t, mapAbs).1;
}
private def mapHeapType(ht: HeapType) -> HeapType {
match (ht) {
Func(sig) => {
var nsig = outputs[sig.heaptype_index];
if (nsig == sig) return ht;
return HeapType.Func(SigDecl.!(nsig));
}
Struct(decl) => {
var ndecl = outputs[decl.heaptype_index];
if (ndecl == decl) return ht;
return HeapType.Struct(StructDecl.!(ndecl));
}
Array(decl) => {
var ndecl = outputs[decl.heaptype_index];
if (ndecl == decl) return ht;
return HeapType.Array(ArrayDecl.!(ndecl));
}
_ => return ht;
}
}
private def substSig(sig: SigDecl) -> SigDecl {
if (args.length == 0) return sig; // TODO: check sig.open
Expand Down

0 comments on commit 40399d6

Please sign in to comment.