Swapped i and w in type

This commit is contained in:
Louis Burke 2023-12-19 00:48:15 -05:00
parent 13f9330eea
commit d234d5180d

View file

@ -10,8 +10,8 @@ type
ArcticType* {.union.} = object ArcticType* {.union.} = object
b: int8 b: int8
s: int16 s: int16
i: int32 w: int32
w: int64 # TODO: swap i and w to match instruction naming -.- i: int64
u: uint64 u: uint64
d: float64 d: float64
f: ArcticSymbol # also used for pointers f: ArcticSymbol # also used for pointers
@ -357,7 +357,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
# Memory Ops ----------------------------------------------------------- # Memory Ops -----------------------------------------------------------
of '1': # LDAB of '1': # LDAB
let p = state.stack.pop.f let p = state.stack.pop.f
state.stack.add ArcticType(w: state[p].int64) state.stack.add ArcticType(i: state[p].int64)
of '2': # LDAS of '2': # LDAS
let let
@ -365,9 +365,9 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
a = state[p].int64 a = state[p].int64
b = state[p+1].int64 b = state[p+1].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: a or b shl 8) state.stack.add ArcticType(i: a or b shl 8)
else: else:
state.stack.add ArcticType(w: b or a shl 8) state.stack.add ArcticType(i: b or a shl 8)
of '3': # LDAI of '3': # LDAI
let let
@ -377,9 +377,9 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
c = state[p+2].int64 c = state[p+2].int64
d = state[p+3].int64 d = state[p+3].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: d or c shl 8 or b shl 16 or a shl 24) state.stack.add ArcticType(i: d or c shl 8 or b shl 16 or a shl 24)
else: else:
state.stack.add ArcticType(w: a or b shl 8 or c shl 16 or d shl 24) state.stack.add ArcticType(i: a or b shl 8 or c shl 16 or d shl 24)
of '4': # LDAW of '4': # LDAW
let let
@ -393,14 +393,14 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
g = state[p+6].int64 g = state[p+6].int64
h = state[p+7].int64 h = state[p+7].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: h or g shl 8 or f shl 16 or e shl 24 or d shl 32 or c shl 40 or b shl 48 or a shl 56) state.stack.add ArcticType(i: h or g shl 8 or f shl 16 or e shl 24 or d shl 32 or c shl 40 or b shl 48 or a shl 56)
else: else:
state.stack.add ArcticType(w: a or b shl 8 or c shl 16 or d shl 24 or e shl 32 or f shl 40 or g shl 48 or h shl 56) state.stack.add ArcticType(i: a or b shl 8 or c shl 16 or d shl 24 or e shl 32 or f shl 40 or g shl 48 or h shl 56)
of 'o': # LDOB of 'o': # LDOB
assert op.immediate.kind == INTEGER assert op.immediate.kind == INTEGER
let p = state.stack.pop.f let p = state.stack.pop.f
state.stack.add ArcticType(w: state[p+op.immediate.i].int64) state.stack.add ArcticType(i: state[p+op.immediate.i].int64)
of 'H': # LDOS of 'H': # LDOS
assert op.immediate.kind == INTEGER assert op.immediate.kind == INTEGER
@ -409,9 +409,9 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
a = state[p].int64 a = state[p].int64
b = state[p+1].int64 b = state[p+1].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: a or b shl 8) state.stack.add ArcticType(i: a or b shl 8)
else: else:
state.stack.add ArcticType(w: b or a shl 8) state.stack.add ArcticType(i: b or a shl 8)
of 'G': # LDOI of 'G': # LDOI
let let
@ -421,9 +421,9 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
c = state[p+2].int64 c = state[p+2].int64
d = state[p+3].int64 d = state[p+3].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: d or c shl 8 or b shl 16 or a shl 24) state.stack.add ArcticType(i: d or c shl 8 or b shl 16 or a shl 24)
else: else:
state.stack.add ArcticType(w: a or b shl 8 or c shl 16 or d shl 24) state.stack.add ArcticType(i: a or b shl 8 or c shl 16 or d shl 24)
of 'Q': # LDOW of 'Q': # LDOW
let let
@ -437,9 +437,9 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
g = state[p+6].int64 g = state[p+6].int64
h = state[p+7].int64 h = state[p+7].int64
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state.stack.add ArcticType(w: h or g shl 8 or f shl 16 or e shl 24 or d shl 32 or c shl 40 or b shl 48 or a shl 56) state.stack.add ArcticType(i: h or g shl 8 or f shl 16 or e shl 24 or d shl 32 or c shl 40 or b shl 48 or a shl 56)
else: else:
state.stack.add ArcticType(w: a or b shl 8 or c shl 16 or d shl 24 or e shl 32 or f shl 40 or g shl 48 or h shl 56) state.stack.add ArcticType(i: a or b shl 8 or c shl 16 or d shl 24 or e shl 32 or f shl 40 or g shl 48 or h shl 56)
of '5': # STAB of '5': # STAB
let let
@ -475,7 +475,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of '8': # STAW of '8': # STAW
let let
x = cast[uint64](state.stack.pop.w) x = cast[uint64](state.stack.pop.i)
p = state.stack.pop.f p = state.stack.pop.f
if state.pc.section == "CODE": # bigendian if state.pc.section == "CODE": # bigendian
state[p] = uint8(x and 0xFF) state[p] = uint8(x and 0xFF)
@ -498,7 +498,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of 'D': # MCLR of 'D': # MCLR
let let
x = state.stack.pop.w x = state.stack.pop.i
p = state.stack.pop.f p = state.stack.pop.f
for i in 0 .. x: for i in 0 .. x:
state[p+i] = 0 state[p+i] = 0
@ -506,7 +506,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of 'd': # MSET of 'd': # MSET
assert op.immediate.kind == INTEGER assert op.immediate.kind == INTEGER
let let
x = state.stack.pop.w x = state.stack.pop.i
p = state.stack.pop.f p = state.stack.pop.f
b = op.immediate.i.uint8 b = op.immediate.i.uint8
for i in 0 .. x: for i in 0 .. x:
@ -514,7 +514,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of 'K': # MCPY of 'K': # MCPY
let let
x = state.stack.pop.w x = state.stack.pop.i
q = state.stack.pop.f q = state.stack.pop.f
p = state.stack.pop.f p = state.stack.pop.f
for i in 0 .. x: for i in 0 .. x:
@ -522,7 +522,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of 'J': # MOFF of 'J': # MOFF
let let
x = state.stack.pop.w x = state.stack.pop.i
p = state.stack.pop.f p = state.stack.pop.f
state.stack.add ArcticType(f: (section: p.section, index: p.index + 1)) state.stack.add ArcticType(f: (section: p.section, index: p.index + 1))
@ -533,11 +533,11 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
n = op.immediate.i n = op.immediate.i
if n == 0: if n == 0:
if top.w != 0: if top.i != 0:
state.sections.excl top.f.section state.sections.excl top.f.section
state.stack.add ArcticType(w: 0) state.stack.add ArcticType(i: 0)
elif n > 0: elif n > 0:
if top.w == 0: if top.i == 0:
state.sections.incl("allocated " & $next_malloc_id, ArcticSection(iscode: false, data: @[])) state.sections.incl("allocated " & $next_malloc_id, ArcticSection(iscode: false, data: @[]))
inc next_malloc_id inc next_malloc_id
else: else:
@ -552,11 +552,11 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
x = state.stack.pop.i x = state.stack.pop.i
if x == 0: if x == 0:
if top.w != 0: if top.i != 0:
state.sections.excl top.f.section state.sections.excl top.f.section
state.stack.add ArcticType(w: 0) state.stack.add ArcticType(i: 0)
elif x > 0: elif x > 0:
if top.w == 0: if top.i == 0:
state.sections.incl("allocated " & $next_malloc_id, ArcticSection(iscode: false, data: @[])) state.sections.incl("allocated " & $next_malloc_id, ArcticSection(iscode: false, data: @[]))
inc next_malloc_id inc next_malloc_id
else: else:
@ -570,8 +570,8 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
# implementation would probably require an "atomic" memory # implementation would probably require an "atomic" memory
# section # section
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
p = state.stack.pop.f p = state.stack.pop.f
a = state[p].int64 a = state[p].int64
b = state[p+1].int64 b = state[p+1].int64
@ -609,59 +609,59 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
state[p+6] = uint8((y shr 8) and 0xFF) state[p+6] = uint8((y shr 8) and 0xFF)
state[p+7] = uint8(y and 0xFF) state[p+7] = uint8(y and 0xFF)
else: else:
state.stack.add ArcticType(w: 0) state.stack.add ArcticType(i: 0)
# Math Ops ----------------------------------------------------------- # Math Ops -----------------------------------------------------------
of '+': # IADD of '+': # IADD
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x + y) state.stack.add ArcticType(i: x + y)
of '-': # ISUB of '-': # ISUB
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x - y) state.stack.add ArcticType(i: x - y)
of '*': # IMUL of '*': # IMUL
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x * y) state.stack.add ArcticType(i: x * y)
of '/': # IDIV of '/': # IDIV
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: int(x / y)) state.stack.add ArcticType(i: int(x / y))
of '%': # IMOD of '%': # IMOD
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x.floorMod(y)) state.stack.add ArcticType(i: x.floorMod(y))
of '\\': # IREM of '\\': # IREM
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x mod y) state.stack.add ArcticType(i: x mod y)
of '_': # INEG of '_': # INEG
let x = state.stack.pop.w let x = state.stack.pop.i
state.stack.add ArcticType(w: -x) state.stack.add ArcticType(i: -x)
of '|': # IABS of '|': # IABS
let x = state.stack.pop.w let x = state.stack.pop.i
state.stack.add ArcticType(w: x.abs) state.stack.add ArcticType(i: x.abs)
of 's': # FADD of 's': # FADD
let let
@ -719,53 +719,53 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of 'V': # BIOR of 'V': # BIOR
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x or y) state.stack.add ArcticType(i: x or y)
of '&': # BAND of '&': # BAND
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x and y) state.stack.add ArcticType(i: x and y)
of '^': # BXOR of '^': # BXOR
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x xor y) state.stack.add ArcticType(i: x xor y)
of 'l': # BITC of 'l': # BITC
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
state.stack.add ArcticType(w: x and (not y)) state.stack.add ArcticType(i: x and (not y))
of '!': # BNOT of '!': # BNOT
let x = state.stack.pop.w let x = state.stack.pop.i
state.stack.add ArcticType(w: not x) state.stack.add ArcticType(i: not x)
of 'u': # USHR of 'u': # USHR
let x = state.stack.pop.w let x = state.stack.pop.i
var i: int64 var i: int64
case op.immediate.kind: case op.immediate.kind:
of INTEGER: of INTEGER:
i = op.immediate.i i = op.immediate.i
of VARIABLE: of VARIABLE:
let v = op.immediate.v let v = op.immediate.v
i = state.registers[v].w i = state.registers[v].i
else: else:
assert false assert false
if i > 0: if i > 0:
state.stack.add ArcticType(w: x shr i) state.stack.add ArcticType(i: x shr i)
else: else:
state.stack.add ArcticType(w: x shl (-i)) state.stack.add ArcticType(i: x shl (-i))
of '[': # ROTR of '[': # ROTR
let x = state.stack.pop.u let x = state.stack.pop.u
@ -775,7 +775,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
i = op.immediate.i i = op.immediate.i
of VARIABLE: of VARIABLE:
let v = op.immediate.v let v = op.immediate.v
i = state.registers[v].w i = state.registers[v].i
else: else:
assert false assert false
@ -792,7 +792,7 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
i = op.immediate.i i = op.immediate.i
of VARIABLE: of VARIABLE:
let v = op.immediate.v let v = op.immediate.v
i = state.registers[v].w i = state.registers[v].i
else: else:
assert false assert false
@ -803,14 +803,14 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
of '?': # CMPI of '?': # CMPI
let let
y = state.stack.pop.w y = state.stack.pop.i
x = state.stack.pop.w x = state.stack.pop.i
if x > y: if x > y:
state.stack.add ArcticType(w: 1) state.stack.add ArcticType(i: 1)
elif y > x: elif y > x:
state.stack.add ArcticType(w: -1) state.stack.add ArcticType(i: -1)
else: else:
state.stack.add ArcticType(w: 0) state.stack.add ArcticType(i: 0)
of '~': # CMPF of '~': # CMPF
assert op.immediate.kind == INTEGER assert op.immediate.kind == INTEGER
@ -829,11 +829,11 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
y = state.stack.pop.u y = state.stack.pop.u
x = state.stack.pop.u x = state.stack.pop.u
if x > y: if x > y:
state.stack.add ArcticType(w: 1) state.stack.add ArcticType(i: 1)
elif y > x: elif y > x:
state.stack.add ArcticType(w: -1) state.stack.add ArcticType(i: -1)
else: else:
state.stack.add ArcticType(w: 0) state.stack.add ArcticType(i: 0)
of 'F': # BMIS of 'F': # BMIS
discard # TODO: define BMIS discard # TODO: define BMIS
@ -841,22 +841,22 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
# Type Conversion Ops -------------------------------------------------- # Type Conversion Ops --------------------------------------------------
of 'E': # FTOI of 'E': # FTOI
let a = state.stack.pop.d let a = state.stack.pop.d
state.stack.add ArcticType(w: a.int64) state.stack.add ArcticType(i: a.int64)
of 'O': # ITOC of 'O': # ITOC
let x = state.stack.pop.b let x = state.stack.pop.b
state.stack.add ArcticType(w: x.int64) state.stack.add ArcticType(i: x.int64)
of 'S': # ITOS of 'S': # ITOS
let x = state.stack.pop.s let x = state.stack.pop.s
state.stack.add ArcticType(w: x.int64) state.stack.add ArcticType(i: x.int64)
of 'W': # ITOW of 'W': # ITOW
let x = state.stack.pop.i let x = state.stack.pop.i
state.stack.add ArcticType(w: x.int64) state.stack.add ArcticType(i: x.int64)
of '.': # ITOF of '.': # ITOF
let x = state.stack.pop.w let x = state.stack.pop.i
state.stack.add ArcticType(d: x.float64) state.stack.add ArcticType(d: x.float64)
# Stack Ops ------------------------------------------------------------ # Stack Ops ------------------------------------------------------------
@ -910,11 +910,11 @@ proc step*(state: var ArcticState, builtins: CritBitTree[ArcticBuiltin]): Arctic
state.stack.insert(x, idx) state.stack.insert(x, idx)
of '(': # DPTH of '(': # DPTH
state.stack.add ArcticType(w: state.stack.len) state.stack.add ArcticType(i: state.stack.len)
of ')': # PACK of ')': # PACK
let let
x = state.stack.pop.w x = state.stack.pop.i
p = state.stack.pop.f p = state.stack.pop.f
# TODO: Can't implement this until we have unified addresses # TODO: Can't implement this until we have unified addresses
# Once we have the addresses, can pack x items of stack at p+... # Once we have the addresses, can pack x items of stack at p+...