Merge branch 'devel' of github.com:Araq/Nim into patch2
This commit is contained in:
commit
770914bc16
3 changed files with 277 additions and 249 deletions
|
|
@ -378,7 +378,7 @@ proc symToYaml(n: PSym, indent: int = 0, maxRecDepth: int = - 1): PRope =
|
||||||
var marker = initIntSet()
|
var marker = initIntSet()
|
||||||
result = symToYamlAux(n, marker, indent, maxRecDepth)
|
result = symToYamlAux(n, marker, indent, maxRecDepth)
|
||||||
|
|
||||||
proc debugTree(n: PNode, indent: int, maxRecDepth: int; renderType=false): PRope
|
proc debugTree*(n: PNode, indent: int, maxRecDepth: int; renderType=false): PRope
|
||||||
proc debugType(n: PType, maxRecDepth=100): PRope =
|
proc debugType(n: PType, maxRecDepth=100): PRope =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
result = toRope("null")
|
result = toRope("null")
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,24 @@ y.v() --> y.v() is correct
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
proc skipAddrDeref(node: PNode): PNode =
|
||||||
|
var n = node
|
||||||
|
var isAddr = false
|
||||||
|
case n.kind
|
||||||
|
of nkAddr, nkHiddenAddr:
|
||||||
|
n = n.sons[0]
|
||||||
|
isAddr = true
|
||||||
|
of nkDerefExpr, nkHiddenDeref:
|
||||||
|
n = n.sons[0]
|
||||||
|
else: return n
|
||||||
|
if n.kind == nkObjDownConv: n = n.sons[0]
|
||||||
|
if isAddr and n.kind in {nkDerefExpr, nkHiddenDeref}:
|
||||||
|
result = n.sons[0]
|
||||||
|
elif n.kind in {nkAddr, nkHiddenAddr}:
|
||||||
|
result = n.sons[0]
|
||||||
|
else:
|
||||||
|
result = node
|
||||||
|
|
||||||
proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
|
proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
|
||||||
# for better or worse c2nim translates the 'this' argument to a 'var T'.
|
# for better or worse c2nim translates the 'this' argument to a 'var T'.
|
||||||
# However manual wrappers may also use 'ptr T'. In any case we support both
|
# However manual wrappers may also use 'ptr T'. In any case we support both
|
||||||
|
|
@ -301,7 +319,8 @@ proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
|
||||||
# skip the deref:
|
# skip the deref:
|
||||||
var ri = ri[i]
|
var ri = ri[i]
|
||||||
while ri.kind == nkObjDownConv: ri = ri[0]
|
while ri.kind == nkObjDownConv: ri = ri[0]
|
||||||
if typ.sons[i].kind == tyVar:
|
let t = typ.sons[i].skipTypes({tyGenericInst})
|
||||||
|
if t.kind == tyVar:
|
||||||
let x = if ri.kind == nkHiddenAddr: ri[0] else: ri
|
let x = if ri.kind == nkHiddenAddr: ri[0] else: ri
|
||||||
if x.typ.kind == tyPtr:
|
if x.typ.kind == tyPtr:
|
||||||
result = genArgNoParam(p, x)
|
result = genArgNoParam(p, x)
|
||||||
|
|
@ -312,7 +331,7 @@ proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
|
||||||
else:
|
else:
|
||||||
result = genArgNoParam(p, x)
|
result = genArgNoParam(p, x)
|
||||||
result.app(".")
|
result.app(".")
|
||||||
elif typ.sons[i].kind == tyPtr:
|
elif t.kind == tyPtr:
|
||||||
if ri.kind in {nkAddr, nkHiddenAddr}:
|
if ri.kind in {nkAddr, nkHiddenAddr}:
|
||||||
result = genArgNoParam(p, ri[0])
|
result = genArgNoParam(p, ri[0])
|
||||||
result.app(".")
|
result.app(".")
|
||||||
|
|
@ -320,6 +339,8 @@ proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
|
||||||
result = genArgNoParam(p, ri)
|
result = genArgNoParam(p, ri)
|
||||||
result.app("->")
|
result.app("->")
|
||||||
else:
|
else:
|
||||||
|
ri = skipAddrDeref(ri)
|
||||||
|
if ri.kind in {nkAddr, nkHiddenAddr}: ri = ri[0]
|
||||||
result = genArgNoParam(p, ri) #, typ.n.sons[i].sym)
|
result = genArgNoParam(p, ri) #, typ.n.sons[i].sym)
|
||||||
result.app(".")
|
result.app(".")
|
||||||
|
|
||||||
|
|
@ -354,6 +375,11 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): PRope =
|
||||||
elif pat[i+1] == '.':
|
elif pat[i+1] == '.':
|
||||||
result.app genThisArg(p, ri, j, typ)
|
result.app genThisArg(p, ri, j, typ)
|
||||||
inc i
|
inc i
|
||||||
|
elif pat[i+1] == '[':
|
||||||
|
var arg = ri.sons[j].skipAddrDeref
|
||||||
|
while arg.kind in {nkAddr, nkHiddenAddr, nkObjDownConv}: arg = arg[0]
|
||||||
|
result.app genArgNoParam(p, arg)
|
||||||
|
#result.app debugTree(arg, 0, 10)
|
||||||
else:
|
else:
|
||||||
result.app genOtherArg(p, ri, j, typ)
|
result.app genOtherArg(p, ri, j, typ)
|
||||||
inc j
|
inc j
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,8 @@ elif defined(JS):
|
||||||
|
|
||||||
proc getTimezone(): int = result = newDate().getTimezoneOffset()
|
proc getTimezone(): int = result = newDate().getTimezoneOffset()
|
||||||
|
|
||||||
|
proc epochTime*(): float {.tags: [TimeEffect].} = newDate().toSeconds()
|
||||||
|
|
||||||
proc getDateStr*(): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
proc getDateStr*(): string {.rtl, extern: "nt$1", tags: [TimeEffect].} =
|
||||||
## gets the current date as a string of the format ``YYYY-MM-DD``.
|
## gets the current date as a string of the format ``YYYY-MM-DD``.
|
||||||
var ti = getLocalTime(getTime())
|
var ti = getLocalTime(getTime())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue