Merge ../Nim into devel
This commit is contained in:
commit
2d9a0c96c6
22 changed files with 875 additions and 657 deletions
|
|
@ -6,7 +6,7 @@ Name: "Nim"
|
||||||
Version: "$version"
|
Version: "$version"
|
||||||
Platforms: """
|
Platforms: """
|
||||||
windows: i386;amd64
|
windows: i386;amd64
|
||||||
linux: i386;amd64;powerpc64;arm;sparc;mips;powerpc
|
linux: i386;amd64;powerpc64;arm;sparc;mips;mipsel;powerpc;powerpc64el;arm64
|
||||||
macosx: i386;amd64;powerpc64
|
macosx: i386;amd64;powerpc64
|
||||||
solaris: i386;amd64;sparc
|
solaris: i386;amd64;sparc
|
||||||
freebsd: i386;amd64
|
freebsd: i386;amd64
|
||||||
|
|
|
||||||
|
|
@ -729,14 +729,13 @@ proc genBreakStmt(p: PProc, n: PNode) =
|
||||||
p.blocks[idx].id = abs(p.blocks[idx].id) # label is used
|
p.blocks[idx].id = abs(p.blocks[idx].id) # label is used
|
||||||
addf(p.body, "break L$1;$n" | "goto ::L$1::;$n", [rope(p.blocks[idx].id)])
|
addf(p.body, "break L$1;$n" | "goto ::L$1::;$n", [rope(p.blocks[idx].id)])
|
||||||
|
|
||||||
proc genAsmStmt(p: PProc, n: PNode) =
|
proc genAsmOrEmitStmt(p: PProc, n: PNode) =
|
||||||
genLineDir(p, n)
|
genLineDir(p, n)
|
||||||
assert(n.kind == nkAsmStmt)
|
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
case n.sons[i].kind
|
case n.sons[i].kind
|
||||||
of nkStrLit..nkTripleStrLit: add(p.body, n.sons[i].strVal)
|
of nkStrLit..nkTripleStrLit: add(p.body, n.sons[i].strVal)
|
||||||
of nkSym: add(p.body, mangleName(n.sons[i].sym))
|
of nkSym: add(p.body, mangleName(n.sons[i].sym))
|
||||||
else: internalError(n.sons[i].info, "jsgen: genAsmStmt()")
|
else: internalError(n.sons[i].info, "jsgen: genAsmOrEmitStmt()")
|
||||||
|
|
||||||
proc genIf(p: PProc, n: PNode, r: var TCompRes) =
|
proc genIf(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
var cond, stmt: TCompRes
|
var cond, stmt: TCompRes
|
||||||
|
|
@ -1578,6 +1577,12 @@ proc genStmt(p: PProc, n: PNode) =
|
||||||
gen(p, n, r)
|
gen(p, n, r)
|
||||||
if r.res != nil: addf(p.body, "$#;$n", [r.res])
|
if r.res != nil: addf(p.body, "$#;$n", [r.res])
|
||||||
|
|
||||||
|
proc genPragma(p: PProc, n: PNode) =
|
||||||
|
for it in n.sons:
|
||||||
|
case whichPragma(it)
|
||||||
|
of wEmit: genAsmOrEmitStmt(p, it.sons[1])
|
||||||
|
else: discard
|
||||||
|
|
||||||
proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
r.typ = etyNone
|
r.typ = etyNone
|
||||||
r.kind = resNone
|
r.kind = resNone
|
||||||
|
|
@ -1677,12 +1682,13 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
if n.sons[0].kind != nkEmpty:
|
if n.sons[0].kind != nkEmpty:
|
||||||
genLineDir(p, n)
|
genLineDir(p, n)
|
||||||
gen(p, n.sons[0], r)
|
gen(p, n.sons[0], r)
|
||||||
of nkAsmStmt: genAsmStmt(p, n)
|
of nkAsmStmt: genAsmOrEmitStmt(p, n)
|
||||||
of nkTryStmt: genTry(p, n, r)
|
of nkTryStmt: genTry(p, n, r)
|
||||||
of nkRaiseStmt: genRaiseStmt(p, n)
|
of nkRaiseStmt: genRaiseStmt(p, n)
|
||||||
of nkTypeSection, nkCommentStmt, nkIteratorDef, nkIncludeStmt,
|
of nkTypeSection, nkCommentStmt, nkIteratorDef, nkIncludeStmt,
|
||||||
nkImportStmt, nkImportExceptStmt, nkExportStmt, nkExportExceptStmt,
|
nkImportStmt, nkImportExceptStmt, nkExportStmt, nkExportExceptStmt,
|
||||||
nkFromStmt, nkTemplateDef, nkMacroDef, nkPragma: discard
|
nkFromStmt, nkTemplateDef, nkMacroDef: discard
|
||||||
|
of nkPragma: genPragma(p, n)
|
||||||
of nkProcDef, nkMethodDef, nkConverterDef:
|
of nkProcDef, nkMethodDef, nkConverterDef:
|
||||||
var s = n.sons[namePos].sym
|
var s = n.sons[namePos].sym
|
||||||
if {sfExportc, sfCompilerProc} * s.flags == {sfExportc}:
|
if {sfExportc, sfCompilerProc} * s.flags == {sfExportc}:
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,8 @@ type
|
||||||
TSystemCPU* = enum # Also add CPU for in initialization section and
|
TSystemCPU* = enum # Also add CPU for in initialization section and
|
||||||
# alias conditionals to condsyms (end of module).
|
# alias conditionals to condsyms (end of module).
|
||||||
cpuNone, cpuI386, cpuM68k, cpuAlpha, cpuPowerpc, cpuPowerpc64,
|
cpuNone, cpuI386, cpuM68k, cpuAlpha, cpuPowerpc, cpuPowerpc64,
|
||||||
cpuSparc, cpuVm, cpuIa64, cpuAmd64, cpuMips, cpuArm,
|
cpuPowerpc64el, cpuSparc, cpuVm, cpuIa64, cpuAmd64, cpuMips, cpuMipsel,
|
||||||
cpuJS, cpuNimrodVM, cpuAVR
|
cpuArm, cpuArm64, cpuJS, cpuNimrodVM, cpuAVR
|
||||||
|
|
||||||
type
|
type
|
||||||
TEndian* = enum
|
TEndian* = enum
|
||||||
|
|
@ -175,12 +175,15 @@ const
|
||||||
(name: "alpha", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
(name: "alpha", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
||||||
(name: "powerpc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "powerpc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
(name: "powerpc64", intSize: 64, endian: bigEndian, floatSize: 64,bit: 64),
|
(name: "powerpc64", intSize: 64, endian: bigEndian, floatSize: 64,bit: 64),
|
||||||
|
(name: "powerpc64el", intSize: 64, endian: littleEndian, floatSize: 64,bit: 64),
|
||||||
(name: "sparc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "sparc", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
(name: "vm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
(name: "vm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||||
(name: "ia64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
(name: "ia64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
||||||
(name: "amd64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
(name: "amd64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
||||||
(name: "mips", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "mips", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
|
(name: "mipsel", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||||
(name: "arm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
(name: "arm", intSize: 32, endian: littleEndian, floatSize: 64, bit: 32),
|
||||||
|
(name: "arm64", intSize: 64, endian: littleEndian, floatSize: 64, bit: 64),
|
||||||
(name: "js", intSize: 32, endian: bigEndian,floatSize: 64,bit: 32),
|
(name: "js", intSize: 32, endian: bigEndian,floatSize: 64,bit: 32),
|
||||||
(name: "nimrodvm", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
(name: "nimrodvm", intSize: 32, endian: bigEndian, floatSize: 64, bit: 32),
|
||||||
(name: "avr", intSize: 16, endian: littleEndian, floatSize: 32, bit: 16)]
|
(name: "avr", intSize: 16, endian: littleEndian, floatSize: 32, bit: 16)]
|
||||||
|
|
|
||||||
|
|
@ -591,280 +591,282 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
validPragmas: TSpecialWords): bool =
|
validPragmas: TSpecialWords): bool =
|
||||||
var it = n.sons[i]
|
var it = n.sons[i]
|
||||||
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
|
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
|
||||||
if key.kind == nkIdent:
|
if key.kind == nkBracketExpr:
|
||||||
var userPragma = strTableGet(c.userPragmas, key.ident)
|
processNote(c, it)
|
||||||
if userPragma != nil:
|
return
|
||||||
inc c.instCounter
|
let ident = considerQuotedIdent(key)
|
||||||
if c.instCounter > 100:
|
var userPragma = strTableGet(c.userPragmas, ident)
|
||||||
globalError(it.info, errRecursiveDependencyX, userPragma.name.s)
|
if userPragma != nil:
|
||||||
pragma(c, sym, userPragma.ast, validPragmas)
|
inc c.instCounter
|
||||||
# ensure the pragma is also remember for generic instantiations in other
|
if c.instCounter > 100:
|
||||||
# modules:
|
globalError(it.info, errRecursiveDependencyX, userPragma.name.s)
|
||||||
n.sons[i] = userPragma.ast
|
pragma(c, sym, userPragma.ast, validPragmas)
|
||||||
dec c.instCounter
|
# ensure the pragma is also remember for generic instantiations in other
|
||||||
else:
|
# modules:
|
||||||
var k = whichKeyword(key.ident)
|
n.sons[i] = userPragma.ast
|
||||||
if k in validPragmas:
|
dec c.instCounter
|
||||||
case k
|
else:
|
||||||
of wExportc:
|
var k = whichKeyword(ident)
|
||||||
makeExternExport(sym, getOptionalStr(c, it, "$1"), it.info)
|
if k in validPragmas:
|
||||||
incl(sym.flags, sfUsed) # avoid wrong hints
|
case k
|
||||||
of wImportc: makeExternImport(sym, getOptionalStr(c, it, "$1"))
|
of wExportc:
|
||||||
of wImportCompilerProc:
|
makeExternExport(sym, getOptionalStr(c, it, "$1"), it.info)
|
||||||
processImportCompilerProc(sym, getOptionalStr(c, it, "$1"))
|
incl(sym.flags, sfUsed) # avoid wrong hints
|
||||||
of wExtern: setExternName(sym, expectStrLit(c, it))
|
of wImportc: makeExternImport(sym, getOptionalStr(c, it, "$1"))
|
||||||
of wImmediate:
|
of wImportCompilerProc:
|
||||||
if sym.kind in {skTemplate, skMacro}: incl(sym.flags, sfImmediate)
|
processImportCompilerProc(sym, getOptionalStr(c, it, "$1"))
|
||||||
else: invalidPragma(it)
|
of wExtern: setExternName(sym, expectStrLit(c, it))
|
||||||
of wDirty:
|
of wImmediate:
|
||||||
if sym.kind == skTemplate: incl(sym.flags, sfDirty)
|
if sym.kind in {skTemplate, skMacro}: incl(sym.flags, sfImmediate)
|
||||||
else: invalidPragma(it)
|
|
||||||
of wImportCpp:
|
|
||||||
processImportCpp(sym, getOptionalStr(c, it, "$1"))
|
|
||||||
of wImportObjC:
|
|
||||||
processImportObjC(sym, getOptionalStr(c, it, "$1"))
|
|
||||||
of wAlign:
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
var align = expectIntLit(c, it)
|
|
||||||
if (not isPowerOfTwo(align) and align != 0) or align >% high(int16):
|
|
||||||
localError(it.info, errPowerOfTwoExpected)
|
|
||||||
else:
|
|
||||||
sym.typ.align = align.int16
|
|
||||||
of wSize:
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
var size = expectIntLit(c, it)
|
|
||||||
if not isPowerOfTwo(size) or size <= 0 or size > 8:
|
|
||||||
localError(it.info, errPowerOfTwoExpected)
|
|
||||||
else:
|
|
||||||
sym.typ.size = size
|
|
||||||
of wNodecl:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.loc.flags, lfNoDecl)
|
|
||||||
of wPure, wAsmNoStackFrame:
|
|
||||||
noVal(it)
|
|
||||||
if sym != nil:
|
|
||||||
if k == wPure and sym.kind in routineKinds: invalidPragma(it)
|
|
||||||
else: incl(sym.flags, sfPure)
|
|
||||||
of wVolatile:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfVolatile)
|
|
||||||
of wRegister:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfRegister)
|
|
||||||
of wThreadVar:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfThread)
|
|
||||||
of wDeadCodeElim: pragmaDeadCodeElim(c, it)
|
|
||||||
of wNoForward: pragmaNoForward(c, it)
|
|
||||||
of wMagic: processMagic(c, it, sym)
|
|
||||||
of wCompileTime:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfCompileTime)
|
|
||||||
incl(sym.loc.flags, lfNoDecl)
|
|
||||||
of wGlobal:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfGlobal)
|
|
||||||
incl(sym.flags, sfPure)
|
|
||||||
of wMerge:
|
|
||||||
# only supported for backwards compat, doesn't do anything anymore
|
|
||||||
noVal(it)
|
|
||||||
of wConstructor:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfConstructor)
|
|
||||||
of wHeader:
|
|
||||||
var lib = getLib(c, libHeader, getStrLitNode(c, it))
|
|
||||||
addToLib(lib, sym)
|
|
||||||
incl(sym.flags, sfImportc)
|
|
||||||
incl(sym.loc.flags, lfHeader)
|
|
||||||
incl(sym.loc.flags, lfNoDecl)
|
|
||||||
# implies nodecl, because otherwise header would not make sense
|
|
||||||
if sym.loc.r == nil: sym.loc.r = rope(sym.name.s)
|
|
||||||
of wDestructor:
|
|
||||||
sym.flags.incl sfOverriden
|
|
||||||
if sym.name.s.normalize != "destroy":
|
|
||||||
localError(n.info, errGenerated, "destructor has to be named 'destroy'")
|
|
||||||
of wOverride:
|
|
||||||
sym.flags.incl sfOverriden
|
|
||||||
of wNosideeffect:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfNoSideEffect)
|
|
||||||
if sym.typ != nil: incl(sym.typ.flags, tfNoSideEffect)
|
|
||||||
of wSideeffect:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfSideEffect)
|
|
||||||
of wNoreturn:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfNoReturn)
|
|
||||||
of wDynlib:
|
|
||||||
processDynLib(c, it, sym)
|
|
||||||
of wCompilerproc:
|
|
||||||
noVal(it) # compilerproc may not get a string!
|
|
||||||
if sfFromGeneric notin sym.flags: markCompilerProc(sym)
|
|
||||||
of wProcVar:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfProcvar)
|
|
||||||
of wDeprecated:
|
|
||||||
if it.kind == nkExprColonExpr: deprecatedStmt(c, it)
|
|
||||||
elif sym != nil: incl(sym.flags, sfDeprecated)
|
|
||||||
else: incl(c.module.flags, sfDeprecated)
|
|
||||||
of wVarargs:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfVarargs)
|
|
||||||
of wBorrow:
|
|
||||||
if sym.kind == skType:
|
|
||||||
typeBorrow(sym, it)
|
|
||||||
else:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfBorrow)
|
|
||||||
of wFinal:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfFinal)
|
|
||||||
of wInheritable:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil or tfFinal in sym.typ.flags: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfInheritable)
|
|
||||||
of wAcyclic:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfAcyclic)
|
|
||||||
of wShallow:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfShallow)
|
|
||||||
of wThread:
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfThread)
|
|
||||||
incl(sym.flags, sfProcvar)
|
|
||||||
if sym.typ != nil: incl(sym.typ.flags, tfThread)
|
|
||||||
of wGcSafe:
|
|
||||||
noVal(it)
|
|
||||||
if sym.kind != skType: incl(sym.flags, sfThread)
|
|
||||||
if sym.typ != nil: incl(sym.typ.flags, tfGcSafe)
|
|
||||||
else: invalidPragma(it)
|
|
||||||
of wPacked:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfPacked)
|
|
||||||
of wHint: message(it.info, hintUser, expectStrLit(c, it))
|
|
||||||
of wWarning: message(it.info, warnUser, expectStrLit(c, it))
|
|
||||||
of wError:
|
|
||||||
if sym != nil and sym.isRoutine:
|
|
||||||
# This is subtle but correct: the error *statement* is only
|
|
||||||
# allowed for top level statements. Seems to be easier than
|
|
||||||
# distinguishing properly between
|
|
||||||
# ``proc p() {.error}`` and ``proc p() = {.error: "msg".}``
|
|
||||||
noVal(it)
|
|
||||||
incl(sym.flags, sfError)
|
|
||||||
else:
|
|
||||||
localError(it.info, errUser, expectStrLit(c, it))
|
|
||||||
of wFatal: fatal(it.info, errUser, expectStrLit(c, it))
|
|
||||||
of wDefine: processDefine(c, it)
|
|
||||||
of wUndef: processUndef(c, it)
|
|
||||||
of wCompile: processCompile(c, it)
|
|
||||||
of wLink: processCommonLink(c, it, linkNormal)
|
|
||||||
of wLinksys: processCommonLink(c, it, linkSys)
|
|
||||||
of wPassl: extccomp.addLinkOption(expectStrLit(c, it))
|
|
||||||
of wPassc: extccomp.addCompileOption(expectStrLit(c, it))
|
|
||||||
of wBreakpoint: pragmaBreakpoint(c, it)
|
|
||||||
of wWatchPoint: pragmaWatchpoint(c, it)
|
|
||||||
of wPush:
|
|
||||||
processPush(c, n, i + 1)
|
|
||||||
result = true
|
|
||||||
of wPop: processPop(c, it)
|
|
||||||
of wPragma:
|
|
||||||
processPragma(c, n, i)
|
|
||||||
result = true
|
|
||||||
of wDiscardable:
|
|
||||||
noVal(it)
|
|
||||||
if sym != nil: incl(sym.flags, sfDiscardable)
|
|
||||||
of wNoInit:
|
|
||||||
noVal(it)
|
|
||||||
if sym != nil: incl(sym.flags, sfNoInit)
|
|
||||||
of wCodegenDecl: processCodegenDecl(c, it, sym)
|
|
||||||
of wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks,
|
|
||||||
wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
|
||||||
wLinedir, wStacktrace, wLinetrace, wOptimization,
|
|
||||||
wCallconv,
|
|
||||||
wDebugger, wProfiler, wFloatchecks, wNanChecks, wInfChecks,
|
|
||||||
wPatterns:
|
|
||||||
if processOption(c, it):
|
|
||||||
# calling conventions (boring...):
|
|
||||||
localError(it.info, errOptionExpected)
|
|
||||||
of FirstCallConv..LastCallConv:
|
|
||||||
assert(sym != nil)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: sym.typ.callConv = wordToCallConv(k)
|
|
||||||
of wEmit: pragmaEmit(c, it)
|
|
||||||
of wUnroll: pragmaUnroll(c, it)
|
|
||||||
of wLinearScanEnd, wComputedGoto: noVal(it)
|
|
||||||
of wEffects:
|
|
||||||
# is later processed in effect analysis:
|
|
||||||
noVal(it)
|
|
||||||
of wIncompleteStruct:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfIncompleteStruct)
|
|
||||||
of wUnchecked:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfUncheckedArray)
|
|
||||||
of wUnion:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfUnion)
|
|
||||||
of wRequiresInit:
|
|
||||||
noVal(it)
|
|
||||||
if sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfNeedsInit)
|
|
||||||
of wByRef:
|
|
||||||
noVal(it)
|
|
||||||
if sym == nil or sym.typ == nil:
|
|
||||||
if processOption(c, it): localError(it.info, errOptionExpected)
|
|
||||||
else:
|
|
||||||
incl(sym.typ.flags, tfByRef)
|
|
||||||
of wByCopy:
|
|
||||||
noVal(it)
|
|
||||||
if sym.kind != skType or sym.typ == nil: invalidPragma(it)
|
|
||||||
else: incl(sym.typ.flags, tfByCopy)
|
|
||||||
of wInject, wGensym:
|
|
||||||
# We check for errors, but do nothing with these pragmas otherwise
|
|
||||||
# as they are handled directly in 'evalTemplate'.
|
|
||||||
noVal(it)
|
|
||||||
if sym == nil: invalidPragma(it)
|
|
||||||
of wLine: pragmaLine(c, it)
|
|
||||||
of wRaises, wTags: pragmaRaisesOrTags(c, it)
|
|
||||||
of wLocks:
|
|
||||||
if sym == nil: pragmaLockStmt(c, it)
|
|
||||||
elif sym.typ == nil: invalidPragma(it)
|
|
||||||
else: sym.typ.lockLevel = pragmaLocks(c, it)
|
|
||||||
of wGuard:
|
|
||||||
if sym == nil or sym.kind notin {skVar, skLet, skField}:
|
|
||||||
invalidPragma(it)
|
|
||||||
else:
|
|
||||||
sym.guard = pragmaGuard(c, it, sym.kind)
|
|
||||||
of wGoto:
|
|
||||||
if sym == nil or sym.kind notin {skVar, skLet}:
|
|
||||||
invalidPragma(it)
|
|
||||||
else:
|
|
||||||
sym.flags.incl sfGoto
|
|
||||||
of wInjectStmt:
|
|
||||||
if it.kind != nkExprColonExpr:
|
|
||||||
localError(it.info, errExprExpected)
|
|
||||||
else:
|
|
||||||
it.sons[1] = c.semExpr(c, it.sons[1])
|
|
||||||
of wExperimental:
|
|
||||||
noVal(it)
|
|
||||||
if isTopLevel(c):
|
|
||||||
c.module.flags.incl sfExperimental
|
|
||||||
else:
|
|
||||||
localError(it.info, "'experimental' pragma only valid as toplevel statement")
|
|
||||||
of wNoRewrite:
|
|
||||||
noVal(it)
|
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
|
of wDirty:
|
||||||
|
if sym.kind == skTemplate: incl(sym.flags, sfDirty)
|
||||||
|
else: invalidPragma(it)
|
||||||
|
of wImportCpp:
|
||||||
|
processImportCpp(sym, getOptionalStr(c, it, "$1"))
|
||||||
|
of wImportObjC:
|
||||||
|
processImportObjC(sym, getOptionalStr(c, it, "$1"))
|
||||||
|
of wAlign:
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
var align = expectIntLit(c, it)
|
||||||
|
if (not isPowerOfTwo(align) and align != 0) or align >% high(int16):
|
||||||
|
localError(it.info, errPowerOfTwoExpected)
|
||||||
|
else:
|
||||||
|
sym.typ.align = align.int16
|
||||||
|
of wSize:
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
var size = expectIntLit(c, it)
|
||||||
|
if not isPowerOfTwo(size) or size <= 0 or size > 8:
|
||||||
|
localError(it.info, errPowerOfTwoExpected)
|
||||||
|
else:
|
||||||
|
sym.typ.size = size
|
||||||
|
of wNodecl:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.loc.flags, lfNoDecl)
|
||||||
|
of wPure, wAsmNoStackFrame:
|
||||||
|
noVal(it)
|
||||||
|
if sym != nil:
|
||||||
|
if k == wPure and sym.kind in routineKinds: invalidPragma(it)
|
||||||
|
else: incl(sym.flags, sfPure)
|
||||||
|
of wVolatile:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfVolatile)
|
||||||
|
of wRegister:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfRegister)
|
||||||
|
of wThreadVar:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfThread)
|
||||||
|
of wDeadCodeElim: pragmaDeadCodeElim(c, it)
|
||||||
|
of wNoForward: pragmaNoForward(c, it)
|
||||||
|
of wMagic: processMagic(c, it, sym)
|
||||||
|
of wCompileTime:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfCompileTime)
|
||||||
|
incl(sym.loc.flags, lfNoDecl)
|
||||||
|
of wGlobal:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfGlobal)
|
||||||
|
incl(sym.flags, sfPure)
|
||||||
|
of wMerge:
|
||||||
|
# only supported for backwards compat, doesn't do anything anymore
|
||||||
|
noVal(it)
|
||||||
|
of wConstructor:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfConstructor)
|
||||||
|
of wHeader:
|
||||||
|
var lib = getLib(c, libHeader, getStrLitNode(c, it))
|
||||||
|
addToLib(lib, sym)
|
||||||
|
incl(sym.flags, sfImportc)
|
||||||
|
incl(sym.loc.flags, lfHeader)
|
||||||
|
incl(sym.loc.flags, lfNoDecl)
|
||||||
|
# implies nodecl, because otherwise header would not make sense
|
||||||
|
if sym.loc.r == nil: sym.loc.r = rope(sym.name.s)
|
||||||
|
of wDestructor:
|
||||||
|
sym.flags.incl sfOverriden
|
||||||
|
if sym.name.s.normalize != "destroy":
|
||||||
|
localError(n.info, errGenerated, "destructor has to be named 'destroy'")
|
||||||
|
of wOverride:
|
||||||
|
sym.flags.incl sfOverriden
|
||||||
|
of wNosideeffect:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfNoSideEffect)
|
||||||
|
if sym.typ != nil: incl(sym.typ.flags, tfNoSideEffect)
|
||||||
|
of wSideeffect:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfSideEffect)
|
||||||
|
of wNoreturn:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfNoReturn)
|
||||||
|
of wDynlib:
|
||||||
|
processDynLib(c, it, sym)
|
||||||
|
of wCompilerproc:
|
||||||
|
noVal(it) # compilerproc may not get a string!
|
||||||
|
if sfFromGeneric notin sym.flags: markCompilerProc(sym)
|
||||||
|
of wProcVar:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfProcvar)
|
||||||
|
of wDeprecated:
|
||||||
|
if it.kind == nkExprColonExpr: deprecatedStmt(c, it)
|
||||||
|
elif sym != nil: incl(sym.flags, sfDeprecated)
|
||||||
|
else: incl(c.module.flags, sfDeprecated)
|
||||||
|
of wVarargs:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfVarargs)
|
||||||
|
of wBorrow:
|
||||||
|
if sym.kind == skType:
|
||||||
|
typeBorrow(sym, it)
|
||||||
|
else:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfBorrow)
|
||||||
|
of wFinal:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfFinal)
|
||||||
|
of wInheritable:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil or tfFinal in sym.typ.flags: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfInheritable)
|
||||||
|
of wAcyclic:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfAcyclic)
|
||||||
|
of wShallow:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfShallow)
|
||||||
|
of wThread:
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfThread)
|
||||||
|
incl(sym.flags, sfProcvar)
|
||||||
|
if sym.typ != nil: incl(sym.typ.flags, tfThread)
|
||||||
|
of wGcSafe:
|
||||||
|
noVal(it)
|
||||||
|
if sym.kind != skType: incl(sym.flags, sfThread)
|
||||||
|
if sym.typ != nil: incl(sym.typ.flags, tfGcSafe)
|
||||||
|
else: invalidPragma(it)
|
||||||
|
of wPacked:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfPacked)
|
||||||
|
of wHint: message(it.info, hintUser, expectStrLit(c, it))
|
||||||
|
of wWarning: message(it.info, warnUser, expectStrLit(c, it))
|
||||||
|
of wError:
|
||||||
|
if sym != nil and sym.isRoutine:
|
||||||
|
# This is subtle but correct: the error *statement* is only
|
||||||
|
# allowed for top level statements. Seems to be easier than
|
||||||
|
# distinguishing properly between
|
||||||
|
# ``proc p() {.error}`` and ``proc p() = {.error: "msg".}``
|
||||||
|
noVal(it)
|
||||||
|
incl(sym.flags, sfError)
|
||||||
|
else:
|
||||||
|
localError(it.info, errUser, expectStrLit(c, it))
|
||||||
|
of wFatal: fatal(it.info, errUser, expectStrLit(c, it))
|
||||||
|
of wDefine: processDefine(c, it)
|
||||||
|
of wUndef: processUndef(c, it)
|
||||||
|
of wCompile: processCompile(c, it)
|
||||||
|
of wLink: processCommonLink(c, it, linkNormal)
|
||||||
|
of wLinksys: processCommonLink(c, it, linkSys)
|
||||||
|
of wPassl: extccomp.addLinkOption(expectStrLit(c, it))
|
||||||
|
of wPassc: extccomp.addCompileOption(expectStrLit(c, it))
|
||||||
|
of wBreakpoint: pragmaBreakpoint(c, it)
|
||||||
|
of wWatchPoint: pragmaWatchpoint(c, it)
|
||||||
|
of wPush:
|
||||||
|
processPush(c, n, i + 1)
|
||||||
|
result = true
|
||||||
|
of wPop: processPop(c, it)
|
||||||
|
of wPragma:
|
||||||
|
processPragma(c, n, i)
|
||||||
|
result = true
|
||||||
|
of wDiscardable:
|
||||||
|
noVal(it)
|
||||||
|
if sym != nil: incl(sym.flags, sfDiscardable)
|
||||||
|
of wNoInit:
|
||||||
|
noVal(it)
|
||||||
|
if sym != nil: incl(sym.flags, sfNoInit)
|
||||||
|
of wCodegenDecl: processCodegenDecl(c, it, sym)
|
||||||
|
of wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks,
|
||||||
|
wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
||||||
|
wLinedir, wStacktrace, wLinetrace, wOptimization,
|
||||||
|
wCallconv,
|
||||||
|
wDebugger, wProfiler, wFloatchecks, wNanChecks, wInfChecks,
|
||||||
|
wPatterns:
|
||||||
|
if processOption(c, it):
|
||||||
|
# calling conventions (boring...):
|
||||||
|
localError(it.info, errOptionExpected)
|
||||||
|
of FirstCallConv..LastCallConv:
|
||||||
|
assert(sym != nil)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: sym.typ.callConv = wordToCallConv(k)
|
||||||
|
of wEmit: pragmaEmit(c, it)
|
||||||
|
of wUnroll: pragmaUnroll(c, it)
|
||||||
|
of wLinearScanEnd, wComputedGoto: noVal(it)
|
||||||
|
of wEffects:
|
||||||
|
# is later processed in effect analysis:
|
||||||
|
noVal(it)
|
||||||
|
of wIncompleteStruct:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfIncompleteStruct)
|
||||||
|
of wUnchecked:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfUncheckedArray)
|
||||||
|
of wUnion:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfUnion)
|
||||||
|
of wRequiresInit:
|
||||||
|
noVal(it)
|
||||||
|
if sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfNeedsInit)
|
||||||
|
of wByRef:
|
||||||
|
noVal(it)
|
||||||
|
if sym == nil or sym.typ == nil:
|
||||||
|
if processOption(c, it): localError(it.info, errOptionExpected)
|
||||||
|
else:
|
||||||
|
incl(sym.typ.flags, tfByRef)
|
||||||
|
of wByCopy:
|
||||||
|
noVal(it)
|
||||||
|
if sym.kind != skType or sym.typ == nil: invalidPragma(it)
|
||||||
|
else: incl(sym.typ.flags, tfByCopy)
|
||||||
|
of wInject, wGensym:
|
||||||
|
# We check for errors, but do nothing with these pragmas otherwise
|
||||||
|
# as they are handled directly in 'evalTemplate'.
|
||||||
|
noVal(it)
|
||||||
|
if sym == nil: invalidPragma(it)
|
||||||
|
of wLine: pragmaLine(c, it)
|
||||||
|
of wRaises, wTags: pragmaRaisesOrTags(c, it)
|
||||||
|
of wLocks:
|
||||||
|
if sym == nil: pragmaLockStmt(c, it)
|
||||||
|
elif sym.typ == nil: invalidPragma(it)
|
||||||
|
else: sym.typ.lockLevel = pragmaLocks(c, it)
|
||||||
|
of wGuard:
|
||||||
|
if sym == nil or sym.kind notin {skVar, skLet, skField}:
|
||||||
|
invalidPragma(it)
|
||||||
|
else:
|
||||||
|
sym.guard = pragmaGuard(c, it, sym.kind)
|
||||||
|
of wGoto:
|
||||||
|
if sym == nil or sym.kind notin {skVar, skLet}:
|
||||||
|
invalidPragma(it)
|
||||||
|
else:
|
||||||
|
sym.flags.incl sfGoto
|
||||||
|
of wInjectStmt:
|
||||||
|
if it.kind != nkExprColonExpr:
|
||||||
|
localError(it.info, errExprExpected)
|
||||||
|
else:
|
||||||
|
it.sons[1] = c.semExpr(c, it.sons[1])
|
||||||
|
of wExperimental:
|
||||||
|
noVal(it)
|
||||||
|
if isTopLevel(c):
|
||||||
|
c.module.flags.incl sfExperimental
|
||||||
|
else:
|
||||||
|
localError(it.info, "'experimental' pragma only valid as toplevel statement")
|
||||||
|
of wNoRewrite:
|
||||||
|
noVal(it)
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else: processNote(c, it)
|
else: invalidPragma(it)
|
||||||
|
|
||||||
proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
|
proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
|
||||||
validPragmas: TSpecialWords) =
|
validPragmas: TSpecialWords) =
|
||||||
|
|
|
||||||
|
|
@ -171,11 +171,15 @@ proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
||||||
|
|
||||||
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
|
proc `$`(kind: TSymKind): string = substr(system.`$`(kind), 2).toLower
|
||||||
|
|
||||||
# like newSymS, but considers gensym'ed symbols
|
# like newSymS, but considers gensym'ed symbols
|
||||||
if n.kind == nkSym:
|
if n.kind == nkSym:
|
||||||
# and sfGenSym in n.sym.flags:
|
# and sfGenSym in n.sym.flags:
|
||||||
result = n.sym
|
result = n.sym
|
||||||
internalAssert result.kind == kind
|
if result.kind != kind:
|
||||||
|
localError(n.info, "cannot use symbol of kind '" &
|
||||||
|
$result.kind & "' as a '" & $kind & "'")
|
||||||
# when there is a nested proc inside a template, semtmpl
|
# when there is a nested proc inside a template, semtmpl
|
||||||
# will assign a wrong owner during the first pass over the
|
# will assign a wrong owner during the first pass over the
|
||||||
# template; we must fix it here: see #909
|
# template; we must fix it here: see #909
|
||||||
|
|
|
||||||
|
|
@ -307,12 +307,12 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||||
of mToU8: result = newIntNodeT(getInt(a) and 0x000000FF, n)
|
of mToU8: result = newIntNodeT(getInt(a) and 0x000000FF, n)
|
||||||
of mToU16: result = newIntNodeT(getInt(a) and 0x0000FFFF, n)
|
of mToU16: result = newIntNodeT(getInt(a) and 0x0000FFFF, n)
|
||||||
of mToU32: result = newIntNodeT(getInt(a) and 0x00000000FFFFFFFF'i64, n)
|
of mToU32: result = newIntNodeT(getInt(a) and 0x00000000FFFFFFFF'i64, n)
|
||||||
of mUnaryLt: result = newIntNodeT(getOrdValue(a) - 1, n)
|
of mUnaryLt: result = newIntNodeT(getOrdValue(a) |-| 1, n)
|
||||||
of mSucc: result = newIntNodeT(getOrdValue(a) + getInt(b), n)
|
of mSucc: result = newIntNodeT(getOrdValue(a) |+| getInt(b), n)
|
||||||
of mPred: result = newIntNodeT(getOrdValue(a) - getInt(b), n)
|
of mPred: result = newIntNodeT(getOrdValue(a) |-| getInt(b), n)
|
||||||
of mAddI: result = newIntNodeT(getInt(a) + getInt(b), n)
|
of mAddI: result = newIntNodeT(getInt(a) |+| getInt(b), n)
|
||||||
of mSubI: result = newIntNodeT(getInt(a) - getInt(b), n)
|
of mSubI: result = newIntNodeT(getInt(a) |-| getInt(b), n)
|
||||||
of mMulI: result = newIntNodeT(getInt(a) * getInt(b), n)
|
of mMulI: result = newIntNodeT(getInt(a) |*| getInt(b), n)
|
||||||
of mMinI:
|
of mMinI:
|
||||||
if getInt(a) > getInt(b): result = newIntNodeT(getInt(b), n)
|
if getInt(a) > getInt(b): result = newIntNodeT(getInt(b), n)
|
||||||
else: result = newIntNodeT(getInt(a), n)
|
else: result = newIntNodeT(getInt(a), n)
|
||||||
|
|
@ -338,11 +338,11 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode =
|
||||||
of mDivI:
|
of mDivI:
|
||||||
let y = getInt(b)
|
let y = getInt(b)
|
||||||
if y != 0:
|
if y != 0:
|
||||||
result = newIntNodeT(getInt(a) div y, n)
|
result = newIntNodeT(`|div|`(getInt(a), y), n)
|
||||||
of mModI:
|
of mModI:
|
||||||
let y = getInt(b)
|
let y = getInt(b)
|
||||||
if y != 0:
|
if y != 0:
|
||||||
result = newIntNodeT(getInt(a) mod y, n)
|
result = newIntNodeT(`|mod|`(getInt(a), y), n)
|
||||||
of mAddF64: result = newFloatNodeT(getFloat(a) + getFloat(b), n)
|
of mAddF64: result = newFloatNodeT(getFloat(a) + getFloat(b), n)
|
||||||
of mSubF64: result = newFloatNodeT(getFloat(a) - getFloat(b), n)
|
of mSubF64: result = newFloatNodeT(getFloat(a) - getFloat(b), n)
|
||||||
of mMulF64: result = newFloatNodeT(getFloat(a) * getFloat(b), n)
|
of mMulF64: result = newFloatNodeT(getFloat(a) * getFloat(b), n)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,9 @@ proc newConstraint(c: PContext, k: TTypeKind): PType =
|
||||||
|
|
||||||
proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||||
if n.sonsLen == 0: return newConstraint(c, tyEnum)
|
if n.sonsLen == 0: return newConstraint(c, tyEnum)
|
||||||
|
elif n.sonsLen == 1:
|
||||||
|
# don't create an empty tyEnum; fixes #3052
|
||||||
|
return errorType(c)
|
||||||
var
|
var
|
||||||
counter, x: BiggestInt
|
counter, x: BiggestInt
|
||||||
e: PSym
|
e: PSym
|
||||||
|
|
|
||||||
|
|
@ -120,10 +120,10 @@ template decodeBx(k: expr) {.immediate, dirty.} =
|
||||||
template move(a, b: expr) {.immediate, dirty.} = system.shallowCopy(a, b)
|
template move(a, b: expr) {.immediate, dirty.} = system.shallowCopy(a, b)
|
||||||
# XXX fix minor 'shallowCopy' overloading bug in compiler
|
# XXX fix minor 'shallowCopy' overloading bug in compiler
|
||||||
|
|
||||||
proc createStrKeepNode(x: var TFullReg) =
|
proc createStrKeepNode(x: var TFullReg; keepNode=true) =
|
||||||
if x.node.isNil:
|
if x.node.isNil:
|
||||||
x.node = newNode(nkStrLit)
|
x.node = newNode(nkStrLit)
|
||||||
elif x.node.kind == nkNilLit:
|
elif x.node.kind == nkNilLit and keepNode:
|
||||||
when defined(useNodeIds):
|
when defined(useNodeIds):
|
||||||
let id = x.node.id
|
let id = x.node.id
|
||||||
system.reset(x.node[])
|
system.reset(x.node[])
|
||||||
|
|
@ -385,6 +385,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
#if c.traceActive:
|
#if c.traceActive:
|
||||||
# echo "PC ", pc, " ", c.code[pc].opcode, " ra ", ra
|
# echo "PC ", pc, " ", c.code[pc].opcode, " ra ", ra
|
||||||
# message(c.debug[pc], warnUser, "Trace")
|
# message(c.debug[pc], warnUser, "Trace")
|
||||||
|
|
||||||
case instr.opcode
|
case instr.opcode
|
||||||
of opcEof: return regs[ra]
|
of opcEof: return regs[ra]
|
||||||
of opcRet:
|
of opcRet:
|
||||||
|
|
@ -407,8 +408,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
decodeB(rkInt)
|
decodeB(rkInt)
|
||||||
regs[ra].intVal = regs[rb].intVal
|
regs[ra].intVal = regs[rb].intVal
|
||||||
of opcAsgnStr:
|
of opcAsgnStr:
|
||||||
decodeB(rkNode)
|
decodeBC(rkNode)
|
||||||
createStrKeepNode regs[ra]
|
createStrKeepNode regs[ra], rc != 0
|
||||||
regs[ra].node.strVal = regs[rb].node.strVal
|
regs[ra].node.strVal = regs[rb].node.strVal
|
||||||
of opcAsgnFloat:
|
of opcAsgnFloat:
|
||||||
decodeB(rkFloat)
|
decodeB(rkFloat)
|
||||||
|
|
@ -509,8 +510,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of rkNode:
|
of rkNode:
|
||||||
if regs[rb].node.kind == nkNilLit:
|
if regs[rb].node.kind == nkNilLit:
|
||||||
stackTrace(c, tos, pc, errNilAccess)
|
stackTrace(c, tos, pc, errNilAccess)
|
||||||
assert regs[rb].node.kind == nkRefTy
|
if regs[rb].node.kind == nkRefTy:
|
||||||
regs[ra].node = regs[rb].node.sons[0]
|
regs[ra].node = regs[rb].node.sons[0]
|
||||||
|
else:
|
||||||
|
stackTrace(c, tos, pc, errGenerated, "limited VM support for 'ref'")
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errNilAccess)
|
stackTrace(c, tos, pc, errNilAccess)
|
||||||
of opcWrDeref:
|
of opcWrDeref:
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,9 @@ proc codeListing(c: PCtx, result: var string, start=0; last = -1) =
|
||||||
result.addf("\t$#\tr$#, L$#", ($opc).substr(3), x.regA,
|
result.addf("\t$#\tr$#, L$#", ($opc).substr(3), x.regA,
|
||||||
i+x.regBx-wordExcess)
|
i+x.regBx-wordExcess)
|
||||||
elif opc in {opcLdConst, opcAsgnConst}:
|
elif opc in {opcLdConst, opcAsgnConst}:
|
||||||
result.addf("\t$#\tr$#, $#", ($opc).substr(3), x.regA,
|
let idx = x.regBx-wordExcess
|
||||||
c.constants[x.regBx-wordExcess].renderTree)
|
result.addf("\t$#\tr$#, $# ($#)", ($opc).substr(3), x.regA,
|
||||||
|
c.constants[idx].renderTree, $idx)
|
||||||
elif opc in {opcMarshalLoad, opcMarshalStore}:
|
elif opc in {opcMarshalLoad, opcMarshalStore}:
|
||||||
let y = c.code[i+1]
|
let y = c.code[i+1]
|
||||||
result.addf("\t$#\tr$#, r$#, $#", ($opc).substr(3), x.regA, x.regB,
|
result.addf("\t$#\tr$#, r$#, $#", ($opc).substr(3), x.regA, x.regB,
|
||||||
|
|
@ -184,7 +185,7 @@ proc getTemp(cc: PCtx; typ: PType): TRegister =
|
||||||
return TRegister(i)
|
return TRegister(i)
|
||||||
|
|
||||||
# if register pressure is high, we re-use more aggressively:
|
# if register pressure is high, we re-use more aggressively:
|
||||||
if c.maxSlots >= HighRegisterPressure:
|
if c.maxSlots >= HighRegisterPressure and false:
|
||||||
for i in 0 .. c.maxSlots-1:
|
for i in 0 .. c.maxSlots-1:
|
||||||
if not c.slots[i].inUse:
|
if not c.slots[i].inUse:
|
||||||
c.slots[i] = (inUse: true, kind: k)
|
c.slots[i] = (inUse: true, kind: k)
|
||||||
|
|
@ -1073,6 +1074,7 @@ const
|
||||||
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64}
|
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64}
|
||||||
|
|
||||||
proc fitsRegister*(t: PType): bool =
|
proc fitsRegister*(t: PType): bool =
|
||||||
|
assert t != nil
|
||||||
t.skipTypes(abstractInst-{tyTypeDesc}).kind in {
|
t.skipTypes(abstractInst-{tyTypeDesc}).kind in {
|
||||||
tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar}
|
tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar}
|
||||||
|
|
||||||
|
|
@ -1110,6 +1112,7 @@ proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
if not isAddr:
|
if not isAddr:
|
||||||
gABC(c, n, opc, dest, tmp)
|
gABC(c, n, opc, dest, tmp)
|
||||||
|
assert n.typ != nil
|
||||||
if gfAddrOf notin flags and fitsRegister(n.typ):
|
if gfAddrOf notin flags and fitsRegister(n.typ):
|
||||||
c.gABC(n, opcNodeToReg, dest, dest)
|
c.gABC(n, opcNodeToReg, dest, dest)
|
||||||
elif c.prc.slots[tmp].kind >= slotTempUnknown:
|
elif c.prc.slots[tmp].kind >= slotTempUnknown:
|
||||||
|
|
@ -1143,7 +1146,7 @@ proc whichAsgnOpc(n: PNode; opc: TOpcode): TOpcode = opc
|
||||||
proc genAsgn(c: PCtx; dest: TDest; ri: PNode; requiresCopy: bool) =
|
proc genAsgn(c: PCtx; dest: TDest; ri: PNode; requiresCopy: bool) =
|
||||||
let tmp = c.genx(ri)
|
let tmp = c.genx(ri)
|
||||||
assert dest >= 0
|
assert dest >= 0
|
||||||
gABC(c, ri, whichAsgnOpc(ri), dest, tmp)
|
gABC(c, ri, whichAsgnOpc(ri), dest, tmp, 1-ord(requiresCopy))
|
||||||
c.freeTemp(tmp)
|
c.freeTemp(tmp)
|
||||||
|
|
||||||
proc setSlot(c: PCtx; v: PSym) =
|
proc setSlot(c: PCtx; v: PSym) =
|
||||||
|
|
@ -1194,9 +1197,10 @@ proc preventFalseAlias(c: PCtx; n: PNode; opc: TOpcode;
|
||||||
# opcLdObj et al really means "load address". We sometimes have to create a
|
# opcLdObj et al really means "load address". We sometimes have to create a
|
||||||
# copy in order to not introduce false aliasing:
|
# copy in order to not introduce false aliasing:
|
||||||
# mylocal = a.b # needs a copy of the data!
|
# mylocal = a.b # needs a copy of the data!
|
||||||
|
assert n.typ != nil
|
||||||
if needsAdditionalCopy(n):
|
if needsAdditionalCopy(n):
|
||||||
var cc = c.getTemp(n.typ)
|
var cc = c.getTemp(n.typ)
|
||||||
c.gABC(n, whichAsgnOpc(n), cc, value)
|
c.gABC(n, whichAsgnOpc(n), cc, value, 0)
|
||||||
c.gABC(n, opc, dest, idx, cc)
|
c.gABC(n, opc, dest, idx, cc)
|
||||||
c.freeTemp(cc)
|
c.freeTemp(cc)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1241,10 +1245,11 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
||||||
internalAssert s.position > 0 or (s.position == 0 and
|
internalAssert s.position > 0 or (s.position == 0 and
|
||||||
s.kind in {skParam,skResult})
|
s.kind in {skParam,skResult})
|
||||||
var dest: TRegister = s.position + ord(s.kind == skParam)
|
var dest: TRegister = s.position + ord(s.kind == skParam)
|
||||||
|
assert le.typ != nil
|
||||||
if needsAdditionalCopy(le) and s.kind in {skResult, skVar, skParam}:
|
if needsAdditionalCopy(le) and s.kind in {skResult, skVar, skParam}:
|
||||||
var cc = c.getTemp(le.typ)
|
var cc = c.getTemp(le.typ)
|
||||||
gen(c, ri, cc)
|
gen(c, ri, cc)
|
||||||
c.gABC(le, whichAsgnOpc(le), dest, cc)
|
c.gABC(le, whichAsgnOpc(le), dest, cc, 1)
|
||||||
c.freeTemp(cc)
|
c.freeTemp(cc)
|
||||||
else:
|
else:
|
||||||
gen(c, ri, dest)
|
gen(c, ri, dest)
|
||||||
|
|
@ -1303,6 +1308,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
|
||||||
if sfImportc in s.flags: c.importcSym(n.info, s)
|
if sfImportc in s.flags: c.importcSym(n.info, s)
|
||||||
else: genGlobalInit(c, n, s)
|
else: genGlobalInit(c, n, s)
|
||||||
if dest < 0: dest = c.getTemp(n.typ)
|
if dest < 0: dest = c.getTemp(n.typ)
|
||||||
|
assert s.typ != nil
|
||||||
if gfAddrOf notin flags and fitsRegister(s.typ):
|
if gfAddrOf notin flags and fitsRegister(s.typ):
|
||||||
var cc = c.getTemp(n.typ)
|
var cc = c.getTemp(n.typ)
|
||||||
c.gABx(n, opcLdGlobal, cc, s.position)
|
c.gABx(n, opcLdGlobal, cc, s.position)
|
||||||
|
|
@ -1426,6 +1432,7 @@ proc getNullValue(typ: PType, info: TLineInfo): PNode =
|
||||||
globalError(info, "cannot create null element for: " & $t.kind)
|
globalError(info, "cannot create null element for: " & $t.kind)
|
||||||
|
|
||||||
proc ldNullOpcode(t: PType): TOpcode =
|
proc ldNullOpcode(t: PType): TOpcode =
|
||||||
|
assert t != nil
|
||||||
if fitsRegister(t): opcLdNullReg else: opcLdNull
|
if fitsRegister(t): opcLdNullReg else: opcLdNull
|
||||||
|
|
||||||
proc genVarSection(c: PCtx; n: PNode) =
|
proc genVarSection(c: PCtx; n: PNode) =
|
||||||
|
|
@ -1453,7 +1460,7 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||||
if a.sons[2].kind != nkEmpty:
|
if a.sons[2].kind != nkEmpty:
|
||||||
let tmp = c.genx(a.sons[0], {gfAddrOf})
|
let tmp = c.genx(a.sons[0], {gfAddrOf})
|
||||||
let val = c.genx(a.sons[2])
|
let val = c.genx(a.sons[2])
|
||||||
c.preventFalseAlias(a, opcWrDeref, tmp, 0, val)
|
c.preventFalseAlias(a.sons[2], opcWrDeref, tmp, 0, val)
|
||||||
c.freeTemp(val)
|
c.freeTemp(val)
|
||||||
c.freeTemp(tmp)
|
c.freeTemp(tmp)
|
||||||
else:
|
else:
|
||||||
|
|
@ -1461,13 +1468,15 @@ proc genVarSection(c: PCtx; n: PNode) =
|
||||||
if a.sons[2].kind == nkEmpty:
|
if a.sons[2].kind == nkEmpty:
|
||||||
c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ))
|
c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ))
|
||||||
else:
|
else:
|
||||||
|
assert s.typ != nil
|
||||||
if not fitsRegister(s.typ):
|
if not fitsRegister(s.typ):
|
||||||
c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ))
|
c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ))
|
||||||
let le = a.sons[0]
|
let le = a.sons[0]
|
||||||
|
assert le.typ != nil
|
||||||
if not fitsRegister(le.typ) and s.kind in {skResult, skVar, skParam}:
|
if not fitsRegister(le.typ) and s.kind in {skResult, skVar, skParam}:
|
||||||
var cc = c.getTemp(le.typ)
|
var cc = c.getTemp(le.typ)
|
||||||
gen(c, a.sons[2], cc)
|
gen(c, a.sons[2], cc)
|
||||||
c.gABC(le, whichAsgnOpc(le), s.position.TRegister, cc)
|
c.gABC(le, whichAsgnOpc(le), s.position.TRegister, cc, 1)
|
||||||
c.freeTemp(cc)
|
c.freeTemp(cc)
|
||||||
else:
|
else:
|
||||||
gen(c, a.sons[2], s.position.TRegister)
|
gen(c, a.sons[2], s.position.TRegister)
|
||||||
|
|
@ -1694,7 +1703,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
|
||||||
c.freeTemp(tmp1)
|
c.freeTemp(tmp1)
|
||||||
c.freeTemp(tmp2)
|
c.freeTemp(tmp2)
|
||||||
if dest >= 0:
|
if dest >= 0:
|
||||||
gABC(c, n, whichAsgnOpc(n), dest, tmp0)
|
gABC(c, n, whichAsgnOpc(n), dest, tmp0, 1)
|
||||||
c.freeTemp(tmp0)
|
c.freeTemp(tmp0)
|
||||||
else:
|
else:
|
||||||
dest = tmp0
|
dest = tmp0
|
||||||
|
|
|
||||||
|
|
@ -216,3 +216,5 @@ General commit rules
|
||||||
git diff --check --cached || exit $?
|
git diff --check --cached || exit $?
|
||||||
|
|
||||||
3. Describe your commit and use your common sense.
|
3. Describe your commit and use your common sense.
|
||||||
|
|
||||||
|
.. include:: styleguide.rst
|
||||||
|
|
|
||||||
|
|
@ -588,7 +588,8 @@ can also be defined with indentation instead of ``[]``:
|
||||||
|
|
||||||
Objects provide many features that tuples do not. Object provide inheritance
|
Objects provide many features that tuples do not. Object provide inheritance
|
||||||
and information hiding. Objects have access to their type at runtime, so that
|
and information hiding. Objects have access to their type at runtime, so that
|
||||||
the ``of`` operator can be used to determine the object's type.
|
the ``of`` operator can be used to determine the object's type. The ``of`` operator
|
||||||
|
is similar to the ``instanceof`` operator in Java.
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
type
|
type
|
||||||
|
|
|
||||||
140
docstyle.rst
Normal file
140
docstyle.rst
Normal file
|
|
@ -0,0 +1,140 @@
|
||||||
|
Documentation Style
|
||||||
|
===================
|
||||||
|
|
||||||
|
General Guidelines
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* Authors should document anything that is exported.
|
||||||
|
* Within documentation, a period (`.`) should follow each sentence (or sentence fragment) in a comment block. The documentation may be limited to one sentence fragment, but if multiple sentences are within the documentation, each sentence after the first should be complete and in present tense.
|
||||||
|
* Documentation is parsed as ReStructuredText (RST).
|
||||||
|
* Inline code should be surrounded by double tick marks ("``````"). If you would like a character to immediately follow inline code (e.g., "``int8``s are great!"), escape the following character with a backslash (``\``). The preceding is typed as ``` ``int8``\s are great!```.
|
||||||
|
|
||||||
|
Module-level documentation
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
Documentation of a module is placed at the top of the module itself. Each line of documentation begins with double hashes (``##``).
|
||||||
|
Code samples are encouraged, and should follow the general RST syntax:
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
## The ``universe`` module computes the answer to life, the universe, and everything.
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## echo computeAnswerString() # "42"
|
||||||
|
|
||||||
|
|
||||||
|
Within this top-level comment, you can indicate the authorship and copyright of the code, which will be featured in the produced documentation.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
## This is the best module ever. It provides answers to everything!
|
||||||
|
##
|
||||||
|
## :Author: Steve McQueen
|
||||||
|
## :Copyright: 1965
|
||||||
|
##
|
||||||
|
|
||||||
|
Leave a space between the last line of top-level documentation and the beginning of Nim code (the imports, etc.).
|
||||||
|
|
||||||
|
Procs, Templates, Macros, Converters, and Iterators
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
The documentation of a procedure should begin with a capital letter and should be in present tense. Variables referenced in the documentation should be surrounded by double tick marks (``````).
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
proc example1*(x: int) =
|
||||||
|
## Prints the value of ``x``.
|
||||||
|
echo x
|
||||||
|
|
||||||
|
Whenever an example of usage would be helpful to the user, you should include one within the documentation in RST format as below.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
proc addThree*(x, y, z: int8): int =
|
||||||
|
## Adds three ``int8`` values, treating them as unsigned and
|
||||||
|
## truncating the result.
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## echo addThree(3, 125, 6) # -122
|
||||||
|
result = x +% y +% z
|
||||||
|
|
||||||
|
The commands ``nim doc`` and ``nim doc2`` will then correctly syntax highlight the Nim code within the documentation.
|
||||||
|
|
||||||
|
Types
|
||||||
|
-----
|
||||||
|
|
||||||
|
Exported types should also be documented. This documentation can also contain code samples, but those are better placed with the functions to which they refer.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
type
|
||||||
|
NamedQueue*[T] = object ## Provides a linked data structure with names
|
||||||
|
## throughout. It is named for convenience. I'm making
|
||||||
|
## this comment long to show how you can, too.
|
||||||
|
name*: string ## The name of the item
|
||||||
|
val*: T ## Its value
|
||||||
|
next*: ref NamedQueue[T] ## The next item in the queue
|
||||||
|
|
||||||
|
|
||||||
|
You have some flexibility when placing the documentation:
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
type
|
||||||
|
NamedQueue*[T] = object
|
||||||
|
## Provides a linked data structure with names
|
||||||
|
## throughout. It is named for convenience. I'm making
|
||||||
|
## this comment long to show how you can, too.
|
||||||
|
name*: string ## The name of the item
|
||||||
|
val*: T ## Its value
|
||||||
|
next*: ref NamedQueue[T] ## The next item in the queue
|
||||||
|
|
||||||
|
Make sure to place the documentation beside or within the object.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
type
|
||||||
|
## This documentation disappears because it annotates the ``type`` keyword
|
||||||
|
## above, not ``NamedQueue``.
|
||||||
|
NamedQueue*[T] = object
|
||||||
|
name*: string ## This becomes the main documentation for the object, which
|
||||||
|
## is not what we want.
|
||||||
|
val*: T ## Its value
|
||||||
|
next*: ref NamedQueue[T] ## The next item in the queue
|
||||||
|
|
||||||
|
Var, Let, and Const
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
When declaring module-wide constants and values, documentation is encouraged. The placement of doc comments is similar to the ``type`` sections.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
const
|
||||||
|
X* = 42 ## An awesome number.
|
||||||
|
SpreadArray* = [
|
||||||
|
[1,2,3],
|
||||||
|
[2,3,1],
|
||||||
|
[3,1,2],
|
||||||
|
] ## Doc comment for ``SpreadArray``.
|
||||||
|
|
||||||
|
Placement of comments in other areas is usually allowed, but will not become part of the documentation output and should therefore be prefaced by a single hash (``#``).
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
const
|
||||||
|
BadMathVals* = [
|
||||||
|
3.14, # pi
|
||||||
|
2.72, # e
|
||||||
|
0.58, # gamma
|
||||||
|
] ## A bunch of badly rounded values.
|
||||||
|
|
||||||
|
Nim supports Unicode in comments, so the above can be replaced with the following:
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
|
||||||
|
const
|
||||||
|
BadMathVals* = [
|
||||||
|
3.14, # π
|
||||||
|
2.72, # e
|
||||||
|
0.58, # γ
|
||||||
|
] ## A bunch of badly rounded values (including π!).
|
||||||
|
|
@ -755,7 +755,7 @@ proc renderTocEntries*(d: var RstGenerator, j: var int, lvl: int,
|
||||||
|
|
||||||
proc renderImage(d: PDoc, n: PRstNode, result: var string) =
|
proc renderImage(d: PDoc, n: PRstNode, result: var string) =
|
||||||
template valid(s): expr =
|
template valid(s): expr =
|
||||||
s.len > 0 and allCharsInSet(s, {'/',':','%','_','\\','\128'..'\xFF'} +
|
s.len > 0 and allCharsInSet(s, {'.','/',':','%','_','\\','\128'..'\xFF'} +
|
||||||
Digits + Letters + WhiteSpace)
|
Digits + Letters + WhiteSpace)
|
||||||
|
|
||||||
var options = ""
|
var options = ""
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,7 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||||
|
|
||||||
headers.add(" HTTP/1.1\c\L")
|
headers.add(" HTTP/1.1\c\L")
|
||||||
|
|
||||||
add(headers, "Host: " & r.hostname & "\c\L")
|
add(headers, "Host: " & parseUri(url).hostname & "\c\L")
|
||||||
if userAgent != "":
|
if userAgent != "":
|
||||||
add(headers, "User-Agent: " & userAgent & "\c\L")
|
add(headers, "User-Agent: " & userAgent & "\c\L")
|
||||||
if proxy != nil and proxy.auth != "":
|
if proxy != nil and proxy.auth != "":
|
||||||
|
|
|
||||||
|
|
@ -176,10 +176,16 @@ proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||||
## creates a new object of type ``T`` and returns a safe (traced)
|
## creates a new object of type ``T`` and returns a safe (traced)
|
||||||
## reference to it in ``a``.
|
## reference to it in ``a``.
|
||||||
|
|
||||||
proc new*(T: typedesc): ref T =
|
proc new*(T: typedesc): auto =
|
||||||
## creates a new object of type ``T`` and returns a safe (traced)
|
## creates a new object of type ``T`` and returns a safe (traced)
|
||||||
## reference to it as result value
|
## reference to it as result value
|
||||||
new(result)
|
when (T is ref):
|
||||||
|
var r: T
|
||||||
|
else:
|
||||||
|
var r: ref T
|
||||||
|
new(r)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
proc internalNew*[T](a: var ref T) {.magic: "New", noSideEffect.}
|
||||||
## leaked implementation detail. Do not use.
|
## leaked implementation detail. Do not use.
|
||||||
|
|
@ -481,6 +487,7 @@ type
|
||||||
## See the full `exception hierarchy`_.
|
## See the full `exception hierarchy`_.
|
||||||
ObjectConversionError* = object of Exception ## \
|
ObjectConversionError* = object of Exception ## \
|
||||||
## Raised if an object is converted to an incompatible object type.
|
## Raised if an object is converted to an incompatible object type.
|
||||||
|
## You can use ``of`` operator to check if conversion will succeed.
|
||||||
##
|
##
|
||||||
## See the full `exception hierarchy`_.
|
## See the full `exception hierarchy`_.
|
||||||
FloatingPointError* = object of Exception ## \
|
FloatingPointError* = object of Exception ## \
|
||||||
|
|
@ -1150,7 +1157,8 @@ const
|
||||||
|
|
||||||
hostCPU* {.magic: "HostCPU".}: string = ""
|
hostCPU* {.magic: "HostCPU".}: string = ""
|
||||||
## a string that describes the host CPU. Possible values:
|
## a string that describes the host CPU. Possible values:
|
||||||
## "i386", "alpha", "powerpc", "powerpc64", "sparc", "amd64", "mips", "arm".
|
## "i386", "alpha", "powerpc", "powerpc64", "powerpc64el", "sparc",
|
||||||
|
## "amd64", "mips", "mipsel", "arm", "arm64".
|
||||||
|
|
||||||
seqShallowFlag = low(int)
|
seqShallowFlag = low(int)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,14 @@ type
|
||||||
alpha, ## Alpha processor
|
alpha, ## Alpha processor
|
||||||
powerpc, ## 32 bit PowerPC
|
powerpc, ## 32 bit PowerPC
|
||||||
powerpc64, ## 64 bit PowerPC
|
powerpc64, ## 64 bit PowerPC
|
||||||
|
powerpc64el, ## Little Endian 64 bit PowerPC
|
||||||
sparc, ## Sparc based processor
|
sparc, ## Sparc based processor
|
||||||
ia64, ## Intel Itanium
|
ia64, ## Intel Itanium
|
||||||
amd64, ## x86_64 (AMD64); 64 bit x86 compatible CPU
|
amd64, ## x86_64 (AMD64); 64 bit x86 compatible CPU
|
||||||
mips, ## Mips based processor
|
mips, ## Mips based processor
|
||||||
|
mipsel, ## Little Endian Mips based processor
|
||||||
arm, ## ARM based processor
|
arm, ## ARM based processor
|
||||||
|
arm64, ## ARM64 based processor
|
||||||
vm, ## Some Virtual machine: Nim's VM or JavaScript
|
vm, ## Some Virtual machine: Nim's VM or JavaScript
|
||||||
avr ## AVR based processor
|
avr ## AVR based processor
|
||||||
|
|
||||||
|
|
@ -63,11 +66,14 @@ const
|
||||||
elif defined(alpha): CpuPlatform.alpha
|
elif defined(alpha): CpuPlatform.alpha
|
||||||
elif defined(powerpc): CpuPlatform.powerpc
|
elif defined(powerpc): CpuPlatform.powerpc
|
||||||
elif defined(powerpc64): CpuPlatform.powerpc64
|
elif defined(powerpc64): CpuPlatform.powerpc64
|
||||||
|
elif defined(powerpc64el): CpuPlatform.powerpc64el
|
||||||
elif defined(sparc): CpuPlatform.sparc
|
elif defined(sparc): CpuPlatform.sparc
|
||||||
elif defined(ia64): CpuPlatform.ia64
|
elif defined(ia64): CpuPlatform.ia64
|
||||||
elif defined(amd64): CpuPlatform.amd64
|
elif defined(amd64): CpuPlatform.amd64
|
||||||
elif defined(mips): CpuPlatform.mips
|
elif defined(mips): CpuPlatform.mips
|
||||||
|
elif defined(mipsel): CpuPlatform.mipsel
|
||||||
elif defined(arm): CpuPlatform.arm
|
elif defined(arm): CpuPlatform.arm
|
||||||
|
elif defined(arm64): CpuPlatform.arm64
|
||||||
elif defined(vm): CpuPlatform.vm
|
elif defined(vm): CpuPlatform.vm
|
||||||
elif defined(avr): CpuPlatform.avr
|
elif defined(avr): CpuPlatform.avr
|
||||||
else: CpuPlatform.none
|
else: CpuPlatform.none
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,10 @@ when not defined(useNimRtl):
|
||||||
of tyBool: add result, reprBool(cast[ptr bool](p)[])
|
of tyBool: add result, reprBool(cast[ptr bool](p)[])
|
||||||
of tyChar: add result, reprChar(cast[ptr char](p)[])
|
of tyChar: add result, reprChar(cast[ptr char](p)[])
|
||||||
of tyString: reprStrAux(result, cast[ptr string](p)[])
|
of tyString: reprStrAux(result, cast[ptr string](p)[])
|
||||||
of tyCString: reprStrAux(result, $(cast[ptr cstring](p)[]))
|
of tyCString:
|
||||||
|
let cs = cast[ptr cstring](p)[]
|
||||||
|
if cs.isNil: add result, "nil"
|
||||||
|
else: reprStrAux(result, $cs)
|
||||||
of tyRange: reprAux(result, p, typ.base, cl)
|
of tyRange: reprAux(result, p, typ.base, cl)
|
||||||
of tyProc, tyPointer:
|
of tyProc, tyPointer:
|
||||||
if cast[PPointer](p)[] == nil: add result, "nil"
|
if cast[PPointer](p)[] == nil: add result, "nil"
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ proc countBits32(n: int32): int {.compilerproc.} =
|
||||||
result = ((v +% (v shr 4'i32) and 0xF0F0F0F'i32) *% 0x1010101'i32) shr 24'i32
|
result = ((v +% (v shr 4'i32) and 0xF0F0F0F'i32) *% 0x1010101'i32) shr 24'i32
|
||||||
|
|
||||||
proc countBits64(n: int64): int {.compilerproc.} =
|
proc countBits64(n: int64): int {.compilerproc.} =
|
||||||
result = countBits32(toU32(n and 0xffff'i64)) +
|
result = countBits32(toU32(n and 0xffffffff'i64)) +
|
||||||
countBits32(toU32(n shr 16'i64))
|
countBits32(toU32(n shr 32'i64))
|
||||||
|
|
||||||
proc cardSet(s: NimSet, len: int): int {.compilerproc.} =
|
proc cardSet(s: NimSet, len: int): int {.compilerproc.} =
|
||||||
result = 0
|
result = 0
|
||||||
|
|
|
||||||
8
tests/pragmas/tsym_as_pragma.nim
Normal file
8
tests/pragmas/tsym_as_pragma.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
# bug #3171
|
||||||
|
|
||||||
|
template newDataWindow(): stmt =
|
||||||
|
let eventClosure = proc (closure: pointer): bool {.closure, cdecl.} =
|
||||||
|
discard
|
||||||
|
|
||||||
|
newDataWindow()
|
||||||
|
|
@ -210,7 +210,7 @@ proc parse_complex_stmt(value, identifier: string, index: var int): NimNode {.co
|
||||||
inc(index, read + 1)
|
inc(index, read + 1)
|
||||||
|
|
||||||
# Insert body into result
|
# Insert body into result
|
||||||
var stmtIndex = macros.high(result[resultIndex])
|
var stmtIndex = result[resultIndex].len-1
|
||||||
result[resultIndex][stmtIndex] = body
|
result[resultIndex][stmtIndex] = body
|
||||||
|
|
||||||
# Parse through EOL again & increment result index
|
# Parse through EOL again & increment result index
|
||||||
|
|
@ -245,7 +245,7 @@ proc parse_simple_statement(value: string, index: var int): NimNode {.compiletim
|
||||||
inc(index, read + 1)
|
inc(index, read + 1)
|
||||||
|
|
||||||
# Insert body into result
|
# Insert body into result
|
||||||
var stmtIndex = macros.high(result)
|
var stmtIndex = result.len-1
|
||||||
result[stmtIndex] = body
|
result[stmtIndex] = body
|
||||||
|
|
||||||
# Parse through EOL again
|
# Parse through EOL again
|
||||||
|
|
|
||||||
20
tests/template/twrongsymkind.nim
Normal file
20
tests/template/twrongsymkind.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "cannot use symbol of kind 'var' as a 'param'"
|
||||||
|
line: 20
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #3158
|
||||||
|
|
||||||
|
type
|
||||||
|
MyData = object
|
||||||
|
x: int
|
||||||
|
|
||||||
|
template newDataWindow(data: ref MyData): stmt =
|
||||||
|
proc testProc(data: ref MyData) =
|
||||||
|
echo "Hello, ", data.x
|
||||||
|
testProc(data)
|
||||||
|
|
||||||
|
var d: ref MyData
|
||||||
|
new(d)
|
||||||
|
d.x = 10
|
||||||
|
newDataWindow(d)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue