diff options
-rw-r--r-- | compiler/aliases.nim | 2 | ||||
-rw-r--r-- | compiler/jstypes.nim | 5 | ||||
-rw-r--r-- | compiler/vm.nim | 13 | ||||
-rw-r--r-- | doc/manual/procs.txt | 8 | ||||
-rw-r--r-- | lib/pure/json.nim | 13 | ||||
-rw-r--r-- | lib/system/repr.nim | 20 | ||||
-rw-r--r-- | tests/alias/talias.nim | 5 | ||||
-rw-r--r-- | web/news.txt | 20 |
8 files changed, 74 insertions, 12 deletions
diff --git a/compiler/aliases.nim b/compiler/aliases.nim index 3d3fc9a79..4b592ee60 100644 --- a/compiler/aliases.nim +++ b/compiler/aliases.nim @@ -146,7 +146,7 @@ proc isPartOf*(a, b: PNode): TAnalysisResult = # go down recursively; this is quite demanding: const Ix0Kinds = {nkDotExpr, nkBracketExpr, nkObjUpConv, nkObjDownConv, - nkCheckedFieldExpr} + nkCheckedFieldExpr, nkHiddenAddr} Ix1Kinds = {nkHiddenStdConv, nkHiddenSubConv, nkConv} DerefKinds = {nkHiddenDeref, nkDerefExpr} case b.kind diff --git a/compiler/jstypes.nim b/compiler/jstypes.nim index 851938327..832d9996c 100644 --- a/compiler/jstypes.nim +++ b/compiler/jstypes.nim @@ -116,8 +116,7 @@ proc genEnumInfo(p: PProc, typ: PType, name: Rope) = [name, genTypeInfo(p, typ.sons[0])]) proc genTypeInfo(p: PProc, typ: PType): Rope = - var t = typ - if t.kind == tyGenericInst: t = lastSon(t) + let t = typ.skipTypes({tyGenericInst}) result = "NTI$1" % [rope(t.id)] if containsOrIncl(p.g.typeInfoGenerated, t.id): return case t.kind @@ -141,7 +140,7 @@ proc genTypeInfo(p: PProc, typ: PType): Rope = [result, rope(ord(t.kind))] prepend(p.g.typeInfo, s) addf(p.g.typeInfo, "$1.base = $2;$n", - [result, genTypeInfo(p, typ.sons[1])]) + [result, genTypeInfo(p, t.sons[1])]) of tyEnum: genEnumInfo(p, t, result) of tyObject: genObjectInfo(p, t, result) of tyTuple: genTupleInfo(p, t, result) diff --git a/compiler/vm.nim b/compiler/vm.nim index 0db287c6a..4dd3b5232 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -320,8 +320,19 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool = dest.node.strVal = if src.intVal == 0: "false" else: "true" of tyFloat..tyFloat128: dest.node.strVal = $src.floatVal - of tyString, tyCString: + of tyString: dest.node.strVal = src.node.strVal + of tyCString: + if src.node.kind == nkBracket: + # Array of chars + var strVal = "" + for son in src.node.sons: + let c = char(son.intVal) + if c == '\0': break + strVal.add(c) + dest.node.strVal = strVal + else: + dest.node.strVal = src.node.strVal of tyChar: dest.node.strVal = $chr(src.intVal) else: diff --git a/doc/manual/procs.txt b/doc/manual/procs.txt index 9d00b7e3c..ee74b2ea6 100644 --- a/doc/manual/procs.txt +++ b/doc/manual/procs.txt @@ -137,6 +137,14 @@ to supply any type of first argument for procedures: Another way to look at the method call syntax is that it provides the missing postfix notation. +The method call syntax conflicts with explicit generic instantiations: +``p[T](x)`` cannot be written as ``x.p[T]`` because ``x.p[T]`` is always +parsed as ``(x.p)[T]``. + +**Future directions**: ``p[.T.]`` might be introduced as an alternative syntax +to pass explict types to a generic and then ``x.p[.T.]`` can be parsed as +``x.(p[.T.])``. + See also: `Limitations of the method call syntax`_. diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 540a1a8eb..abf6305f2 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -1074,9 +1074,9 @@ when not defined(js): ## for nice error messages. var p: JsonParser p.open(s, filename) + defer: p.close() discard getTok(p) # read first token result = p.parseJson() - p.close() proc parseJson*(buffer: string): JsonNode = ## Parses JSON from `buffer`. @@ -1203,6 +1203,17 @@ when isMainModule: testJson{["c", "d"]} = %true assert(testJson["c"]["d"].bval) + # make sure no memory leek when parsing invalid string + let startMemory = getOccupiedMem() + for i in 0 .. 10000: + try: + discard parseJson"""{ invalid""" + except: + discard + # memory diff should less than 2M + assert(abs(getOccupiedMem() - startMemory) < 2 * 1024 * 1024) + + # test `$` let stringified = $testJson let parsedAgain = parseJson(stringified) diff --git a/lib/system/repr.nim b/lib/system/repr.nim index b4188527f..1f81a0813 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -21,9 +21,22 @@ proc reprPointer(x: pointer): string {.compilerproc.} = return $buf proc `$`(x: uint64): string = - var buf: array [0..59, char] - discard c_sprintf(buf, "%llu", x) - return $buf + if x == 0: + result = "0" + else: + var buf: array [60, char] + var i = 0 + var n = x + while n != 0: + let nn = n div 10'u64 + buf[i] = char(n - 10'u64 * nn + ord('0')) + inc i + n = nn + + let half = i div 2 + # Reverse + for t in 0 .. < half: swap(buf[t], buf[i-t-1]) + result = $buf proc reprStrAux(result: var string, s: string) = if cast[pointer](s) == nil: @@ -294,4 +307,3 @@ when not defined(useNimRtl): reprAux(result, addr(p), typ, cl) add result, "\n" deinitReprClosure(cl) - diff --git a/tests/alias/talias.nim b/tests/alias/talias.nim index 6addc4704..810ea2095 100644 --- a/tests/alias/talias.nim +++ b/tests/alias/talias.nim @@ -30,7 +30,7 @@ type c: char se: seq[TA] -proc p(param1, param2: TC): TC = +proc p(param1, param2: TC, param3: var TC): TC = var local: TC plocal: ptr TC @@ -43,6 +43,7 @@ proc p(param1, param2: TC): TC = plocal2[] ?<| local param1 ?<| param2 + local ?<| param3 local.arr[0] !<| param1 local.arr !<| param1 @@ -62,5 +63,5 @@ var a <| a a !<| b -discard p(x, x) +discard p(x, x, x) diff --git a/web/news.txt b/web/news.txt index 4c7f23cf6..1a312f67b 100644 --- a/web/news.txt +++ b/web/news.txt @@ -306,6 +306,26 @@ xist" (`#2183 <https://github.com/Araq/Nim/issues/2183>`_) - Fixed "gctest segfaults with --gc:markandsweep on x86_64" (`#2305 <https://github.com/Araq/Nim/issues/2305>`_) + - Fixed "Coroutine changes break compilation on unsupported architectures" + (`#3245 <https://github.com/Araq/Nim/issues/3245>`_) + - Fixed "Bugfix: Windows 32bit TinyCC support issue fixed" + (`#3237 <https://github.com/Araq/Nim/issues/3237>`_) + - Fixed "db_mysql getValue() followed by exec() causing error" + (`#3220 <https://github.com/Araq/Nim/issues/3220>`_) + - Fixed "xmltree.newEntity creates xnCData instead of xnEntity" + (`#3282 <https://github.com/Araq/Nim/issues/3282>`_) + - Fixed "Methods and modules don't work together" + (`#2590 <https://github.com/Araq/Nim/issues/2590>`_) + - Fixed "String slicing not working in the vm" + (`#3300 <https://github.com/Araq/Nim/issues/3300>`_) + - Fixed "internal error: evalOp(mTypeOf)" + (`#3230 <https://github.com/Araq/Nim/issues/3230>`_) + - Fixed "#! source code prefix collides with Unix Shebang" + (`#2559 <https://github.com/Araq/Nim/issues/2559>`_) + - Fixed "wrong codegen for constant object" + (`#3195 <https://github.com/Araq/Nim/issues/3195>`_) + - Fixed "Doc comments inside procs with implicit returns don't work" + (`#1528 <https://github.com/Araq/Nim/issues/1528>`_) 2015-05-04 Version 0.11.2 released |