Merge remote-tracking branch 'nim-lang/devel' into emscripten-support

This commit is contained in:
Andrey Sobolev
2015-09-15 14:13:25 +06:00
7 changed files with 66 additions and 12 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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:

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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