cpu

package
v0.0.0-...-d05d51b Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callable

type Callable = func([]Value) []Value

type Cmd

type Cmd = uint8
const (
	// Do nothing
	SKIP Cmd = iota
	// return an `*ExitErr`
	EXIT
	// register opers
	// copy value of a register to another one
	MOV
	// set the register value
	SETB
	// load variable value to register
	LOADB
	// store register value to variable
	STOREB
	SETW
	LOADW
	STOREW
	SETI
	LOADI
	STOREI
	SETQ
	LOADQ
	STOREQ
	// TODO: Memory alloc opers
	NEW
	MAKE_SLICE
	MAKE_MAP
	MAKE_CHAN
	LOADP
	STOREP
	// String opers
	SETS
	LOADS
	STORES
	// Stack opers
	PUSHU
	PUSHB
	PUSHW
	PUSHI
	PUSHQ
	PUSHP
	PUSHS
	POP
	POPU
	POPP
	POPS

	B2Q
	W2Q
	I2Q
	I2F
	I2D
	UI2F
	UI2D
	Q2F
	Q2D
	UQ2F
	UQ2D
	F2I
	F2UI
	F2Q
	F2UQ
	F2D
	D2I
	D2UI
	D2Q
	D2UQ
	D2F

	// integer opers
	ADD
	SUB
	MUL
	SMUL
	QUO
	SQUO
	REM
	SREM
	// bit opers
	NOT
	AND
	OR
	XOR
	SHL
	SHR
	SSHR
	SSHRW
	SSHRI
	SSHRQ
	// increse and decrese
	INC
	DEC
	// float opers
	FNEG
	FADD
	FSUB
	FMUL
	FQUO
	DNEG
	DADD
	DSUB
	DMUL
	DQUO
	// Boolean opers and compare
	LNOT
	LAND
	LOR
	EQ
	NE
	GT
	LT
	CMP
	ICMP
	FCMP
	DCMP
	// String opers
	CAT
	CUT
	B2S
	S2B
	// program pointer control
	GOTO
	JMP
	JMP_IF
	JMP_IFN
	// function things
	CALL
	CALLN
	CALLG
	CALLD
	ARG
	RET
	// panic and recover
	PAN
	REC
	// opers of `chan`
	SEND
	RECV
	RECVB
)

type Context

type Context struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext(label encoding.LabelMeta, p *Context, args ...Value) *Context

func (*Context) Arg

func (c *Context) Arg(i uint8) Value

func (*Context) Args

func (c *Context) Args() []Value

func (*Context) GetCmd

func (c *Context) GetCmd() (cmd Cmd)

func (*Context) GrowVals

func (c *Context) GrowVals(n uint32)

func (*Context) IsNative

func (c *Context) IsNative() bool

func (*Context) NewNativeCall

func (c *Context) NewNativeCall(label string, args ...Value) (nc *Context)

func (*Context) Parent

func (c *Context) Parent() *Context

func (*Context) Pop

func (c *Context) Pop() (v Value)

func (*Context) PopArr

func (c *Context) PopArr(v []Value) []Value

func (*Context) PopN

func (c *Context) PopN(n uint32) (v []Value)

func (*Context) Push

func (c *Context) Push(v ...Value)

func (*Context) Read

func (c *Context) Read(buf []byte) (n int, err error)

func (*Context) SetVal

func (c *Context) SetVal(i int32, v Value)

func (*Context) Strlst

func (c *Context) Strlst() string

func (*Context) Val

func (c *Context) Val(i int32) *Value

func (*Context) Vals

func (c *Context) Vals() []Value

type Cpu

type Cpu struct {
	R [32]uint64
	P [32]Pointer
	S [16]string
	// contains filtered or unexported fields
}

func NewCpu

func NewCpu(context *Context, reg Registry) *Cpu

func (*Cpu) Context

func (cpu *Cpu) Context() *Context

func (*Cpu) Registry

func (cpu *Cpu) Registry() Registry

func (*Cpu) Run

func (cpu *Cpu) Run() (err error)

func (*Cpu) Tick

func (cpu *Cpu) Tick() (err error)

type ExitErr

type ExitErr struct {
	Code int
}

func (*ExitErr) Error

func (e *ExitErr) Error() string

type LookupErr

type LookupErr struct {
	Label string
}

func (*LookupErr) Error

func (e *LookupErr) Error() string

type NativeCall

type NativeCall = func(ctx *Context) (n uint8)

type Pointer

type Pointer = unsafe.Pointer

type Registry

type Registry interface {
	Lookup(label string) (meta LabelMeta, ok bool)
	GetNative(label string) NativeCall
}

type StructField

type StructField struct {
	Name string
	Size uint32
	Tags []string
}

type StructType

type StructType struct {
	Fields  []StructField
	Methods []string
}

type Value

type Value interface {
	Bool() bool
	Int8() int8
	Int16() int16
	Int32() int32
	Int64() int64
	Uint8() uint8
	Uint16() uint16
	Uint32() uint32
	Uint64() uint64
	Float32() float32
	Float64() float64
	Pointer() Pointer
	String() string

	Len() int64
	Cap() int64
	Index(n int64) Value
	SetIndex(n int64, val Value)
	Keys() []Value
	Values() []Value
	Items() [][2]Value
	Key(k Value) Value
	HasKey(k Value) bool
	SetKey(k Value, val Value)
}
var Nil Value = nilItem{}

Jump to

Keyboard shortcuts

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