Files
Nim/tests/vm/tzero_extend.nim
metagn 919a889ba8 moderate system cleanup & refactor (#20355)
* system refactor, move out 600 lines

* compilation, slice, backwardsindex, misc_num moved out of system
* some procs/types moved into arithmetics, basic_types
* system no longer depends on syncio
* some procs moved around to fit with their surroundings

* make exceptions an import, old ops to misc_num

* move instantiationInfo back

* move back nim version, fix windows echo

* include compilation

* better docs for imported modules, fix unsigned ops

also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem

* fix terminal

* workaround IC test & weird csize bug, changelog

* move NimMajor etc back to compilation, rebase for CI

* try ic fix

* form single `indices`, slim out TaintedString, try fix IC

* fix CI, update changelog, addQuitProc

* fix CI

* try fix CI

* actually fix CI finally hopefully

* Update lib/system/compilation.nim

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* update kochdocs

* hopefully fix csize uses for slimsystem

* fix tquit

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-09-28 15:28:45 -04:00

45 lines
1.3 KiB
Nim

const RANGE = -384.. -127
proc get_values(): (seq[int8], seq[int16], seq[int32]) =
let i8 = -3'i8
let i16 = -3'i16
let i32 = -3'i32
doAssert int(cast[uint8](i8)) == 0xFD
doAssert int64(cast[uint8](i8)) == 0xFD
doAssert int(cast[uint16](i16)) == 0xFFFD
doAssert int64(cast[uint16](i16)) == 0xFFFD
result[0] = @[]; result[1] = @[]; result[2] = @[]
for offset in RANGE:
let i8 = -(1'i64 shl 9) + offset
let i16 = -(1'i64 shl 17) + offset
let i32 = -(1'i64 shl 33) + offset
# higher bits are masked. these should be exactly equal to offset.
result[0].add cast[int8](cast[uint64](i8))
result[1].add cast[int16](cast[uint64](i16))
result[2].add cast[int32](cast[uint64](i32))
# these values this computed by VM
const COMPILETIME_VALUES = get_values()
# these values this computed by compiler
let RUNTIME_VALUES = get_values()
template check_values(int_type: static[int]) =
var index = 0
let cvalues = COMPILETIME_VALUES[int_type]
let rvalues = RUNTIME_VALUES[int_type]
for offset in RANGE:
let moffset = cast[type(rvalues[0])](offset)
doAssert(moffset == rvalues[index] and moffset == cvalues[index],
"expected: " & $moffset & " got runtime: " & $rvalues[index] & " && compiletime: " & $cvalues[index] )
inc(index)
check_values(0) # uint8
check_values(1) # uint16
check_values(2) # uint32