Merge branch 'devel' into araq-new-mm2

This commit is contained in:
Araq 2017-12-08 10:06:56 +01:00
commit b0c682de4d
11 changed files with 103 additions and 28 deletions

View file

@ -654,6 +654,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
gListFullPaths = true gListFullPaths = true
of "dynliboverride": of "dynliboverride":
dynlibOverride(switch, arg, pass, info) dynlibOverride(switch, arg, pass, info)
of "dynliboverrideall":
expectNoArg(switch, arg, pass, info)
gDynlibOverrideAll = true
of "cs": of "cs":
# only supported for compatibility. Does nothing. # only supported for compatibility. Does nothing.
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)

View file

@ -1563,14 +1563,22 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
internalError("createVar: " & $t.kind) internalError("createVar: " & $t.kind)
result = nil result = nil
template returnType: untyped =
~""
proc genVarInit(p: PProc, v: PSym, n: PNode) = proc genVarInit(p: PProc, v: PSym, n: PNode) =
var var
a: TCompRes a: TCompRes
s: Rope s: Rope
varCode: string
if v.constraint.isNil:
varCode = "var $2"
else:
varCode = v.constraint.strVal
if n.kind == nkEmpty: if n.kind == nkEmpty:
let mname = mangleName(v, p.target) let mname = mangleName(v, p.target)
lineF(p, "var $1 = $2;$n" | "$$$1 = $2;$n", lineF(p, varCode & " = $3;$n" | "$$$2 = $3;$n",
[mname, createVar(p, v.typ, isIndirect(v))]) [returnType, mname, createVar(p, v.typ, isIndirect(v))])
if v.typ.kind in { tyVar, tyPtr, tyRef } and mapType(p, v.typ) == etyBaseIndex: if v.typ.kind in { tyVar, tyPtr, tyRef } and mapType(p, v.typ) == etyBaseIndex:
lineF(p, "var $1_Idx = 0;$n", [ mname ]) lineF(p, "var $1_Idx = 0;$n", [ mname ])
else: else:
@ -1587,25 +1595,25 @@ proc genVarInit(p: PProc, v: PSym, n: PNode) =
let targetBaseIndex = {sfAddrTaken, sfGlobal} * v.flags == {} let targetBaseIndex = {sfAddrTaken, sfGlobal} * v.flags == {}
if a.typ == etyBaseIndex: if a.typ == etyBaseIndex:
if targetBaseIndex: if targetBaseIndex:
lineF(p, "var $1 = $2, $1_Idx = $3;$n", lineF(p, varCode & " = $3, $2_Idx = $4;$n",
[v.loc.r, a.address, a.res]) [returnType, v.loc.r, a.address, a.res])
else: else:
lineF(p, "var $1 = [$2, $3];$n", lineF(p, varCode & " = [$3, $4];$n",
[v.loc.r, a.address, a.res]) [returnType, v.loc.r, a.address, a.res])
else: else:
if targetBaseIndex: if targetBaseIndex:
let tmp = p.getTemp let tmp = p.getTemp
lineF(p, "var $1 = $2, $3 = $1[0], $3_Idx = $1[1];$n", lineF(p, "var $1 = $2, $3 = $1[0], $3_Idx = $1[1];$n",
[tmp, a.res, v.loc.r]) [tmp, a.res, v.loc.r])
else: else:
lineF(p, "var $1 = $2;$n", [v.loc.r, a.res]) lineF(p, varCode & " = $3;$n", [returnType, v.loc.r, a.res])
return return
else: else:
s = a.res s = a.res
if isIndirect(v): if isIndirect(v):
lineF(p, "var $1 = [$2];$n", [v.loc.r, s]) lineF(p, varCode & " = [$3];$n", [returnType, v.loc.r, s])
else: else:
lineF(p, "var $1 = $2;$n" | "$$$1 = $2;$n", [v.loc.r, s]) lineF(p, varCode & " = $3;$n" | "$$$2 = $3;$n", [returnType, v.loc.r, s])
proc genVarStmt(p: PProc, n: PNode) = proc genVarStmt(p: PProc, n: PNode) =
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
@ -2162,8 +2170,22 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
returnStmt = "return $#;$n" % [a.res] returnStmt = "return $#;$n" % [a.res]
p.nested: genStmt(p, prc.getBody) p.nested: genStmt(p, prc.getBody)
let def = "function $#($#) {$n$#$#$#$#$#" %
[name, header, var def: Rope
if not prc.constraint.isNil:
def = (prc.constraint.strVal & " {$n$#$#$#$#$#") %
[ returnType,
name,
header,
optionaLine(p.globals),
optionaLine(p.locals),
optionaLine(resultAsgn),
optionaLine(genProcBody(p, prc)),
optionaLine(p.indentLine(returnStmt))]
else:
def = "function $#($#) {$n$#$#$#$#$#" %
[ name,
header,
optionaLine(p.globals), optionaLine(p.globals),
optionaLine(p.locals), optionaLine(p.locals),
optionaLine(resultAsgn), optionaLine(resultAsgn),

View file

@ -145,6 +145,7 @@ var
gNoNimblePath* = false gNoNimblePath* = false
gExperimentalMode*: bool gExperimentalMode*: bool
newDestructors*: bool newDestructors*: bool
gDynlibOverrideAll*: bool
proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools} proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
@ -427,7 +428,7 @@ proc inclDynlibOverride*(lib: string) =
gDllOverrides[lib.canonDynlibName] = "true" gDllOverrides[lib.canonDynlibName] = "true"
proc isDynlibOverride*(lib: string): bool = proc isDynlibOverride*(lib: string): bool =
result = gDllOverrides.hasKey(lib.canonDynlibName) result = gDynlibOverrideAll or gDllOverrides.hasKey(lib.canonDynlibName)
proc binaryStrSearch*(x: openArray[string], y: string): int = proc binaryStrSearch*(x: openArray[string], y: string): int =
var a = 0 var a = 0

View file

@ -121,22 +121,25 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t) result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
for i in 0 ..< t.len: for i in 0 ..< t.len:
result.add mapTypeToAst(t.sons[i], info) result.add mapTypeToAst(t.sons[i], info)
of tyGenericInst, tyAlias: of tyGenericInst:
if inst: if inst:
if allowRecursion: if allowRecursion:
result = mapTypeToAstR(t.lastSon, info) result = mapTypeToAstR(t.lastSon, info)
else: else:
result = newNodeX(nkBracketExpr) result = newNodeX(nkBracketExpr)
result.add mapTypeToAst(t.lastSon, info) #result.add mapTypeToAst(t.lastSon, info)
result.add mapTypeToAst(t[0], info)
for i in 1 ..< t.len-1: for i in 1 ..< t.len-1:
result.add mapTypeToAst(t.sons[i], info) result.add mapTypeToAst(t.sons[i], info)
else: else:
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion) result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
of tyGenericBody: of tyGenericBody:
if inst: if inst:
result = mapTypeToAstX(t.lastSon, info, inst, true) result = mapTypeToAstR(t.lastSon, info)
else: else:
result = mapTypeToAst(t.lastSon, info) result = mapTypeToAst(t.lastSon, info)
of tyAlias:
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)
of tyOrdinal: of tyOrdinal:
result = mapTypeToAst(t.lastSon, info) result = mapTypeToAst(t.lastSon, info)
of tyDistinct: of tyDistinct:

