mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-29 01:51:43 +00:00
added 'reset' magic proc
This commit is contained in:
@@ -331,8 +331,9 @@ type
|
||||
mPlusSet, mMinusSet, mSymDiffSet, mConStrStr, mConArrArr, mConArrT,
|
||||
mConTArr, mConTT, mSlice, mAppendStrCh, mAppendStrStr, mAppendSeqElem,
|
||||
mInRange, mInSet, mRepr, mExit, mSetLengthStr, mSetLengthSeq, mAssert,
|
||||
mSwap, mIsNil, mArrToSeq, mCopyStr, mCopyStrLast, mNewString, mArray,
|
||||
mOpenArray, mRange, mSet, mSeq, mOrdinal, mInt, mInt8, mInt16, mInt32,
|
||||
mSwap, mIsNil, mArrToSeq, mCopyStr, mCopyStrLast, mNewString, mReset,
|
||||
mArray, mOpenArray, mRange, mSet, mSeq,
|
||||
mOrdinal, mInt, mInt8, mInt16, mInt32,
|
||||
mInt64, mFloat, mFloat32, mFloat64, mBool, mChar, mString, mCstring,
|
||||
mPointer, mEmptySet, mIntSetBaseType, mNil, mExpr, mStmt, mTypeDesc,
|
||||
mIsMainModule, mCompileDate, mCompileTime, mNimrodVersion, mNimrodMajor,
|
||||
|
||||
@@ -931,6 +931,12 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||
dest.r = ropef("$1->data[$1->Sup.len-1]", [rdLoc(a)])
|
||||
genAssignment(p, dest, b, {needToCopy, afDestIsNil})
|
||||
|
||||
proc genReset(p: BProc, n: PNode) =
|
||||
var a: TLoc
|
||||
InitLocExpr(p, n.sons[1], a)
|
||||
appcg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
||||
[addrLoc(a), genTypeInfo(p.module, skipTypes(a.t, abstractVarRange))])
|
||||
|
||||
proc genNew(p: BProc, e: PNode) =
|
||||
var
|
||||
a, b: TLoc
|
||||
@@ -1449,6 +1455,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
mInSet:
|
||||
genSetOp(p, e, d, op)
|
||||
of mNewString, mCopyStr, mCopyStrLast, mExit: genCall(p, e, d)
|
||||
of mReset: genReset(p, e)
|
||||
of mEcho: genEcho(p, e)
|
||||
of mArrToSeq: genArrToSeq(p, e, d)
|
||||
of mNLen..mNError:
|
||||
|
||||
@@ -98,6 +98,9 @@ proc isSpecial(n: PNode): bool {.inline.} =
|
||||
# XXX this does not work yet! Better to compile too much than to compile to
|
||||
# few programs
|
||||
|
||||
proc myreset(n: PNode) {.inline.} =
|
||||
when defined(system.reset): reset(n^)
|
||||
|
||||
proc evalIf(c: PEvalContext, n: PNode): PNode =
|
||||
var i = 0
|
||||
var length = sonsLen(n)
|
||||
@@ -361,7 +364,7 @@ proc evalAsgn(c: PEvalContext, n: PNode): PNode =
|
||||
var x = result
|
||||
result = evalAux(c, n.sons[1], {})
|
||||
if isSpecial(result): return
|
||||
when defined(system.reset): reset(x)
|
||||
myreset(x)
|
||||
x.kind = result.kind
|
||||
x.typ = result.typ
|
||||
case x.kind
|
||||
@@ -479,17 +482,13 @@ proc evalNew(c: PEvalContext, n: PNode): PNode =
|
||||
var a = result
|
||||
var t = skipTypes(n.sons[1].typ, abstractVar)
|
||||
if a.kind == nkEmpty: InternalError(n.info, "first parameter is empty")
|
||||
# changing the node kind is ugly and suggests deep problems:
|
||||
myreset(a)
|
||||
a.kind = nkRefTy
|
||||
a.info = n.info
|
||||
a.typ = t
|
||||
a.sons = nil
|
||||
addSon(a, getNullValue(t.sons[0], n.info))
|
||||
result = emptyNode
|
||||
when false:
|
||||
var t = skipTypes(n.sons[1].typ, abstractVar)
|
||||
result = newNodeIT(nkRefTy, n.info, t)
|
||||
addSon(result, getNullValue(t.sons[0], n.info))
|
||||
|
||||
proc evalDeref(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
|
||||
result = evalAux(c, n.sons[0], {efLValue})
|
||||
@@ -646,7 +645,7 @@ proc evalNewSeq(c: PEvalContext, n: PNode): PNode =
|
||||
var b = result
|
||||
var t = skipTypes(n.sons[1].typ, abstractVar)
|
||||
if a.kind == nkEmpty: InternalError(n.info, "first parameter is empty")
|
||||
# changing the node kind is ugly and suggests deep problems:
|
||||
myreset(a)
|
||||
a.kind = nkBracket
|
||||
a.info = n.info
|
||||
a.typ = t
|
||||
|
||||
@@ -392,7 +392,7 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) =
|
||||
const
|
||||
FakeVarParams = {mNew, mNewFinalize, mInc, ast.mDec, mIncl, mExcl,
|
||||
mSetLengthStr, mSetLengthSeq, mAppendStrCh, mAppendStrStr, mSwap,
|
||||
mAppendSeqElem, mNewSeq}
|
||||
mAppendSeqElem, mNewSeq, mReset}
|
||||
checkMinSonsLen(n, 1)
|
||||
var t = n.sons[0].typ
|
||||
if (n.sons[0].kind == nkSym) and (n.sons[0].sym.magic in FakeVarParams):
|
||||
|
||||
Reference in New Issue
Block a user