fix: implements null pointer checks
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user