feat: implements outofbounds error. array negative bounds check added

This commit is contained in:
Jonny
2025-02-27 23:02:10 +00:00
parent 4727d6c399
commit 3a2af6f95d
2 changed files with 25 additions and 1 deletions

View File

@@ -190,9 +190,13 @@ object asmGenerator {
case ArrayElem(x, i) =>
chain ++= evalExprOntoStack(rhs)
chain ++= evalExprOntoStack(i)
chain += Compare(stack.head, ImmediateVal(0))
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
chain ++= evalExprOntoStack(x)
chain += stack.pop(RAX)
chain += stack.pop(RCX)
// chain += Compare(RAX, RCX)
// chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.GreaterEqual)
chain += stack.pop(RDX)
chain += Move(
@@ -294,6 +298,8 @@ object asmGenerator {
chain ++= evalExprOntoStack(x)
chain ++= evalExprOntoStack(i)
chain += stack.pop(RCX)
chain += Compare(RCX, ImmediateVal(0))
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
chain += stack.pop(RAX)
// + Int because we store the length of the array at the start
chain += Move(