parent
72acf5de94
commit
dd082b6ec8
3 changed files with 17 additions and 10 deletions
|
|
@ -73,6 +73,15 @@ proc toInt64*(arg: Int128): int64 =
|
||||||
|
|
||||||
cast[int64](bitconcat(arg.udata[1], arg.udata[0]))
|
cast[int64](bitconcat(arg.udata[1], arg.udata[0]))
|
||||||
|
|
||||||
|
proc toInt64Checked*(arg: Int128; onError: int64): int64 =
|
||||||
|
if isNegative(arg):
|
||||||
|
if arg.sdata(3) != -1 or arg.sdata(2) != -1:
|
||||||
|
return onError
|
||||||
|
else:
|
||||||
|
if arg.sdata(3) != 0 or arg.sdata(2) != 0:
|
||||||
|
return onError
|
||||||
|
return cast[int64](bitconcat(arg.udata[1], arg.udata[0]))
|
||||||
|
|
||||||
proc toInt32*(arg: Int128): int32 =
|
proc toInt32*(arg: Int128): int32 =
|
||||||
if isNegative(arg):
|
if isNegative(arg):
|
||||||
assert(arg.sdata(3) == -1, "out of range")
|
assert(arg.sdata(3) == -1, "out of range")
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ const
|
||||||
szUnknownSize* = -3
|
szUnknownSize* = -3
|
||||||
szIllegalRecursion* = -2
|
szIllegalRecursion* = -2
|
||||||
szUncomputedSize* = -1
|
szUncomputedSize* = -1
|
||||||
|
szTooBigSize* = -4
|
||||||
|
|
||||||
type IllegalTypeRecursionError = object of Exception
|
type IllegalTypeRecursionError = object of Exception
|
||||||
|
|
||||||
|
|
@ -111,7 +112,7 @@ proc setOffsetsToUnknown(n: PNode) =
|
||||||
for i in 0 ..< safeLen(n):
|
for i in 0 ..< safeLen(n):
|
||||||
setOffsetsToUnknown(n[i])
|
setOffsetsToUnknown(n[i])
|
||||||
|
|
||||||
proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, packed: bool, accum: var OffsetAccum): void =
|
proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode, packed: bool, accum: var OffsetAccum) =
|
||||||
## ``offset`` is the offset within the object, after the node has been written, no padding bytes added
|
## ``offset`` is the offset within the object, after the node has been written, no padding bytes added
|
||||||
## ``align`` maximum alignment from all sub nodes
|
## ``align`` maximum alignment from all sub nodes
|
||||||
assert n != nil
|
assert n != nil
|
||||||
|
|
@ -256,7 +257,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||||
typ.size = elemSize
|
typ.size = elemSize
|
||||||
typ.align = int16(elemSize)
|
typ.align = int16(elemSize)
|
||||||
else:
|
else:
|
||||||
typ.size = toInt64(lengthOrd(conf, typ.sons[0]) * int32(elemSize))
|
typ.size = toInt64Checked(lengthOrd(conf, typ.sons[0]) * int32(elemSize), szTooBigSize)
|
||||||
typ.align = typ.sons[1].align
|
typ.align = typ.sons[1].align
|
||||||
|
|
||||||
of tyUncheckedArray:
|
of tyUncheckedArray:
|
||||||
|
|
|
||||||
|
|
@ -814,11 +814,8 @@ proc floatRangeCheck*(x: BiggestFloat, t: PType): bool =
|
||||||
false
|
false
|
||||||
|
|
||||||
proc lengthOrd*(conf: ConfigRef; t: PType): Int128 =
|
proc lengthOrd*(conf: ConfigRef; t: PType): Int128 =
|
||||||
case t.skipTypes(tyUserTypeClasses).kind
|
if t.skipTypes(tyUserTypeClasses).kind == tyDistinct:
|
||||||
of tyInt64, tyInt32, tyInt:
|
result = lengthOrd(conf, t.sons[0])
|
||||||
# XXX: this is just wrong
|
|
||||||
result = lastOrd(conf, t)
|
|
||||||
of tyDistinct: result = lengthOrd(conf, t.sons[0])
|
|
||||||
else:
|
else:
|
||||||
let last = lastOrd(conf, t)
|
let last = lastOrd(conf, t)
|
||||||
let first = firstOrd(conf, t)
|
let first = firstOrd(conf, t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue