summary refs log tree commit diff stats
path: root/nim/seminst.pas
diff options
context:
space:
mode:
Diffstat (limited to 'nim/seminst.pas')
-rw-r--r--nim/seminst.pas34
1 files changed, 34 insertions, 0 deletions
diff --git a/nim/seminst.pas b/nim/seminst.pas
index 4c3d416d4..a49d8478e 100644
--- a/nim/seminst.pas
+++ b/nim/seminst.pas
@@ -58,10 +58,29 @@ begin
   end
 end;
 
+procedure genericToConcreteTypeKind(t: PType);
+var
+  body: PNode;
+begin
+  if (t.kind = tyGeneric) and (t.sym <> nil) then begin
+    body := t.sym.ast.sons[2];
+    case body.kind of
+      nkObjectTy: t.kind := tyObject;
+      nkTupleTy: t.kind := tyTuple;
+      nkRefTy: t.kind := tyRef;
+      nkPtrTy: t.kind := tyPtr;
+      nkVarTy: t.kind := tyVar;
+      nkProcTy: t.kind := tyProc;
+      else InternalError('genericToConcreteTypeKind');
+    end
+  end
+end;
+
 function instantiateType(c: PInstantiateClosure; typ: PType): PType;
 var
   i: int;
 begin
+  if typ = nil then begin result := nil; exit end;
   result := PType(idTableGet(c.typeMap, typ));
   if result <> nil then exit;
   //if typ.kind = tyOpenArray then
@@ -73,6 +92,7 @@ begin
       result.sons[i] := instantiateType(c, result.sons[i]);
     if result.n <> nil then
       result.n := instTypeNode(c, result.n);
+    genericToConcreteTypeKind(result);
   end
   else
     result := typ;
@@ -272,6 +292,20 @@ begin
   result := instantiateType(c, t);
 end;
 
+function newInstantiateClosure(p: PContext;
+          const instantiator: TLineInfo): PInstantiateClosure;
+begin
+  new(result);
+{@ignore}
+  fillChar(result^, sizeof(result^), 0);
+{@emit}
+  InitIdTable(result.typeMap);
+  InitIdTable(result.symMap);
+  result.fn := nil;
+  result.instantiator := instantiator;
+  result.module := p.module;
+end;
+
 function partialSpecialization(c: PContext; n: PNode; s: PSym): PNode;
 begin
   result := n;