View file

@ -79,6 +79,7 @@ Advanced options:
symbol matching is fuzzy so symbol matching is fuzzy so
that --dynlibOverride:lua matches that --dynlibOverride:lua matches
dynlib: "liblua.so.3" dynlib: "liblua.so.3"
--dynlibOverrideAll makes the dynlib pragma have no effect
--listCmd list the commands used to execute external programs --listCmd list the commands used to execute external programs
--parallelBuild:0|1|... perform a parallel build --parallelBuild:0|1|... perform a parallel build
value = number of processors (0 for auto-detect) value = number of processors (0 for auto-detect)

View file

@ -66,7 +66,7 @@ proc cycle*[T](s: openArray[T], n: Natural): seq[T] =
## ##
## Example: ## Example:
## ##
## .. code-block: ## .. code-block::
## ##
## let ## let
## s = @[1, 2, 3] ## s = @[1, 2, 3]
@ -84,7 +84,7 @@ proc repeat*[T](x: T, n: Natural): seq[T] =
## ##
## Example: ## Example:
## ##
## .. code-block: ## .. code-block::
## ##
## let ## let
## total = repeat(5, 3) ## total = repeat(5, 3)

View file

@ -259,7 +259,7 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
result.reserved = r result.reserved = r
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {. proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
compilerRtl.} = compilerRtl, inl.} =
result = seq result = seq
if result.space < newLen: if result.space < newLen:
let r = max(resize(result.space), newLen) let r = max(resize(result.space), newLen)
@ -282,10 +282,11 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic) doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
gch.tempStack.len = len0 gch.tempStack.len = len0
else: else:
for i in newLen..result.len-1: if ntfNoRefs notin extGetCellType(result).base.flags:
forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +% for i in newLen..result.len-1:
GenericSeqSize +% (i*%elemSize)), forAllChildrenAux(cast[pointer](cast[ByteAddress](result) +%
extGetCellType(result).base, waZctDecRef) GenericSeqSize +% (i*%elemSize)),
extGetCellType(result).base, waZctDecRef)
# XXX: zeroing out the memory can still result in crashes if a wiped-out # XXX: zeroing out the memory can still result in crashes if a wiped-out
# cell is aliased by another pointer (ie proc parameter or a let variable). # cell is aliased by another pointer (ie proc parameter or a let variable).

