op

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 0 Imported by: 7

Documentation

Overview

Package op defines opcodes used by the Risor compiler and virtual machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinaryOpType

type BinaryOpType uint16

BinaryOpType describes a type of binary operation, as in an operation that takes two operands. For example, addition, subtraction, multiplication, etc.

const (
	Add        BinaryOpType = 1
	Subtract   BinaryOpType = 2
	Multiply   BinaryOpType = 3
	Divide     BinaryOpType = 4
	Modulo     BinaryOpType = 5
	And        BinaryOpType = 6
	Or         BinaryOpType = 7
	Xor        BinaryOpType = 8
	Power      BinaryOpType = 9
	LShift     BinaryOpType = 10
	RShift     BinaryOpType = 11
	BitwiseAnd BinaryOpType = 12
	BitwiseOr  BinaryOpType = 13
)

func (BinaryOpType) String added in v1.5.0

func (bop BinaryOpType) String() string

String returns a string representation of the binary operation. For example "+" for addition.

type Code

type Code uint16

Code is an integer opcode that indicates an operation to execute.

const (
	Invalid Code = 0

	// Execution
	Nop         Code = 1
	Halt        Code = 2
	Call        Code = 3
	ReturnValue Code = 4
	Defer       Code = 5
	Go          Code = 6

	// Jump
	JumpBackward          Code = 10
	JumpForward           Code = 11
	PopJumpForwardIfFalse Code = 12
	PopJumpForwardIfTrue  Code = 13

	// Load
	LoadAttr   Code = 20
	LoadFast   Code = 21
	LoadFree   Code = 22
	LoadGlobal Code = 23
	LoadConst  Code = 24

	// Store
	StoreAttr   Code = 30
	StoreFast   Code = 31
	StoreFree   Code = 32
	StoreGlobal Code = 33

	// Operations
	BinaryOp      Code = 40
	CompareOp     Code = 41
	UnaryNegative Code = 42
	UnaryNot      Code = 43

	// Build
	BuildList   Code = 50
	BuildMap    Code = 51
	BuildSet    Code = 52
	BuildString Code = 53

	// Containers
	BinarySubscr Code = 60
	StoreSubscr  Code = 61
	ContainsOp   Code = 62
	Length       Code = 63
	Slice        Code = 64
	Unpack       Code = 65

	// Stack
	Swap   Code = 70
	Copy   Code = 71
	PopTop Code = 72

	// Push constants
	Nil   Code = 80
	False Code = 81
	True  Code = 82

	// Iteration
	ForIter Code = 90
	GetIter Code = 91
	Range   Code = 92

	// Import
	FromImport Code = 100
	Import     Code = 101

	// Channels
	Receive Code = 110
	Send    Code = 111

	// Closures
	LoadClosure Code = 120
	MakeCell    Code = 121

	// Partials
	Partial Code = 130
)

type CompareOpType

type CompareOpType uint16

CompareOpType describes a type of comparison operation. For example, less than, greater than, equal, etc.

const (
	LessThan           CompareOpType = 1
	LessThanOrEqual    CompareOpType = 2
	Equal              CompareOpType = 3
	NotEqual           CompareOpType = 4
	GreaterThan        CompareOpType = 5
	GreaterThanOrEqual CompareOpType = 6
)

func (CompareOpType) String added in v1.5.0

func (cop CompareOpType) String() string

String returns a string representation of the comparison operation. For example "<" for less than.

type Info

type Info struct {
	Code         Code
	Name         string
	OperandCount int
}

Info contains information about an opcode.

func GetInfo

func GetInfo(op Code) Info

GetInfo returns information about the given opcode.

Jump to

Keyboard shortcuts

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