fix: implements null pointer checks

This commit is contained in:
Jonny
2025-02-27 23:57:42 +00:00
parent 1b2df507ba
commit edcac2782b
3 changed files with 6 additions and 2 deletions

View File

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

View File

@@ -196,6 +196,8 @@ object asmGenerator {
chain ++= evalExprOntoStack(x)
chain += stack.pop(RAX)
chain += stack.pop(RCX)
chain += Compare(EAX, ImmediateVal(0))
chain += Jump(LabelArg(NullPtrError.errLabel), Cond.Equal)
chain += Compare(MemLocation(RAX, D32), ECX)
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.LessEqual)
chain += stack.pop(RDX)
@@ -302,6 +304,8 @@ object asmGenerator {
chain += Compare(RCX, ImmediateVal(0))
chain += Jump(LabelArg(OutOfBoundsError.errLabel), Cond.Less)
chain += stack.pop(RAX)
chain += Compare(EAX, ImmediateVal(0))
chain += Jump(LabelArg(NullPtrError.errLabel), Cond.Equal)
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

View File

@@ -107,7 +107,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll {
// "^.*wacc-examples/valid/IO/IOLoop.wacc.*$",
// "^.*wacc-examples/valid/IO/IOSequence.wacc.*$",
// "^.*wacc-examples/valid/pairs.*$",
"^.*wacc-examples/valid/runtimeErr.*$",
//"^.*wacc-examples/valid/runtimeErr.*$",
// "^.*wacc-examples/valid/scope.*$",
// "^.*wacc-examples/valid/sequence.*$",
// "^.*wacc-examples/valid/variables.*$",