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>
This commit is contained in:
parent
b463c8aedf
commit
919a889ba8
37 changed files with 1167 additions and 1102 deletions
|
|
@ -7,7 +7,7 @@ import
|
|||
strutils
|
||||
|
||||
type
|
||||
TBuffer = array[0..10, int8]
|
||||
TBuffer = array[0..10, uint8]
|
||||
|
||||
proc toVarNum(x: int32, b: var TBuffer) =
|
||||
# encoding: first bit indicates end of number (0 if at end)
|
||||
|
|
@ -21,11 +21,11 @@ proc toVarNum(x: int32, b: var TBuffer) =
|
|||
# anyway
|
||||
a = abs(x)
|
||||
# first 6 bits:
|
||||
b[0] = toU8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63))
|
||||
b[0] = uint8(ord(a >% 63'i32) shl 7 or (ord(x < 0'i32) shl 6) or (int(a) and 63))
|
||||
a = (a shr 6'i32) and 0x03ffffff # skip first 6 bits
|
||||
var i = 1
|
||||
while a != 0'i32:
|
||||
b[i] = toU8(ord(a >% 127'i32) shl 7 or (int(a) and 127))
|
||||
b[i] = uint8(ord(a >% 127'i32) shl 7 or (int(a) and 127))
|
||||
inc(i)
|
||||
a = a shr 7'i32
|
||||
|
||||
|
|
@ -41,40 +41,40 @@ proc toVarNum64(x: int64, b: var TBuffer) =
|
|||
# anyway
|
||||
a = abs(x)
|
||||
# first 6 bits:
|
||||
b[0] = toU8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63))
|
||||
b[0] = uint8(ord(a >% 63'i64) shl 7 or (ord(x < 0'i64) shl 6) or int(a and 63))
|
||||
a = (a shr 6) and 0x03ffffffffffffff # skip first 6 bits
|
||||
var i = 1
|
||||
while a != 0'i64:
|
||||
b[i] = toU8(ord(a >% 127'i64) shl 7 or int(a and 127))
|
||||
b[i] = uint8(ord(a >% 127'i64) shl 7 or int(a and 127))
|
||||
inc(i)
|
||||
a = a shr 7
|
||||
|
||||
proc toNum64(b: TBuffer): int64 =
|
||||
# treat first byte different:
|
||||
result = ze64(b[0]) and 63
|
||||
result = int64(b[0]) and 63
|
||||
var
|
||||
i = 0
|
||||
Shift = 6'i64
|
||||
while (ze(b[i]) and 128) != 0:
|
||||
while (int(b[i]) and 128) != 0:
|
||||
inc(i)
|
||||
result = result or ((ze64(b[i]) and 127) shl Shift)
|
||||
result = result or ((int64(b[i]) and 127) shl Shift)
|
||||
inc(Shift, 7)
|
||||
if (ze(b[0]) and 64) != 0: # sign bit set?
|
||||
if (int(b[0]) and 64) != 0: # sign bit set?
|
||||
result = not result +% 1
|
||||
# this is the same as ``- result``
|
||||
# but gives no overflow error for low(int)
|
||||
|
||||
proc toNum(b: TBuffer): int32 =
|
||||
# treat first byte different:
|
||||
result = int32 ze(b[0]) and 63
|
||||
result = int32(b[0]) and 63
|
||||
var
|
||||
i = 0
|
||||
Shift = 6'i32
|
||||
while (ze(b[i]) and 128) != 0:
|
||||
while (int(b[i]) and 128) != 0:
|
||||
inc(i)
|
||||
result = result or ((int32(ze(b[i])) and 127'i32) shl Shift)
|
||||
result = result or ((int32(b[i]) and 127'i32) shl Shift)
|
||||
Shift = Shift + 7'i32
|
||||
if (ze(b[0]) and (1 shl 6)) != 0: # sign bit set?
|
||||
if (int(b[0]) and (1 shl 6)) != 0: # sign bit set?
|
||||
result = (not result) +% 1'i32
|
||||
# this is the same as ``- result``
|
||||
# but gives no overflow error for low(int)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue