This commit is contained in:
Chuck Smith
2024-01-25 11:35:16 -05:00
parent fe78b7069b
commit ca263209a4
6 changed files with 179 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ type Opcode byte
const (
OpConstant Opcode = iota
OpAdd
)
type Definition struct {
@@ -21,6 +22,7 @@ type Definition struct {
var definitions = map[Opcode]*Definition{
OpConstant: {"OpConstant", []int{2}},
OpAdd: {"OpAdd", []int{}},
}
func Lookup(op byte) (*Definition, error) {
@@ -88,6 +90,8 @@ func (ins Instructions) fmtInstruction(def *Definition, operands []int) string {
}
switch operandCount {
case 0:
return def.Name
case 1:
return fmt.Sprintf("%s %d", def.Name, operands[0])
}