From 9ea99dbf369c498215705650b111e78cd53c94da Mon Sep 17 00:00:00 2001 From: Reimer Behrends Date: Fri, 18 Sep 2015 14:05:04 +0200 Subject: [PATCH 01/23] Add option to disable munmap() use in the allocator. When compiling with '-d:nimAllocNoUnmap', the allocator will not attempt to return large chunks to the OS. For certain allocation behaviors, this can be a significant speedup. --- lib/system/alloc.nim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 13a10e46f7..3a1d7b6664 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -27,8 +27,11 @@ sysAssert(roundup(65, 8) == 72, "roundup broken 2") # some platforms have really weird unmap behaviour: unmap(blockStart, PageSize) # really frees the whole block. Happens for Linux/PowerPC for example. Amd64 # and x86 are safe though; Windows is special because MEM_RELEASE can only be -# used with a size of 0: -const weirdUnmap = not (defined(amd64) or defined(i386)) or defined(windows) +# used with a size of 0. We also allow unmapping to be turned off with +# -d:nimAllocNoUnmap: +const doNotUnmap = not (defined(amd64) or defined(i386)) or + defined(windows) or defined(nimAllocNoUnmap) + when defined(posix): const @@ -478,7 +481,7 @@ proc freeBigChunk(a: var MemRegion, c: PBigChunk) = excl(a.chunkStarts, pageIndex(c)) c = cast[PBigChunk](le) - if c.size < ChunkOsReturn or weirdUnmap: + if c.size < ChunkOsReturn or doNotUnmap: incl(a, a.chunkStarts, pageIndex(c)) updatePrevSize(a, c, c.size) listAdd(a.freeChunksList, c) @@ -762,7 +765,7 @@ proc deallocOsPages(a: var MemRegion) = # we free every 'ordinarily' allocated page by iterating over the page bits: for p in elements(a.chunkStarts): var page = cast[PChunk](p shl PageShift) - when not weirdUnmap: + when not doNotUnmap: var size = if page.size < PageSize: PageSize else: page.size osDeallocPages(page, size) else: From 5e9ce88dafbaa0bf72a7c7c3ce11a8d827ab3200 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 28 Sep 2015 14:34:36 -0700 Subject: [PATCH 02/23] implement bitsize pragma for bitfields --- compiler/ast.nim | 1 + compiler/ccgtypes.nim | 2 ++ compiler/pragmas.nim | 7 ++++++- compiler/wordrecg.nim | 2 ++ tests/pragmas/tbitsize.nim | 7 +++++++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/pragmas/tbitsize.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index 4001e896e3..9db5a4e34f 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -784,6 +784,7 @@ type tab*: TStrTable # interface table for modules of skLet, skVar, skField, skForVar: guard*: PSym + bitsize*: BiggestInt else: nil magic*: TMagic typ*: PType diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 84d02d1da6..1ed9ce1139 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -441,6 +441,8 @@ proc genRecordFieldsAux(m: BModule, n: PNode, elif fieldType.kind == tySequence: # we need to use a weak dependency here for trecursive_table. addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname]) + elif field.bitsize != 0: + addf(result, "$1 $2:$3;$n", [getTypeDescAux(m, field.loc.t, check), sname, rope($field.bitsize)]) else: # don't use fieldType here because we need the # tyGenericInst for C++ template support diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 1c51251fe7..ba05b2792a 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -56,7 +56,7 @@ const wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked, wBorrow, wGcSafe} fieldPragmas* = {wImportc, wExportc, wDeprecated, wExtern, - wImportCpp, wImportObjC, wError, wGuard} + wImportCpp, wImportObjC, wError, wGuard, wBitsize} varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl, wMagic, wHeader, wDeprecated, wCompilerproc, wDynlib, wExtern, wImportCpp, wImportObjC, wError, wNoInit, wCompileTime, wGlobal, @@ -844,6 +844,11 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int, if sym == nil: pragmaLockStmt(c, it) elif sym.typ == nil: invalidPragma(it) else: sym.typ.lockLevel = pragmaLocks(c, it) + of wBitsize: + if sym == nil or sym.kind != skField or it.kind != nkExprColonExpr: + invalidPragma(it) + else: + sym.bitsize = expectIntLit(c, it) of wGuard: if sym == nil or sym.kind notin {skVar, skLet, skField}: invalidPragma(it) diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index 23f012ea50..d1e5438f3d 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -82,6 +82,7 @@ type wStdIn, wStdOut, wStdErr, wInOut, wByCopy, wByRef, wOneWay, + wBitsize, TSpecialWords* = set[TSpecialWord] @@ -168,6 +169,7 @@ const "stdin", "stdout", "stderr", "inout", "bycopy", "byref", "oneway", + "bitsize", ] proc findStr*(a: openArray[string], s: string): int = diff --git a/tests/pragmas/tbitsize.nim b/tests/pragmas/tbitsize.nim new file mode 100644 index 0000000000..d2c646ef74 --- /dev/null +++ b/tests/pragmas/tbitsize.nim @@ -0,0 +1,7 @@ +type + bits* = object + flag* {.bitsize: 1.}: cint + opts* {.bitsize: 4.}: cint + +var b: bits +echo b.flag From 4be68447564fbf19d2c9e260ecb127b391dece07 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Mon, 28 Sep 2015 23:34:52 +0200 Subject: [PATCH 03/23] vm: Don't fail on unknown enum position to string Previously trying to convert constant of enum type, where this enum type has no entry with given constant position leaded to "internal error: opConv for enum". Instead of producing error, now we gracefully convert it to "EnumType position". --- compiler/vm.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index 4dd3b5232d..ad4aa1017f 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -311,7 +311,7 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool = if f.position == x: dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal return - internalError("opConv for enum") + dest.node.strVal = styp.sym.name.s & " " & $x of tyInt..tyInt64: dest.node.strVal = $src.intVal of tyUInt..tyUInt64: From 0679340b52e521306c3d5dc44ba94d7eaacdb662 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 14:39:20 -0700 Subject: [PATCH 04/23] switch to bitsize:int --- compiler/ast.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 9db5a4e34f..25958f580b 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -784,7 +784,7 @@ type tab*: TStrTable # interface table for modules of skLet, skVar, skField, skForVar: guard*: PSym - bitsize*: BiggestInt + bitsize*: int else: nil magic*: TMagic typ*: PType From fa404dc532f61b78bd0e714c121b41ba8fc15ca7 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 14:53:34 -0700 Subject: [PATCH 05/23] better assertions for bitfield behavior --- tests/pragmas/tbitsize.nim | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/pragmas/tbitsize.nim b/tests/pragmas/tbitsize.nim index d2c646ef74..b9b478a7f1 100644 --- a/tests/pragmas/tbitsize.nim +++ b/tests/pragmas/tbitsize.nim @@ -1,7 +1,18 @@ type bits* = object - flag* {.bitsize: 1.}: cint + flag* {.bitsize: 1.}: cuint opts* {.bitsize: 4.}: cint -var b: bits -echo b.flag +var + b: bits + +assert b.flag == 0 +b.flag = 1 +assert b.flag == 1 +b.flag = 2 +assert b.flag == 0 + +b.opts = 7 +assert b.opts == 7 +b.opts = 9 +assert b.opts == -7 From 243e66596554bdd318ff26f15b377403ea1fee6a Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 15:42:45 -0700 Subject: [PATCH 06/23] fix current directory --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2509c0b97d..6a04c4c937 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: c os: linux script: - git clone --depth 1 https://github.com/nim-lang/csources.git - - cd csources && sh build.sh + - cd csources + - sh build.sh + - cd .. - ./bin/nim c koch - ./koch boot - ./koch boot -d:release From 52230e2ae05a927ced6feb566440430760ce0545 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 15:51:18 -0700 Subject: [PATCH 07/23] set PATH for tests --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6a04c4c937..c451586511 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ script: - ./koch boot - ./koch boot -d:release after_script: + - export PATH=$(pwd)/bin:$PATH - ./koch test From dd1e0bd8366d96a8d7b800b5528880d0fe505489 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 15:51:31 -0700 Subject: [PATCH 08/23] run in travisci containers --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c451586511..8001b43554 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: c os: linux script: From 7f619c75e62cd615b0c4789d3e211718024e6eb8 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 15:51:43 -0700 Subject: [PATCH 09/23] build on macosx too --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8001b43554..061dd8188d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ sudo: false language: c -os: linux +os: + - linux + - osx script: - git clone --depth 1 https://github.com/nim-lang/csources.git - cd csources From a90241b8c455f176f24e5866d20afea156ba92fc Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 16:20:51 -0700 Subject: [PATCH 10/23] remove mac builds for now --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 061dd8188d..27daab34b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false language: c os: - linux - - osx script: - git clone --depth 1 https://github.com/nim-lang/csources.git - cd csources From 517312467eb5be2406572384aaa3c75f7bb4a532 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Tue, 29 Sep 2015 16:22:47 -0700 Subject: [PATCH 11/23] add libcurl and libsdl1 headers --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 27daab34b1..486feb1274 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,11 @@ sudo: false language: c os: - linux +addons: + apt: + packages: + - libcurl4-openssl-dev + - libsdl1.2-dev script: - git clone --depth 1 https://github.com/nim-lang/csources.git - cd csources From d80f1633844597f3a8020fc156d2d889bf897d97 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Sep 2015 11:02:23 +0200 Subject: [PATCH 12/23] NimScript: --define works as expected --- compiler/scriptconfig.nim | 5 ++++- tests/newconfig/tfoo.nim | 3 +++ tests/newconfig/tfoo.nims | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index aaa2486e5d..22cd282fda 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -140,4 +140,7 @@ proc runNimScript*(scriptName: string) = # ensure we load 'system.nim' again for the real non-config stuff! resetAllModulesHard() vm.globalCtx = nil - initDefines() + # do not remove the defined symbols + #initDefines() + undefSymbol("nimscript") + undefSymbol("nimconfig") diff --git a/tests/newconfig/tfoo.nim b/tests/newconfig/tfoo.nim index 0ace7c88a7..d593d4a756 100644 --- a/tests/newconfig/tfoo.nim +++ b/tests/newconfig/tfoo.nim @@ -4,4 +4,7 @@ discard """ msg: '''[NimScript] exec: gcc -v''' """ +when not defined(definedefine): + {.fatal: "wrong nim script configuration".} + echo "hello world!" diff --git a/tests/newconfig/tfoo.nims b/tests/newconfig/tfoo.nims index 90205cddba..a2166576d0 100644 --- a/tests/newconfig/tfoo.nims +++ b/tests/newconfig/tfoo.nims @@ -10,5 +10,6 @@ task listDirs, "lists every subdirectory": echo "DIR ", x task default, "default target": + --define: definedefine setCommand "c" From 374b65289c258b2c33f6087b87b336dc5908b9d9 Mon Sep 17 00:00:00 2001 From: Radu Oana Date: Wed, 30 Sep 2015 08:20:24 -0400 Subject: [PATCH 13/23] Move magic numbers to const --- lib/pure/streams.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim index 68f31e9fea..88ac626a67 100644 --- a/lib/pure/streams.nim +++ b/lib/pure/streams.nim @@ -103,15 +103,16 @@ proc readData*(s: Stream, buffer: pointer, bufLen: int): int = proc readAll*(s: Stream): string = ## Reads all available data. - result = newString(1000) + let bufferSize = 1000 + result = newString(bufferSize) var r = 0 while true: - let readBytes = readData(s, addr(result[r]), 1000) - if readBytes < 1000: + let readBytes = readData(s, addr(result[r]), bufferSize) + if readBytes < bufferSize: setLen(result, r+readBytes) break - inc r, 1000 - setLen(result, r+1000) + inc r, bufferSize + setLen(result, r+bufferSize) proc readData*(s, unused: Stream, buffer: pointer, bufLen: int): int {.deprecated.} = From 4bba8e026a266dd7ab0622ce580b517078516cd9 Mon Sep 17 00:00:00 2001 From: Radu Oana Date: Wed, 30 Sep 2015 09:49:22 -0400 Subject: [PATCH 14/23] use const instead of let --- lib/pure/streams.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/streams.nim b/lib/pure/streams.nim index 88ac626a67..38e91fee48 100644 --- a/lib/pure/streams.nim +++ b/lib/pure/streams.nim @@ -103,7 +103,7 @@ proc readData*(s: Stream, buffer: pointer, bufLen: int): int = proc readAll*(s: Stream): string = ## Reads all available data. - let bufferSize = 1000 + const bufferSize = 1000 result = newString(bufferSize) var r = 0 while true: From 700b63ad895eaa4004d681e6a23cc382dd3600ca Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 30 Sep 2015 12:38:18 +0200 Subject: [PATCH 15/23] Use new #? filter prefix in various places This silences deprecation warnings and prevent collision with UNIX shebang. --- examples/filterex.nim | 2 +- tests/template/sunset.tmpl | 2 +- tools/niminst/buildbat.tmpl | 2 +- tools/niminst/buildsh.tmpl | 2 +- tools/niminst/deinstall.tmpl | 2 +- tools/niminst/inno.tmpl | 2 +- tools/niminst/install.tmpl | 2 +- tools/niminst/makefile.tmpl | 2 +- tools/niminst/nsis.tmpl | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/filterex.nim b/examples/filterex.nim index d9bfb67822..0839452544 100644 --- a/examples/filterex.nim +++ b/examples/filterex.nim @@ -1,4 +1,4 @@ -#! stdtmpl | standard +#? stdtmpl | standard #proc generateHTMLPage(title, currentTab, content: string, # tabs: openArray[string]): string = # result = "" diff --git a/tests/template/sunset.tmpl b/tests/template/sunset.tmpl index 6475bac4ec..465b12a5ea 100644 --- a/tests/template/sunset.tmpl +++ b/tests/template/sunset.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl +#? stdtmpl #proc sunsetTemplate*(current, ticker, content: string, # tabs: openarray[array[0..1, string]]): string = # result = "" diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 2c6a2b5a80..2a8da144d2 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string = # result = "@echo off\nREM Generated by niminst\n" SET CC=gcc diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 52da351bee..463a1ad527 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateBuildShellScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated from niminst\n" & # "# Template is in tools/niminst/buildsh.tmpl\n" & diff --git a/tools/niminst/deinstall.tmpl b/tools/niminst/deinstall.tmpl index c4717a2579..7349abcb43 100644 --- a/tools/niminst/deinstall.tmpl +++ b/tools/niminst/deinstall.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateDeinstallScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated by niminst\n" # var proj = c.name.toLower diff --git a/tools/niminst/inno.tmpl b/tools/niminst/inno.tmpl index 4acf0557c8..ef2da8a755 100644 --- a/tools/niminst/inno.tmpl +++ b/tools/niminst/inno.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl | standard +#? stdtmpl | standard #proc generateInnoSetup(c: ConfigData): string = # result = "" ; Default Template for NimInst diff --git a/tools/niminst/install.tmpl b/tools/niminst/install.tmpl index 3ec42c2874..14d88e07df 100644 --- a/tools/niminst/install.tmpl +++ b/tools/niminst/install.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar = '?') | standard +#? stdtmpl(subsChar = '?') | standard #proc generateInstallScript(c: ConfigData): string = # result = "#! /bin/sh\n# Generated by niminst\n" # var proj = c.name.toLower diff --git a/tools/niminst/makefile.tmpl b/tools/niminst/makefile.tmpl index 8ab3b89d15..6615ddc022 100644 --- a/tools/niminst/makefile.tmpl +++ b/tools/niminst/makefile.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateMakefile(c: ConfigData): string = # result = "# Generated from niminst\n" & # "# Template is in tools/niminst/makefile.tmpl\n" & diff --git a/tools/niminst/nsis.tmpl b/tools/niminst/nsis.tmpl index 843a8cf440..abf4623887 100644 --- a/tools/niminst/nsis.tmpl +++ b/tools/niminst/nsis.tmpl @@ -1,4 +1,4 @@ -#! stdtmpl(subsChar='?') | standard +#? stdtmpl(subsChar='?') | standard #proc generateNsisSetup(c: ConfigData): string = # result = "; NSIS script generated by niminst\n" & # "; To regenerate run ``niminst nsis`` or ``koch nsis``\n" From dd2225fe073c51cee144a06745c9b3ef620b2bbd Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Sep 2015 17:18:41 +0200 Subject: [PATCH 16/23] NimScript: --threads:on works in a nims file --- lib/system.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system.nim b/lib/system.nim index 59d0d04b78..1d2ca6a9a5 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1256,7 +1256,7 @@ proc compileOption*(option, arg: string): bool {. ## echo "compiled with optimization for size and uses Boehm's GC" const - hasThreadSupport = compileOption("threads") + hasThreadSupport = compileOption("threads") and not defined(nimscript) hasSharedHeap = defined(boehmgc) or defined(gogc) # don't share heaps; every thread has its own taintMode = compileOption("taintmode") From 8450ee9d5998e12158b590120321760a8f4b85d9 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Wed, 30 Sep 2015 11:42:50 -0700 Subject: [PATCH 17/23] ensure generated c-code matches --- tests/pragmas/tbitsize.nim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pragmas/tbitsize.nim b/tests/pragmas/tbitsize.nim index b9b478a7f1..7a44944d24 100644 --- a/tests/pragmas/tbitsize.nim +++ b/tests/pragmas/tbitsize.nim @@ -1,3 +1,7 @@ +discard """ +ccodeCheck: "\\i @'unsigned int flag:1;' .*" +""" + type bits* = object flag* {.bitsize: 1.}: cuint From 435fbbc943fb0d932e4d2750a3e8e76a102c8d00 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Wed, 30 Sep 2015 12:09:58 -0700 Subject: [PATCH 18/23] allow testament/tester to run single file --- tests/testament/categories.nim | 4 ++-- tests/testament/tester.nim | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 4de1edeee1..afc4a616f3 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -339,7 +339,7 @@ proc `&?.`(a, b: string): string = # candidate for the stdlib? result = if a.endswith(b): a else: a & b -proc processCategory(r: var TResults, cat: Category, options: string) = +proc processCategory(r: var TResults, cat: Category, options: string, fileGlob: string = "t*.nim") = case cat.string.normalize of "rodfiles": discard # Disabled for now @@ -376,5 +376,5 @@ proc processCategory(r: var TResults, cat: Category, options: string) = of "nimble-all": testNimblePackages(r, cat, pfAll) else: - for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"): + for name in os.walkFiles("tests" & DirSep &.? cat.string / fileGlob): testSpec r, makeTest(name, options, cat) diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index b138c9909d..3961f15c40 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -23,6 +23,7 @@ const Command: all run all tests c|category run all the tests of a certain category + r|run run single test file html [commit] generate $1 from the database; uses the latest commit or a specific one (use -1 for the commit before latest etc) @@ -376,6 +377,11 @@ proc main() = var cat = Category(p.key) p.next processCategory(r, cat, p.cmdLineRest.string) + of "r", "run": + let (dir, file) = splitPath(p.key.string) + let (_, subdir) = splitPath(dir) + var cat = Category(subdir) + processCategory(r, cat, p.cmdLineRest.string, file) of "html": var commit = 0 discard parseInt(p.cmdLineRest.string, commit) From 5a003532d0660a962a978ee6763dd9b3a5425ab8 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 30 Sep 2015 21:04:21 +0200 Subject: [PATCH 19/23] fixes #2473; cleanup of some tests --- compiler/vmgen.nim | 15 +++++++++------ examples/curlex.nim | 10 ---------- examples/iupex1.nim | 37 ------------------------------------- tests/stdlib/tmemfiles2.nim | 2 ++ tests/vm/tsimpleglobals.nim | 16 ++++++++++++++++ tests/vm/twrongconst.nim | 2 +- 6 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 examples/curlex.nim delete mode 100644 examples/iupex1.nim create mode 100644 tests/vm/tsimpleglobals.nim diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 0559acc880..92db0d513f 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -37,7 +37,7 @@ when hasFFI: import evalffi type - TGenFlag = enum gfNone, gfAddrOf + TGenFlag = enum gfAddrOf, gfFieldAccess TGenFlags = set[TGenFlag] proc debugInfo(info: TLineInfo): string = @@ -535,7 +535,7 @@ proc genIndex(c: PCtx; n: PNode; arr: PType): TRegister = proc genAsgnPatch(c: PCtx; le: PNode, value: TRegister) = case le.kind of nkBracketExpr: - let dest = c.genx(le.sons[0], {gfAddrOf}) + let dest = c.genx(le.sons[0], {gfAddrOf, gfFieldAccess}) let idx = c.genIndex(le.sons[1], le.sons[0].typ) c.gABC(le, opcWrArr, dest, idx, value) c.freeTemp(dest) @@ -543,7 +543,7 @@ proc genAsgnPatch(c: PCtx; le: PNode, value: TRegister) = of nkDotExpr, nkCheckedFieldExpr: # XXX field checks here let left = if le.kind == nkDotExpr: le else: le.sons[0] - let dest = c.genx(left.sons[0], {gfAddrOf}) + let dest = c.genx(left.sons[0], {gfAddrOf, gfFieldAccess}) let idx = genField(left.sons[1]) c.gABC(left, opcWrObj, dest, idx, value) c.freeTemp(dest) @@ -1216,7 +1216,7 @@ proc preventFalseAlias(c: PCtx; n: PNode; opc: TOpcode; proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) = case le.kind of nkBracketExpr: - let dest = c.genx(le.sons[0], {gfAddrOf}) + let dest = c.genx(le.sons[0], {gfAddrOf, gfFieldAccess}) let idx = c.genIndex(le.sons[1], le.sons[0].typ) let tmp = c.genx(ri) if le.sons[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in { @@ -1228,7 +1228,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) = of nkDotExpr, nkCheckedFieldExpr: # XXX field checks here let left = if le.kind == nkDotExpr: le else: le.sons[0] - let dest = c.genx(left.sons[0], {gfAddrOf}) + let dest = c.genx(left.sons[0], {gfAddrOf, gfFieldAccess}) let idx = genField(left.sons[1]) let tmp = c.genx(ri) c.preventFalseAlias(left, opcWrObj, dest, idx, tmp) @@ -1321,7 +1321,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) = c.gABx(n, opcLdGlobal, cc, s.position) c.gABC(n, opcNodeToReg, dest, cc) c.freeTemp(cc) - elif gfAddrOf in flags: + elif {gfAddrOf, gfFieldAccess} * flags == {gfAddrOf}: c.gABx(n, opcLdGlobalAddr, dest, s.position) else: c.gABx(n, opcLdGlobal, dest, s.position) @@ -1773,6 +1773,9 @@ proc genExpr*(c: PCtx; n: PNode, requiresValue = true): int = d = 0 c.gABC(n, opcEof, d) + #echo renderTree(n) + #c.echoCode(result) + proc genParams(c: PCtx; params: PNode) = # res.sym.position is already 0 c.prc.slots[0] = (inUse: true, kind: slotFixedVar) diff --git a/examples/curlex.nim b/examples/curlex.nim deleted file mode 100644 index 21786a6eeb..0000000000 --- a/examples/curlex.nim +++ /dev/null @@ -1,10 +0,0 @@ -import - libcurl - -var hCurl = easy_init() -if hCurl != nil: - discard easy_setopt(hCurl, OPT_VERBOSE, true) - discard easy_setopt(hCurl, OPT_URL, "http://nim-lang.org/") - discard easy_perform(hCurl) - easy_cleanup(hCurl) - diff --git a/examples/iupex1.nim b/examples/iupex1.nim deleted file mode 100644 index f768fb23f9..0000000000 --- a/examples/iupex1.nim +++ /dev/null @@ -1,37 +0,0 @@ -# Example IUP program - -# iupTabs: Creates a iupTabs control. - -import iup - -discard iup.open(nil, nil) - -var vbox1 = iup.vbox(iup.label("Inside Tab A"), iup.button("Button A", ""), nil) -var vbox2 = iup.vbox(iup.label("Inside Tab B"), iup.button("Button B", ""), nil) - -iup.setAttribute(vbox1, "TABTITLE", "Tab A") -iup.setAttribute(vbox2, "TABTITLE", "Tab B") - -var tabs1 = iup.tabs(vbox1, vbox2, nil) - -vbox1 = iup.vbox(iup.label("Inside Tab C"), iup.button("Button C", ""), nil) -vbox2 = iup.vbox(iup.label("Inside Tab D"), iup.button("Button D", ""), nil) - -iup.setAttribute(vbox1, "TABTITLE", "Tab C") -iup.setAttribute(vbox2, "TABTITLE", "Tab D") - -var tabs2 = iup.tabs(vbox1, vbox2, nil) -iup.setAttribute(tabs2, "TABTYPE", "LEFT") - -var box = iup.hbox(tabs1, tabs2, nil) -iup.setAttribute(box, "MARGIN", "10x10") -iup.setAttribute(box, "GAP", "10") - -var dlg = iup.dialog(box) -iup.setAttribute(dlg, "TITLE", "iupTabs") -iup.setAttribute(dlg, "SIZE", "200x100") - -discard showXY(dlg, IUP_CENTER, IUP_CENTER) -discard mainLoop() -close() - diff --git a/tests/stdlib/tmemfiles2.nim b/tests/stdlib/tmemfiles2.nim index 28af3296a7..026443e93e 100644 --- a/tests/stdlib/tmemfiles2.nim +++ b/tests/stdlib/tmemfiles2.nim @@ -1,8 +1,10 @@ discard """ file: "tmemfiles2.nim" + disabled: true output: '''Full read size: 20 Half read size: 10 Data: Hello''' """ +# doesn't work on windows. fmReadWrite doesn't create a file. import memfiles, os var mm, mm_full, mm_half: MemFile diff --git a/tests/vm/tsimpleglobals.nim b/tests/vm/tsimpleglobals.nim new file mode 100644 index 0000000000..27bfdce502 --- /dev/null +++ b/tests/vm/tsimpleglobals.nim @@ -0,0 +1,16 @@ +discard """ + msg: "abc xyz bb" +""" + +# bug #2473 +type + Test = tuple[a,b: string] + +static: + var s:seq[Test] = @[(a:"a", b:"b")] + s[0] = (a:"aa", b:"bb") + + var x: Test + x.a = "abc" + x.b = "xyz" + echo x.a, " ", x.b, " ", s[0].b diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim index 68ab2757cf..424ed080ee 100644 --- a/tests/vm/twrongconst.nim +++ b/tests/vm/twrongconst.nim @@ -1,6 +1,6 @@ discard """ errormsg: "cannot evaluate at compile time: x" - line: 9 + line: 7 """ var x: array[100, char] From 8c8646773024ea740c4c9f090619ddaf61bc16f0 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Wed, 30 Sep 2015 12:29:32 -0700 Subject: [PATCH 20/23] document new bitsize pragma --- doc/manual/pragmas.txt | 18 ++++++++++++++++++ web/news.txt | 2 ++ 2 files changed, 20 insertions(+) diff --git a/doc/manual/pragmas.txt b/doc/manual/pragmas.txt index 68a88f865a..f89194c9ad 100644 --- a/doc/manual/pragmas.txt +++ b/doc/manual/pragmas.txt @@ -531,6 +531,24 @@ Implementation Specific Pragmas This section describes additional pragmas that the current Nim implementation supports but which should not be seen as part of the language specification. +Bitsize pragma +-------------- + +The ``bitsize`` pragma is for object field members. It declares the field as +a bitfield in C/C++. + +.. code-block:: Nim + type + mybitfield = object + flag {.bitsize:1.}: cuint + +generates: + +.. code-block:: C + struct mybitfield { + unsigned int flag:1; + }; + Volatile pragma --------------- diff --git a/web/news.txt b/web/news.txt index cfa40c65ca..33ceac49e4 100644 --- a/web/news.txt +++ b/web/news.txt @@ -108,6 +108,8 @@ News - The compiler finally considers symbol binding rules in templates and generics for overloaded ``[]``, ``[]=``, ``{}``, ``{}=`` operators (issue `#2599 `_). + - The compiler now supports a `bitsize pragma `_ + for constructing bitfields. Language Additions From d6b7f0ad9e7a07cdd8295083e1c737a7bf0c6305 Mon Sep 17 00:00:00 2001 From: JamesP Date: Thu, 1 Oct 2015 15:02:46 +1000 Subject: [PATCH 21/23] add assertion for zero denominator --- lib/pure/rationals.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pure/rationals.nim b/lib/pure/rationals.nim index 60d09c71ac..79dc6de168 100644 --- a/lib/pure/rationals.nim +++ b/lib/pure/rationals.nim @@ -20,6 +20,7 @@ type Rational*[T] = object proc initRational*[T](num, den: T): Rational[T] = ## Create a new rational number. + assert(den != 0, "a denominator of zero value is invalid") result.num = num result.den = den From 2f4cc4efce714f036018107f73cf1f5db40cbffd Mon Sep 17 00:00:00 2001 From: JamesP Date: Thu, 1 Oct 2015 15:07:23 +1000 Subject: [PATCH 22/23] add a few type checks to limit type to SomeInteger (adding a compund type to the Rational type definition made it too difficult to define new variables using integer literals) --- lib/pure/rationals.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pure/rationals.nim b/lib/pure/rationals.nim index 79dc6de168..7d9241412a 100644 --- a/lib/pure/rationals.nim +++ b/lib/pure/rationals.nim @@ -18,7 +18,7 @@ type Rational*[T] = object ## a rational number, consisting of a numerator and denominator num*, den*: T -proc initRational*[T](num, den: T): Rational[T] = +proc initRational*[T:SomeInteger](num, den: T): Rational[T] = ## Create a new rational number. assert(den != 0, "a denominator of zero value is invalid") result.num = num @@ -34,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string = ## Turn a rational number into a string. result = $x.num & "/" & $x.den -proc toRational*[T](x: T): Rational[T] = +proc toRational*[T:SomeInteger](x: T): Rational[T] = ## Convert some integer `x` to a rational number. result.num = x result.den = 1 @@ -48,7 +48,7 @@ proc toInt*[T](x: Rational[T]): int = ## `x` does not contain an integer value. x.num div x.den -proc reduce*[T](x: var Rational[T]) = +proc reduce*[T:SomeInteger](x: var Rational[T]) = ## Reduce rational `x`. let common = gcd(x.num, x.den) if x.den > 0: From ce18b85d2cfa89a148c9530ac654605475f19a73 Mon Sep 17 00:00:00 2001 From: JamesP Date: Thu, 1 Oct 2015 20:32:49 +1000 Subject: [PATCH 23/23] add two test: zero denominator assert fail, float type compile failure --- tests/rational/trat_float.nim | 9 +++++++++ tests/rational/trat_init.nim | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/rational/trat_float.nim create mode 100644 tests/rational/trat_init.nim diff --git a/tests/rational/trat_float.nim b/tests/rational/trat_float.nim new file mode 100644 index 0000000000..24797c4a01 --- /dev/null +++ b/tests/rational/trat_float.nim @@ -0,0 +1,9 @@ +discard """ + file: "trat_float.nim" + line: "9,19" + errormsg: '''type mismatch: got''' +""" +import rationals +var + # this fails - no floats as num or den + r = initRational(1.0'f, 1.0'f) diff --git a/tests/rational/trat_init.nim b/tests/rational/trat_init.nim new file mode 100644 index 0000000000..df29ff6e33 --- /dev/null +++ b/tests/rational/trat_init.nim @@ -0,0 +1,10 @@ +discard """ + file: "trat_init.nim" + exitcode: "1" +""" +import rationals +var + z = Rational[int](num: 0, den: 1) + o = initRational(num=1, den=1) + a = initRational(1, 2) + r = initRational(1, 0) # this fails - no zero denominator