Documentation
¶
Overview ¶
Tolang: deterministic Lua VM for the TOS blockchain
Index ¶
- Constants
- Variables
- func BuildInterface(mod *tolast.Module) ([]byte, error)
- func BuildInterfaceForContract(mod *tolast.Module, c *tolast.ContractDecl, interfaceName string) ([]byte, error)
- func BuildInterfaceForDecl(mod *tolast.Module, iface *tolast.InterfaceDecl) ([]byte, error)
- func BuildInterfaceWithOptions(mod *tolast.Module, opts *InterfaceOptions) ([]byte, error)
- func BuildLowered(source []byte, name string) (*lower.Program, error)
- func BuildOpenlibFamilyBundlePackage(entries []OpenlibReleaseEntry, sources map[string][]byte) ([]byte, error)
- func CompileArtifact(source []byte, name string) ([]byte, error)
- func CompileArtifactWithOptions(source []byte, name string, opts *ArtifactOptions) ([]byte, error)
- func CompileBytecode(source []byte, name string) ([]byte, error)
- func CompileBytecodeFromLowered(prog *lower.Program, name string) ([]byte, error)
- func CompileBytecodeWithOptions(source []byte, name string, opts *CompileOptions) ([]byte, error)
- func CompileInitBytecode(source []byte, name string) ([]byte, error)
- func CompileInterface(source []byte, name string) ([]byte, error)
- func CompileInterfaceWithOptions(source []byte, name string, opts *InterfaceOptions) ([]byte, error)
- func CompilePackage(source []byte, name string, opts *PackageOptions) ([]byte, error)
- func CompileSourceToBytecode(source []byte, name string) ([]byte, error)
- func EncodeArtifact(a *Artifact) ([]byte, error)
- func EncodeFunctionProto(proto *FunctionProto) ([]byte, error)
- func EncodePackage(manifestJSON []byte, files map[string][]byte) ([]byte, error)
- func IsArtifact(data []byte) bool
- func IsBytecode(data []byte) bool
- func IsPackage(data []byte) bool
- func LVAsBool(v LValue) bool
- func LVAsString(v LValue) string
- func LVCanConvToString(v LValue) bool
- func LVIsFalse(v LValue) bool
- func Lu256Cmp(a, b LUint256) int
- func NewOSFileResolver(baseDir string) sema.FileResolver
- func OpenBase(L *LState) int
- func OpenMath(L *LState) int
- func OpenString(L *LState) int
- func OpenTable(L *LState) int
- func PackageHash(data []byte) string
- func ParseModule(source []byte, name string) (*ast.Module, error)
- func SignPackage(pkgBytes []byte, privKeySeed []byte) ([]byte, error)
- func UpvalueIndex(i int) int
- func ValidateInterface(data []byte) error
- func VerifyPackageSignature(pkgBytes []byte) error
- func VerifySourceHash(art *Artifact, source []byte) error
- type ApiError
- type ApiErrorType
- type Artifact
- type ArtifactOptions
- type CompileError
- type CompileOptions
- type DbgCall
- type DbgLocalInfo
- type Debug
- type FunctionProto
- type Global
- type IRFunction
- type IRInstruction
- type IRProgram
- func BuildIR(source []byte, name string) (*IRProgram, error)
- func BuildIRFromChunk(chunk []ast.Stmt, name string) (*IRProgram, error)
- func BuildIRFromLowered(prog *lower.Program, name string) (*IRProgram, error)
- func BuildIRFromLoweredInit(prog *lower.Program, name string) (*IRProgram, error)
- func BuildIRFromProto(proto *FunctionProto, name string) *IRProgram
- func BuildIRWithResolver(source []byte, name string, resolver sema.FileResolver) (*IRProgram, error)
- type InterfaceInfo
- type InterfaceOptions
- type LAgent
- type LBool
- type LFunction
- type LGFunction
- type LNilType
- type LState
- func (ls *LState) ArgError(n int, message string)
- func (ls *LState) Call(nargs, nret int)
- func (ls *LState) CallByParam(cp P, args ...LValue) error
- func (ls *LState) CallMeta(obj LValue, event string) LValue
- func (ls *LState) CheckAgent(n int) LAgent
- func (ls *LState) CheckAny(n int) LValue
- func (ls *LState) CheckBool(n int) bool
- func (ls *LState) CheckFunction(n int) *LFunction
- func (ls *LState) CheckInt(n int) int
- func (ls *LState) CheckInt64(n int) int64
- func (ls *LState) CheckOption(n int, options []string) int
- func (ls *LState) CheckString(n int) string
- func (ls *LState) CheckTable(n int) *LTable
- func (ls *LState) CheckType(n int, typ LValueType)
- func (ls *LState) CheckTypes(n int, typs ...LValueType)
- func (ls *LState) CheckUint256(n int) LUint256
- func (ls *LState) CheckUserData(n int) *LUserData
- func (ls *LState) Close()
- func (ls *LState) Concat(values ...LValue) string
- func (ls *LState) CreateTable(acap, hcap int) *LTable
- func (ls *LState) DoBytecode(data []byte) error
- func (ls *LState) DoString(source string) error
- func (ls *LState) Equal(lhs, rhs LValue) bool
- func (ls *LState) Error(lv LValue, level int)
- func (ls *LState) FindTable(obj *LTable, n string, size int) LValue
- func (ls *LState) ForEach(tb *LTable, cb func(LValue, LValue))
- func (ls *LState) GPCall(fn LGFunction, data LValue) error
- func (ls *LState) GasUsed() uint64
- func (ls *LState) Get(idx int) LValue
- func (ls *LState) GetFEnv(obj LValue) LValue
- func (ls *LState) GetField(obj LValue, skey string) LValue
- func (ls *LState) GetGlobal(name string) LValue
- func (ls *LState) GetInfo(what string, dbg *Debug, fn LValue) (LValue, error)
- func (ls *LState) GetLocal(dbg *Debug, no int) (string, LValue)
- func (ls *LState) GetMetaField(obj LValue, event string) LValue
- func (ls *LState) GetMetatable(obj LValue) LValue
- func (ls *LState) GetStack(level int) (*Debug, bool)
- func (ls *LState) GetTable(obj LValue, key LValue) LValue
- func (ls *LState) GetTop() int
- func (ls *LState) GetTypeMetatable(typ string) LValue
- func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue)
- func (ls *LState) Insert(value LValue, index int)
- func (ls *LState) IsClosed() bool
- func (ls *LState) LessThan(lhs, rhs LValue) bool
- func (ls *LState) Load(reader io.Reader, name string) (*LFunction, error)
- func (ls *LState) LoadBytecode(data []byte) (*LFunction, error)
- func (ls *LState) LoadIR(program *IRProgram) (*LFunction, error)
- func (ls *LState) LoadString(source string) (*LFunction, error)
- func (ls *LState) NewClosure(fn LGFunction, upvalues ...LValue) *LFunction
- func (ls *LState) NewFunction(fn LGFunction) *LFunction
- func (ls *LState) NewFunctionFromProto(proto *FunctionProto) *LFunction
- func (ls *LState) NewTable() *LTable
- func (ls *LState) NewTypeMetatable(typ string) *LTable
- func (ls *LState) NewUserData() *LUserData
- func (ls *LState) Next(tb *LTable, key LValue) (LValue, LValue)
- func (ls *LState) ObjLen(v1 LValue) int
- func (ls *LState) OpenLibs()
- func (ls *LState) OptAgent(n int, d LAgent) LAgent
- func (ls *LState) OptBool(n int, d bool) bool
- func (ls *LState) OptFunction(n int, d *LFunction) *LFunction
- func (ls *LState) OptInt(n int, d int) int
- func (ls *LState) OptInt64(n int, d int64) int64
- func (ls *LState) OptString(n int, d string) string
- func (ls *LState) OptTable(n int, d *LTable) *LTable
- func (ls *LState) OptUint256(n int, d LUint256) LUint256
- func (ls *LState) OptUserData(n int, d *LUserData) *LUserData
- func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error)
- func (ls *LState) Pop(n int)
- func (ls *LState) PreloadModule(name string, loader LGFunction)
- func (ls *LState) Push(value LValue)
- func (ls *LState) RaiseError(format string, args ...interface{})
- func (ls *LState) RawEqual(lhs, rhs LValue) bool
- func (ls *LState) RawGet(tb *LTable, key LValue) LValue
- func (ls *LState) RawGetInt(tb *LTable, key int) LValue
- func (ls *LState) RawSet(tb *LTable, key LValue, value LValue)
- func (ls *LState) RawSetInt(tb *LTable, key int, value LValue)
- func (ls *LState) Register(name string, fn LGFunction)
- func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue
- func (ls *LState) Remove(index int)
- func (ls *LState) RemoveCallerFrame() *callFrame
- func (ls *LState) Replace(idx int, value LValue)
- func (ls *LState) SetFEnv(obj LValue, env LValue)
- func (ls *LState) SetField(obj LValue, key string, value LValue)
- func (ls *LState) SetFuncs(tb *LTable, funcs map[string]LGFunction, upvalues ...LValue) *LTable
- func (ls *LState) SetGasLimit(limit uint64)
- func (ls *LState) SetGlobal(name string, value LValue)
- func (ls *LState) SetLineHook(fn func(string, int))
- func (ls *LState) SetLocal(dbg *Debug, no int, lv LValue) string
- func (ls *LState) SetMetatable(obj LValue, mt LValue)
- func (ls *LState) SetTable(obj LValue, key LValue, value LValue)
- func (ls *LState) SetTop(idx int)
- func (ls *LState) SetUpvalue(fn *LFunction, no int, lv LValue) string
- func (ls *LState) ToAgent(n int) LAgent
- func (ls *LState) ToBool(n int) bool
- func (ls *LState) ToFunction(n int) *LFunction
- func (ls *LState) ToInt(n int) int
- func (ls *LState) ToInt64(n int) int64
- func (ls *LState) ToString(n int) string
- func (ls *LState) ToStringMeta(lv LValue) LValue
- func (ls *LState) ToTable(n int) *LTable
- func (ls *LState) ToUint256(n int) LUint256
- func (ls *LState) ToUserData(n int) *LUserData
- func (ls *LState) TypeError(n int, typ LValueType)
- func (ls *LState) Where(level int) string
- type LString
- type LTable
- func (tb *LTable) Append(value LValue)
- func (tb *LTable) ForEach(cb func(LValue, LValue))
- func (tb *LTable) Insert(i int, value LValue)
- func (tb *LTable) InsertWithCost(i int, value LValue) int
- func (tb *LTable) Len() int
- func (tb *LTable) LenWithCost() (int, int)
- func (tb *LTable) MaxN() int
- func (tb *LTable) MaxNWithCost() (int, int)
- func (tb *LTable) Next(key LValue) (LValue, LValue)
- func (tb *LTable) NextWithCost(key LValue) (LValue, LValue, int)
- func (tb *LTable) RawGet(key LValue) LValue
- func (tb *LTable) RawGetH(key LValue) LValue
- func (tb *LTable) RawGetInt(key int) LValue
- func (tb *LTable) RawGetString(key string) LValue
- func (tb *LTable) RawSet(key LValue, value LValue)
- func (tb *LTable) RawSetH(key LValue, value LValue)
- func (tb *LTable) RawSetInt(key int, value LValue)
- func (tb *LTable) RawSetString(key string, value LValue)
- func (tb *LTable) Remove(pos int) LValue
- func (tb *LTable) RemoveWithCost(pos int) (LValue, int)
- func (tb *LTable) String() string
- func (tb *LTable) Type() LValueType
- type LUint256
- type LUserData
- type LValue
- type LValueType
- type OSFileResolver
- type OpenlibReleaseArtifacts
- type OpenlibReleaseEntry
- type Options
- type P
- type Package
- type PackageOptions
- type Upvalue
Constants ¶
const ( VarArgHasArg uint8 = 1 VarArgIsVarArg uint8 = 2 VarArgNeedsArg uint8 = 4 )
const ( // BaseLibName is here for consistency; the base functions have no namespace/library. BaseLibName = "" // LoadLibName is here for consistency; the loading system has no namespace/library. LoadLibName = "package" // TabLibName is the name of the table Library. TabLibName = "table" // IoLibName is the name of the io Library. IoLibName = "io" // OsLibName is the name of the os Library. OsLibName = "os" // StringLibName is the name of the string Library. StringLibName = "string" // MathLibName is the name of the math Library. MathLibName = "math" // DebugLibName is the name of the debug Library. DebugLibName = "debug" // CoroutineLibName is the name of the coroutine Library. CoroutineLibName = "coroutine" )
const ( OP_MOVE int = iota /* A B R(A) := R(B) */ OP_MOVEN /* A B R(A) := R(B); followed by R(C) MOVE ops */ OP_LOADK /* A Bx R(A) := Kst(Bx) */ OP_LOADBOOL /* A B C R(A) := (Bool)B; if (C) pc++ */ OP_LOADNIL /* A B R(A) := ... := R(B) := nil */ OP_GETUPVAL /* A B R(A) := UpValue[B] */ OP_GETGLOBAL /* A Bx R(A) := Gbl[Kst(Bx)] */ OP_GETTABLE /* A B C R(A) := R(B)[RK(C)] */ OP_GETTABLEKS /* A B C R(A) := R(B)[RK(C)] ; RK(C) is constant string */ OP_SETGLOBAL /* A Bx Gbl[Kst(Bx)] := R(A) */ OP_SETUPVAL /* A B UpValue[B] := R(A) */ OP_SETTABLE /* A B C R(A)[RK(B)] := RK(C) */ OP_SETTABLEKS /* A B C R(A)[RK(B)] := RK(C) ; RK(B) is constant string */ OP_NEWTABLE /* A B C R(A) := {} (size = BC) */ OP_SELF /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */ OP_ADD /* A B C R(A) := RK(B) + RK(C) */ OP_SUB /* A B C R(A) := RK(B) - RK(C) */ OP_MUL /* A B C R(A) := RK(B) * RK(C) */ OP_DIV /* A B C R(A) := RK(B) / RK(C) */ OP_MOD /* A B C R(A) := RK(B) % RK(C) */ OP_POW /* A B C R(A) := RK(B) ^ RK(C) */ OP_UNM /* A B R(A) := -R(B) */ OP_NOT /* A B R(A) := not R(B) */ OP_LEN /* A B R(A) := length of R(B) */ OP_CONCAT /* A B C R(A) := R(B).. ... ..R(C) */ OP_JMP /* sBx pc+=sBx */ OP_EQ /* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ OP_LT /* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ OP_LE /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ OP_TEST /* A C if not (R(A) <=> C) then pc++ */ OP_TESTSET /* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ OP_CALL /* A B C R(A) ... R(A+C-2) := R(A)(R(A+1) ... R(A+B-1)) */ OP_TAILCALL /* A B C return R(A)(R(A+1) ... R(A+B-1)) */ OP_RETURN /* A B return R(A) ... R(A+B-2) (see note) */ OP_FORLOOP /* A sBx R(A)+=R(A+2); if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ OP_FORPREP /* A sBx R(A)-=R(A+2); pc+=sBx */ OP_TFORLOOP /* A C R(A+3) ... R(A+3+C) := R(A)(R(A+1) R(A+2)); if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); } */ OP_SETLIST /* A B C R(A)[(C-1)*FPF+i] := R(A+i) 1 <= i <= B */ OP_CLOSE /* A close all variables in the stack up to (>=) R(A)*/ OP_CLOSURE /* A Bx R(A) := closure(KPROTO[Bx] R(A) ... R(A+n)) */ OP_VARARG /* A B R(A) R(A+1) ... R(A+B-1) = vararg */ OP_BAND /* A B C R(A) := RK(B) & RK(C) */ OP_BOR /* A B C R(A) := RK(B) | RK(C) */ OP_BXOR /* A B C R(A) := RK(B) ~ RK(C) */ OP_SHL /* A B C R(A) := RK(B) << RK(C) */ OP_SHR /* A B C R(A) := RK(B) >> RK(C) */ OP_IDIV /* A B C R(A) := RK(B) // RK(C) */ OP_BNOT /* A B R(A) := ~R(B) */ OP_NOP /* NOP */ )
const ArtifactFormatVersion uint16 = 1
ArtifactFormatVersion is the binary format version for .toc artifacts.
const BytecodeFormatVersion uint16 = 1
BytecodeFormatVersion is the binary format version for tolang bytecode.
const EnvironIndex = -10001
const FramesPerSegment = 8
FramesPerSegment should be a power of 2 constant for performance reasons. It will allow the go compiler to change the divs and mods into bitshifts. Max is 256 due to current use of uint8 to count how many frames in a segment are used.
const GlobalsIndex = -10002
const LUint256Bit = 256
const LuaVersion = "Lua 5.1 (uint256)"
const MappingLibName = "mapping"
const MultRet = -1
const PackageAuthors = "TOS Network"
const PackageCopyRight = PackageName + " " + PackageVersion + " Copyright (C) 2024-2025 " + PackageAuthors
const PackageName = "Tolang"
const PackageVersion = "0.2"
const RegistryIndex = -10000
Variables ¶
var CallStackSize = 256
var CompatVarArg = true
var FieldsPerFlush = 50
var LFalse = LBool(false)
var LNil = LValue(&LNilType{})
var LTrue = LBool(true)
var LUint256One = LUint256{/* contains filtered or unexported fields */}
var LUint256Zero = LUint256{}
var LuaDirSep string
var LuaExecDir = "!"
var LuaIgMark = "-"
var LuaLDir string
var LuaOS string
var LuaPath = "LUA_PATH"
var LuaPathDefault string
var LuaPathMark = "?"
var LuaPathSep = ";"
var MaxArrayHoleGrowth = 64
var MaxArrayIndex = 67108864
var MaxTableGetLoop = 100
var RegistryGrowStep = 32
var RegistrySize = 256 * 20
Functions ¶
func BuildInterface ¶
BuildInterface renders a parsed module into a textual interface declaration.
func BuildInterfaceForContract ¶
func BuildInterfaceForContract(mod *tolast.Module, c *tolast.ContractDecl, interfaceName string) ([]byte, error)
BuildInterfaceForContract renders a specific ContractDecl as a .abi interface.
func BuildInterfaceForDecl ¶
BuildInterfaceForDecl renders a top-level InterfaceDecl as a .abi file.
func BuildInterfaceWithOptions ¶
func BuildInterfaceWithOptions(mod *tolast.Module, opts *InterfaceOptions) ([]byte, error)
BuildInterfaceWithOptions renders a parsed module into textual interface declaration. When opts.ContractName is set, that contract is used; otherwise the first contract.
func BuildLowered ¶
BuildLowered builds typed and lowered TOL program for diagnostics/testing. Import declarations are resolved relative to the directory of name using the OS filesystem.
func BuildOpenlibFamilyBundlePackage ¶
func BuildOpenlibFamilyBundlePackage(entries []OpenlibReleaseEntry, sources map[string][]byte) ([]byte, error)
BuildOpenlibFamilyBundlePackage builds a multi-contract family bundle .tor for families that contain more than one published contract release.
func CompileArtifact ¶
CompileArtifact compiles TOL source into a .toc artifact.
func CompileArtifactWithOptions ¶
func CompileArtifactWithOptions(source []byte, name string, opts *ArtifactOptions) ([]byte, error)
CompileArtifactWithOptions compiles TOL source into a .toc artifact with configurable bytecode debug metadata emission.
func CompileBytecode ¶
CompileBytecode compiles TOL source into deterministic bytecode.
func CompileBytecodeFromLowered ¶
CompileBytecodeFromLowered compiles a lowered TOL program into deterministic bytecode.
func CompileBytecodeWithOptions ¶
func CompileBytecodeWithOptions(source []byte, name string, opts *CompileOptions) ([]byte, error)
CompileBytecodeWithOptions compiles TOL source into deterministic bytecode with configurable debug metadata emission.
func CompileInitBytecode ¶
CompileInitBytecode compiles TOL source into init-mode bytecode (constructor only, no tos.oninvoke dispatch). The init artifact is used for constructor-at-deploy-time execution and exposes tos.oncreate for test-path constructor calls.
func CompileInterface ¶
CompileInterface compiles TOL source into a textual .abi interface declaration.
func CompileInterfaceWithOptions ¶
func CompileInterfaceWithOptions(source []byte, name string, opts *InterfaceOptions) ([]byte, error)
CompileInterfaceWithOptions compiles TOL source into textual .abi with options.
func CompilePackage ¶
func CompilePackage(source []byte, name string, opts *PackageOptions) ([]byte, error)
CompilePackage compiles source into a deterministic .tor package. For single-contract files the behaviour is identical to before. For multi-contract files every contract is compiled to its own .toc/.abi entry. PackageOptions path overrides (ArtifactPath, InterfacePath, InterfaceName) are applied only when there is exactly one contract; they are ignored for multi-contract packages.
func CompileSourceToBytecode ¶
CompileSourceToBytecode compiles Lua source into deterministic bytecode.
func EncodeArtifact ¶
EncodeArtifact serializes a compiled artifact into deterministic binary bytes.
func EncodeFunctionProto ¶
func EncodeFunctionProto(proto *FunctionProto) ([]byte, error)
EncodeFunctionProto serializes an executable function prototype into a deterministic bytecode blob.
func EncodePackage ¶
EncodePackage serializes manifest + files into deterministic .tor bytes.
func IsArtifact ¶
IsArtifact reports whether the input starts with .toc magic bytes.
func IsBytecode ¶
IsBytecode reports whether the input starts with tolang bytecode magic bytes.
func LVAsString ¶
LVAsString returns string representation of a given LValue if the LValue is a string or number, otherwise an empty string.
func LVCanConvToString ¶
LVCanConvToString returns true if a given LValue is a string or number otherwise false.
func Lu256Cmp ¶
Lu256Cmp is the exported comparison function for LUint256. Returns -1 if a < b, 0 if a == b, +1 if a > b.
func NewOSFileResolver ¶
func NewOSFileResolver(baseDir string) sema.FileResolver
NewOSFileResolver returns a FileResolver that resolves paths relative to baseDir.
func OpenString ¶
func PackageHash ¶
PackageHash computes blake3 hash of a .tor archive.
func ParseModule ¶
ParseModule parses TOL source into a syntax tree.
func SignPackage ¶
SignPackage adds an ed25519 publisher signature to an existing .tor archive. privKeySeed must be a 32-byte ed25519 seed (hex-encoded or raw bytes). Returns the new .tor bytes with publisher_key and signature embedded in manifest.json.
func UpvalueIndex ¶
func ValidateInterface ¶
ValidateInterface performs a lightweight structural validation for textual .abi content.
func VerifyPackageSignature ¶
VerifyPackageSignature verifies the ed25519 publisher signature embedded in a .tor archive. Returns nil if the package is unsigned (no signature field) — unsigned packages are accepted. Returns an error if a signature is present but invalid or the public key is malformed.
func VerifySourceHash ¶
VerifySourceHash checks whether a decoded artifact matches the given source bytes.
Types ¶
type ApiError ¶
type ApiError struct {
Type ApiErrorType
Object LValue
StackTrace string
// Underlying error. This attribute is set only if the Type is ApiErrorFile or ApiErrorSyntax
Cause error
}
type ApiErrorType ¶
type ApiErrorType int
const ( ApiErrorSyntax ApiErrorType = iota ApiErrorFile ApiErrorRun ApiErrorError ApiErrorPanic )
type Artifact ¶
type Artifact struct {
Version uint16
Compiler string
ContractName string
Bytecode []byte
ABIJSON []byte
StorageLayoutJSON []byte
SourceHash string
BytecodeHash string
// Gas metadata (ArtifactFormatVersion >= 2)
MaxStackSlots uint32
BytecodeLen uint32
ContainsUnboundedLoop bool
}
Artifact is a decoded .toc payload.
func CompileAllArtifacts ¶
func CompileAllArtifacts(source []byte, name string, opts *CompileOptions) ([]*Artifact, error)
CompileAllArtifacts compiles all contracts in a multi-contract TOL source file, returning one Artifact per contract.
func DecodeArtifact ¶
DecodeArtifact deserializes a .toc payload into a structured artifact.
type ArtifactOptions ¶
type ArtifactOptions struct {
// IncludeSourceMap controls whether embedded bytecode contains source map/debug metadata.
// Default is false for reproducible builds.
IncludeSourceMap bool
// PackageSearchPaths provides explicit directories for package-style import
// resolution, passed through to the underlying CompileOptions.
PackageSearchPaths []string
}
ArtifactOptions controls .artifact compilation behavior.
type CompileError ¶
func (*CompileError) Error ¶
func (e *CompileError) Error() string
type CompileOptions ¶
type CompileOptions struct {
// IncludeSourceMap controls whether debug metadata (source map / line table /
// local/call/upvalue debug sections) is embedded in output bytecode.
// Default is false for reproducible builds.
IncludeSourceMap bool
// PackageSearchPaths provides explicit directories where package-style
// imports are resolved before falling back to the directory-walk heuristic.
// This eliminates the need for synthetic compile paths in tests.
PackageSearchPaths []string
}
CompileOptions controls bytecode debug metadata emission.
type DbgLocalInfo ¶
type FunctionProto ¶
type FunctionProto struct {
SourceName string
LineDefined int
LastLineDefined int
NumUpvalues uint8
NumParameters uint8
IsVarArg uint8
NumUsedRegisters uint8
Code []uint32
Constants []LValue
FunctionPrototypes []*FunctionProto
DbgSourcePositions []int
DbgLocals []*DbgLocalInfo
DbgCalls []DbgCall
DbgUpvalues []string
// contains filtered or unexported fields
}
func Compile ¶
func Compile(chunk []ast.Stmt, name string) (proto *FunctionProto, err error)
Compile compiles AST statements using a multi-stage pipeline: AST -> IR -> bytecode(FunctionProto).
func CompileIR ¶
func CompileIR(program *IRProgram) (*FunctionProto, error)
CompileIR lowers IR back to executable FunctionProto bytecode.
func DecodeFunctionProto ¶
func DecodeFunctionProto(data []byte) (*FunctionProto, error)
DecodeFunctionProto deserializes a bytecode blob into an executable function prototype.
func (*FunctionProto) String ¶
func (fp *FunctionProto) String() string
type IRFunction ¶
type IRFunction struct {
SourceName string
LineDefined int
LastLineDefined int
NumUpvalues uint8
NumParameters uint8
IsVarArg uint8
NumUsedRegs uint8
Instructions []IRInstruction
Constants []LValue
Functions []*IRFunction
DbgSourcePositions []int
DbgLocals []*DbgLocalInfo
DbgCalls []DbgCall
DbgUpvalues []string
}
IRFunction mirrors FunctionProto but stores decoded instructions.
type IRInstruction ¶
IRInstruction is a normalized representation of one VM instruction. It keeps decoded operands and original op encoding kind.
type IRProgram ¶
type IRProgram struct {
Name string
Root *IRFunction
}
IRProgram is a compiled unit root.
func BuildIR ¶
BuildIR parses and type-checks TOL source and prepares lowering to VM IR. Import declarations are resolved relative to the directory of name using the OS filesystem.
func BuildIRFromChunk ¶
BuildIRFromChunk compiles a Lua AST chunk to the IR layer.
func BuildIRFromLowered ¶
BuildIRFromLowered lowers a typed/lowered TOL program directly into VM IR (runtime mode). The emitted artifact contains tos.oninvoke dispatch but no constructor entry point.
func BuildIRFromLoweredInit ¶
BuildIRFromLoweredInit lowers a typed/lowered TOL program into VM IR for the init artifact. The emitted artifact contains only the constructor, called directly at module top-level (no tos.oninvoke, no tos.oncreate wrapper). Used for init_code in the init/runtime split.
func BuildIRFromProto ¶
func BuildIRFromProto(proto *FunctionProto, name string) *IRProgram
BuildIRFromProto decodes a FunctionProto into IR.
func BuildIRWithResolver ¶
func BuildIRWithResolver(source []byte, name string, resolver sema.FileResolver) (*IRProgram, error)
BuildIRWithResolver is like BuildIR but uses the provided resolver for import resolution. Pass nil to disable import resolution.
type InterfaceInfo ¶
InterfaceInfo is lightweight metadata extracted from textual .abi content.
func InspectInterface ¶
func InspectInterface(data []byte) (*InterfaceInfo, error)
InspectInterface validates and extracts lightweight metadata from textual .abi content.
type InterfaceOptions ¶
type InterfaceOptions struct {
InterfaceName string // interface name to emit (defaults to "I"+ContractName)
ContractName string // which contract to render (defaults to first contract in module)
}
InterfaceOptions configures .abi textual generation.
type LFunction ¶
type LFunction struct {
IsG bool
Env *LTable
Proto *FunctionProto
GFunction LGFunction
Upvalues []*Upvalue
}
func (*LFunction) Type ¶
func (fn *LFunction) Type() LValueType
type LGFunction ¶
type LNilType ¶
type LNilType struct{}
func (*LNilType) Type ¶
func (nl *LNilType) Type() LValueType
type LState ¶
type LState struct {
G *Global
Env *LTable
Panic func(*LState)
Dead bool
Options Options
// contains filtered or unexported fields
}
func (*LState) CheckAgent ¶
func (*LState) CheckFunction ¶
func (*LState) CheckInt64 ¶
func (*LState) CheckString ¶
func (*LState) CheckTable ¶
func (*LState) CheckType ¶
func (ls *LState) CheckType(n int, typ LValueType)
func (*LState) CheckTypes ¶
func (ls *LState) CheckTypes(n int, typs ...LValueType)
func (*LState) CheckUint256 ¶
func (*LState) CheckUserData ¶
func (*LState) CreateTable ¶
func (*LState) DoBytecode ¶
DoBytecode executes precompiled bytecode.
func (*LState) Error ¶
This function is equivalent to lua_error( http://www.lua.org/manual/5.1/manual.html#lua_error ).
func (*LState) GetMetatable ¶
func (*LState) GetTypeMetatable ¶
func (*LState) LoadBytecode ¶
LoadBytecode loads a precompiled bytecode blob.
func (*LState) NewClosure ¶
func (ls *LState) NewClosure(fn LGFunction, upvalues ...LValue) *LFunction
func (*LState) NewFunction ¶
func (ls *LState) NewFunction(fn LGFunction) *LFunction
func (*LState) NewFunctionFromProto ¶
func (ls *LState) NewFunctionFromProto(proto *FunctionProto) *LFunction
func (*LState) NewTypeMetatable ¶
func (*LState) NewUserData ¶
func (*LState) OpenLibs ¶
func (ls *LState) OpenLibs()
OpenLibs loads the built-in libraries. It is equivalent to running OpenLoad, then OpenBase, then iterating over the other OpenXXX functions in any order.
func (*LState) PreloadModule ¶
func (ls *LState) PreloadModule(name string, loader LGFunction)
Set a module loader to the package.preload table.
func (*LState) RaiseError ¶
This function is equivalent to luaL_error( http://www.lua.org/manual/5.1/manual.html#luaL_error ).
func (*LState) Register ¶
func (ls *LState) Register(name string, fn LGFunction)
func (*LState) RegisterModule ¶
func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue
func (*LState) RemoveCallerFrame ¶
func (ls *LState) RemoveCallerFrame() *callFrame
RemoveCallerFrame removes the stack frame above the current stack frame. This is useful in tail calls. It returns the new current frame.
func (*LState) SetGasLimit ¶
SetGasLimit configures the maximum number of VM instructions this LState may execute. Must be called before DoString/DoFile/Call. Zero means unlimited.
func (*LState) SetLineHook ¶
SetLineHook installs a hook function that is called after each VM instruction with the FunctionProto.SourceName and the source line from DbgSourcePositions. Pass nil to disable. Host hooks are disabled by default and must be enabled with Options.AllowHostHooks for off-chain testing/debugging only.
func (*LState) SetMetatable ¶
func (*LState) ToFunction ¶
func (*LState) ToStringMeta ¶
ToStringMeta returns string representation of given LValue. This method calls the `__tostring` meta method if defined. If __tostring is absent but __name is in the metatable, falls back to the stable type label in __name. Unlike stock Lua, TOL must never expose host pointer addresses in contract-visible strings.
func (*LState) ToUserData ¶
func (*LState) TypeError ¶
func (ls *LState) TypeError(n int, typ LValueType)
type LTable ¶
type LTable struct {
Metatable LValue
// contains filtered or unexported fields
}
func (*LTable) ForEach ¶
ForEach iterates over this table of elements, yielding each in turn to a given function.
func (*LTable) LenWithCost ¶
func (*LTable) MaxNWithCost ¶
func (*LTable) Next ¶
This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ).
func (*LTable) RawGet ¶
RawGet returns an LValue associated with a given key without __index metamethod.
func (*LTable) RawGetH ¶
RawGet returns an LValue associated with a given key without __index metamethod.
func (*LTable) RawGetInt ¶
RawGetInt returns an LValue at position `key` without __index metamethod.
func (*LTable) RawGetString ¶
RawGetString returns an LValue associated with a given key without __index metamethod.
func (*LTable) RawSet ¶
RawSet sets a given LValue to a given index without the __newindex metamethod. It is recommended to use `RawSetString` or `RawSetInt` for performance if you already know the given LValue is a string or number.
func (*LTable) RawSetH ¶
RawSetH sets a given LValue to a given index without the __newindex metamethod.
func (*LTable) RawSetInt ¶
RawSetInt sets a given LValue at a position `key` without the __newindex metamethod.
func (*LTable) RawSetString ¶
RawSetString sets a given LValue to a given string index without the __newindex metamethod.
func (*LTable) Type ¶
func (tb *LTable) Type() LValueType
type LUint256 ¶
type LUint256 struct {
// contains filtered or unexported fields
}
LUint256 is a 256-bit unsigned integer stored as four 64-bit words in little-endian order: lo holds bits 0–63, ml bits 64–127, mh bits 128–191, hi bits 192–255. Simple operations (add, sub, bitwise, shifts, compare) are implemented natively with math/bits; complex operations (div, mod, pow) bridge to math/big.Int.
func LVAsUint256 ¶
LVAsUint256 tries to convert a given LValue to a uint256.
func Lu256FromUint64 ¶
Lu256FromUint64 creates an LUint256 from a uint64.
func (LUint256) Type ¶
func (nm LUint256) Type() LValueType
type LValue ¶
type LValue interface {
String() string
Type() LValueType
}
type LValueType ¶
type LValueType int
const ( LTNil LValueType = iota LTBool LTUint256 LTString LTAgent LTFunction LTUserData LTTable )
func (LValueType) String ¶
func (vt LValueType) String() string
type OSFileResolver ¶
OSFileResolver is a sema.FileResolver that reads files from the OS filesystem. Relative import paths are resolved against BaseDir.
PackageSearchPaths provides explicit directories where package-style imports are resolved before falling back to the walk-up heuristic. Each entry is a root directory that may contain package family subdirectories (e.g., if PackageSearchPaths includes "/repo/openlib" then "tolang.openlib.account" will check "/repo/openlib/account/" first).
func (*OSFileResolver) ListPackage ¶
func (r *OSFileResolver) ListPackage(pkgPath string) ([]string, error)
ListPackage implements sema.PackageLister. It returns the names of all TOL contracts/interfaces available in pkgPath by scanning the corresponding directory (e.g. "tol.lang" -> <base>/tol/lang/). Only files with recognised TOL extensions (.tol, .abi, .toc, .tor) are listed; the extension is stripped to produce the bare contract name.
type OpenlibReleaseArtifacts ¶
type OpenlibReleaseArtifacts struct {
ArtifactPath string
ArtifactTOC []byte
InterfacePath string
InterfaceABI []byte
InitPath string
InitTOC []byte
PackageTOR []byte
}
OpenlibReleaseArtifacts is the deterministic release payload generated from a openlib source file.
func BuildOpenlibReleaseArtifacts ¶
func BuildOpenlibReleaseArtifacts(source []byte, sourcePath string, entry OpenlibReleaseEntry) (*OpenlibReleaseArtifacts, error)
BuildOpenlibReleaseArtifacts compiles a openlib source file into deterministic release artifacts (.toc/.abi/init .toc if needed/.tor).
type OpenlibReleaseEntry ¶
type OpenlibReleaseEntry struct {
Family string
Contract string
SourcePath string
SourcePackagePath string
ReleasePackageName string
}
OpenlibReleaseEntry describes one published openlib contract artifact set.
func OpenlibReleaseCatalog ¶
func OpenlibReleaseCatalog() []OpenlibReleaseEntry
OpenlibReleaseCatalog returns the published openlib contract set.
type Options ¶
type Options struct {
// Call stack size. This defaults to `lua.CallStackSize`.
CallStackSize int
// Data stack size. This defaults to `lua.RegistrySize`.
RegistrySize int
// Allow the registry to grow from the registry size specified up to a value of RegistryMaxSize. A value of 0
// indicates no growth is permitted. The registry will not shrink again after any growth.
RegistryMaxSize int
// If growth is enabled, step up by an additional `RegistryGrowStep` each time to avoid having to resize too often.
// This defaults to `lua.RegistryGrowStep`
RegistryGrowStep int
// Controls whether or not libraries are opened by default
SkipOpenLibs bool
// Tells whether a Go stacktrace should be included in a Lua stacktrace when panics occur.
IncludeGoStackTrace bool
// If `MinimizeStackMemory` is set, the call stack will be automatically grown or shrank up to a limit of
// `CallStackSize` in order to minimize memory usage. This does incur a slight performance penalty.
MinimizeStackMemory bool
// AllowHostHooks enables host-installed debug hooks such as SetLineHook.
// It is disabled by default so consensus execution remains gas-driven only.
AllowHostHooks bool
}
Options is a configuration that is used to create a new LState.
type Package ¶
Package is a decoded .tor archive payload.
func DecodePackage ¶
DecodePackage deserializes .tor bytes and validates manifest/files.
type PackageOptions ¶
type PackageOptions struct {
PackageName string
PackageVersion string
ArtifactPath string
InterfacePath string
InterfaceName string
// IncludeSourceMap controls whether embedded .toc bytecode contains source map/debug metadata.
// nil means default-off for reproducible builds.
IncludeSourceMap *bool
IncludeSource bool
SourcePath string
// SigningKey is an ed25519 private key seed (32 bytes) used to sign the package.
// If nil, the package is produced unsigned. Unsigned packages are always accepted.
SigningKey []byte
}
PackageOptions configures one-shot .tol -> .tor compilation.
Source Files
¶
- agent.go
- alloc.go
- auxlib.go
- baselib.go
- bytecode.go
- compile.go
- config.go
- cryptolib.go
- function.go
- ir.go
- linit.go
- mappinglib.go
- mathlib.go
- opcode.go
- openlib_release.go
- package.go
- resource_gas.go
- state.go
- string_limit.go
- stringlib.go
- table.go
- tablelib.go
- tol_api.go
- tol_artifact.go
- tol_interface.go
- tol_ir_direct_lowering.go
- tol_package.go
- uint256.go
- utils.go
- value.go
- vm.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
openlib-export
command
|
|
|
tolang
command
|
|
|
Package metadata defines the stable, versioned metadata schema for the GTOS 2046 architecture.
|
Package metadata defines the stable, versioned metadata schema for the GTOS 2046 architecture. |
|
Lua pattern match functions for Go
|
Lua pattern match functions for Go |
|
tol
|
|
|
format
Package format implements canonical formatting for TOL source files.
|
Package format implements canonical formatting for TOL source files. |
|
test
Package toltest provides the P2 test runner for TOL test blocks.
|
Package toltest provides the P2 test runner for TOL test blocks. |