From 6e0e3b75cf419f9f2e61aeccaa59f91160e29628 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 10 May 2017 10:29:30 +0300 Subject: [PATCH 1/9] Fixed const sets in JS (#5790) --- compiler/jsgen.nim | 1 - compiler/jstypes.nim | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index eb3fb9f479..ee35356c92 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2272,7 +2272,6 @@ proc myProcess(b: PPassContext, n: PNode): PNode = genModule(p, n) add(p.g.code, p.locals) add(p.g.code, p.body) - globals.unique = p.unique proc wholeCode(graph: ModuleGraph; m: BModule): Rope = for prc in globals.forwarded: diff --git a/compiler/jstypes.nim b/compiler/jstypes.nim index f49bd76683..ae30861e7b 100644 --- a/compiler/jstypes.nim +++ b/compiler/jstypes.nim @@ -59,7 +59,7 @@ proc genObjectFields(p: PProc, typ: PType, n: PNode): Rope = u = rope(lengthOrd(field.typ)) else: internalError(n.info, "genObjectFields(nkRecCase)") if result != nil: add(result, ", " & tnl) - addf(result, "[SetConstr($1), $2]", + addf(result, "[setConstr($1), $2]", [u, genObjectFields(p, typ, lastSon(b))]) result = ("{kind: 3, offset: \"$1\", len: $3, " & "typ: $2, name: $4, sons: [$5]}") % [ From 2e7551f17eeff16715dd788e076d40fe3eb07879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mice=20P=C3=A1pai?= Date: Wed, 10 May 2017 14:04:38 +0200 Subject: [PATCH 2/9] Fix a typo in the Result variable block --- doc/tut1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tut1.rst b/doc/tut1.rst index 06ee84c0db..de89a0b2d9 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -599,7 +599,7 @@ Result variable A procedure that returns a value has an implicit ``result`` variable declared that represents the return value. A ``return`` statement with no expression is a shorthand for ``return result``. The ``result`` value is always returned -automatically at the end a procedure if there is no ``return`` statement at +automatically at the end of a procedure if there is no ``return`` statement at the exit. .. code-block:: nim From 1a29069ececd4514195a58e1fe68385fa1240d46 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 11 May 2017 17:00:50 +0200 Subject: [PATCH 3/9] attempt to make nimsuggest work with choosenim --- nimsuggest/nimsuggest.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index c1adb87a1c..93a418dd72 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -595,6 +595,8 @@ proc handleCmdLine(cache: IdentCache; config: ConfigRef) = raise newException(IOError, "Cannot find Nim standard library: Nim compiler not in PATH") gPrefixDir = binaryPath.splitPath().head.parentDir() + if not dirExists(gPrefixDir / "lib"): gPrefixDir = "" + #msgs.writelnHook = proc (line: string) = log(line) myLog("START " & gProjectFull) From 29507d2491939d2979fbdfc4704142bc6ef2565c Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Fri, 12 May 2017 03:30:48 +0700 Subject: [PATCH 4/9] Consider optNoCppExceptions in blockLeaveActions (#5801) --- compiler/ccgstmts.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index cc925b150c..a094da783e 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -332,7 +332,7 @@ proc blockLeaveActions(p: BProc, howManyTrys, howManyExcepts: int) = var alreadyPoppedCnt = p.inExceptBlock for i in countup(1, howManyTrys): - if not p.module.compileToCpp: + if not p.module.compileToCpp or optNoCppExceptions in gGlobalOptions: # Pop safe points generated by try if alreadyPoppedCnt > 0: dec alreadyPoppedCnt @@ -354,7 +354,7 @@ proc blockLeaveActions(p: BProc, howManyTrys, howManyExcepts: int) = for i in countdown(howManyTrys-1, 0): p.nestedTryStmts.add(stack[i]) - if not p.module.compileToCpp: + if not p.module.compileToCpp or optNoCppExceptions in gGlobalOptions: # Pop exceptions that was handled by the # except-blocks we are in for i in countdown(howManyExcepts-1, 0): From 2e420dfa382dc5af3a225a7b073da2d0eb3d899f Mon Sep 17 00:00:00 2001 From: Parashurama Date: Fri, 12 May 2017 11:21:43 +0200 Subject: [PATCH 5/9] fixes multiple nil-checks for methods (#5806) --- compiler/cgmeth.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index e14306e568..1165ec9323 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -233,6 +233,12 @@ proc genDispatcher(methods: TSymSeq, relevantCols: IntSet): PSym = var disp = newNodeI(nkIfStmt, base.info) var ands = getSysSym("and") var iss = getSysSym("of") + for col in countup(1, paramLen - 1): + if contains(relevantCols, col): + let param = base.typ.n.sons[col].sym + if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: + addSon(nilchecks, newTree(nkCall, + newSymNode(getCompilerProc"chckNilDisp"), newSymNode(param))) for meth in countup(0, high(methods)): var curr = methods[meth] # generate condition: var cond: PNode = nil @@ -242,9 +248,6 @@ proc genDispatcher(methods: TSymSeq, relevantCols: IntSet): PSym = addSon(isn, newSymNode(iss)) let param = base.typ.n.sons[col].sym addSon(isn, newSymNode(param)) - if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: - addSon(nilchecks, newTree(nkCall, - newSymNode(getCompilerProc"chckNilDisp"), newSymNode(param))) addSon(isn, newNodeIT(nkType, base.info, curr.typ.sons[col])) if cond != nil: var a = newNodeIT(nkCall, base.info, getSysType(tyBool)) From 77cadd07f9079ef9c5f3907cbe273b075aa1f76d Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Fri, 12 May 2017 16:24:45 +0700 Subject: [PATCH 6/9] Fix atomicInc under vcc, C++, amd64 (#5809) Also, fixed inconsistent behaviour of atomicInc on vcc. Previously it would return the old value, while it must return the new value. Fixes: #5808 --- lib/system/atomics.nim | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/system/atomics.nim b/lib/system/atomics.nim index 3a43729dc2..885b01621b 100644 --- a/lib/system/atomics.nim +++ b/lib/system/atomics.nim @@ -165,8 +165,22 @@ when someGcc and hasThreadSupport: template fence*() = atomicThreadFence(ATOMIC_SEQ_CST) elif defined(vcc) and hasThreadSupport: - proc addAndFetch*(p: ptr int, val: int): int {. - importc: "_InterlockedExchangeAdd", header: "".} + when defined(cpp): + when sizeof(int) == 8: + proc addAndFetch*(p: ptr int, val: int): int {. + importcpp: "_InterlockedExchangeAdd64(static_cast(#), #)", + header: "".} + else: + proc addAndFetch*(p: ptr int, val: int): int {. + importcpp: "_InterlockedExchangeAdd(static_cast(#), #)", + header: "".} + else: + when sizeof(int) == 8: + proc addAndFetch*(p: ptr int, val: int): int {. + importc: "_InterlockedExchangeAdd64", header: "".} + else: + proc addAndFetch*(p: ptr int, val: int): int {. + importc: "_InterlockedExchangeAdd", header: "".} proc fence*() {.importc: "_ReadWriteBarrier", header: "".} @@ -180,6 +194,7 @@ proc atomicInc*(memLoc: var int, x: int = 1): int = result = atomic_add_fetch(memLoc.addr, x, ATOMIC_RELAXED) elif defined(vcc) and hasThreadSupport: result = addAndFetch(memLoc.addr, x) + inc(result, x) else: inc(memLoc, x) result = memLoc @@ -192,6 +207,7 @@ proc atomicDec*(memLoc: var int, x: int = 1): int = result = atomic_add_fetch(memLoc.addr, -x, ATOMIC_RELAXED) elif defined(vcc) and hasThreadSupport: result = addAndFetch(memLoc.addr, -x) + dec(result, x) else: dec(memLoc, x) result = memLoc From 534d8a6b59bce5eadd543929d01ccb2f40747fcb Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Fri, 12 May 2017 13:11:58 +0300 Subject: [PATCH 7/9] Fixed syslocks for ios (#5804) --- lib/system/syslocks.nim | 112 +++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 23 deletions(-) diff --git a/lib/system/syslocks.nim b/lib/system/syslocks.nim index fb354880f9..f61b887ad2 100644 --- a/lib/system/syslocks.nim +++ b/lib/system/syslocks.nim @@ -99,7 +99,7 @@ elif defined(genode): else: type - SysLock {.importc: "pthread_mutex_t", pure, final, + SysLockObj {.importc: "pthread_mutex_t", pure, final, header: """#include #include """.} = object when defined(linux) and defined(amd64): @@ -111,7 +111,7 @@ else: when defined(linux) and defined(amd64): abi: array[4 div sizeof(cint), cint] # actually a cint - SysCond {.importc: "pthread_cond_t", pure, final, + SysCondObj {.importc: "pthread_cond_t", pure, final, header: """#include #include """.} = object when defined(linux) and defined(amd64): @@ -119,8 +119,62 @@ else: SysLockType = distinct cint - proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {. + proc initSysLockAux(L: var SysLockObj, attr: ptr SysLockAttr) {. importc: "pthread_mutex_init", header: "", noSideEffect.} + proc deinitSysAux(L: var SysLockObj) {.noSideEffect, + importc: "pthread_mutex_destroy", header: "".} + + proc acquireSysAux(L: var SysLockObj) {.noSideEffect, + importc: "pthread_mutex_lock", header: "".} + proc tryAcquireSysAux(L: var SysLockObj): cint {.noSideEffect, + importc: "pthread_mutex_trylock", header: "".} + + proc releaseSysAux(L: var SysLockObj) {.noSideEffect, + importc: "pthread_mutex_unlock", header: "".} + + when defined(ios): + # iOS will behave badly if sync primitives are moved in memory. In order + # to prevent this once and for all, we're doing an extra malloc when + # initializing the primitive. + type + SysLock = ptr SysLockObj + SysCond = ptr SysCondObj + + when not declared(c_malloc): + proc c_malloc(size: csize): pointer {. + importc: "malloc", header: "".} + proc c_free(p: pointer) {. + importc: "free", header: "".} + + proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) = + L = cast[SysLock](c_malloc(sizeof(SysLockObj))) + initSysLockAux(L[], attr) + + proc deinitSys(L: var SysLock) = + deinitSysAux(L[]) + c_free(L) + + template acquireSys(L: var SysLock) = + acquireSysAux(L[]) + template tryAcquireSys(L: var SysLock): bool = + tryAcquireSysAux(L[]) == 0'i32 + template releaseSys(L: var SysLock) = + releaseSysAux(L[]) + else: + type + SysLock = SysLockObj + SysCond = SysCondObj + + template initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) = + initSysLockAux(L, attr) + template deinitSys(L: var SysLock) = + deinitSysAux(L) + template acquireSys(L: var SysLock) = + acquireSysAux(L) + template tryAcquireSys(L: var SysLock): bool = + tryAcquireSysAux(L) == 0'i32 + template releaseSys(L: var SysLock) = + releaseSysAux(L) when insideRLocksModule: proc SysLockType_Reentrant: SysLockType = @@ -130,27 +184,39 @@ else: proc setSysLockType(a: var SysLockAttr, t: SysLockType) {. importc: "pthread_mutexattr_settype", header: "", noSideEffect.} - proc acquireSys(L: var SysLock) {.noSideEffect, - importc: "pthread_mutex_lock", header: "".} - proc tryAcquireSysAux(L: var SysLock): cint {.noSideEffect, - importc: "pthread_mutex_trylock", header: "".} - - proc tryAcquireSys(L: var SysLock): bool {.inline.} = - result = tryAcquireSysAux(L) == 0'i32 - - proc releaseSys(L: var SysLock) {.noSideEffect, - importc: "pthread_mutex_unlock", header: "".} - proc deinitSys(L: var SysLock) {.noSideEffect, - importc: "pthread_mutex_destroy", header: "".} - - when not insideRLocksModule: - proc initSysCond(cond: var SysCond, cond_attr: pointer = nil) {. + else: + proc initSysCondAux(cond: var SysCondObj, cond_attr: pointer) {. importc: "pthread_cond_init", header: "", noSideEffect.} - proc waitSysCond(cond: var SysCond, lock: var SysLock) {. - importc: "pthread_cond_wait", header: "", noSideEffect.} - proc signalSysCond(cond: var SysCond) {. - importc: "pthread_cond_signal", header: "", noSideEffect.} - proc deinitSysCond(cond: var SysCond) {.noSideEffect, + proc deinitSysCondAux(cond: var SysCondObj) {.noSideEffect, importc: "pthread_cond_destroy", header: "".} + proc waitSysCondAux(cond: var SysCondObj, lock: var SysLockObj) {. + importc: "pthread_cond_wait", header: "", noSideEffect.} + proc signalSysCondAux(cond: var SysCondObj) {. + importc: "pthread_cond_signal", header: "", noSideEffect.} + + when defined(ios): + proc initSysCond(cond: var SysCond, cond_attr: pointer = nil) = + cond = cast[SysCond](c_malloc(sizeof(SysCondObj))) + initSysCondAux(cond[], cond_attr) + + proc deinitSysCond(cond: var SysCond) = + deinitSysCondAux(cond[]) + c_free(cond) + + template waitSysCond(cond: var SysCond, lock: var SysLock) = + waitSysCondAux(cond[], lock[]) + template signalSysCond(cond: var SysCond) = + signalSysCondAux(cond[]) + else: + template initSysCond(cond: var SysCond, cond_attr: pointer = nil) = + initSysCondAux(cond, cond_attr) + template deinitSysCond(cond: var SysCond) = + deinitSysCondAux(cond) + + template waitSysCond(cond: var SysCond, lock: var SysLock) = + waitSysCondAux(cond, lock) + template signalSysCond(cond: var SysCond) = + signalSysCondAux(cond) + {.pop.} From 40e9e751f0e77211442707820b4737a253334a4f Mon Sep 17 00:00:00 2001 From: Simon Krauter Date: Sat, 13 May 2017 21:50:44 +0200 Subject: [PATCH 8/9] Extend documenation of formatFloat() (#5799) Added line: "If ``precision == 0``, it tries to format it nicely." (copied from formatBiggestFloat()) --- lib/pure/strutils.nim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 9383675f46..458c22f3a5 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -1881,6 +1881,8 @@ proc formatFloat*(f: float, format: FloatFormatMode = ffDefault, ## of significant digits to be printed. ## `precision`'s default value is the maximum number of meaningful digits ## after the decimal point for Nim's ``float`` type. + ## + ## If ``precision == 0``, it tries to format it nicely. result = formatBiggestFloat(f, format, precision, decimalSep) proc trimZeros*(x: var string) {.noSideEffect.} = From f5717490d9498f6399ca15a90e9ecf60488ae80f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mice=20P=C3=A1pai?= Date: Sat, 13 May 2017 21:52:19 +0200 Subject: [PATCH 9/9] tut1.rst: Fix alignment, Change Subrange to MySubrange for clarity (#5798) * tut1.rst: Fix alignment * tut1.rst: Change Subrange to MySubrange for clarity --- doc/tut1.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/tut1.rst b/doc/tut1.rst index de89a0b2d9..436b3880d8 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -1074,8 +1074,8 @@ at runtime by 0, the second by 1 and so on. For example: Direction = enum north, east, south, west - var x = south # `x` is of type `Direction`; its value is `south` - echo x # writes "south" to `stdout` + var x = south # `x` is of type `Direction`; its value is `south` + echo x # writes "south" to `stdout` All the comparison operators can be used with enumeration types. @@ -1132,11 +1132,11 @@ A subrange type is a range of values from an integer or enumeration type .. code-block:: nim type - Subrange = range[0..5] + MySubrange = range[0..5] -``Subrange`` is a subrange of ``int`` which can only hold the values 0 -to 5. Assigning any other value to a variable of type ``Subrange`` is a +``MySubrange`` is a subrange of ``int`` which can only hold the values 0 +to 5. Assigning any other value to a variable of type ``MySubrange`` is a compile-time or runtime error. Assignments from the base type to one of its subrange types (and vice versa) are allowed.