Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Andreas Rumpf
2016-07-06 16:48:14 +02:00
25 changed files with 3914 additions and 1574 deletions

View File

@@ -610,7 +610,7 @@ type
mEqIdent, mEqNimrodNode, mSameNodeType, mGetImpl,
mNHint, mNWarning, mNError,
mInstantiationInfo, mGetTypeInfo, mNGenSym,
mNimvm
mNimvm, mIntDefine, mStrDefine
# things that we can evaluate safely at compile time, even if not asked for it:
const

View File

@@ -260,7 +260,11 @@ proc genOtherArg(p: BProc; ri: PNode; i: int; typ: PType): Rope =
else:
result = genArgNoParam(p, ri.sons[i]) #, typ.n.sons[i].sym)
else:
result = genArgNoParam(p, ri.sons[i])
if tfVarargs notin typ.flags:
localError(ri.info, "wrong argument count")
result = nil
else:
result = genArgNoParam(p, ri.sons[i])
discard """
Dot call syntax in C++

View File

@@ -342,7 +342,11 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
discard "allow for backwards compatibility, but don't do anything"
of "define", "d":
expectArg(switch, arg, pass, info)
defineSymbol(arg)
if {':', '='} in arg:
splitSwitch(arg, key, val, pass, info)
defineSymbol(key, val)
else:
defineSymbol(arg)
of "undef", "u":
expectArg(switch, arg, pass, info)
undefSymbol(arg)

View File

@@ -19,8 +19,8 @@ var gSymbols: StringTableRef
const
catNone = "false"
proc defineSymbol*(symbol: string) =
gSymbols[symbol] = "true"
proc defineSymbol*(symbol: string, value: string = "true") =
gSymbols[symbol] = value
proc undefSymbol*(symbol: string) =
gSymbols[symbol] = catNone
@@ -62,6 +62,11 @@ proc isDefined*(symbol: string): bool =
proc isDefined*(symbol: PIdent): bool = isDefined(symbol.s)
proc lookupSymbol*(symbol: string): string =
result = if isDefined(symbol): gSymbols[symbol] else: nil
proc lookupSymbol*(symbol: PIdent): string = lookupSymbol(symbol.s)
iterator definedSymbolNames*: string =
for key, val in pairs(gSymbols):
if val != catNone: yield key

View File

@@ -1557,8 +1557,16 @@ proc genRepr(p: PProc, n: PNode, r: var TCompRes) =
of tyEnum, tyOrdinal:
gen(p, n.sons[1], r)
useMagic(p, "cstrToNimstr")
var offset = ""
if t.kind == tyEnum:
let firstFieldOffset = t.n.sons[0].sym.position
if firstFieldOffset < 0:
offset = "+" & $(-firstFieldOffset)
elif firstFieldOffset > 0:
offset = "-" & $firstFieldOffset
r.kind = resExpr
r.res = "cstrToNimstr($1.node.sons[$2].name)" % [genTypeInfo(p, t), r.res]
r.res = "cstrToNimstr($1.node.sons[$2$3].name)" % [genTypeInfo(p, t), r.res, rope(offset)]
else:
# XXX:
internalError(n.info, "genRepr: Not implemented")

View File

@@ -63,7 +63,8 @@ const
wImportCpp, wImportObjC, wError, wNoInit, wCompileTime, wGlobal,
wGensym, wInject, wCodegenDecl, wGuard, wGoto, wExportNims}
constPragmas* = {wImportc, wExportc, wHeader, wDeprecated, wMagic, wNodecl,
wExtern, wImportCpp, wImportObjC, wError, wGensym, wInject, wExportNims}
wExtern, wImportCpp, wImportObjC, wError, wGensym, wInject, wExportNims,
wIntDefine, wStrDefine}
letPragmas* = varPragmas
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect,
wThread, wRaises, wLocks, wTags, wGcSafe}
@@ -898,6 +899,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
of wBase:
noVal(it)
sym.flags.incl sfBase
of wIntDefine:
sym.magic = mIntDefine
of wStrDefine:
sym.magic = mStrDefine
else: invalidPragma(it)
else: invalidPragma(it)

View File

@@ -640,6 +640,12 @@ proc getConstExpr(m: PSym, n: PNode): PNode =
of mNaN: result = newFloatNodeT(NaN, n)
of mInf: result = newFloatNodeT(Inf, n)
of mNegInf: result = newFloatNodeT(NegInf, n)
of mIntDefine:
if isDefined(s.name):
result = newIntNodeT(lookupSymbol(s.name).parseInt, n)
of mStrDefine:
if isDefined(s.name):
result = newStrNodeT(lookupSymbol(s.name), n)
else:
if sfFakeConst notin s.flags: result = copyTree(s.ast)
of {skProc, skMethod}:

View File

@@ -727,6 +727,7 @@ proc equalParam(a, b: PSym): TParamsEquality =
result = paramsNotEqual
proc sameConstraints(a, b: PNode): bool =
if isNil(a) and isNil(b): return true
internalAssert a.len == b.len
for i in 1 .. <a.len:
if not exprStructuralEquivalent(a[i].sym.constraint,

View File

@@ -516,8 +516,11 @@ proc genCall(c: PCtx; n: PNode; dest: var TDest) =
if dest < 0 and not isEmptyType(n.typ): dest = getTemp(c, n.typ)
let x = c.getTempRange(n.len, slotTempUnknown)
# varargs need 'opcSetType' for the FFI support:
let fntyp = n.sons[0].typ
let fntyp = skipTypes(n.sons[0].typ, abstractInst)
for i in 0.. <n.len:
if i > 0 and i < sonsLen(fntyp):
let paramType = fntyp.n.sons[i]
if paramType.typ.isCompileTimeOnly: continue
var r: TRegister = x+i
c.gen(n.sons[i], r)
if i >= fntyp.len:

View File

@@ -36,6 +36,7 @@ type
wColon, wColonColon, wEquals, wDot, wDotDot,
wStar, wMinus,
wMagic, wThread, wFinal, wProfiler, wObjChecks,
wIntDefine, wStrDefine,
wDestroy,
@@ -121,7 +122,7 @@ const
":", "::", "=", ".", "..",
"*", "-",
"magic", "thread", "final", "profiler", "objchecks",
"magic", "thread", "final", "profiler", "objchecks", "intdefine", "strdefine",
"destroy",