Documentation
¶
Index ¶
- Constants
- Variables
- func Encode(w io.Writer, m *Module) error
- func EncodeBundle(w io.Writer, consts *vm.Consts, nsChunks map[string]*vm.CodeChunk) error
- func EncodeCompilation(w io.Writer, consts *vm.Consts, mainChunk *vm.CodeChunk) error
- func EncodeModule(w io.Writer, consts *vm.Consts, chunks []*vm.CodeChunk) error
- type ChunkData
- type ExecUnit
- type Module
- type ModuleBuilder
- type Reader
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadBytes(n int) ([]byte, error)
- func (r *Reader) ReadFloat64() (float64, error)
- func (r *Reader) ReadInt32() (int32, error)
- func (r *Reader) ReadSvarint() (int64, error)
- func (r *Reader) ReadUint16() (uint16, error)
- func (r *Reader) ReadVarint() (uint64, error)
- type SourceEntry
- type VarResolver
- type Writer
- func (w *Writer) Flush() error
- func (w *Writer) WriteByte(b byte) error
- func (w *Writer) WriteBytes(b []byte) error
- func (w *Writer) WriteFloat64(v float64) error
- func (w *Writer) WriteInt32(v int32) error
- func (w *Writer) WriteSvarint(v int64) error
- func (w *Writer) WriteUint16(v uint16) error
- func (w *Writer) WriteVarint(v uint64) error
Constants ¶
const ( TagNil byte = 0x00 TagTrue byte = 0x01 TagFalse byte = 0x02 TagInt byte = 0x03 TagFloat byte = 0x04 TagString byte = 0x05 TagKeyword byte = 0x06 TagSymbol byte = 0x07 TagChar byte = 0x08 TagBigInt byte = 0x09 TagVoid byte = 0x0A TagFunc byte = 0x10 TagVarRef byte = 0x11 TagEmptyList byte = 0x20 TagList byte = 0x21 TagVector byte = 0x22 TagMap byte = 0x23 TagSet byte = 0x24 TagRecordType byte = 0x30 TagRecord byte = 0x31 TagRegex byte = 0x32 TagAtom byte = 0x33 )
Type tags for const pool entries.
const (
FlagConstsBase uint16 = 1 << 0 // ConstsBase field is present in consts section
)
Module flags.
const FormatVersion uint16 = 1
FormatVersion is the current serialization format version.
Variables ¶
var Magic = [4]byte{'L', 'G', 'B', 0x01}
Magic bytes identifying an LGB file.
Functions ¶
func EncodeBundle ¶
EncodeBundle serializes a multi-namespace compilation bundle. nsChunks maps namespace names to their main CodeChunks. The "core" entry (chunk index 0) is treated as the entry point.
func EncodeCompilation ¶
EncodeCompilation serializes a compilation result (main chunk + const pool). The main chunk is always chunk index 0. All CodeChunks referenced by Funcs in the const pool are collected automatically. If consts is a child pool, only the child's entries are serialized with the base offset stored so the decoder can reconstruct the layering.
Types ¶
type ChunkData ¶
type ChunkData struct {
MaxStack int
Code []int32
SourceMap []SourceEntry
}
ChunkData holds the data for a single code chunk.
type ExecUnit ¶
type ExecUnit struct {
Consts *vm.Consts
MainChunk *vm.CodeChunk
// NSChunks maps namespace names to their main chunks (for bundles).
NSChunks map[string]*vm.CodeChunk
}
ExecUnit is a decoded compilation unit ready for execution.
func DecodeToExecUnit ¶
func DecodeToExecUnit(r io.Reader, resolve VarResolver) (*ExecUnit, error)
DecodeToExecUnit decodes an LGB module and returns a ready-to-execute unit. The main chunk is chunk index 0. All decoded consts are populated into a shared Consts pool that all chunks reference.
func DecodeToExecUnitWithParent ¶
func DecodeToExecUnitWithParent(r io.Reader, resolve VarResolver, parent *vm.Consts) (*ExecUnit, error)
DecodeToExecUnitWithParent decodes an LGB module with an optional parent const pool. If parent is non-nil and the module has a ConstsBase, the decoded consts are layered on top of the parent pool — indices < base resolve from the parent.
type Module ¶
type Module struct {
Version uint16
Flags uint16
Strings []string
Chunks []*ChunkData
Consts []vm.Value
// ConstsBase is the starting global index for the consts in this module.
// For layered pools, indices 0..ConstsBase-1 are in a parent pool.
ConstsBase int
// NSTable maps namespace names to their main chunk indices (for bundles).
NSTable map[string]int
}
Module is the serializable unit — a complete compilation result.
func DecodeWithResolver ¶
func DecodeWithResolver(r io.Reader, resolve VarResolver) (*Module, error)
DecodeWithResolver reads a binary module, resolving var references with the given function.
type ModuleBuilder ¶
type ModuleBuilder struct {
// contains filtered or unexported fields
}
ModuleBuilder collects strings, chunks, and consts for serialization.
func NewModuleBuilder ¶
func NewModuleBuilder() *ModuleBuilder
NewModuleBuilder creates a new builder.
func (*ModuleBuilder) AddChunk ¶
func (b *ModuleBuilder) AddChunk(c *vm.CodeChunk) int
AddChunk registers a CodeChunk and interns its strings.
func (*ModuleBuilder) AddConst ¶
func (b *ModuleBuilder) AddConst(v vm.Value)
AddConst registers a const value and interns related strings/chunks.
func (*ModuleBuilder) ChunkIndex ¶
func (b *ModuleBuilder) ChunkIndex(c *vm.CodeChunk) (int, bool)
ChunkIndex returns the index for a given CodeChunk pointer.
func (*ModuleBuilder) SetNSEntry ¶
func (b *ModuleBuilder) SetNSEntry(name string, chunk *vm.CodeChunk)
SetNSEntry records a namespace name → main chunk mapping for bundle modules.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps a buffered reader with binary decoding helpers.
func (*Reader) ReadFloat64 ¶
ReadFloat64 reads an IEEE 754 little-endian float64.
func (*Reader) ReadSvarint ¶
ReadSvarint reads a signed zigzag-encoded varint.
func (*Reader) ReadUint16 ¶
ReadUint16 reads a little-endian uint16.
func (*Reader) ReadVarint ¶
ReadVarint reads an unsigned LEB128-encoded integer.
type SourceEntry ¶
SourceEntry is a source map entry for serialization.
type VarResolver ¶
VarResolver resolves a var reference by namespace and name.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps a buffered writer with binary encoding helpers.
func (*Writer) WriteBytes ¶
WriteBytes writes a byte slice.
func (*Writer) WriteFloat64 ¶
WriteFloat64 writes an IEEE 754 little-endian float64.
func (*Writer) WriteInt32 ¶
WriteInt32 writes a little-endian int32.
func (*Writer) WriteSvarint ¶
WriteSvarint writes a signed zigzag-encoded varint.
func (*Writer) WriteUint16 ¶
WriteUint16 writes a little-endian uint16.
func (*Writer) WriteVarint ¶
WriteVarint writes an unsigned LEB128-encoded integer.