Untyped pointers godegen changed. addr expression fixed.
This commit is contained in:
parent
0cc662d8b8
commit
a5be556a4c
4 changed files with 21 additions and 10 deletions
|
|
@ -136,7 +136,7 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||||
result = etyBaseIndex
|
result = etyBaseIndex
|
||||||
of tyPointer:
|
of tyPointer:
|
||||||
# treat a tyPointer like a typed pointer to an array of bytes
|
# treat a tyPointer like a typed pointer to an array of bytes
|
||||||
result = etyInt
|
result = etyBaseIndex
|
||||||
of tyRange, tyDistinct, tyOrdinal, tyConst, tyMutable, tyIter, tyProxy:
|
of tyRange, tyDistinct, tyOrdinal, tyConst, tyMutable, tyIter, tyProxy:
|
||||||
result = mapType(t.sons[0])
|
result = mapType(t.sons[0])
|
||||||
of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyChar: result = etyInt
|
of tyInt..tyInt64, tyUInt..tyUInt64, tyEnum, tyChar: result = etyInt
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
proc semAddr(c: PContext; n: PNode; isUnsafeAddr=false): PNode =
|
proc semAddr(c: PContext; n: PNode; isUnsafeAddr=false): PNode =
|
||||||
result = newNodeI(nkAddr, n.info)
|
result = newNodeI(nkAddr, n.info)
|
||||||
let x = semExprWithType(c, n)
|
let x = semExprWithType(c, n)
|
||||||
|
if x.kind == nkSym:
|
||||||
|
x.sym.flags.incl(sfAddrTaken)
|
||||||
if isAssignable(c, x, isUnsafeAddr) notin {arLValue, arLocalLValue}:
|
if isAssignable(c, x, isUnsafeAddr) notin {arLValue, arLocalLValue}:
|
||||||
localError(n.info, errExprHasNoAddress)
|
localError(n.info, errExprHasNoAddress)
|
||||||
result.add x
|
result.add x
|
||||||
|
|
|
||||||
|
|
@ -532,15 +532,17 @@ proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
|
||||||
type NimString = string # hack for hti.nim
|
type NimString = string # hack for hti.nim
|
||||||
include "system/hti"
|
include "system/hti"
|
||||||
|
|
||||||
|
type JSRef = int # Fake type.
|
||||||
|
|
||||||
proc isFatPointer(ti: PNimType): bool =
|
proc isFatPointer(ti: PNimType): bool =
|
||||||
# This has to be consistent with the code generator!
|
# This has to be consistent with the code generator!
|
||||||
return ti.base.kind notin {tyObject,
|
return ti.base.kind notin {tyObject,
|
||||||
tyArray, tyArrayConstr, tyTuple,
|
tyArray, tyArrayConstr, tyTuple,
|
||||||
tyOpenArray, tySet, tyVar, tyRef, tyPtr}
|
tyOpenArray, tySet, tyVar, tyRef, tyPtr}
|
||||||
|
|
||||||
proc nimCopy(dest, src: pointer, ti: PNimType): pointer {.compilerproc.}
|
proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef {.compilerproc.}
|
||||||
|
|
||||||
proc nimCopyAux(dest, src: pointer, n: ptr TNimNode) {.compilerproc.} =
|
proc nimCopyAux(dest, src: JSRef, n: ptr TNimNode) {.compilerproc.} =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkNone: sysAssert(false, "nimCopyAux")
|
of nkNone: sysAssert(false, "nimCopyAux")
|
||||||
of nkSlot:
|
of nkSlot:
|
||||||
|
|
@ -562,7 +564,7 @@ proc nimCopyAux(dest, src: pointer, n: ptr TNimNode) {.compilerproc.} =
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc nimCopy(dest, src: pointer, ti: PNimType): pointer =
|
proc nimCopy(dest, src: JSRef, ti: PNimType): JSRef =
|
||||||
case ti.kind
|
case ti.kind
|
||||||
of tyPtr, tyRef, tyVar, tyNil:
|
of tyPtr, tyRef, tyVar, tyNil:
|
||||||
if not isFatPointer(ti):
|
if not isFatPointer(ti):
|
||||||
|
|
@ -603,12 +605,11 @@ proc nimCopy(dest, src: pointer, ti: PNimType): pointer =
|
||||||
else:
|
else:
|
||||||
result = src
|
result = src
|
||||||
|
|
||||||
proc genericReset(x: pointer, ti: PNimType): pointer {.compilerproc.} =
|
proc genericReset(x: JSRef, ti: PNimType): JSRef {.compilerproc.} =
|
||||||
|
asm "`result` = null;"
|
||||||
case ti.kind
|
case ti.kind
|
||||||
of tyPtr, tyRef, tyVar, tyNil:
|
of tyPtr, tyRef, tyVar, tyNil:
|
||||||
if not isFatPointer(ti):
|
if isFatPointer(ti):
|
||||||
result = nil
|
|
||||||
else:
|
|
||||||
asm """
|
asm """
|
||||||
`result` = [null, 0];
|
`result` = [null, 0];
|
||||||
"""
|
"""
|
||||||
|
|
@ -633,9 +634,9 @@ proc genericReset(x: pointer, ti: PNimType): pointer {.compilerproc.} =
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
result = nil
|
discard
|
||||||
|
|
||||||
proc arrayConstr(len: int, value: pointer, typ: PNimType): pointer {.
|
proc arrayConstr(len: int, value: JSRef, typ: PNimType): JSRef {.
|
||||||
asmNoStackFrame, compilerproc.} =
|
asmNoStackFrame, compilerproc.} =
|
||||||
# types are fake
|
# types are fake
|
||||||
asm """
|
asm """
|
||||||
|
|
|
||||||
|
|
@ -62,3 +62,11 @@ var t : tuple[a, b: int]
|
||||||
var pt = addr t[1]
|
var pt = addr t[1]
|
||||||
pt[] = 123
|
pt[] = 123
|
||||||
doAssert(t.b == 123)
|
doAssert(t.b == 123)
|
||||||
|
|
||||||
|
#block: # Test "untyped" pointer.
|
||||||
|
proc testPtr(p: pointer, a: int) =
|
||||||
|
doAssert(a == 5)
|
||||||
|
(cast[ptr int](p))[] = 124
|
||||||
|
var i = 123
|
||||||
|
testPtr(addr i, 5)
|
||||||
|
doAssert(i == 124)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue