bytecode

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionMajor = 1
	VersionMinor = 0
	VersionPatch = 0
)

Version represents the bytecode format version

View Source
const Magic = 0x4E584230 // "NXB0" in hex

Magic number for Nxlang bytecode files

Variables

View Source
var FullVersion = uint32(VersionMajor<<16 | VersionMinor<<8 | VersionPatch)

FullVersion combines version numbers into a single uint32

Functions

This section is empty.

Types

type BoolConstant

type BoolConstant struct {
	Value bool
}

BoolConstant represents a boolean value

func (*BoolConstant) Type

func (c *BoolConstant) Type() ConstantType

type Bytecode

type Bytecode struct {
	Constants       []Constant
	MainFunc        int // Index of main function in constant pool
	SourceFile      string
	LineNumberTable []LineInfo // Maps instruction positions to line numbers
}

Bytecode represents a complete compiled program

type CharConstant

type CharConstant struct {
	Value rune
}

CharConstant represents a Unicode character value

func (*CharConstant) Type

func (c *CharConstant) Type() ConstantType

type ClassConstant

type ClassConstant struct {
	Name          string
	SuperClass    string         // Name of superclass
	Interfaces    []string       // List of interface names this class implements
	Methods       map[string]int // Map of method name to function constant index
	StaticMethods map[string]int // Map of static method name to function constant index
}

ClassConstant represents a compiled class

func (*ClassConstant) Type

func (c *ClassConstant) Type() ConstantType

type Constant

type Constant interface {
	Type() ConstantType
}

Constant represents an entry in the constant pool

type ConstantType

type ConstantType byte

ConstantType identifies the type of constant in the constant pool

const (
	ConstNil       ConstantType = 0x00
	ConstBool      ConstantType = 0x01
	ConstInt       ConstantType = 0x02
	ConstFloat     ConstantType = 0x03
	ConstString    ConstantType = 0x04
	ConstFunction  ConstantType = 0x05
	ConstClass     ConstantType = 0x06
	ConstChar      ConstantType = 0x07
	ConstInterface ConstantType = 0x08
)

type ErrInvalidConstantType

type ErrInvalidConstantType struct {
	Type ConstantType
}

ErrInvalidConstantType is returned when an unknown constant type is encountered

func (*ErrInvalidConstantType) Error

func (e *ErrInvalidConstantType) Error() string

type FloatConstant

type FloatConstant struct {
	Value float64
}

FloatConstant represents a floating point value

func (*FloatConstant) Type

func (c *FloatConstant) Type() ConstantType

type FunctionConstant

type FunctionConstant struct {
	Name           string
	Instructions   []byte
	NumLocals      int
	NumParameters  int
	IsVariadic     bool
	IsStatic       bool  // Whether this is a static method
	AccessModifier uint8 // 0=public, 1=private, 2=protected
	Flags          uint8 // Bit flags: bit 0=isGetter, bit 1=isSetter
	DefaultValues  []int // Indices of default values in constant pool
}

FunctionConstant represents a compiled function

func (*FunctionConstant) Type

func (c *FunctionConstant) Type() ConstantType
type Header struct {
	Magic      uint32
	Version    uint32
	Flags      uint32
	ConstCount uint32
	CodeSize   uint32
	LineCount  uint32
	Reserved   [16]byte
}

Header represents the header of a .nxb bytecode file

type IntConstant

type IntConstant struct {
	Value int64
}

IntConstant represents an integer value

func (*IntConstant) Type

func (c *IntConstant) Type() ConstantType

type InterfaceConstant

type InterfaceConstant struct {
	Name    string
	Methods map[string][]string // Method name -> list of parameter names (for signature matching)
}

InterfaceConstant represents a compiled interface

func (*InterfaceConstant) Type

func (c *InterfaceConstant) Type() ConstantType

type LineInfo

type LineInfo struct {
	Offset int
	Line   int
	Column int
}

LineInfo maps an instruction offset to a source line number

type NilConstant

type NilConstant struct{}

NilConstant represents a nil value

func (*NilConstant) Type

func (c *NilConstant) Type() ConstantType

type Reader

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

Reader deserializes binary .nxb files into Bytecode structure

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a new bytecode reader from an io.Reader

func NewReaderFromBytes

func NewReaderFromBytes(data []byte) *Reader

NewReaderFromBytes creates a new bytecode reader from a byte slice

func (*Reader) Read

func (r *Reader) Read() (*Bytecode, error)

Read reads and parses the bytecode from the input

type StringConstant

type StringConstant struct {
	Value string
}

StringConstant represents a string value

func (*StringConstant) Type

func (c *StringConstant) Type() ConstantType

type Writer

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

Writer serializes Bytecode into binary format

func NewWriter

func NewWriter() *Writer

NewWriter creates a new bytecode writer

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the serialized bytecode

func (*Writer) Write

func (w *Writer) Write(bc *Bytecode) error

Write writes the bytecode to the internal buffer

func (*Writer) WriteTo

func (w *Writer) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the serialized bytecode to an io.Writer

Jump to

Keyboard shortcuts

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