opcode

package
v0.0.0-...-95ae90b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmpEq byte = iota
	CmpNotEq
	CmpLT
	CmpGT
	CmpLTEq
	CmpGTEq
	MaxCmpCodes
)

Variables

View Source
var CmpOps = map[byte]string{
	CmpEq:    "==",
	CmpNotEq: "!=",
	CmpLT:    "<",
	CmpGT:    ">",
	CmpLTEq:  "<=",
	CmpGTEq:  ">=",
}
View Source
var HasFourByteArg = map[Opcode]bool{
	StartLoop: true,
}

2 16-bit arguments

View Source
var HasOneByteArg = map[Opcode]bool{
	Compare: true,
}

1 8-bit argument

1 16-bit argument

View Source
var Names = map[Opcode]string{
	Noop:             "NOOP",
	LoadConst:        "LOAD_CONST",
	StoreConst:       "STORE_CONST",
	LoadFast:         "LOAD_FAST",
	StoreFast:        "STORE_FAST",
	DeleteFast:       "DELETE_FAST",
	Define:           "DEFINE",
	LoadGlobal:       "LOAD_GLOBAL",
	StoreGlobal:      "STORE_GLOBAL",
	LoadIndex:        "LOAD_INDEX",
	StoreIndex:       "STORE_INDEX",
	LoadAttribute:    "LOAD_ATTRIBUTE",
	StoreAttribute:   "STORE_ATTRIBUTE",
	BinaryAdd:        "BINARY_ADD",
	BinarySub:        "BINARY_SUB",
	BinaryMul:        "BINARY_MUL",
	BinaryDivide:     "BINARY_DIVIDE",
	BinaryMod:        "BINARY_MOD",
	BinaryShiftL:     "BINARY_SHIFTL",
	BinaryShiftR:     "BINARY_SHIFTR",
	BinaryAnd:        "BINARY_AND",
	BinaryOr:         "BINARY_OR",
	BinaryNot:        "BINARY_NOT",
	BinaryAndNot:     "BINARY_ANDNOT",
	Implements:       "IMPLEMENTS",
	UnaryNeg:         "UNARY_NEG",
	UnaryNot:         "UNARY_NOT",
	Compare:          "COMPARE",
	Call:             "CALL",
	Return:           "RETURN",
	Pop:              "POP",
	MakeArray:        "MAKE_ARRAY",
	MakeMap:          "MAKE_MAP",
	MakeFunction:     "MAKE_FUNCTION",
	PopJumpIfTrue:    "POP_JUMP_IF_TRUE",
	PopJumpIfFalse:   "POP_JUMP_IF_FALSE",
	JumpIfTrueOrPop:  "JUMP_IF_TRUE_OR_POP",
	JumpIfFalseOrPop: "JUMP_IF_FALSE_OR_POP",
	JumpAbsolute:     "JUMP_ABSOLUTE",
	JumpForward:      "JUMP_FORWARD",
	EndBlock:         "END_BLOCK",
	StartLoop:        "START_LOOP",
	Continue:         "CONTINUE",
	NextIter:         "NEXT_ITER",
	Break:            "BREAK",
	StartTry:         "START_TRY",
	Throw:            "THROW",
	BuildClass:       "BUILD_CLASS",
	MakeInstance:     "MAKE_INSTANCE",
	OpenScope:        "OPEN_SCOPE",
	CloseScope:       "CLOSE_SCOPE",
	Import:           "IMPORT",
	Dup:              "DUP",
	GetIter:          "GET_ITER",
}

Functions

This section is empty.

Types

type Opcode

type Opcode byte
const (
	Noop Opcode = iota
	LoadConst
	StoreConst
	LoadFast
	StoreFast
	DeleteFast
	Define
	LoadGlobal
	StoreGlobal
	LoadIndex
	StoreIndex
	LoadAttribute
	StoreAttribute
	BinaryAdd
	BinarySub
	BinaryMul
	BinaryDivide
	BinaryMod
	BinaryShiftL
	BinaryShiftR
	BinaryAnd
	BinaryOr
	BinaryNot
	BinaryAndNot
	UnaryNeg
	UnaryNot
	Implements
	Compare
	Call
	Return
	Pop
	MakeArray
	MakeMap
	MakeFunction
	PopJumpIfTrue
	PopJumpIfFalse
	JumpIfTrueOrPop
	JumpIfFalseOrPop
	JumpAbsolute
	JumpForward
	EndBlock
	StartLoop
	Continue
	NextIter
	Break
	StartTry
	Throw
	BuildClass
	MakeInstance
	OpenScope
	CloseScope
	Import
	Dup
	GetIter

	MaxOpcode // Not a real opcode, just used to denote the maximum value of a valid opcode
	Label
)

When adding a new opcode, make sure to check and make any needed changes to the following places:

- Add the opcode to the appropiate arg count map below. - Add a string representation of the opcode below. - If the opcode changes the stack in any way, edit the calculateStackSize function in the compiler. - If the opcode changes the block stack in any way, edit the calculateBlockSize function in the compiler. - If the opcode takes any arguments, edit the compiler.CodeBlock.Print() method to print the correct output. - And obviously, implement it in the virtual machine.

func (Opcode) String

func (o Opcode) String() string

func (Opcode) ToByte

func (o Opcode) ToByte() byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL