feat: implement all runtime errors #32

Merged
jt2622 merged 16 commits from runtime-errors into master 2025-02-28 00:23:13 +00:00
5 changed files with 177 additions and 57 deletions
Showing only changes of commit 1b2df507ba - Show all commits

View File

@@ -22,6 +22,7 @@ object asmGenerator {
private val RSI = Register(Q64, SI)
private val RDX = Register(Q64, DX)
private val RCX = Register(Q64, CX)
private val ECX = Register(D32, CX)
private val argRegs = List(DI, SI, DX, CX, R8, R9)
extension [T](chain: Chain[T])
@@ -195,8 +196,8 @@ object asmGenerator {
chain ++= evalExprOntoStack(x)
chain += stack.pop(RAX)
chain += stack.pop(RCX)
// chain += Compare(RAX, RCX)
// chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.GreaterEqual)
chain += Compare(MemLocation(RAX, D32), ECX)
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual)
chain += stack.pop(RDX)
chain += Move(
@@ -301,6 +302,8 @@ object asmGenerator {
chain += Compare(RCX, ImmediateVal(0))
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
chain += stack.pop(RAX)
chain += Compare(MemLocation(RAX, D32), ECX)
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual)
// + Int because we store the length of the array at the start
chain += Move(
Register(x.ty.elemSize, AX),