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

@@ -100,5 +100,23 @@ object RuntimeError {
}
val all: Chain[RuntimeError] = Chain(ZeroDivError, BadChrError, NullPtrError, OverflowError)
case object OutOfBoundsError extends RuntimeError {
val strLabel = ".L._errOutOfBounds_str0"
val errStr = "fatal error: array index %d out of bounds"
val errLabel = ".L._errOutOfBounds"
def generateHandler: Chain[AsmLine] = Chain(
LabelDef(OutOfBoundsError.errLabel),
Pop(RSI), // le index
stackAlign,
Load(RDI, IndexAddress(RIP, LabelArg(OutOfBoundsError.strLabel))),
assemblyIR.Call(CLibFunc.PrintF),
Move(RDI, ImmediateVal(255)),
assemblyIR.Call(CLibFunc.Exit)
)
}
val all: Chain[RuntimeError] =
Chain(ZeroDivError, BadChrError, NullPtrError, OverflowError, OutOfBoundsError)
}