diff options
-rwxr-xr-x | compiler/ast.nim | 1 | ||||
-rwxr-xr-x | compiler/ccgtypes.nim | 13 | ||||
-rwxr-xr-x | compiler/ccgutils.nim | 6 | ||||
-rwxr-xr-x | compiler/cgen.nim | 4 | ||||
-rwxr-xr-x | compiler/pragmas.nim | 6 | ||||
-rwxr-xr-x | compiler/wordrecg.nim | 4 | ||||
-rwxr-xr-x | doc/nimrodc.txt | 11 | ||||
-rwxr-xr-x | koch.nim | 32 | ||||
-rwxr-xr-x | lib/nimbase.h | 6 | ||||
-rwxr-xr-x | lib/posix/posix.nim | 15 | ||||
-rwxr-xr-x | lib/system/alloc.nim | 4 | ||||
-rw-r--r-- | tests/specials.nim | 9 | ||||
-rwxr-xr-x | todo.txt | 3 | ||||
-rwxr-xr-x | tools/nimgrep.nim | 4 | ||||
-rwxr-xr-x | tools/niminst.nim | 4 | ||||
-rwxr-xr-x | tools/nimrepl.nim | 2 | ||||
-rwxr-xr-x | tools/nimweb.nim | 4 | ||||
-rwxr-xr-x | tools/sunset.tmpl | 2 | ||||
-rwxr-xr-x | web/news.txt | 2 |
19 files changed, 85 insertions, 47 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", diff --git a/doc/nimrodc.txt b/doc/nimrodc.txt index 315c21435..53efb6a22 100755 --- a/doc/nimrodc.txt +++ b/doc/nimrodc.txt @@ -167,6 +167,17 @@ encloses the header file in ``""`` in the generated C code. **Note**: This will not work for the LLVM backend. +IncompleteStruct pragma +----------------------- +The `incompleteStruct`:idx: pragma tells the compiler to not use the +underlying C ``struct`` in a ``sizeof`` expression: + +.. code-block:: Nimrod +type + TDIR* {.importc: "DIR", header: "<dirent.h>", + final, pure, incompleteStruct.} = object + + Compile pragma -------------- The `compile`:idx: pragma can be used to compile and link a C/C++ source file diff --git a/koch.nim b/koch.nim index 3af0dcc37..a19de3f2f 100755 --- a/koch.nim +++ b/koch.nim @@ -85,8 +85,8 @@ proc web(args: string) = proc update(args: string) = when defined(windows): - echo("Windows Users: Make sure to be running this in Bash. If you aren't, press CTRL+C now.") - + echo("Windows users: Make sure to be running this in Bash. ", + "If you aren't, press CTRL+C now.") var thisDir = getAppDir() var git = findExe("git") @@ -109,42 +109,36 @@ proc update(args: string) = echo("Fetching updates from repo...") var pullout = execCmdEx(git & " pull origin master") if pullout[1] != 0: - echo("An error has occured.") - return + quit("An error has occured.") else: - if pullout[0] == "Already up-to-date.\r\n": - echo("No new changes fetched from the repo. Local branch must be ahead of it. Exiting...") - return + if pullout[0].startsWith("Already up-to-date."): + quit("No new changes fetched from the repo. " & + "Local branch must be ahead of it. Exiting...") else: - echo("An error has occured.") - return + quit("An error has occured.") else: echo("No repo or executable found!") when defined(haveZipLib): echo("Falling back.. Downloading source code from repo...") # use dom96's httpclient to download zip - downloadFile("https://github.com/Araq/Nimrod/zipball/master",thisDir & "/update.zip") - + downloadFile("https://github.com/Araq/Nimrod/zipball/master", + thisDir / "update.zip") try: echo("Extracting source code from archive...") - var zip :TZipArchive - discard open(zip,thisDir & "/update.zip", fmRead) # will add error checking later + var zip: TZipArchive + discard open(zip, thisDir & "/update.zip", fmRead) extractAll(zip, thisDir & "/") except: - echo("Error reading archive.") - return + quit("Error reading archive.") else: - echo("No failback available. Exiting...") - return + quit("No failback available. Exiting...") echo("Starting update...") boot(args) echo("Update complete!") - - # -------------- boot --------------------------------------------------------- const diff --git a/lib/nimbase.h b/lib/nimbase.h index e2afed8f9..f52185800 100755 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -1,7 +1,7 @@ /* Nimrod's Runtime Library - (c) Copyright 2011 Andreas Rumpf + (c) Copyright 2012 Andreas Rumpf See the file "copying.txt", included in this distribution, for details about the copyright. @@ -438,7 +438,9 @@ __declspec(naked) int __fastcall NimXadd(volatile int* pNum, int val) { # define unlikely(x) (x) #endif -#if defined(__GNUC__) || defined(__clang__) +#if 0 // defined(__GNUC__) || defined(__clang__) +// not needed anymore because the stack marking cares about +// interior pointers now static inline void GCGuard (void *ptr) { asm volatile ("" :: "X" (ptr)); } # define GC_GUARD __attribute__ ((cleanup(GCGuard))) #else diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 58801d83e..f8d49ddb4 100755 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -68,10 +68,19 @@ const STDIN_FILENO* = 0 ## File number of stdin; STDOUT_FILENO* = 1 ## File number of stdout; +when defined(endb): + # to not break bootstrapping again ... + type + TDIR* {.importc: "DIR", header: "<dirent.h>", + final, pure, incompleteStruct.} = object + ## A type representing a directory stream. +else: + type + TDIR* {.importc: "DIR", header: "<dirent.h>", + final, pure.} = object + ## A type representing a directory stream. + type - TDIR* {.importc: "DIR", header: "<dirent.h>", final, pure.} = object - ## A type representing a directory stream. - Tdirent* {.importc: "struct dirent", header: "<dirent.h>", final, pure.} = object ## dirent_t struct d_ino*: TIno ## File serial number. diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 8bf173fc1..c3478a739 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -683,6 +683,10 @@ proc getOccupiedMem(a: TMemRegion): int {.inline.} = # ---------------------- thread memory region ------------------------------- template InstantiateForRegion(allocator: expr) = + when false: + proc interiorAllocatedPtr*(p: pointer): pointer = + result = interiorAllocatedPtr(allocator, p) + proc deallocOsPages = deallocOsPages(allocator) proc alloc(size: int): pointer = diff --git a/tests/specials.nim b/tests/specials.nim index e707ee9f5..3d4c8cfc4 100644 --- a/tests/specials.nim +++ b/tests/specials.nim @@ -138,7 +138,7 @@ proc rejectThreadTests(r: var TResults, options: string) = rejectSingleTest(r, "tests/threads/tthreadanalysis3", options) rejectSingleTest(r, "tests/threads/tthreadheapviolation1", options) -# ------------------------- IO tests ----------------------------------- +# ------------------------- IO tests ------------------------------------------ proc runIOTests(r: var TResults, options: string) = # We need readall_echo to be compiled for this test to run. @@ -146,6 +146,12 @@ proc runIOTests(r: var TResults, options: string) = var c = initResults() compileSingleTest(c, "tests/system/helpers/readall_echo", options) runSingleTest(r, "tests/system/io", options) + +# ------------------------- debugger tests ------------------------------------ + +proc compileDebuggerTests(r: var TResults, options: string) = + compileSingleTest(r, "tools/nimgrep", options & + " --debugger:on") # ------------------------- register special tests here ----------------------- proc runSpecialTests(r: var TResults, options: string) = @@ -165,4 +171,5 @@ proc compileSpecialTests(r: var TResults, options: string) = compileSingleTest(r, "compiler/pas2nim/pas2nim.nim", options) compileDLLTests(r, options) + compileDebuggerTests(r, options) diff --git a/todo.txt b/todo.txt index 1080e3a77..380e9469d 100755 --- a/todo.txt +++ b/todo.txt @@ -2,8 +2,7 @@ version 0.8.14 ============== - BUG: type TX = TTable[string, int] -- BUG: temp3.nim triggers weird compiler bug -- BUG: --debugger:on does not work with talloc.nim +- BUG: temp2.nim triggers weird compiler bug - implicit invokation of `items`/`pairs` seems nice; ensure items(23) does not compile though diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim index 87849178e..01669f002 100755 --- a/tools/nimgrep.nim +++ b/tools/nimgrep.nim @@ -1,7 +1,7 @@ # # # Nimrod Grep Utility -# (c) Copyright 2011 Andreas Rumpf +# (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -14,7 +14,7 @@ const Version = "0.8" Usage = "nimgrep - Nimrod Grep Utility Version " & version & """ - (c) 2011 Andreas Rumpf + (c) 2012 Andreas Rumpf Usage: nimgrep [options] [pattern] [replacement] (file/directory)* Options: diff --git a/tools/niminst.nim b/tools/niminst.nim index 2a1041e17..02e501a26 100755 --- a/tools/niminst.nim +++ b/tools/niminst.nim @@ -1,7 +1,7 @@ # # # The Nimrod Installation Generator -# (c) Copyright 2011 Andreas Rumpf +# (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -104,7 +104,7 @@ const Version = "0.9" Usage = "niminst - Nimrod Installation Generator Version " & version & """ - (c) 2010 Andreas Rumpf + (c) 2012 Andreas Rumpf Usage: niminst [options] command[;command2...] ini-file[.ini] [compile_options] Command: diff --git a/tools/nimrepl.nim b/tools/nimrepl.nim index 220307dba..fe047e1d5 100755 --- a/tools/nimrepl.nim +++ b/tools/nimrepl.nim @@ -1,7 +1,7 @@ # # # Nimrod REPL -# (c) Copyright 2010 Dominik Picheta +# (c) Copyright 2012 Dominik Picheta # # See the file "copying.txt", included in this # distribution, for details about the copyright. diff --git a/tools/nimweb.nim b/tools/nimweb.nim index 556d9a6e6..cc5ea97a6 100755 --- a/tools/nimweb.nim +++ b/tools/nimweb.nim @@ -1,7 +1,7 @@ # # # Nimrod Website Generator -# (c) Copyright 2011 Andreas Rumpf +# (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -44,7 +44,7 @@ const Version = "0.7" Usage = "nimweb - Nimrod Website Generator Version " & version & """ - (c) 2011 Andreas Rumpf + (c) 2012 Andreas Rumpf Usage: nimweb [options] ini-file[.ini] [compile_options] Options: diff --git a/tools/sunset.tmpl b/tools/sunset.tmpl index 6127da568..c8e06c659 100755 --- a/tools/sunset.tmpl +++ b/tools/sunset.tmpl @@ -65,7 +65,7 @@ </div> </div> <div id="footer"> - copyright © 2011 $c.authors | Last update: ${getDateStr()} + copyright © 2012 $c.authors | Last update: ${getDateStr()} | <a class="reference" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a> | <a class="reference" href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> | <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a> diff --git a/web/news.txt b/web/news.txt index fc936aee6..670950519 100755 --- a/web/news.txt +++ b/web/news.txt @@ -89,6 +89,8 @@ Compiler Additions Objective C. - The new pragmas ``importcpp`` and ``importobjc`` make interfacing with C++ and Objective C somewhat easier. +- Added a new pragma ``incompleteStruct`` to deal with incomplete C struct + definitions. - Added a ``--nimcache:PATH`` configuration option for control over the output directory for generated code. - The ``--genScript`` option now produces different compilation scripts |