View file

@ -526,6 +526,9 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
of cmdEnd: break of cmdEnd: break
of cmdLongoption, cmdShortOption: of cmdLongoption, cmdShortOption:
case p.key.normalize case p.key.normalize
of "help":
stdout.writeline(Usage)
quit()
of "port": of "port":
gPort = parseInt(p.val).Port gPort = parseInt(p.val).Port
gMode = mtcp gMode = mtcp

View file

@ -0,0 +1,11 @@
discard """
output: '''
-1
8
'''
ccodecheck: "'console.log(-1); function fac_' \\d+ '(n_' \\d+ ')'"
"""
proc fac(n: int): int {.codegenDecl: "console.log(-1); function $2($3)".} =
return n
echo fac(8)

View file

@ -0,0 +1,10 @@
discard """
output: '''
-1
2
'''
ccodecheck: "'console.log(-1); var v_' \\d+ ' = [2]'"
"""
var v {.codegenDecl: "console.log(-1); var $2".} = 2
echo v

View file

@ -27,9 +27,10 @@ macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed =
let inst = x.getTypeInst let inst = x.getTypeInst
let instr = inst.symToIdent.treeRepr let instr = inst.symToIdent.treeRepr
let inst0r = inst0.symToIdent.treeRepr let inst0r = inst0.symToIdent.treeRepr
#echo instr if instr != inst0r:
#echo inst0r echo "instr:\n", instr
doAssert(instr == inst0r) echo "inst0r:\n", inst0r
doAssert(instr == inst0r)
# check that getTypeImpl(x) is correct # check that getTypeImpl(x) is correct
# if implX is nil then compare to inst0 # if implX is nil then compare to inst0
@ -41,9 +42,10 @@ macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed =
else: implX[0][2] else: implX[0][2]
let implr = impl.symToIdent.treerepr let implr = impl.symToIdent.treerepr
let impl0r = impl0.symToIdent.treerepr let impl0r = impl0.symToIdent.treerepr
#echo implr if implr != impl0r:
#echo impl0r echo "implr:\n", implr
doAssert(implr == impl0r) echo "impl0r:\n", impl0r
doAssert(implr == impl0r)
result = newStmtList() result = newStmtList()
#template echoString(s: string) = echo s.replace("\n","\n ") #template echoString(s: string) = echo s.replace("\n","\n ")
@ -111,6 +113,14 @@ type
Generic[T] = seq[int] Generic[T] = seq[int]
Concrete = Generic[int] Concrete = Generic[int]
Alias1 = float
Alias2 = Concrete
Vec[N: static[int],T] = object
arr: array[N,T]
Vec4[T] = Vec[4,T]
test(bool) test(bool)
test(char) test(char)
test(int) test(int)
@ -149,6 +159,16 @@ test(Generic[int]):
type _ = seq[int] type _ = seq[int]
test(Generic[float]): test(Generic[float]):
type _ = seq[int] type _ = seq[int]
test(Alias1):
type _ = float
test(Alias2):
type _ = Generic[int]
test(Vec[4,float32]):
type _ = object
arr: array[0..3,float32]
test(Vec4[float32]):
type _ = object
arr: array[0..3,float32]
# bug #4862 # bug #4862
static: static: