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 184 additions and 58 deletions
Showing only changes of commit cdf32d93c3 - Show all commits

View File

@@ -108,7 +108,7 @@ object RuntimeError {
def generateHandler: Chain[AsmLine] = Chain( def generateHandler: Chain[AsmLine] = Chain(
LabelDef(OutOfBoundsError.errLabel), LabelDef(OutOfBoundsError.errLabel),
Pop(RSI), Move(RSI, Register(Q64, CX)),
stackAlign, stackAlign,
Load(RDI, IndexAddress(RIP, LabelArg(OutOfBoundsError.strLabel))), Load(RDI, IndexAddress(RIP, LabelArg(OutOfBoundsError.strLabel))),
assemblyIR.Call(CLibFunc.PrintF), assemblyIR.Call(CLibFunc.PrintF),

View File

@@ -191,8 +191,10 @@ object asmGenerator {
case ArrayElem(x, i) => case ArrayElem(x, i) =>
chain ++= evalExprOntoStack(rhs) chain ++= evalExprOntoStack(rhs)
chain ++= evalExprOntoStack(i) chain ++= evalExprOntoStack(i)
chain += Compare(stack.head, ImmediateVal(0)) chain += stack.pop(RCX)
chain += Compare(ECX, ImmediateVal(0))
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less) chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
chain += stack.push(Q64, RCX)
chain ++= evalExprOntoStack(x) chain ++= evalExprOntoStack(x)
chain += stack.pop(RAX) chain += stack.pop(RAX)
chain += stack.pop(RCX) chain += stack.pop(RCX)