t3xf

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidArg = errors.New("invalid argument")

ErrInvalidArg is returned when an argument is not of the expected type or size.

View Source
var ErrUnknownReference = errors.New("unknown reference")

ErrUnknownReference is returned when a reference to an unknown instruction is encountered.

Functions

func Decode added in v0.19.0

func Decode(b []byte) (n int, op opcode.Opcode, arg interface{})

Decode decodes a T3XF instruction from a byte slice. It returns the number of bytes read, the opcode and its argument.

The type of the argument depends on the opcode:

  • LINE, NATLONG, SCAN, IFIELD, IGET and IDEF: the argument is an int.
  • IEEE754DP: the argument is a float64.
  • BITS, NIBBLES and OCTETS: the argument is a *t3xf.String. The underlying byte slice is the given byte slice b. Note, that the number of bytes read and the number of bytes in the String slice may differ, because T3XF instructions are 4-byte aligned.
  • NAME, UTF8, ISTR and FSTR: the argument is a string.
  • REF, GOTO and FROZEN_REF: the argument is a t3xf.Reference.

Types

type Compiler added in v0.19.0

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

func NewCompiler added in v0.19.0

func NewCompiler() *Compiler

func (*Compiler) Assemble added in v0.19.0

func (c *Compiler) Assemble() ([]byte, error)

func (*Compiler) Compile added in v0.19.0

func (c *Compiler) Compile(n syntax.Node) error

func (*Compiler) Err added in v0.19.0

func (c *Compiler) Err() error

type Encoder added in v0.19.0

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

func NewEncoder added in v0.19.0

func NewEncoder() *Encoder

func (*Encoder) Assemble added in v0.19.0

func (e *Encoder) Assemble() ([]byte, error)

Assemble returns the assembled T3XF byte code. References are resolved when possible, otherwise they are left unresolved and an error is returned.

It is safe to call Assemble multiple times during the lifetime of an Encoder.

func (*Encoder) Encode added in v0.19.0

func (e *Encoder) Encode(op opcode.Opcode, arg any) error

Encode the given opcode and argument. If an argument is not of the expected type or size, an error is returned.

  • References are given as the index of the Encode call that will be referenced.
  • String arguments are expected to implement the Len() and Bytes() methods.
  • Integer arguments are expected to be of type int.
  • Float arguments are expected to be of type float64.

func (*Encoder) Len added in v0.19.0

func (e *Encoder) Len() int

func (*Encoder) Reset added in v0.19.0

func (e *Encoder) Reset()

Reset resets the encoder to its initial state.

type EncoderError added in v0.19.0

type EncoderError struct {
	Err error         // Underlying error
	I   int           // Instruction index
	Op  opcode.Opcode // Current Opcode
}

func (*EncoderError) Error added in v0.19.0

func (e *EncoderError) Error() string

func (*EncoderError) Unwrap added in v0.19.0

func (e *EncoderError) Unwrap() error

type Reference added in v0.19.0

type Reference int

Reference is a T3XF offset.

type String added in v0.19.0

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

String is a T3XF string.

func NewString added in v0.19.0

func NewString(l int, b []byte) *String

func (*String) Bytes added in v0.19.0

func (s *String) Bytes() []byte

Bytes returns the byte slice for the string.

func (*String) Len added in v0.19.0

func (s *String) Len() int

Len returns the number of elements in the string. For a bitstring, this is the number of bits, for a charstring the number of characters.

Directories

Path Synopsis
Package opcode defines the opcodes used in T3XF.
Package opcode defines the opcodes used in T3XF.

Jump to

Keyboard shortcuts

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