Reduced token size

This commit is contained in:
2024-07-21 14:35:06 +02:00
parent ca36d34cb9
commit 04ba68a075
47 changed files with 543 additions and 764 deletions

View File

@ -9,27 +9,27 @@ import (
// ExecuteRegisterNumber performs an operation on a register and a number.
func (f *Function) ExecuteRegisterNumber(operation token.Token, register cpu.Register, number int) error {
switch operation.Text() {
case "+", "+=":
switch operation.Kind {
case token.Add, token.AddAssign:
f.RegisterNumber(asm.ADD, register, number)
case "-", "-=":
case token.Sub, token.SubAssign:
f.RegisterNumber(asm.SUB, register, number)
case "*", "*=":
case token.Mul, token.MulAssign:
f.RegisterNumber(asm.MUL, register, number)
case "/", "/=":
case token.Div, token.DivAssign:
f.RegisterNumber(asm.DIV, register, number)
case "==", "!=", "<", "<=", ">", ">=":
case token.Equal, token.NotEqual, token.Less, token.LessEqual, token.Greater, token.GreaterEqual:
f.RegisterNumber(asm.COMPARE, register, number)
case "=":
case token.Assign:
f.RegisterNumber(asm.MOVE, register, number)
default:
return errors.New(&errors.InvalidOperator{Operator: operation.Text()}, f.File, operation.Position)
return errors.New(&errors.InvalidOperator{Operator: operation.Text(f.File.Bytes)}, f.File, operation.Position)
}
return nil