|
|
@@ -49,6 +49,8 @@ func (ins Instructions) fmtInstructions(def *Definition, operands []int) string
|
|
|
}
|
|
|
|
|
|
switch operandCount {
|
|
|
+ case 0:
|
|
|
+ return def.Name
|
|
|
case 1:
|
|
|
return fmt.Sprintf("%s %d", def.Name, operands[0])
|
|
|
}
|
|
|
@@ -60,6 +62,7 @@ type Opcode byte
|
|
|
|
|
|
const (
|
|
|
OpConstant Opcode = iota
|
|
|
+ OpAdd
|
|
|
)
|
|
|
|
|
|
// Definition For debugging and testing purposes
|
|
|
@@ -75,7 +78,8 @@ type Definition struct {
|
|
|
}
|
|
|
|
|
|
var definitions = map[Opcode]*Definition{
|
|
|
- OpConstant: {Name: "OpConstant", OperandWidths: []int{2}},
|
|
|
+ OpConstant: {"OpConstant", []int{2}},
|
|
|
+ OpAdd: {"OpAdd", []int{}}, // doesn't have any operands
|
|
|
}
|
|
|
|
|
|
func Lookup(op byte) (*Definition, error) {
|