summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ast.nim1
-rwxr-xr-xcompiler/ccgtypes.nim13
-rwxr-xr-xcompiler/ccgutils.nim6
-rwxr-xr-xcompiler/cgen.nim4
-rwxr-xr-xcompiler/pragmas.nim6
-rwxr-xr-xcompiler/wordrecg.nim4
6 files changed, 22 insertions, 12 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 3719bc664..9eb2d21ac 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -339,6 +339,7 @@ type
 const
   routineKinds* = {skProc, skMethod, skIterator, skConverter,
     skMacro, skTemplate}
+  tfIncompleteStruct* = tfVarargs
 
 type
   TMagic* = enum # symbols that require compiler magic:
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index eb1c23dd5..6bbb33b4f 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -241,8 +241,8 @@ proc typeNameOrLiteral(t: PType, literal: string): PRope =
   
 proc getSimpleTypeDesc(m: BModule, typ: PType): PRope = 
   const 
-    NumericalTypeToStr: array[tyInt..tyFloat128, string] = ["NI", "NI8", "NI16", 
-      "NI32", "NI64", "NF", "NF32", "NF64", "NF128"]
+    NumericalTypeToStr: array[tyInt..tyFloat128, string] = ["NI", "NI8",
+      "NI16", "NI32", "NI64", "NF", "NF32", "NF64", "NF128"]
   case typ.Kind
   of tyPointer: 
     result = typeNameOrLiteral(typ, "void*")
@@ -301,7 +301,8 @@ proc mangleRecFieldName(field: PSym, rectype: PType): PRope =
     result = toRope(mangle(field.name.s))
   if result == nil: InternalError(field.info, "mangleRecFieldName")
   
-proc genRecordFieldsAux(m: BModule, n: PNode, accessExpr: PRope, rectype: PType, 
+proc genRecordFieldsAux(m: BModule, n: PNode, 
+                        accessExpr: PRope, rectype: PType, 
                         check: var TIntSet): PRope = 
   var 
     ae, uname, sname, a: PRope
@@ -560,9 +561,13 @@ proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) =
     nimtypeKind = ord(tyPureObject)
   else:
     nimtypeKind = ord(typ.kind)
+  
+  var size: PRope
+  if tfIncompleteStruct in typ.flags: size = toRope"void*"
+  else: size = getTypeDesc(m, typ)
   appf(m.s[cfsTypeInit3], 
        "$1->size = sizeof($2);$n" & "$1->kind = $3;$n" & "$1->base = $4;$n", 
-       [name, getTypeDesc(m, typ), toRope(nimtypeKind), base])     
+       [name, size, toRope(nimtypeKind), base])     
   # compute type flags for GC optimization
   var flags = 0
   if not containsGarbageCollectedRef(typ): flags = flags or 1
diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim
index e3d13509f..578512bb0 100755
--- a/compiler/ccgutils.nim
+++ b/compiler/ccgutils.nim
@@ -90,7 +90,7 @@ proc GetUniqueType*(key: PType): PType =
     result = GetUniqueType(lastSon(key))
   of tyArrayConstr, tyGenericInvokation, tyGenericBody, tyGenericParam,
      tyOpenArray, tyArray, tyTuple, tySet, tyRange, 
-     tyPtr, tyRef, tySequence, tyForward, tyVarargs, tyProxy:
+     tyPtr, tyRef, tySequence, tyForward, tyVarargs, tyProxy, tyVar:
     # we have to do a slow linear search because types may need
     # to be compared by their structure:
     if IdTableHasObjectAsKey(gTypeTable[k], key): return key 
@@ -121,8 +121,8 @@ proc GetUniqueType*(key: PType): PType =
     if result == nil: 
       IdTablePut(gTypeTable[k], key, key)
       result = key
-  of tyProc, tyVar: 
-    # tyVar is not 100% correct, but speeds things up a little:
+  of tyProc:
+    # tyVar is not 100% correct, but would speeds things up a little:
     result = key
 
 proc TableGetType*(tab: TIdTable, key: PType): PObject = 
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 6ce69f765..6a5d890a8 100755
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -383,8 +383,8 @@ proc assignLocalVar(p: BProc, s: PSym) =
     if s.kind == skLet: incl(s.loc.flags, lfNoDeepCopy)
   app(p.s[cpsLocals], getTypeDesc(p.module, s.loc.t))
   if sfRegister in s.flags: app(p.s[cpsLocals], " register")
-  elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds:
-    app(p.s[cpsLocals], " GC_GUARD")
+  #elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds:
+  #  app(p.s[cpsLocals], " GC_GUARD")
   if (sfVolatile in s.flags) or (p.nestedTryStmts.len > 0): 
     app(p.s[cpsLocals], " volatile")
   appf(p.s[cpsLocals], " $1;$n", [s.loc.r])
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 560a24afe..762bfa5bf 100755
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -44,7 +44,7 @@ const
     wDeprecated, wExtern, wThread, wImportcpp, wImportobjc, wNoStackFrame}
   typePragmas* = {wImportc, wExportc, wDeprecated, wMagic, wAcyclic, wNodecl, 
     wPure, wHeader, wCompilerProc, wFinal, wSize, wExtern, wShallow, 
-    wImportcpp, wImportobjc, wError}
+    wImportcpp, wImportobjc, wError, wIncompleteStruct}
   fieldPragmas* = {wImportc, wExportc, wDeprecated, wExtern, 
     wImportcpp, wImportobjc, wError}
   varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl, 
@@ -571,6 +571,10 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) =
           of wEmit: PragmaEmit(c, it)
           of wUnroll: PragmaUnroll(c, it)
           of wLinearScanEnd: PragmaLinearScanEnd(c, it)
+          of wIncompleteStruct:
+            noVal(it)
+            if sym.typ == nil: invalidPragma(it)
+            incl(sym.typ.flags, tfIncompleteStruct)
           else: invalidPragma(it)
         else: invalidPragma(it)
     else: processNote(c, it)
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim
index 1f3ec939a..489850d93 100755
--- a/compiler/wordrecg.nim
+++ b/compiler/wordrecg.nim
@@ -36,7 +36,7 @@ type
     wMagic, wThread, wFinal, wProfiler, wObjChecks,
     wImportCpp, wImportObjC,
     wImportCompilerProc,
-    wImportc, wExportc, wExtern,
+    wImportc, wExportc, wExtern, wIncompleteStruct,
     wAlign, wNodecl, wPure, wVolatile, wRegister, wSideeffect, wHeader, 
     wNosideeffect, wNoreturn, wMerge, wLib, wDynlib, wCompilerproc, wProcVar, 
     wFatal, wError, wWarning, wHint, wLine, wPush, wPop, wDefine, wUndef, 
@@ -80,7 +80,7 @@ const
     "magic", "thread", "final", "profiler", "objchecks", 
     
     "importcpp", "importobjc",
-    "importcompilerproc", "importc", "exportc", "extern",
+    "importcompilerproc", "importc", "exportc", "extern", "incompletestruct",
     "align", "nodecl", "pure", "volatile", "register", "sideeffect", 
     "header", "nosideeffect", "noreturn", "merge", "lib", "dynlib", 
     "compilerproc", "procvar", "fatal", "error", "warning", "hint", "line",