refactor: merge comments and extracting constants & renaming refactors #36

Merged
gk1623 merged 9 commits from comments-and-refactors into master 2025-02-28 15:32:47 +00:00
4 changed files with 133 additions and 122 deletions
Showing only changes of commit b733d233b0 - Show all commits

View File

@@ -117,6 +117,22 @@ object RuntimeError {
) )
} }
val all: Chain[RuntimeError] = case object OutOfMemoryError extends RuntimeError {
Chain(ZeroDivError, BadChrError, NullPtrError, OverflowError, OutOfBoundsError) val strLabel = ".L._errOutOfMemory_str0"
val errStr = "fatal error: out of memory"
val errLabel = ".L._errOutOfMemory"
def generateHandler: Chain[AsmLine] = Chain(
LabelDef(OutOfMemoryError.errLabel),
stackAlign,
Load(RDI, IndexAddress(RIP, LabelArg(OutOfMemoryError.strLabel))),
assemblyIR.Call(CLibFunc.PrintF),
Move(RDI, ImmediateVal(255)),
assemblyIR.Call(CLibFunc.Exit)
)
}
val all: Chain[RuntimeError] =
Chain(ZeroDivError, BadChrError, NullPtrError, OverflowError, OutOfBoundsError,
OutOfMemoryError)
} }

View File

@@ -141,8 +141,13 @@ object asmGenerator {
chain ++= wrapBuiltinFunc( chain ++= wrapBuiltinFunc(
labelGenerator.getLabel(Builtin.Malloc), labelGenerator.getLabel(Builtin.Malloc),
Chain(stackAlign, assemblyIR.Call(CLibFunc.Malloc)) Chain(
// Out of memory check is optional stackAlign,
assemblyIR.Call(CLibFunc.Malloc),
// Out of memory check
Compare(RAX, ImmediateVal(0)),
Jump(LabelArg(OutOfMemoryError.errLabel), Cond.Equal)
)
) )
chain ++= wrapBuiltinFunc( chain ++= wrapBuiltinFunc(