From 0a84b8fb4d154cb04b1383aa2bf3fcf606b4b8a4 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 29 Apr 2019 13:35:30 +0200 Subject: [PATCH] added system.unown to make 'owned' sane to use in practice; later on we might change the type inference rules to make it more convenient --- compiler/ast.nim | 2 +- compiler/ccgexprs.nim | 2 +- compiler/jsgen.nim | 2 +- compiler/semmagic.nim | 35 +++++++++++++++++++++++++++++++++++ compiler/semstmts.nim | 12 ++++++++---- compiler/vmgen.nim | 2 +- lib/system.nim | 7 ++++++- 7 files changed, 53 insertions(+), 9 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index c98b2a576c..aeb19ae1a6 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -644,7 +644,7 @@ type mSwap, mIsNil, mArrToSeq, mCopyStr, mCopyStrLast, mNewString, mNewStringOfCap, mParseBiggestFloat, mMove, mWasMoved, mDestroy, - mDefault, mAccessEnv, mReset, + mDefault, mUnown, mAccessEnv, mReset, mArray, mOpenArray, mRange, mSet, mSeq, mOpt, mVarargs, mRef, mPtr, mVar, mDistinct, mVoid, mTuple, mOrdinal, diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 0ac6b42f40..e03c4b1c14 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2179,7 +2179,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mCharToStr: genDollar(p, e, d, "#nimCharToStr($1)") of mFloatToStr: genDollar(p, e, d, "#nimFloatToStr($1)") of mCStrToStr: genDollar(p, e, d, "#cstrToNimstr($1)") - of mStrToStr: expr(p, e.sons[1], d) + of mStrToStr, mUnown: expr(p, e.sons[1], d) of mEnumToStr: if optNimV2 in p.config.globalOptions: genEnumToStr(p, e, d) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 750d7c2c2e..8f15d8f493 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -640,7 +640,7 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) = of mInt64ToStr: applyFormat("cstrToNimstr(($1)+\"\")", "cstrToNimstr(($1)+\"\")") of mFloatToStr: applyFormat("cstrToNimstr(($1)+\"\")", "cstrToNimstr(($1)+\"\")") of mCStrToStr: applyFormat("cstrToNimstr($1)", "cstrToNimstr($1)") - of mStrToStr: applyFormat("$1", "$1") + of mStrToStr, mUnown: applyFormat("$1", "$1") else: assert false, $op diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index f290a08d5d..7c75d86245 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -322,6 +322,39 @@ proc semOf(c: PContext, n: PNode): PNode = n.typ = getSysType(c.graph, n.info, tyBool) result = n +proc semUnown(c: PContext; n: PNode): PNode = + proc unownedType(c: PContext; t: PType): PType = + case t.kind + of tyTuple: + var elems = newSeq[PType](t.len) + var someChange = false + for i in 0..