2023-03-31 11:52:04 +02:00
|
|
|
package vm
|
|
|
|
|
2023-03-31 20:24:30 +02:00
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
)
|
2023-03-31 11:52:04 +02:00
|
|
|
const VERSION = 0
|
|
|
|
|
2023-04-02 00:42:34 +02:00
|
|
|
// VM Opcodes
|
2023-03-31 11:52:04 +02:00
|
|
|
const (
|
2023-04-01 22:25:20 +02:00
|
|
|
BACK = 0
|
|
|
|
CATCH = 1
|
|
|
|
CROAK = 2
|
|
|
|
LOAD = 3
|
|
|
|
RELOAD = 4
|
|
|
|
MAP = 5
|
|
|
|
MOVE = 6
|
|
|
|
HALT = 7
|
2023-04-01 23:19:12 +02:00
|
|
|
INCMP = 8
|
|
|
|
_MAX = 8
|
2023-03-31 11:52:04 +02:00
|
|
|
)
|
2023-03-31 20:24:30 +02:00
|
|
|
|
2023-04-01 23:19:12 +02:00
|
|
|
// NewLine creates a new instruction line for the VM.
|
|
|
|
func NewLine(instructionList []byte, instruction uint16, strargs []string, byteargs []byte, numargs []uint8) []byte {
|
2023-03-31 20:24:30 +02:00
|
|
|
b := []byte{0x00, 0x00}
|
|
|
|
binary.BigEndian.PutUint16(b, instruction)
|
2023-04-01 23:19:12 +02:00
|
|
|
for _, arg := range strargs {
|
2023-03-31 20:24:30 +02:00
|
|
|
b = append(b, uint8(len(arg)))
|
|
|
|
b = append(b, []byte(arg)...)
|
|
|
|
}
|
2023-04-01 23:19:12 +02:00
|
|
|
if byteargs != nil {
|
|
|
|
b = append(b, uint8(len(byteargs)))
|
|
|
|
b = append(b, byteargs...)
|
2023-03-31 20:24:30 +02:00
|
|
|
}
|
2023-04-01 23:19:12 +02:00
|
|
|
if numargs != nil {
|
|
|
|
b = append(b, numargs...)
|
2023-03-31 20:24:30 +02:00
|
|
|
}
|
|
|
|
return append(instructionList, b...)
|
|
|
|
}
|