package core import ( "git.akyoto.dev/cli/q/src/build/asm" "git.akyoto.dev/cli/q/src/build/cpu" "git.akyoto.dev/cli/q/src/build/errors" "git.akyoto.dev/cli/q/src/build/token" ) // 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.Kind { case token.Add, token.AddAssign: f.RegisterNumber(asm.ADD, register, number) case token.Sub, token.SubAssign: f.RegisterNumber(asm.SUB, register, number) case token.Mul, token.MulAssign: f.RegisterNumber(asm.MUL, register, number) case token.Div, token.DivAssign: f.RegisterNumber(asm.DIV, register, number) case token.Mod, token.ModAssign: f.RegisterNumber(asm.MODULO, register, number) case token.Equal, token.NotEqual, token.Less, token.LessEqual, token.Greater, token.GreaterEqual: f.RegisterNumber(asm.COMPARE, register, number) case token.Assign: f.RegisterNumber(asm.MOVE, register, number) default: return errors.New(&errors.InvalidOperator{Operator: operation.Text(f.File.Bytes)}, f.File, operation.Position) } return nil }