introduce --newruntime switch for the upcoming destructors and move semantics
This commit is contained in:
parent
a2e4ab2e4e
commit
63530be0b8
6 changed files with 19 additions and 11 deletions
|
|
@ -666,6 +666,10 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
expectArg(switch, arg, pass, info)
|
expectArg(switch, arg, pass, info)
|
||||||
if config != nil:
|
if config != nil:
|
||||||
config.cppDefine(arg)
|
config.cppDefine(arg)
|
||||||
|
of "newruntime":
|
||||||
|
expectNoArg(switch, arg, pass, info)
|
||||||
|
newDestructors = true
|
||||||
|
defineSymbol("nimNewRuntime")
|
||||||
else:
|
else:
|
||||||
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
|
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
|
||||||
else: invalidCmdLineOption(pass, switch, info)
|
else: invalidCmdLineOption(pass, switch, info)
|
||||||
|
|
|
||||||
|
|
@ -290,4 +290,4 @@ proc injectDestructorCalls*(owner: PSym; n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result.add body
|
result.add body
|
||||||
|
|
||||||
echo "transformed into: ", result
|
#echo "transformed into: ", result
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ const
|
||||||
hasTinyCBackend* = defined(tinyc)
|
hasTinyCBackend* = defined(tinyc)
|
||||||
useEffectSystem* = true
|
useEffectSystem* = true
|
||||||
useWriteTracking* = false
|
useWriteTracking* = false
|
||||||
newDestructors* = defined(nimV2)
|
|
||||||
hasFFI* = defined(useFFI)
|
hasFFI* = defined(useFFI)
|
||||||
newScopeForIf* = true
|
newScopeForIf* = true
|
||||||
useCaas* = not defined(noCaas)
|
useCaas* = not defined(noCaas)
|
||||||
|
|
@ -145,6 +144,7 @@ var
|
||||||
isServing*: bool = false
|
isServing*: bool = false
|
||||||
gNoNimblePath* = false
|
gNoNimblePath* = false
|
||||||
gExperimentalMode*: bool
|
gExperimentalMode*: bool
|
||||||
|
newDestructors*: 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
|
||||||
|
|
|
||||||
|
|
@ -1383,7 +1383,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode =
|
||||||
typeMismatch(n.info, lhs.typ, rhs.typ)
|
typeMismatch(n.info, lhs.typ, rhs.typ)
|
||||||
|
|
||||||
n.sons[1] = fitNode(c, le, rhs, n.info)
|
n.sons[1] = fitNode(c, le, rhs, n.info)
|
||||||
when not newDestructors:
|
if not newDestructors:
|
||||||
if tfHasAsgn in lhs.typ.flags and not lhsIsResult and
|
if tfHasAsgn in lhs.typ.flags and not lhsIsResult and
|
||||||
mode != noOverloadedAsgn:
|
mode != noOverloadedAsgn:
|
||||||
return overloadedAsgn(c, lhs, n.sons[1])
|
return overloadedAsgn(c, lhs, n.sons[1])
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ proc semProc(c: PContext, n: PNode): PNode
|
||||||
include semdestruct
|
include semdestruct
|
||||||
|
|
||||||
proc semDestructorCheck(c: PContext, n: PNode, flags: TExprFlags) {.inline.} =
|
proc semDestructorCheck(c: PContext, n: PNode, flags: TExprFlags) {.inline.} =
|
||||||
when not newDestructors:
|
if not newDestructors:
|
||||||
if efAllowDestructor notin flags and
|
if efAllowDestructor notin flags and
|
||||||
n.kind in nkCallKinds+{nkObjConstr,nkBracket}:
|
n.kind in nkCallKinds+{nkObjConstr,nkBracket}:
|
||||||
if instantiateDestructor(c, n.typ) != nil:
|
if instantiateDestructor(c, n.typ) != nil:
|
||||||
|
|
@ -608,7 +608,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
if def.kind == nkPar: v.ast = def[j]
|
if def.kind == nkPar: v.ast = def[j]
|
||||||
setVarType(v, tup.sons[j])
|
setVarType(v, tup.sons[j])
|
||||||
b.sons[j] = newSymNode(v)
|
b.sons[j] = newSymNode(v)
|
||||||
when not newDestructors: addDefer(c, result, v)
|
if not newDestructors: addDefer(c, result, v)
|
||||||
checkNilable(v)
|
checkNilable(v)
|
||||||
if sfCompileTime in v.flags: hasCompileTime = true
|
if sfCompileTime in v.flags: hasCompileTime = true
|
||||||
if hasCompileTime: vm.setupCompileTimeVar(c.module, c.cache, result)
|
if hasCompileTime: vm.setupCompileTimeVar(c.module, c.cache, result)
|
||||||
|
|
@ -1278,9 +1278,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||||
case s.name.s.normalize
|
case s.name.s.normalize
|
||||||
of "destroy", "=destroy":
|
of "destroy", "=destroy":
|
||||||
doDestructorStuff(c, s, n)
|
doDestructorStuff(c, s, n)
|
||||||
when not newDestructors:
|
if not newDestructors and not experimentalMode(c):
|
||||||
if not experimentalMode(c):
|
localError n.info, "use the {.experimental.} pragma to enable destructors"
|
||||||
localError n.info, "use the {.experimental.} pragma to enable destructors"
|
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
of "deepcopy", "=deepcopy":
|
of "deepcopy", "=deepcopy":
|
||||||
if s.typ.len == 2 and
|
if s.typ.len == 2 and
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ type
|
||||||
inlining: int # > 0 if we are in inlining context (copy vars)
|
inlining: int # > 0 if we are in inlining context (copy vars)
|
||||||
nestedProcs: int # > 0 if we are in a nested proc
|
nestedProcs: int # > 0 if we are in a nested proc
|
||||||
contSyms, breakSyms: seq[PSym] # to transform 'continue' and 'break'
|
contSyms, breakSyms: seq[PSym] # to transform 'continue' and 'break'
|
||||||
deferDetected, tooEarly: bool
|
deferDetected, tooEarly, needsDestroyPass: bool
|
||||||
PTransf = ref TTransfContext
|
PTransf = ref TTransfContext
|
||||||
|
|
||||||
proc newTransNode(a: PNode): PTransNode {.inline.} =
|
proc newTransNode(a: PNode): PTransNode {.inline.} =
|
||||||
|
|
@ -780,7 +780,8 @@ proc transform(c: PTransf, n: PNode): PTransNode =
|
||||||
nkBlockStmt, nkBlockExpr}:
|
nkBlockStmt, nkBlockExpr}:
|
||||||
oldDeferAnchor = c.deferAnchor
|
oldDeferAnchor = c.deferAnchor
|
||||||
c.deferAnchor = n
|
c.deferAnchor = n
|
||||||
|
if n.typ != nil and tfHasAsgn in n.typ.flags:
|
||||||
|
c.needsDestroyPass = true
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkSym:
|
of nkSym:
|
||||||
result = transformSym(c, n)
|
result = transformSym(c, n)
|
||||||
|
|
@ -972,7 +973,7 @@ proc transformBody*(module: PSym, n: PNode, prc: PSym): PNode =
|
||||||
#result = liftLambdas(prc, result)
|
#result = liftLambdas(prc, result)
|
||||||
incl(result.flags, nfTransf)
|
incl(result.flags, nfTransf)
|
||||||
when useEffectSystem: trackProc(prc, result)
|
when useEffectSystem: trackProc(prc, result)
|
||||||
if prc.kind == skFunc:
|
if c.needsDestroyPass and newDestructors:
|
||||||
result = injectDestructorCalls(prc, result)
|
result = injectDestructorCalls(prc, result)
|
||||||
#if prc.name.s == "testbody":
|
#if prc.name.s == "testbody":
|
||||||
# echo renderTree(result)
|
# echo renderTree(result)
|
||||||
|
|
@ -989,6 +990,8 @@ proc transformStmt*(module: PSym, n: PNode): PNode =
|
||||||
when useEffectSystem: trackTopLevelStmt(module, result)
|
when useEffectSystem: trackTopLevelStmt(module, result)
|
||||||
#if n.info ?? "temp.nim":
|
#if n.info ?? "temp.nim":
|
||||||
# echo renderTree(result, {renderIds})
|
# echo renderTree(result, {renderIds})
|
||||||
|
if c.needsDestroyPass and newDestructors:
|
||||||
|
result = injectDestructorCalls(module, result)
|
||||||
|
|
||||||
proc transformExpr*(module: PSym, n: PNode): PNode =
|
proc transformExpr*(module: PSym, n: PNode): PNode =
|
||||||
if nfTransf in n.flags:
|
if nfTransf in n.flags:
|
||||||
|
|
@ -998,3 +1001,5 @@ proc transformExpr*(module: PSym, n: PNode): PNode =
|
||||||
result = processTransf(c, n, module)
|
result = processTransf(c, n, module)
|
||||||
liftDefer(c, result)
|
liftDefer(c, result)
|
||||||
incl(result.flags, nfTransf)
|
incl(result.flags, nfTransf)
|
||||||
|
if c.needsDestroyPass and newDestructors:
|
||||||
|
result = injectDestructorCalls(module, result)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue