stdlib and compiler don't use .immediate anymore
This commit is contained in:
parent
9ee5b5eabc
commit
60b187513e
36 changed files with 169 additions and 172 deletions
|
|
@ -278,6 +278,8 @@ const
|
|||
sfImmediate* = sfDeadCodeElim
|
||||
# macro or template is immediately expanded
|
||||
# without considering any possible overloads
|
||||
sfAllUntyped* = sfVolatile # macro or template is immediately expanded \
|
||||
# in a generic context
|
||||
|
||||
sfDirty* = sfPure
|
||||
# template is not hygienic (old styled template)
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ proc processMergeInfo(L: var TBaseLexer, m: BModule) =
|
|||
when not defined(nimhygiene):
|
||||
{.pragma: inject.}
|
||||
|
||||
template withCFile(cfilename: string, body: stmt) {.immediate.} =
|
||||
template withCFile(cfilename: string, body: untyped) =
|
||||
var s = llStreamOpen(cfilename, fmRead)
|
||||
if s == nil: return
|
||||
var L {.inject.}: TBaseLexer
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ proc exprBlock(p: BProc, n: PNode, d: var TLoc) =
|
|||
expr(p, n, d)
|
||||
endBlock(p)
|
||||
|
||||
template preserveBreakIdx(body: stmt): stmt {.immediate.} =
|
||||
template preserveBreakIdx(body: untyped): untyped =
|
||||
var oldBreakIdx = p.breakIdx
|
||||
body
|
||||
p.breakIdx = oldBreakIdx
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ type
|
|||
# When adding new compilers, the cmake sources could be a good reference:
|
||||
# http://cmake.org/gitweb?p=cmake.git;a=tree;f=Modules/Platform;
|
||||
|
||||
template compiler(name: expr, settings: stmt): stmt {.immediate.} =
|
||||
template compiler(name, settings: untyped): untyped =
|
||||
proc name: TInfoCC {.compileTime.} = settings
|
||||
|
||||
# GNU C and C++ Compiler
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ type
|
|||
up: PProc # up the call chain; required for closure support
|
||||
declaredGlobals: IntSet
|
||||
|
||||
template `|`(a, b: expr): expr {.immediate, dirty.} =
|
||||
template `|`(a, b: untyped): untyped {.dirty.} =
|
||||
(if p.target == targetJS: a else: b)
|
||||
|
||||
proc newGlobals(): PGlobals =
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ proc parMessage(p: TParser, msg: TMsgKind, tok: TToken) =
|
|||
## Produce and emit a parser message to output about the token `tok`
|
||||
parMessage(p, msg, prettyTok(tok))
|
||||
|
||||
template withInd(p: expr, body: stmt) {.immediate.} =
|
||||
template withInd(p, body: untyped) =
|
||||
let oldInd = p.currInd
|
||||
p.currInd = p.tok.indent
|
||||
body
|
||||
|
|
|
|||
|
|
@ -626,7 +626,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
|||
processImportCompilerProc(sym, getOptionalStr(c, it, "$1"))
|
||||
of wExtern: setExternName(sym, expectStrLit(c, it))
|
||||
of wImmediate:
|
||||
if sym.kind in {skTemplate, skMacro}: incl(sym.flags, sfImmediate)
|
||||
if sym.kind in {skTemplate, skMacro}:
|
||||
incl(sym.flags, sfImmediate)
|
||||
incl(sym.flags, sfAllUntyped)
|
||||
message(n.info, warnDeprecated, "use 'untyped' parameters instead; immediate")
|
||||
else: invalidPragma(it)
|
||||
of wDirty:
|
||||
if sym.kind == skTemplate: incl(sym.flags, sfDirty)
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
|
|||
const ordIntLit = {nkIntLit..nkUInt64Lit}
|
||||
result = n.typ
|
||||
|
||||
template commutativeOp(opr: expr) {.immediate.} =
|
||||
template commutativeOp(opr: untyped) =
|
||||
let a = n.sons[1]
|
||||
let b = n.sons[2]
|
||||
if isIntRangeOrLit(a.typ) and isIntRangeOrLit(b.typ):
|
||||
|
|
@ -151,7 +151,7 @@ proc getIntervalType*(m: TMagic, n: PNode): PType =
|
|||
opr(pickMinInt(a), pickMinInt(b)),
|
||||
opr(pickMaxInt(a), pickMaxInt(b)))
|
||||
|
||||
template binaryOp(opr: expr) {.immediate.} =
|
||||
template binaryOp(opr: untyped) =
|
||||
let a = n.sons[1]
|
||||
let b = n.sons[2]
|
||||
if isIntRange(a.typ) and b.kind in {nkIntLit..nkUInt64Lit}:
|
||||
|
|
|
|||
|
|
@ -48,7 +48,10 @@ proc semGenericStmtScope(c: PContext, n: PNode,
|
|||
closeScope(c)
|
||||
|
||||
template macroToExpand(s: expr): expr =
|
||||
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfImmediate in s.flags)
|
||||
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfAllUntyped in s.flags)
|
||||
|
||||
template macroToExpandSym(s: expr): expr =
|
||||
s.kind in {skMacro, skTemplate} and (s.typ.len == 1)
|
||||
|
||||
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
|
||||
ctx: var GenericCtx): PNode =
|
||||
|
|
@ -61,14 +64,14 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
|
|||
of skProc, skMethod, skIterator, skConverter, skModule:
|
||||
result = symChoice(c, n, s, scOpen)
|
||||
of skTemplate:
|
||||
if macroToExpand(s):
|
||||
if macroToExpandSym(s):
|
||||
styleCheckUse(n.info, s)
|
||||
result = semTemplateExpr(c, n, s, {efNoSemCheck})
|
||||
result = semGenericStmt(c, result, {}, ctx)
|
||||
else:
|
||||
result = symChoice(c, n, s, scOpen)
|
||||
of skMacro:
|
||||
if macroToExpand(s):
|
||||
if macroToExpandSym(s):
|
||||
styleCheckUse(n.info, s)
|
||||
result = semMacroExpr(c, n, n, s, {efNoSemCheck})
|
||||
result = semGenericStmt(c, result, {}, ctx)
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ proc min(a, b: PNode): PNode =
|
|||
|
||||
proc fromSystem(op: PSym): bool = sfSystemModule in getModule(op).flags
|
||||
|
||||
template pushSpawnId(c: expr, body: stmt) {.immediate, dirty.} =
|
||||
template pushSpawnId(c, body) {.dirty.} =
|
||||
inc c.spawns
|
||||
let oldSpawnId = c.currentSpawnId
|
||||
c.currentSpawnId = c.spawns
|
||||
|
|
|
|||
|
|
@ -577,13 +577,16 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
else:
|
||||
gp = newNodeI(nkGenericParams, n.info)
|
||||
# process parameters:
|
||||
var allUntyped = true
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
semParamList(c, n.sons[paramsPos], gp, s)
|
||||
# a template's parameters are not gensym'ed even if that was originally the
|
||||
# case as we determine whether it's a template parameter in the template
|
||||
# body by the absence of the sfGenSym flag:
|
||||
for i in 1 .. s.typ.n.len-1:
|
||||
s.typ.n.sons[i].sym.flags.excl sfGenSym
|
||||
let param = s.typ.n.sons[i].sym
|
||||
param.flags.excl sfGenSym
|
||||
if param.typ.kind != tyExpr: allUntyped = false
|
||||
if sonsLen(gp) > 0:
|
||||
if n.sons[genericParamsPos].kind == nkEmpty:
|
||||
# we have a list of implicit type parameters:
|
||||
|
|
@ -599,6 +602,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
s.typ.n = newNodeI(nkFormalParams, n.info)
|
||||
rawAddSon(s.typ, newTypeS(tyStmt, c))
|
||||
addSon(s.typ.n, newNodeIT(nkType, n.info, s.typ.sons[0]))
|
||||
if allUntyped: incl(s.flags, sfAllUntyped)
|
||||
if n.sons[patternPos].kind != nkEmpty:
|
||||
n.sons[patternPos] = semPattern(c, n.sons[patternPos])
|
||||
var ctx: TemplCtx
|
||||
|
|
@ -629,7 +633,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
|||
|
||||
proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
|
||||
template templToExpand(s: expr): expr =
|
||||
s.kind == skTemplate and (s.typ.len == 1 or sfImmediate in s.flags)
|
||||
s.kind == skTemplate and (s.typ.len == 1 or sfAllUntyped in s.flags)
|
||||
|
||||
proc newParam(c: var TemplCtx, n: PNode, s: PSym): PNode =
|
||||
# the param added in the current scope is actually wrong here for
|
||||
|
|
|
|||
|
|
@ -691,7 +691,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
|||
put(c.bindings, f, bound)
|
||||
return res
|
||||
|
||||
template considerPreviousT(body: stmt) {.immediate.} =
|
||||
template considerPreviousT(body: untyped) =
|
||||
var prev = PType(idTableGet(c.bindings, f))
|
||||
if prev == nil: body
|
||||
else: return typeRel(c, prev, a)
|
||||
|
|
@ -1591,7 +1591,7 @@ template isVarargsUntyped(x): expr =
|
|||
|
||||
proc matchesAux(c: PContext, n, nOrig: PNode,
|
||||
m: var TCandidate, marker: var IntSet) =
|
||||
template checkConstraint(n: expr) {.immediate, dirty.} =
|
||||
template checkConstraint(n: untyped) {.dirty.} =
|
||||
if not formal.constraint.isNil:
|
||||
if matchNodeKinds(formal.constraint, n):
|
||||
# better match over other routines with no such restriction:
|
||||
|
|
@ -1816,7 +1816,7 @@ proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
|
|||
include suggest
|
||||
|
||||
when not declared(tests):
|
||||
template tests(s: stmt) {.immediate.} = discard
|
||||
template tests(s: untyped) = discard
|
||||
|
||||
tests:
|
||||
var dummyOwner = newSym(skModule, getIdent("test_module"), nil, UnknownLineInfo())
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ proc suggestField(c: PContext, s: PSym, outputs: var int) =
|
|||
suggestResult(symToSuggest(s, isLocal=true, $ideSug, 100))
|
||||
inc outputs
|
||||
|
||||
template wholeSymTab(cond, section: expr) {.immediate.} =
|
||||
template wholeSymTab(cond, section: untyped) =
|
||||
var isLocal = true
|
||||
for scope in walkScopes(c.currentScope):
|
||||
if scope == c.topLevelScope: isLocal = false
|
||||
|
|
|
|||
|
|
@ -806,7 +806,7 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
|
|||
elif a.n != b.n and (a.n == nil or b.n == nil) and IgnoreTupleFields notin c.flags:
|
||||
result = false
|
||||
|
||||
template ifFastObjectTypeCheckFailed(a, b: PType, body: stmt) {.immediate.} =
|
||||
template ifFastObjectTypeCheckFailed(a, b: PType, body: untyped) =
|
||||
if tfFromGeneric notin a.flags + b.flags:
|
||||
# fast case: id comparison suffices:
|
||||
result = a.id == b.id
|
||||
|
|
|
|||
|
|
@ -92,34 +92,34 @@ when not defined(nimComputedGoto):
|
|||
|
||||
proc myreset(n: var TFullReg) = reset(n)
|
||||
|
||||
template ensureKind(k: expr) {.immediate, dirty.} =
|
||||
template ensureKind(k: untyped) {.dirty.} =
|
||||
if regs[ra].kind != k:
|
||||
myreset(regs[ra])
|
||||
regs[ra].kind = k
|
||||
|
||||
template decodeB(k: expr) {.immediate, dirty.} =
|
||||
template decodeB(k: untyped) {.dirty.} =
|
||||
let rb = instr.regB
|
||||
ensureKind(k)
|
||||
|
||||
template decodeBC(k: expr) {.immediate, dirty.} =
|
||||
template decodeBC(k: untyped) {.dirty.} =
|
||||
let rb = instr.regB
|
||||
let rc = instr.regC
|
||||
ensureKind(k)
|
||||
|
||||
template declBC() {.immediate, dirty.} =
|
||||
template declBC() {.dirty.} =
|
||||
let rb = instr.regB
|
||||
let rc = instr.regC
|
||||
|
||||
template decodeBImm(k: expr) {.immediate, dirty.} =
|
||||
template decodeBImm(k: untyped) {.dirty.} =
|
||||
let rb = instr.regB
|
||||
let imm = instr.regC - byteExcess
|
||||
ensureKind(k)
|
||||
|
||||
template decodeBx(k: expr) {.immediate, dirty.} =
|
||||
template decodeBx(k: expr) {.dirty.} =
|
||||
let rbx = instr.regBx - wordExcess
|
||||
ensureKind(k)
|
||||
|
||||
template move(a, b: expr) {.immediate, dirty.} = system.shallowCopy(a, b)
|
||||
template move(a, b: untyped) {.dirty.} = system.shallowCopy(a, b)
|
||||
# XXX fix minor 'shallowCopy' overloading bug in compiler
|
||||
|
||||
proc createStrKeepNode(x: var TFullReg; keepNode=true) =
|
||||
|
|
@ -1573,7 +1573,7 @@ proc setupMacroParam(x: PNode, typ: PType): TFullReg =
|
|||
var evalMacroCounter: int
|
||||
|
||||
proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode =
|
||||
# XXX GlobalError() is ugly here, but I don't know a better solution for now
|
||||
# XXX globalError() is ugly here, but I don't know a better solution for now
|
||||
inc(evalMacroCounter)
|
||||
if evalMacroCounter > 100:
|
||||
globalError(n.info, errTemplateInstantiationTooNested)
|
||||
|
|
@ -1603,7 +1603,7 @@ proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode =
|
|||
|
||||
# return value:
|
||||
tos.slots[0].kind = rkNode
|
||||
tos.slots[0].node = newNodeIT(nkEmpty, n.info, sym.typ.sons[0])
|
||||
tos.slots[0].node = newNodeI(nkEmpty, n.info)
|
||||
|
||||
# setup parameters:
|
||||
for i in 1.. <sym.typ.len:
|
||||
|
|
@ -1623,4 +1623,3 @@ proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode =
|
|||
if cyclicTree(result): globalError(n.info, errCyclicTree)
|
||||
dec(evalMacroCounter)
|
||||
c.callsite = nil
|
||||
#debug result
|
||||
|
|
|
|||
|
|
@ -230,10 +230,10 @@ const
|
|||
slotSomeTemp* = slotTempUnknown
|
||||
relativeJumps* = {opcTJmp, opcFJmp, opcJmp, opcJmpBack}
|
||||
|
||||
template opcode*(x: TInstr): TOpcode {.immediate.} = TOpcode(x.uint32 and 0xff'u32)
|
||||
template regA*(x: TInstr): TRegister {.immediate.} = TRegister(x.uint32 shr 8'u32 and 0xff'u32)
|
||||
template regB*(x: TInstr): TRegister {.immediate.} = TRegister(x.uint32 shr 16'u32 and 0xff'u32)
|
||||
template regC*(x: TInstr): TRegister {.immediate.} = TRegister(x.uint32 shr 24'u32)
|
||||
template regBx*(x: TInstr): int {.immediate.} = (x.uint32 shr 16'u32).int
|
||||
template opcode*(x: TInstr): TOpcode = TOpcode(x.uint32 and 0xff'u32)
|
||||
template regA*(x: TInstr): TRegister = TRegister(x.uint32 shr 8'u32 and 0xff'u32)
|
||||
template regB*(x: TInstr): TRegister = TRegister(x.uint32 shr 16'u32 and 0xff'u32)
|
||||
template regC*(x: TInstr): TRegister = TRegister(x.uint32 shr 24'u32)
|
||||
template regBx*(x: TInstr): int = (x.uint32 shr 16'u32).int
|
||||
|
||||
template jmpDiff*(x: TInstr): int {.immediate.} = regBx(x) - wordExcess
|
||||
template jmpDiff*(x: TInstr): int = regBx(x) - wordExcess
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ proc getTempRange(cc: PCtx; n: int; kind: TSlotKind): TRegister =
|
|||
proc freeTempRange(c: PCtx; start: TRegister, n: int) =
|
||||
for i in start .. start+n-1: c.freeTemp(TRegister(i))
|
||||
|
||||
template withTemp(tmp, typ: expr, body: stmt) {.immediate, dirty.} =
|
||||
template withTemp(tmp, typ, body: untyped) {.dirty.} =
|
||||
var tmp = getTemp(c, typ)
|
||||
body
|
||||
c.freeTemp(tmp)
|
||||
|
|
@ -241,7 +241,7 @@ proc popBlock(c: PCtx; oldLen: int) =
|
|||
c.patch(f)
|
||||
c.prc.blocks.setLen(oldLen)
|
||||
|
||||
template withBlock(labl: PSym; body: stmt) {.immediate, dirty.} =
|
||||
template withBlock(labl: PSym; body: untyped) {.dirty.} =
|
||||
var oldLen {.gensym.} = c.prc.blocks.len
|
||||
c.prc.blocks.add TBlock(label: labl, fixups: @[])
|
||||
body
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
template setX(k, field) {.immediate, dirty.} =
|
||||
template setX(k, field) {.dirty.} =
|
||||
var s: seq[TFullReg]
|
||||
move(s, cast[seq[TFullReg]](a.slots))
|
||||
if s[a.ra].kind != k:
|
||||
|
|
@ -48,7 +48,7 @@ proc setResult*(a: VmArgs; v: seq[string]) =
|
|||
for x in v: n.add newStrNode(nkStrLit, x)
|
||||
s[a.ra].node = n
|
||||
|
||||
template getX(k, field) {.immediate, dirty.} =
|
||||
template getX(k, field) {.dirty.} =
|
||||
doAssert i < a.rc-1
|
||||
let s = cast[seq[TFullReg]](a.slots)
|
||||
doAssert s[i+a.rb+1].kind == k
|
||||
|
|
|
|||
|
|
@ -15,36 +15,36 @@ from math import sqrt, ln, log10, log2, exp, round, arccos, arcsin,
|
|||
|
||||
from os import getEnv, existsEnv, dirExists, fileExists, walkDir
|
||||
|
||||
template mathop(op) {.immediate, dirty.} =
|
||||
template mathop(op) {.dirty.} =
|
||||
registerCallback(c, "stdlib.math." & astToStr(op), `op Wrapper`)
|
||||
|
||||
template osop(op) {.immediate, dirty.} =
|
||||
template osop(op) {.dirty.} =
|
||||
registerCallback(c, "stdlib.os." & astToStr(op), `op Wrapper`)
|
||||
|
||||
template systemop(op) {.immediate, dirty.} =
|
||||
template systemop(op) {.dirty.} =
|
||||
registerCallback(c, "stdlib.system." & astToStr(op), `op Wrapper`)
|
||||
|
||||
template wrap1f_math(op) {.immediate, dirty.} =
|
||||
template wrap1f_math(op) {.dirty.} =
|
||||
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
|
||||
setResult(a, op(getFloat(a, 0)))
|
||||
mathop op
|
||||
|
||||
template wrap2f_math(op) {.immediate, dirty.} =
|
||||
template wrap2f_math(op) {.dirty.} =
|
||||
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
|
||||
setResult(a, op(getFloat(a, 0), getFloat(a, 1)))
|
||||
mathop op
|
||||
|
||||
template wrap1s_os(op) {.immediate, dirty.} =
|
||||
template wrap1s_os(op) {.dirty.} =
|
||||
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
|
||||
setResult(a, op(getString(a, 0)))
|
||||
osop op
|
||||
|
||||
template wrap1s_system(op) {.immediate, dirty.} =
|
||||
template wrap1s_system(op) {.dirty.} =
|
||||
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
|
||||
setResult(a, op(getString(a, 0)))
|
||||
systemop op
|
||||
|
||||
template wrap2svoid_system(op) {.immediate, dirty.} =
|
||||
template wrap2svoid_system(op) {.dirty.} =
|
||||
proc `op Wrapper`(a: VmArgs) {.nimcall.} =
|
||||
op(getString(a, 0), getString(a, 1))
|
||||
systemop op
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue