You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/hal/instructions.go

72 lines
1.3 KiB

package hal
import (
"fmt"
"strings"
)
type ProgrammedInstruction struct {
Instruction *Instruction
Operand int64
}
func (pi *ProgrammedInstruction) Execute(module *Module) error {
if pi.Instruction.ExecuteWithOperand != nil {
pi.Instruction.ExecuteWithOperand(module, pi.Operand)
} else if pi.Instruction.Execute != nil {
pi.Instruction.Execute(module)
} else {
return fmt.Errorf("instruction is not implemented")
}
return nil
}
type Instruction struct {
Name string
ExecuteWithOperand func(module *Module, operand int64)
Execute func(module *Module)
}
func FindInstructionByName(name string) *Instruction {
for _, instruction := range instructions {
if instruction.Name == strings.ToUpper(name) {
return instruction
}
}
return nil
}
var instructions = []*Instruction{
InstructionStart,
InstructionStop,
InstructionIn,
InstructionOut,
}
var InstructionStart = &Instruction{
Name: "START",
Execute: func(module *Module) {
// TODO implement
},
}
var InstructionStop = &Instruction{
Name: "STOP",
Execute: func(module *Module) {
// TODO implement
},
}
var InstructionOut = &Instruction{
Name: "OUT",
Execute: func(module *Module) {
// TODO implement
},
}
var InstructionIn = &Instruction{
Name: "IN",
Execute: func(module *Module) {
// TODO implement
},
}