refactor: merge comments and extracting constants & renaming refactors #36
@@ -3,8 +3,6 @@ package wacc
|
|||||||
import cats.data.Chain
|
import cats.data.Chain
|
||||||
import wacc.assemblyIR._
|
import wacc.assemblyIR._
|
||||||
|
|
||||||
val ERROR_CODE = 255
|
|
||||||
|
|
||||||
sealed trait RuntimeError {
|
sealed trait RuntimeError {
|
||||||
def strLabel: String
|
def strLabel: String
|
||||||
def errStr: String
|
def errStr: String
|
||||||
@@ -28,14 +26,11 @@ object RuntimeError {
|
|||||||
import assemblyIR.Size._
|
import assemblyIR.Size._
|
||||||
import assemblyIR.RegName._
|
import assemblyIR.RegName._
|
||||||
|
|
||||||
// private val RAX = Register(Q64, AX)
|
|
||||||
// private val EAX = Register(D32, AX)
|
|
||||||
private val RDI = Register(Q64, DI)
|
private val RDI = Register(Q64, DI)
|
||||||
private val RIP = Register(Q64, IP)
|
private val RIP = Register(Q64, IP)
|
||||||
// private val RBP = Register(Q64, BP)
|
|
||||||
private val RSI = Register(Q64, SI)
|
private val RSI = Register(Q64, SI)
|
||||||
// private val RDX = Register(Q64, DX)
|
|
||||||
private val RCX = Register(Q64, CX)
|
private val RCX = Register(Q64, CX)
|
||||||
|
private val ERROR_CODE = 255
|
||||||
|
|
||||||
case object ZeroDivError extends RuntimeError {
|
case object ZeroDivError extends RuntimeError {
|
||||||
val strLabel = ".L._errDivZero_str0"
|
val strLabel = ".L._errDivZero_str0"
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ object asmGenerator {
|
|||||||
private val ECX = Register(D32, CX)
|
private val ECX = Register(D32, CX)
|
||||||
private val argRegs = List(DI, SI, DX, CX, R8, R9)
|
private val argRegs = List(DI, SI, DX, CX, R8, R9)
|
||||||
|
|
||||||
|
private val _7_BIT_MASK = 0x7f
|
||||||
|
|
||||||
extension [T](chain: Chain[T])
|
extension [T](chain: Chain[T])
|
||||||
def +(item: T): Chain[T] = chain.append(item)
|
def +(item: T): Chain[T] = chain.append(item)
|
||||||
|
|
||||||
@@ -326,7 +328,7 @@ object asmGenerator {
|
|||||||
op match {
|
op match {
|
||||||
case UnaryOperator.Chr =>
|
case UnaryOperator.Chr =>
|
||||||
chain += Move(EAX, stack.head)
|
chain += Move(EAX, stack.head)
|
||||||
chain += And(EAX, ImmediateVal(-128))
|
chain += And(EAX, ImmediateVal(~_7_BIT_MASK))
|
||||||
chain += Compare(EAX, ImmediateVal(0))
|
chain += Compare(EAX, ImmediateVal(0))
|
||||||
chain += Jump(LabelArg(BadChrError.errLabel), Cond.NotEqual)
|
chain += Jump(LabelArg(BadChrError.errLabel), Cond.NotEqual)
|
||||||
case UnaryOperator.Ord => // No op needed
|
case UnaryOperator.Ord => // No op needed
|
||||||
|
|||||||
Reference in New Issue
Block a user