functions with bindings
Some checks failed
Build / build (push) Failing after 1m42s
Test / build (push) Successful in 2m27s

This commit is contained in:
Chuck Smith
2024-03-08 14:19:20 -05:00
parent 9d06c90e41
commit ec9a586f7f
10 changed files with 350 additions and 30 deletions

View File

@@ -35,6 +35,8 @@ const (
OpCall
OpReturnValue
OpReturn
OpGetLocal
OpSetLocal
)
type Definition struct {
@@ -67,6 +69,8 @@ var definitions = map[Opcode]*Definition{
OpCall: {"OpCall", []int{}},
OpReturnValue: {"OpReturnValue", []int{}},
OpReturn: {"OpReturn", []int{}},
OpGetLocal: {"OpGetLocal", []int{1}},
OpSetLocal: {"OpSetLocal", []int{1}},
}
func Lookup(op byte) (*Definition, error) {
@@ -98,6 +102,8 @@ func Make(op Opcode, operands ...int) []byte {
switch width {
case 2:
binary.BigEndian.PutUint16(instruction[offset:], uint16(o))
case 1:
instruction[offset] = byte(o)
}
offset += width
}
@@ -151,6 +157,9 @@ func ReadOperands(def *Definition, ins Instructions) ([]int, int) {
switch width {
case 2:
operands[i] = int(ReadUint16(ins[offset:]))
case 1:
operands[i] = int(ReadUint8(ins[offset:]))
}
offset += width
@@ -162,3 +171,7 @@ func ReadOperands(def *Definition, ins Instructions) ([]int, int) {
func ReadUint16(ins Instructions) uint16 {
return binary.BigEndian.Uint16(ins)
}
func ReadUint8(ins Instructions) uint8 {
return ins[0]
}