isa

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrBadInstruction is raised when a call to isa.New can't succeed due to
	// either missing or excessive operands
	ErrBadInstruction = "instruction operand mismatch: %s"

	// ErrExpectedOperand is raised when an Operand isn't represented by an
	// unsigned Word that will fit within the number of Operand bits
	ErrExpectedOperand = "expected unsigned operand: %d"
)
View Source
const (
	// OpcodeSize are the number of bits required for an Opcode value
	OpcodeSize = 6

	// OpcodeMask masks the bits for encoding an Opcode into an Instruction
	OpcodeMask = opcodeMask

	// OperandMask masks the bits for encoding an Operand into an Instruction
	OperandMask = ^Operand(OpcodeMask) >> OpcodeSize
)
View Source
const ErrEffectNotDeclared = "effect not declared for opcode: %s"

ErrEffectNotDeclared is raised when an attempt to forcefully retrieve an Effect fails

Variables

View Source
var Effects = map[Opcode]*Effect{
	Add:      {Pop: 2, Push: 1},
	Arg:      {Push: 1, Operand: Arguments},
	ArgLen:   {Push: 1},
	Bind:     {Pop: 2},
	BindRef:  {Pop: 2},
	Call:     {Pop: 1, Push: 1, DPop: true, Operand: Stack},
	Call0:    {Pop: 1, Push: 1},
	Call1:    {Pop: 2, Push: 1},
	CallWith: {Pop: 2, Push: 1},
	Car:      {Pop: 1, Push: 1},
	Cdr:      {Pop: 1, Push: 1},
	Closure:  {Push: 1, Operand: Values},
	CondJump: {Pop: 1, Operand: Labels},
	Cons:     {Pop: 2, Push: 1},
	Const:    {Push: 1, Operand: Constants},
	Declare:  {Pop: 1},
	Deref:    {Pop: 1, Push: 1},
	Div:      {Pop: 2, Push: 1},
	Dup:      {Pop: 1, Push: 2},
	Empty:    {Pop: 1, Push: 1},
	Eq:       {Pop: 2, Push: 1},
	False:    {Push: 1},
	Jump:     {Operand: Labels},
	Label:    {Ignore: true, Operand: Labels},
	Load:     {Push: 1, Operand: Locals},
	Mod:      {Pop: 2, Push: 1},
	Mul:      {Pop: 2, Push: 1},
	Neg:      {Pop: 1, Push: 1},
	NegInt:   {Push: 1, Operand: Integer},
	NewRef:   {Push: 1},
	Null:     {Push: 1},
	NoOp:     {Ignore: true},
	Not:      {Pop: 1, Push: 1},
	NumEq:    {Pop: 2, Push: 1},
	NumGt:    {Pop: 2, Push: 1},
	NumGte:   {Pop: 2, Push: 1},
	NumLt:    {Pop: 2, Push: 1},
	NumLte:   {Pop: 2, Push: 1},
	Panic:    {Pop: 1, Exit: true},
	Pop:      {Pop: 1},
	PopArgs:  {},
	PosInt:   {Push: 1, Operand: Integer},
	Private:  {Pop: 1},
	PushArgs: {DPop: true, Operand: Arguments},
	Resolve:  {Pop: 1, Push: 1},
	RestArg:  {Push: 1, Operand: Arguments},
	RetFalse: {Exit: true},
	RetNull:  {Exit: true},
	RetTrue:  {Exit: true},
	Return:   {Pop: 1, Exit: true},
	Store:    {Pop: 1, Operand: Locals},
	Sub:      {Pop: 2, Push: 1},
	TailCall: {Pop: 1, DPop: true, Operand: Stack},
	True:     {Push: 1},
	Vector:   {Push: 1, DPop: true, Operand: Stack},
	Zero:     {Push: 1},
}

Effects is a lookup table of instruction effects

Functions

func IsValidOperand

func IsValidOperand(i int) bool

IsValidOperand returns true if the int falls within the operand range

Types

type ActOn

type ActOn int
const (
	Nothing ActOn = iota
	Arguments
	Constants
	Integer
	Labels
	Locals
	Stack
	Values
)

type Effect

