* fix #17264 * fix vm * fix js and add tests
This commit is contained in:
parent
2e8325a19c
commit
171b03c386
5 changed files with 25 additions and 5 deletions
|
|
@ -2296,7 +2296,8 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
of mCharToStr: genDollar(p, e, d, "#nimCharToStr($1)")
|
of mCharToStr: genDollar(p, e, d, "#nimCharToStr($1)")
|
||||||
of mFloatToStr: genDollar(p, e, d, "#nimFloatToStr($1)")
|
of mFloatToStr: genDollar(p, e, d, "#nimFloatToStr($1)")
|
||||||
of mCStrToStr: genDollar(p, e, d, "#cstrToNimstr($1)")
|
of mCStrToStr: genDollar(p, e, d, "#cstrToNimstr($1)")
|
||||||
of mStrToStr, mUnown, mIsolate: expr(p, e[1], d)
|
of mStrToStr, mUnown: expr(p, e[1], d)
|
||||||
|
of mIsolate: genCall(p, e, d)
|
||||||
of mEnumToStr:
|
of mEnumToStr:
|
||||||
if optTinyRtti in p.config.globalOptions:
|
if optTinyRtti in p.config.globalOptions:
|
||||||
genEnumToStr(p, e, d)
|
genEnumToStr(p, e, d)
|
||||||
|
|
|
||||||
|
|
@ -1435,7 +1435,7 @@ proc genSym(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
s.name.s)
|
s.name.s)
|
||||||
discard mangleName(p.module, s)
|
discard mangleName(p.module, s)
|
||||||
r.res = s.loc.r
|
r.res = s.loc.r
|
||||||
if lfNoDecl in s.loc.flags or s.magic != mNone or
|
if lfNoDecl in s.loc.flags or s.magic notin {mNone, mIsolate} or
|
||||||
{sfImportc, sfInfixCall} * s.flags != {}:
|
{sfImportc, sfInfixCall} * s.flags != {}:
|
||||||
discard
|
discard
|
||||||
elif s.kind == skMethod and getBody(p.module.graph, s).kind == nkEmpty:
|
elif s.kind == skMethod and getBody(p.module.graph, s).kind == nkEmpty:
|
||||||
|
|
@ -2589,7 +2589,7 @@ proc gen(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
let s = n[namePos].sym
|
let s = n[namePos].sym
|
||||||
discard mangleName(p.module, s)
|
discard mangleName(p.module, s)
|
||||||
r.res = s.loc.r
|
r.res = s.loc.r
|
||||||
if lfNoDecl in s.loc.flags or s.magic != mNone: discard
|
if lfNoDecl in s.loc.flags or s.magic notin {mNone, mIsolate}: discard
|
||||||
elif not p.g.generatedSyms.containsOrIncl(s.id):
|
elif not p.g.generatedSyms.containsOrIncl(s.id):
|
||||||
p.locals.add(genProc(p, s))
|
p.locals.add(genProc(p, s))
|
||||||
of nkType: r.res = genTypeInfo(p, n.typ)
|
of nkType: r.res = genTypeInfo(p, n.typ)
|
||||||
|
|
|
||||||
|
|
@ -1013,7 +1013,9 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
c.genNarrow(n[1], d)
|
c.genNarrow(n[1], d)
|
||||||
c.genAsgnPatch(n[1], d)
|
c.genAsgnPatch(n[1], d)
|
||||||
c.freeTemp(d)
|
c.freeTemp(d)
|
||||||
of mOrd, mChr, mArrToSeq, mUnown, mIsolate: c.gen(n[1], dest)
|
of mOrd, mChr, mArrToSeq, mUnown: c.gen(n[1], dest)
|
||||||
|
of mIsolate:
|
||||||
|
genCall(c, n, dest)
|
||||||
of mNew, mNewFinalize:
|
of mNew, mNewFinalize:
|
||||||
unused(c, n, dest)
|
unused(c, n, dest)
|
||||||
c.genNew(n)
|
c.genNew(n)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ proc `=destroy`*[T](dest: var Isolated[T]) {.inline.} =
|
||||||
# delegate to value's destroy operation
|
# delegate to value's destroy operation
|
||||||
`=destroy`(dest.value)
|
`=destroy`(dest.value)
|
||||||
|
|
||||||
func isolate*[T](value: sink T): Isolated[T] {.magic: "Isolate".}
|
func isolate*[T](value: sink T): Isolated[T] {.magic: "Isolate".} =
|
||||||
## Create an isolated subgraph from the expression `value`.
|
## Create an isolated subgraph from the expression `value`.
|
||||||
## Please read https://github.com/nim-lang/RFCs/issues/244
|
## Please read https://github.com/nim-lang/RFCs/issues/244
|
||||||
## for more details.
|
## for more details.
|
||||||
|
Isolated[T](value: value)
|
||||||
|
|
|
||||||
16
tests/stdlib/isolation.nim
Normal file
16
tests/stdlib/isolation.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
targets: "c cpp js"
|
||||||
|
"""
|
||||||
|
|
||||||
|
import std/[json, isolation]
|
||||||
|
|
||||||
|
|
||||||
|
proc main() =
|
||||||
|
var x: seq[Isolated[JsonNode]]
|
||||||
|
x.add isolate(newJString("1234"))
|
||||||
|
|
||||||
|
doAssert $x == """@[(value: "1234")]"""
|
||||||
|
|
||||||
|
|
||||||
|
static: main()
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue