bytecode

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Index

Constants

View Source
const Version uint32 = 100

Variables

This section is empty.

Functions

func AppendAccess

func AppendAccess(filed string, loc Location, ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendApply

func AppendApply(numArgs uint8, loc Location, ops []Op, locations []Location,
) ([]Op, []Location)

func AppendCall

func AppendCall(
	name string, numArgs uint8, loc Location,
	ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendJump

func AppendJump(jumpDelta int, conditional bool, loc Location, ops []Op, locations []Location) ([]Op, []Location)

func AppendLoadConstCharValue

func AppendLoadConstCharValue(
	v rune, stack StackKind, loc Location,
	ops []Op, locations []Location, binary *Binary,
) ([]Op, []Location)

func AppendLoadConstFloatValue

func AppendLoadConstFloatValue(
	v float64, stack StackKind, loc Location,
	ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendLoadConstIntValue

func AppendLoadConstIntValue(
	v int64, stack StackKind, loc Location,
	ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendLoadConstStringValue

func AppendLoadConstStringValue(
	v string, stack StackKind, loc Location,
	ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendLoadConstUnitValue

func AppendLoadConstUnitValue(
	stack StackKind, loc Location,
	ops []Op, locations []Location, binary *Binary,
) ([]Op, []Location)

func AppendLoadGlobal

func AppendLoadGlobal(
	ptr Pointer, loc Location, ops []Op, locations []Location,
) ([]Op, []Location)

func AppendLoadLocal

func AppendLoadLocal(
	name string, loc Location, ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendMakeObject

func AppendMakeObject(kind ObjectKind, numArgs int, loc Location,
	ops []Op, locations []Location,
) ([]Op, []Location)

func AppendMakePattern

func AppendMakePattern(
	kind PatternKind, name string, numNested uint8,
	loc Location, ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

func AppendMakePatternLong

func AppendMakePatternLong(
	kind PatternKind, numNested uint32,
	loc Location, ops []Op, locations []Location, binary *Binary,
) ([]Op, []Location)

func AppendSwapPop

func AppendSwapPop(loc Location, mode SwapPopMode,
	ops []Op, locations []Location,
) ([]Op, []Location)

func AppendUpdate

func AppendUpdate(field string, loc Location,
	ops []Op, locations []Location, binary *Binary, hash *BinaryHash,
) ([]Op, []Location)

Types

type Binary

type Binary struct {
	CompilerVersion uint32
	Funcs           []Func
	Strings         []string
	Consts          []PackedConst
	Exports         map[FullIdentifier]Pointer
	Entry           FullIdentifier
	Packages        map[QualifiedIdentifier]uint32
}

func NewBinary

func NewBinary() *Binary

func Read

func Read(reader io.Reader) (bin *Binary, err error)

func (*Binary) Write

func (b *Binary) Write(writer io.Writer, debug bool) (err error)

type BinaryHash

type BinaryHash struct {
	FuncsMap  map[FullIdentifier]Pointer
	StringMap map[string]StringHash
	ConstMap  map[PackedConst]ConstHash

	CompiledPaths []QualifiedIdentifier
}

func NewBinaryHash

func NewBinaryHash() *BinaryHash

func (*BinaryHash) HashConst

func (h *BinaryHash) HashConst(v PackedConst, bin *Binary) ConstHash

func (*BinaryHash) HashString

func (h *BinaryHash) HashString(v string, bin *Binary) StringHash

type ConstHash

type ConstHash uint32

type ConstHashKind

type ConstHashKind uint8
const (
	ConstHashKindNone ConstHashKind = iota
	ConstHashKindInt
	ConstHashKindFloat
)

type ConstKind

type ConstKind uint8
const (
	ConstKindUnit ConstKind
	ConstKindChar
	ConstKindInt
	ConstKindFloat
	ConstKindString
)

type FullIdentifier

type FullIdentifier string

type Func

type Func struct {
	Name      StringHash
	NumArgs   uint32
	Ops       []Op
	FilePath  string
	Locations []Location
}

type Location

type Location struct {
	Line, Column uint32
}

type ObjectKind

type ObjectKind uint8
const (
	ObjectKindList ObjectKind
	ObjectKindTuple
	ObjectKindRecord
	ObjectKindOption
)

type Op

type Op uint64

func (Op) Decompose

func (o Op) Decompose() (OpKind, uint8, uint8, uint32)

func (Op) WithDelta

func (o Op) WithDelta(i int32) Op

type OpKind

type OpKind uint32
const (

	// OpKindLoadLocal adds named local object to the top of the stack
	OpKindLoadLocal OpKind
	// OpKindLoadGlobal adds global object to the top of the stack
	OpKindLoadGlobal
	// OpKindLoadConst adds const value object to the top of the stack
	OpKindLoadConst
	// OpKindApply executes the function from the top of the stack.
	// Arguments are taken from the top of the stack in reverse order
	// (topmost object is the last arg). Returned value is left on the top of the stack.
	// In case of NumArgs is less than number of function parameters it creates
	// a closure and leaves it on the top of the stack
	OpKindApply
	// OpKindCall executes native function.
	// Arguments are taken from the top of the stack in reverse order
	// (topmost object is last arg). Returned value is left on the top of the stack.
	OpKindCall
	// OpKindJump moves on delta ops unconditional
	// conditional jump tries to match pattern with object on the top of the stack.
	// If it cannot be matched it moves on delta ops
	// If it matches successfully - locals are extracted from pattern
	// Matched object is left on the top of the stack in both cases
	OpKindJump
	// OpKindMakeObject creates an object on stack.
	// List items stored on stack in reverse order (topmost object is the last item)
	// Record fields stored as repeating pairs const string and value (field name is on the top of the stack)
	// Data stores option name as const string on the top of the stack and
	// args after that in reverse order (topmost is the last arg)
	OpKindMakeObject
	// OpKindMakePattern creates pattern object
	// Arguments are taken from the top of the stack in reverse order
	// (topmost object is the last arg). Created object is left on the top of the stack.
	OpKindMakePattern
	// OpKindAccess takes record object from the top of the stack and leaves its field on the stack
	OpKindAccess
	// OpKindUpdate create new record with replaced field from the top of the stack and rest fields
	// form the second record object from stack. Created record is left on the top of the stack
	OpKindUpdate
	// OpKindSwapPop if pop mode - removes topmost object from the stack
	// if both mode - removes second object from the top of the stack
	OpKindSwapPop
)

type PackedConst

type PackedConst interface {
	Pack() uint64
	Kind() ConstHashKind
	Int() int64
	Float() float64
}

type PackedFloat

type PackedFloat struct {
	Value float64
}

func (PackedFloat) Float

func (c PackedFloat) Float() float64

func (PackedFloat) Int

func (c PackedFloat) Int() int64

func (PackedFloat) Kind

func (c PackedFloat) Kind() ConstHashKind

func (PackedFloat) Pack

func (c PackedFloat) Pack() uint64

type PackedInt

type PackedInt struct {
	Value int64
}

func (PackedInt) Float

func (c PackedInt) Float() float64

func (PackedInt) Int

func (c PackedInt) Int() int64

func (PackedInt) Kind

func (c PackedInt) Kind() ConstHashKind

func (PackedInt) Pack

func (c PackedInt) Pack() uint64

type PatternKind

type PatternKind uint8
const (
	PatternKindAlias PatternKind
	PatternKindAny
	PatternKindCons
	PatternKindConst
	PatternKindDataOption
	PatternKindList
	PatternKindNamed
	PatternKindRecord
	PatternKindTuple
)

type Pointer

type Pointer uint32

type QualifiedIdentifier

type QualifiedIdentifier string

type StackKind

type StackKind uint8
const (
	StackKindObject StackKind
	StackKindPattern
)

type StringHash

type StringHash uint32

type SwapPopMode

type SwapPopMode uint8
const (
	SwapPopModeBoth SwapPopMode
	SwapPopModePop
)

Jump to

Keyboard shortcuts

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