type Effect struct {
	Operand ActOn // Describe elements the operands act on

	Pop  int // A fixed number of items to be popped from the stack
	Push int // A fixed number of items to be pushed onto the stack

	DPop   bool // Dynamic number of items to be popped (in operand)
	Ignore bool // Skip this instruction (ex: Labels and NoOps)
	Exit   bool // Results in a termination of the abstract machine
}

Effect captures how an Instruction impacts the state of the machine

func MustGetEffect

func MustGetEffect(oc Opcode) *Effect

MustGetEffect gives you effect information or explodes violently

type Instruction

type Instruction Word

Instruction represents a single instruction and its operand

func New

func New(oc Opcode, args ...Operand) Instruction

New creates a new Instruction instance

func (Instruction) Equal

func (i Instruction) Equal(other data.Value) bool

Equal compares this Instruction to another for equality

func (Instruction) Opcode

func (i Instruction) Opcode() Opcode

func (Instruction) Operand

func (i Instruction) Operand() Operand

func (Instruction) Split

func (i Instruction) Split() (Opcode, Operand)

func (Instruction) StackChange

func (i Instruction) StackChange() int

func (Instruction) String

func (i Instruction) String() string

type Instructions

type Instructions []Instruction

Instructions represent a set of Instructions

func (Instructions) String

func (i Instructions) String() string

type Opcode

type Opcode Word

Opcode represents an Instruction's operation

const (
	Add      Opcode = iota // Addition
	Arg                    // Retrieve Argument Value
	ArgLen                 // Retrieve Argument Count
	Bind                   // Bind Global
	BindRef                // Bind Reference
	Call                   // Call Procedure
	Call0                  // Zero-Arg Call
	Call1                  // One-Arg Call
	CallWith               // Call with the provided Sequence as Arguments
	Car                    // Contents of the Address part of the Register
	Cdr                    // Contents of the Decrement part of the Register
	Closure                // Retrieve Closure Value
	CondJump               // Conditional Jump
	Cons                   // Form a new Cons Cell (or Prepend)
	Const                  // Retrieve Constant
	Declare                // Declare a public Namespace entry
	Deref                  // Pointer Dereference
	Div                    // Division
	Dup                    // Duplicate Value
	Empty                  // Tests Empty Sequence
	Eq                     // Value Equality
	False                  // Push False
	Jump                   // Absolute Jump
	Label                  // Internal Label
	Load                   // Retrieve Local Value
	Mod                    // Remainder
	Mul                    // Multiplication
	Neg                    // Negation
	NegInt                 // Push Negative Integer (in Operand)
	NewRef                 // New Reference
	NoOp                   // Error-Operator
	Not                    // Boolean Negation
	Null                   // Push Null
	NumEq                  // Numeric Equality
	NumGt                  // Greater Than
	NumGte                 // Greater or Equal To
	NumLt                  // Less Than Comparison
	NumLte                 // Less or Equal To
	Panic                  // Abnormally Halt
	Pop                    // Discard Value
	PopArgs                // Pop Arguments
	PosInt                 // Push Positive Integer (in Operand)
	Private                // Declare a private Namespace entry
	PushArgs               // Push Arguments
	Resolve                // Resolve Global Symbol
	RestArg                // Retrieve Arguments Tail
	RetFalse               // Return False
	RetNull                // Return Null (Empty List)
	RetTrue                // Return True
	Return                 // Return Value
	Store                  // Store Local
	Sub                    // Subtraction
	TailCall               // Tail Call
	True                   // Push True
	Vector                 // Make a new Vector from the Stack
	Zero                   // Push Zero
)

func (Opcode) New

func (o Opcode) New(ops ...Operand) Instruction

func (Opcode) String

func (i Opcode) String() string

type Operand

type Operand Word

Operand allows an Instruction to be parameterized

type Runnable

type Runnable struct {
	Constants  data.Vector
	Globals    env.Namespace
	Code       Instructions
	LocalCount Operand
	StackSize  Operand
}

Runnable is a finalized representation of the Encoded state that can be executed by the abstract machine

type Word

type Word uintptr

Word represents the atomic unit of the ISA's Instruction stream. We've chosen a size that best aligns to the host architecture's standard word size for alignment reasons

Jump to

Keyboard shortcuts

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