Documentation
¶
Overview ¶
glasm: a Lua 5.5 VM, compiler, and Lua→wasm backend in Go — a fork of yuin/gopher-lua (upstream copyright and license in LICENSE).
Index ¶
- Constants
- Variables
- func FormatVarInfo(kind, name string) string
- func FuncNameFromCode(p *FunctionProto, pc int) (kind, name string)
- func GetObjName(p *FunctionProto, lastpc, reg int) (kind, name string)
- func LVAsBool(v LValue) bool
- func LVAsString(v LValue) string
- func LVCanConvToString(v LValue) bool
- func LVIsFalse(v LValue) bool
- func LocalNameAt(p *FunctionProto, localnum, pc int) (string, bool)
- func OpCodeMax() int
- func OpCreateABCk(op, a, b, c, k int) uint32
- func OpCreateABx(op, a, bx int) uint32
- func OpCreateAsBx(op, a, sbx int) uint32
- func OpCreateAx(op, ax int) uint32
- func OpCreateSJ(op, sj int) uint32
- func OpCreatevABCk(op, a, b, c, k int) uint32
- func OpGetArgA(inst uint32) int
- func OpGetArgAx(inst uint32) int
- func OpGetArgB(inst uint32) int
- func OpGetArgBx(inst uint32) int
- func OpGetArgC(inst uint32) int
- func OpGetArgSbx(inst uint32) int
- func OpGetArgk(inst uint32) int
- func OpGetArgsJ(inst uint32) int
- func OpGetArgvB(inst uint32) int
- func OpGetArgvC(inst uint32) int
- func OpGetOpCode(inst uint32) int
- func OpenBase(L *LState) int
- func OpenChannel(L *LState) int
- func OpenCoroutine(L *LState) int
- func OpenDebug(L *LState) int
- func OpenIo(L *LState) int
- func OpenMath(L *LState) int
- func OpenOs(L *LState) int
- func OpenPackage(L *LState) int
- func OpenString(L *LState) int
- func OpenTable(L *LState) int
- func OpenUTF8(L *LState) int
- func UpvalName(p *FunctionProto, uv int) string
- func UpvalueIndex(i int) int
- type ApiError
- type ApiErrorType
- type CompileError
- type DbgCall
- type DbgLocalInfo
- type Debug
- type FunctionProto
- type Global
- type LBool
- type LChannel
- type LFunction
- type LGFunction
- type LInteger
- type LNilType
- type LNumber
- 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) CheckAny(n int) LValue
- func (ls *LState) CheckBool(n int) bool
- func (ls *LState) CheckChannel(n int) chan LValue
- func (ls *LState) CheckFunction(n int) *LFunction
- func (ls *LState) CheckInt(n int) int
- func (ls *LState) CheckInt64(n int) int64
- func (ls *LState) CheckNumber(n int) LNumber
- 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) CheckThread(n int) *LState
- func (ls *LState) CheckType(n int, typ LValueType)
- func (ls *LState) CheckTypes(n int, typs ...LValueType)
- func (ls *LState) CheckUserData(n int) *LUserData
- func (ls *LState) Close()
- func (ls *LState) Concat(values ...LValue) string
- func (ls *LState) Context() context.Context
- func (ls *LState) CreateTable(acap, hcap int) *LTable
- func (ls *LState) DoFile(path string) 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) 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) LoadEnv(reader io.Reader, name string, env LValue) (*LFunction, error)
- func (ls *LState) LoadFile(path string) (*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) NewThread() (*LState, context.CancelFunc)
- 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) OptBool(n int, d bool) bool
- func (ls *LState) OptChannel(n int, ch chan LValue) chan LValue
- 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) OptNumber(n int, d LNumber) LNumber
- func (ls *LState) OptString(n int, d string) string
- func (ls *LState) OptTable(n int, d *LTable) *LTable
- 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) RemoveContext() context.Context
- func (ls *LState) Replace(idx int, value LValue)
- func (ls *LState) Resume(th *LState, fn *LFunction, args ...LValue) (ResumeState, error, []LValue)
- func (ls *LState) SetContext(ctx context.Context)
- 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) SetGlobal(name string, value LValue)
- func (ls *LState) SetLocal(dbg *Debug, no int, lv LValue) string
- func (ls *LState) SetMetatable(obj LValue, mt LValue)
- func (ls *LState) SetMx(mx int)
- 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) Status(th *LState) string
- func (ls *LState) String() string
- func (ls *LState) ToBool(n int) bool
- func (ls *LState) ToChannel(n int) chan LValue
- func (ls *LState) ToFunction(n int) *LFunction
- func (ls *LState) ToInt(n int) int
- func (ls *LState) ToInt64(n int) int64
- func (ls *LState) ToNumber(n int) LNumber
- func (ls *LState) ToString(n int) string
- func (ls *LState) ToStringMeta(lv LValue) LValue
- func (ls *LState) ToTable(n int) *LTable
- func (ls *LState) ToThread(n int) *LState
- func (ls *LState) ToUserData(n int) *LUserData
- func (ls *LState) Type() LValueType
- func (ls *LState) TypeError(n int, typ LValueType)
- func (ls *LState) Where(level int) string
- func (ls *LState) XMoveTo(other *LState, n int)
- func (ls *LState) Yield(values ...LValue) int
- 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) Len() int
- func (tb *LTable) MaxN() int
- func (tb *LTable) Next(key LValue) (LValue, LValue)
- 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) String() string
- func (tb *LTable) Type() LValueType
- type LUserData
- type LValue
- type LValueType
- type Options
- type P
- type ResumeState
- type Upvaldesc
- type Upvalue
Constants ¶
const ( VarArgHidden uint8 = 1 // PF_VAHID — hidden extra args (stock default) VarArgTable uint8 = 2 // PF_VATAB — materialized vararg table )
Vararg model flags (U5b, stock lobject.h PF_*): every vararg function starts hidden-args (VARARGPREP copies func+params above the extras and shifts the frame); a whole-value use / index write / upvalue capture of the named parameter promotes the function to the table model at finish time (needvatab — VARARGPREP then builds {1..n, n=n} into the param slot, GETVARG rewrites to GETTABLE, VARARG gets k=1). NumParameters counts the fixed params only — the vararg parameter itself occupies the register AT NumParameters, reserved by parlist like stock's `adjustlocalvars(ls, 1)` + `luaK_reserveregs`.
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" // ChannelLibName is the name of the channel Library. ChannelLibName = "channel" // CoroutineLibName is the name of the coroutine Library. CoroutineLibName = "coroutine" // UTF8LibName is the name of the utf8 Library (U3e). UTF8LibName = "utf8" )
const ( OP_MOVE int = iota /* A B R[A] := R[B] */ OP_LOADI /* A sBx R[A] := sBx */ OP_LOADF /* A sBx R[A] := (float)sBx */ OP_LOADK /* A Bx R[A] := K[Bx] */ OP_LOADKX /* A R[A] := K[extra arg] */ OP_LOADFALSE /* A R[A] := false */ OP_LFALSESKIP /* A R[A] := false; pc++ */ OP_LOADTRUE /* A R[A] := true */ OP_LOADNIL /* A B R[A], R[A+1], ..., R[A+B] := nil */ OP_GETUPVAL /* A B R[A] := UpValue[B] */ OP_SETUPVAL /* A B UpValue[B] := R[A] */ OP_GETTABUP /* A B C R[A] := UpValue[B][K[C]:string] */ OP_GETTABLE /* A B C R[A] := R[B][R[C]] */ OP_GETI /* A B C R[A] := R[B][C] */ OP_GETFIELD /* A B C R[A] := R[B][K[C]:string] */ OP_SETTABUP /* A B C UpValue[A][K[B]:string] := RK(C) */ OP_SETTABLE /* A B C R[A][R[B]] := RK(C) */ OP_SETI /* A B C R[A][B] := RK(C) */ OP_SETFIELD /* A B C R[A][K[B]:string] := RK(C) */ OP_NEWTABLE /* A vB vC k R[A] := {} */ OP_SELF /* A B C R[A+1] := R[B]; R[A] := R[B][K[C]:string] */ OP_ADDI /* A B sC R[A] := R[B] + sC */ OP_ADDK /* A B C R[A] := R[B] + K[C]:number */ OP_SUBK /* A B C R[A] := R[B] - K[C]:number */ OP_MULK /* A B C R[A] := R[B] * K[C]:number */ OP_MODK /* A B C R[A] := R[B] % K[C]:number */ OP_POWK /* A B C R[A] := R[B] ^ K[C]:number */ OP_DIVK /* A B C R[A] := R[B] / K[C]:number */ OP_IDIVK /* A B C R[A] := R[B] // K[C]:number */ OP_BANDK /* A B C R[A] := R[B] & K[C]:integer */ OP_BORK /* A B C R[A] := R[B] | K[C]:integer */ OP_BXORK /* A B C R[A] := R[B] ~ K[C]:integer */ OP_SHLI /* A B sC R[A] := sC << R[B] */ OP_SHRI /* A B sC R[A] := R[B] >> sC */ OP_ADD /* A B C R[A] := R[B] + R[C] */ OP_SUB /* A B C R[A] := R[B] - R[C] */ OP_MUL /* A B C R[A] := R[B] * R[C] */ OP_MOD /* A B C R[A] := R[B] % R[C] */ OP_POW /* A B C R[A] := R[B] ^ R[C] */ OP_DIV /* A B C R[A] := R[B] / R[C] */ OP_IDIV /* A B C R[A] := R[B] // R[C] */ OP_BAND /* A B C R[A] := R[B] & R[C] */ OP_BOR /* A B C R[A] := R[B] | R[C] */ OP_BXOR /* A B C R[A] := R[B] ~ R[C] */ OP_SHL /* A B C R[A] := R[B] << R[C] */ OP_SHR /* A B C R[A] := R[B] >> R[C] */ OP_MMBIN /* A B C call C metamethod over R[A] and R[B] */ OP_MMBINI /* A sB C k call C metamethod over R[A] and sB */ OP_MMBINK /* A B C k call C metamethod over R[A] and K[B] */ OP_UNM /* A B R[A] := -R[B] */ OP_BNOT /* A B R[A] := ~R[B] */ OP_NOT /* A B R[A] := not R[B] */ OP_LEN /* A B R[A] := #R[B] */ OP_CONCAT /* A B R[A] := R[A].. ... ..R[A + B - 1] */ OP_CLOSE /* A close all upvalues >= R[A] */ OP_TBC /* A mark variable A "to be closed" */ OP_JMP /* sJ pc += sJ */ OP_EQ /* A B k if ((R[A] == R[B]) ~= k) then pc++ */ OP_LT /* A B k if ((R[A] < R[B]) ~= k) then pc++ */ OP_LE /* A B k if ((R[A] <= R[B]) ~= k) then pc++ */ OP_EQK /* A B k if ((R[A] == K[B]) ~= k) then pc++ */ OP_EQI /* A sB k if ((R[A] == sB) ~= k) then pc++ */ OP_LTI /* A sB k if ((R[A] < sB) ~= k) then pc++ */ OP_LEI /* A sB k if ((R[A] <= sB) ~= k) then pc++ */ OP_GTI /* A sB k if ((R[A] > sB) ~= k) then pc++ */ OP_GEI /* A sB k if ((R[A] >= sB) ~= k) then pc++ */ OP_TEST /* A k if (not R[A] == k) then pc++ */ OP_TESTSET /* A B k if (not R[B] == k) then pc++ else R[A] := R[B] */ 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 k return R[A](R[A+1], ... ,R[A+B-1]) */ OP_RETURN /* A B C k return R[A], ... ,R[A+B-2] */ OP_RETURN0 /* return */ OP_RETURN1 /* A return R[A] */ OP_FORLOOP /* A Bx update counters; if loop continues then pc-=Bx */ OP_FORPREP /* A Bx <check values and prepare counters>; if not to run then pc+=Bx+1 */ OP_TFORPREP /* A Bx create upvalue for R[A + 3]; pc+=Bx */ OP_TFORCALL /* A C R[A+4], ... ,R[A+3+C] := R[A](R[A+1], R[A+2]) */ OP_TFORLOOP /* A Bx if R[A+2] ~= nil then { R[A]=R[A+2]; pc -= Bx } */ OP_SETLIST /* A vB vC k R[A][vC+i] := R[A+i], 1 <= i <= vB */ OP_CLOSURE /* A Bx R[A] := closure(KPROTO[Bx]) */ OP_VARARG /* A B C k R[A], ..., R[A+C-2] = varargs */ OP_GETVARG /* A B C R[A] := R[B][R[C]], R[B] is vararg parameter */ OP_ERRNNIL /* A Bx raise error if R[A] ~= nil (K[Bx - 1] is global name) */ OP_VARARGPREP /* (adjust varargs) */ OP_EXTRAARG /* Ax extra (larger) argument for previous opcode */ )
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 LNumberBit = 64
const LNumberScanFormat = "%f"
const LuaVersion = "Lua 5.5"
U5f: _VERSION re-pinned to the 5.5 core the engine now implements (the 5.2→5.5 program, U1..U5) — a script feature-detecting on it must see the integer/float split, _ENV, and the 5.5 libraries. _GLASM_VERSION keeps the implementation identity (renamed from the gopher-lua-era _GOPHER_LUA_VERSION at the D12 release).
const MultRet = -1
const PackageAuthors = "Yusuke Inuzuka"
const PackageName = "glasm"
const RegistryIndex = -10000
const VarArgAny = VarArgHidden | VarArgTable
VarArgAny is the isvararg(p) test mask (either model marks the proto).
Variables ¶
var CallStackSize = 256
var FieldsPerFlush = 50
var LFalse = LBool(false)
var LNil = LValue(&LNilType{})
var LTrue = LBool(true)
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 MaxArrayIndex = 67108864
var MaxTableGetLoop = 100
var PackageCopyRight = PackageName + " " + PackageVersion + " (fork of GopherLua) Copyright (C) 2015 -2017 " + PackageAuthors
PackageCopyRight must stay a var: it is computed from PackageVersion at package init, after the linker has applied any -X override.
var PackageVersion = "1.3.3"
PackageVersion is overridden at link time by the Makefile (make build) via -ldflags "-X github.com/pschlump/glasm.PackageVersion=<version>"; the literal below is the fallback for plain go builds and tests.
var RegistryGrowStep = 32
var RegistrySize = 256 * 20
Functions ¶
func FormatVarInfo ¶
FormatVarInfo is formatVarInfo exported so the backend renders the identical " (%s '%s')" strings the interp raises.
func FuncNameFromCode ¶
func FuncNameFromCode(p *FunctionProto, pc int) (kind, name string)
FuncNameFromCode is funcnamefromcode exported for the backend's call-error hints (the callee name of the instruction at pc).
func GetObjName ¶
func GetObjName(p *FunctionProto, lastpc, reg int) (kind, name string)
GetObjName is getobjname exported for the wasm backend's varinfo hints (U5e, row 71): the backend precomputes the interp's debug-name answer at compile time — the raise site's lastpc follows the cf.Pc-1 convention (the instruction that raised; findSetReg itself steps back over an MMBIN* slot at that pc).
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 LocalNameAt ¶
func LocalNameAt(p *FunctionProto, localnum, pc int) (string, bool)
LocalNameAt is localNameAt exported for the wasm backend's OP_TBC lowering (U4f): the non-closable raise names the variable, and the backend precomputes the interp's DbgLocals answer at compile time.
func OpCreateABCk ¶
func OpCreateABx ¶
func OpCreateAsBx ¶
func OpCreateAx ¶
func OpCreateSJ ¶
func OpCreatevABCk ¶
func OpGetArgAx ¶
func OpGetArgBx ¶
func OpGetArgSbx ¶
func OpGetArgsJ ¶
func OpGetArgvB ¶
func OpGetArgvC ¶
func OpGetOpCode ¶
func OpenChannel ¶
func OpenCoroutine ¶
func OpenPackage ¶
func OpenString ¶
func UpvalName ¶
func UpvalName(p *FunctionProto, uv int) string
UpvalName is upvalName exported for the backend's GETTABUP/SETTABUP object hints (the table operand is an upvalue cell — varinfo's getupvalname arm).
func UpvalueIndex ¶
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 CompileError ¶
func (*CompileError) Error ¶
func (e *CompileError) Error() string
type DbgLocalInfo ¶
type Debug ¶
type Debug struct {
Name string
NameWhat string
What string
Source string
CurrentLine int
NUpvalues int
LineDefined int
LastLineDefined int
// U5c (stock lua_Debug): 'u' adds nparams/isvararg, 't' adds
// istailcall/extraargs — extraargs is the __call-chain count (the
// ci's MAX_CCMT bits, ldebug.c:359), NOT the vararg count: a plain
// vararg call answers 0, a chain-fed call answers its hop count.
NParams int
IsVarArg bool
IsTailCall bool
ExtraArgs int
// 'r' ftransfer/ntransfer (no hooks in the fork: always 0) and 'L'
// activelines (nil for C functions, collectvalidlines' table).
FTransfer int
NTransfer int
ActiveLines *LTable
// contains filtered or unexported fields
}
type FunctionProto ¶
type FunctionProto struct {
SourceName string
// SourceIsNull marks stock's NULL source (U5f): a stripped binary
// chunk carries no source string, and getinfo/where render "?"
// shapes for it. A TEXT load with an explicit empty chunkname
// (load(s, "")) is a REAL empty source — `[string ""]` (db.lua:73)
// — so "" alone must not take the NULL path. Only the undump sets
// the flag (dumping an empty TString is size 0, identical to NULL,
// so every undumped empty source IS stock's NULL).
SourceIsNull bool
LineDefined int
LastLineDefined int
NumUpvalues uint8
NumParameters uint8
IsVarArg uint8
NumUsedRegisters uint8
Code []uint32
Constants []LValue
FunctionPrototypes []*FunctionProto
Upvalues []Upvaldesc
// EnvUpvalueIndex: the upvalue slot holding _ENV, the table global
// accesses resolve through (5.2 scheme, upgrade plan D3). -1 when the
// function references no globals. Used by the loader to seed the
// main chunk's _ENV cell (GETTABUP/SETTABUP address the cell by the
// B operand directly).
EnvUpvalueIndex int8
DbgSourcePositions []int
DbgLocals []*DbgLocalInfo
DbgCalls []DbgCall
DbgUpvalues []string
// contains filtered or unexported fields
}
func (*FunctionProto) String ¶
func (fp *FunctionProto) String() string
func (*FunctionProto) StringConstants ¶
func (fp *FunctionProto) StringConstants() []string
StringConstants exposes the string-constants table used by the *KS opcodes and SETGLOBAL (backend access).
type LChannel ¶
type LChannel chan LValue
func (LChannel) Type ¶
func (ch LChannel) Type() LValueType
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 LInteger ¶
type LInteger int64
LInteger is the 64-bit integer subtype of "number" (5.3+, U2/D1). Integer-ness is observable: tostring(2) == "2" while tostring(2.0) == "2.0" (once float printing re-pins at U5), table keys normalize t[2.0] to the integer 2, and //, shifts and integer for-loops require it. Arithmetic on mixed subtypes promotes to float.
func (LInteger) Type ¶
func (nm LInteger) Type() LValueType
type LNilType ¶
type LNilType struct{}
func (*LNilType) Type ¶
func (nl *LNilType) Type() LValueType
type LNumber ¶
type LNumber float64
func LVAsNumber ¶
LVAsNumber tries to convert a given LValue to a number (float view). The integer subtype converts to its float value; use parseNumber when the syntactic subtype of a string must be preserved.
func (LNumber) String ¶
String is the engine-wide float spelling: the stock tostringbuffFloat (%.15g, re-read, %.17g, ".0" on integer-looking results — U3i, the D7 re-pin pulled forward because math.lua's numeral round-trip asserts tostring(1.0) == "1.0"). The old Go dialect printed "1" there.
func (LNumber) Type ¶
func (nm LNumber) Type() LValueType
type LState ¶
type LState struct {
G *Global
Parent *LState
Env *LTable
Panic func(*LState)
Dead bool
Options Options
// contains filtered or unexported fields
}
func (*LState) CheckChannel ¶
Checks whether the given index is an LChannel and returns this channel.
func (*LState) CheckFunction ¶
func (*LState) CheckInt64 ¶
func (*LState) CheckNumber ¶
func (*LState) CheckString ¶
func (*LState) CheckTable ¶
func (*LState) CheckThread ¶
func (*LState) CheckType ¶
func (ls *LState) CheckType(n int, typ LValueType)
func (*LState) CheckTypes ¶
func (ls *LState) CheckTypes(n int, typs ...LValueType)
func (*LState) CheckUserData ¶
func (*LState) Context ¶
Context returns the LState's context. To change the context, use WithContext.
func (*LState) CreateTable ¶
func (*LState) Error ¶
This function is equivalent to lua_error( http://www.lua.org/manual/5.1/manual.html#lua_error ).
func (*LState) GetInfo ¶
GetInfo is lua_getinfo over the fork's Debug struct (U5c: stock's option-filtered fields). A leading '>' queries the given function instead of dbg.frame's — stock sets ci=NULL there, so the frame-relative options answer their no-frame defaults ('l' -1, 'n' empty, 't' false/0) while 'S'/'u' still read the function. Returns the 'f' payload (nil without 'f'); the activelines table lands in Debug.ActiveLines ('L'). An option outside "flnSrtuL" returns the invalid-option error the debug library converts to its argerror (stock lua_getinfo answers 0 and db_getinfo raises).
func (*LState) GetMetatable ¶
func (*LState) GetStack ¶
GetStack is lua_getstack. Cross-thread queries over a SUSPENDED thread (U5c) run over stock's continuation model: 5.5 keeps the yielded C function's CallInfo alive while the thread is suspended, so level 0 is that C frame and the thread's own frames start at level 1. The fork's Go stack unwinds the yield's G frame instead — the running and normal-at-resume threads keep their boundary frame as a REAL frame, only the suspended ones need the shift. Level 0 hands back a synthetic G frame (C-shaped for 'S'/'u'/'l'/'t'; 'f' on it is not stock's yield function — unpinned corner).
func (*LState) GetTypeMetatable ¶
func (*LState) Load ¶
Load parses, compiles, and wraps a chunk as a callable function. The chunk's _ENV upvalue (D3) is seeded with the thread's environment.
func (*LState) LoadEnv ¶
LoadEnv is Load with an explicit chunk environment (5.2 load's env argument): the compiled main chunk's _ENV upvalue cell is seeded with env, so the chunk (and every closure it creates) resolves globals there. A nil env falls back to the thread environment; 5.5 accepts ANY value for env (calls.lua:415's `load(..., 123)` — only actual global accesses care that it is a table).
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) NewThread ¶
func (ls *LState) NewThread() (*LState, context.CancelFunc)
NewThread returns a new LState that shares with the original state all global objects. If the original state has context.Context, the new state has a new child context of the original state and this function returns its cancel function.
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) OptChannel ¶
If the given index is a LChannel, returns this channel. If this argument is absent or is nil, returns ch. Otherwise, raises an error.
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 ). U2f: the position target is the CURRENT frame when raised from Lua code (luaG_runerror semantics — the VM's own raises) and the caller when raised from a G function (luaL_error semantics) — and a G caller yields NO position (stock's luaL_where over a C frame is empty; the old skipg walk skipped straight past it).
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) RemoveContext ¶
RemoveContext removes the context associated with this LState and returns this context.
func (*LState) SetContext ¶
SetContext set a context ctx to this LState. The provided ctx must be non-nil.
func (*LState) SetMetatable ¶
func (*LState) SetMx ¶
Set maximum memory size. This function can only be called from the main thread.
func (*LState) ToFunction ¶
func (*LState) ToStringMeta ¶
ToStringMeta returns string representation of given LValue — the luaL_tolstring port (U3h): __tostring's result must be a string (a number converts, like lua_isstring); the default rendering for tables/functions/etc. is "kind: 0x..." with kind from a string __name metafield when present.
func (*LState) ToUserData ¶
func (*LState) Type ¶
func (ls *LState) Type() LValueType
func (*LState) TypeError ¶
func (ls *LState) TypeError(n int, typ LValueType)
TypeError is luaL_typeerror with the fork's type-tag spelling; the actual-operand side honors __name and reports "no value" when the argument is absent.
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) Next ¶
This function is equivalent to lua_next ( http://www.lua.org/manual/5.1/manual.html#lua_next ). Unlike RawGet/RawSet, the incoming key is NOT normalized: stock 5.5's findindex accepts array entries only for integer keys (keyinarray is ttisinteger-only) and hashes the raw key for the hash part, so the float spelling of an integer slot is an invalid key (baseNext screens it).
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. An out-of-array-range key reads the hash part (stock luaH_getint), so a {[math.mininteger]=10} table answers at negative indices too.
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 LUserData ¶
type LUserData struct {
Value interface{}
Env *LTable
Metatable LValue
// UserValue is the debug.getuservalue slot (U5c, stock uvalues[0]):
// any Lua value, nil by default — distinct from Env, the legacy 5.1
// environment table the fork's GetFEnv reads. UserValues is the slot
// capacity (stock newuserdatauv's nuvalue): stock's Lua-visible
// userdata — the io files — are created with ZERO slots, so
// debug.get/setuservalue answer nil for them (db.lua:434 pins it);
// NewUserData leaves 0 for the same posture.
UserValue LValue
UserValues int8
// Light marks a light userdata (U5c, stock LUA_VLIGHTUSERDATA): a
// bare pointer in Lua's clothing. It still types as "userdata"
// (5.5's typename table maps both tags to it), but full-userdata
// argument checks reject it naming "light userdata" (luaL_typeerror
// special case), base setmetatable refuses it, and its metatable is
// the per-basic-type table (debug.setmetatable territory), never a
// per-object one. debug.upvalueid is the only creator.
Light bool
}
func (*LUserData) Type ¶
func (ud *LUserData) Type() LValueType
type LValue ¶
type LValue interface {
String() string
Type() LValueType
}
type LValueType ¶
type LValueType int
const ( LTNil LValueType = iota LTBool LTNumber LTString LTFunction LTUserData LTThread LTTable LTChannel // LTInteger is the 5.3+ integer subtype (U2/D1). It is a distinct // LValueType so type switches can tell int from float, but it names // "number": Lua's type() must keep reporting the basic type. LTInteger )
func (LValueType) String ¶
func (vt LValueType) String() string
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
}
Options is a configuration that is used to create a new LState.
type ResumeState ¶
type ResumeState int
const ( ResumeOK ResumeState = iota ResumeYield ResumeError )
type Upvaldesc ¶
Upvaldesc is a compiled upvalue-capture descriptor (U2c, stock lobject.h Upvaldesc minus the kind field — <const> attributes arrive with U5): InStack captures the parent's register Idx, otherwise the parent's upvalue Idx. These replace the fork's old pseudo-instructions after OP_CLOSURE.
type Upvalue ¶
type Upvalue struct {
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
clua55-run
command
Command clua55-run runs a Lua script under stock C Lua 5.5.1 (the wasm oracle blob, lua55_sjlj.wasm) with the CLI-arg surface the other runners provide.
|
Command clua55-run runs a Lua script under stock C Lua 5.5.1 (the wasm oracle blob, lua55_sjlj.wasm) with the CLI-arg surface the other runners provide. |
|
glua
command
|
|
|
luabench
command
Command luabench measures the production EVAL postures for high-frequency scripts (U7c: promoted from note/bench-vs-orig/hostbench — the 2026-09-23 reference numbers in note/bench-vs-orig/out-hostbench.txt were produced by that harness with the same interp/cold/warm rows).
|
Command luabench measures the production EVAL postures for high-frequency scripts (U7c: promoted from note/bench-vs-orig/hostbench — the 2026-09-23 reference numbers in note/bench-vs-orig/out-hostbench.txt were produced by that harness with the same interp/cold/warm rows). |
|
luafuzz
command
Command luafuzz is the M6e differential fuzzer CLI: a deterministic seeded generator driving the testdiff engines, with a chunk- resumable soak designed for a laptop that sleeps and moves between networks daily (all state under -dir; every interruption is safe).
|
Command luafuzz is the M6e differential fuzzer CLI: a deterministic seeded generator driving the testdiff engines, with a chunk- resumable soak designed for a laptop that sleeps and moves between networks daily (all state under -dir; every interruption is safe). |
|
luawasm-run
command
Command luawasm-run executes a module saved by cmd/luawasmc against the C-Lua rt_* runtime (embedded lua55_rt.wasm, ABI v4) on wasmtime — or on the pure-Go wazero production engine when GLUA_WASM_ENGINE=wazero (ledger row 32: one blob, two hosts).
|
Command luawasm-run executes a module saved by cmd/luawasmc against the C-Lua rt_* runtime (embedded lua55_rt.wasm, ABI v4) on wasmtime — or on the pure-Go wazero production engine when GLUA_WASM_ENGINE=wazero (ledger row 32: one blob, two hosts). |
|
luawasmc
command
Command luawasmc compiles a Lua 5.5 script to a WebAssembly module.
|
Command luawasmc compiles a Lua 5.5 script to a WebAssembly module. |
|
perfcmp
command
Command perfcmp compares the glasm engines against native stock C Lua 5.5.1 on the luabench script set — wall time AND process memory.
|
Command perfcmp compares the glasm engines against native stock C Lua 5.5.1 on the luabench script set — wall time AND process memory. |
|
testdiff
command
Command testdiff runs a corpus across engines and reports log diffs.
|
Command testdiff runs a corpus across engines and reports log diffs. |
|
examples
|
|
|
eval
command
Command eval is the minimal host-package demonstration (design §6.3): compile once, run with KEYS/ARGV, print the reply values — plus one host function so the redis.call seam is visible end to end.
|
Command eval is the minimal host-package demonstration (design §6.3): compile once, run with KEYS/ARGV, print the reply values — plus one host function so the redis.call seam is visible end to end. |
|
evalserver
command
Command evalserver is the thread-proofing demonstration (design §6.3): concurrent EVALs against a pool of locked VMs — the deployment shape a daemon actually uses.
|
Command evalserver is the thread-proofing demonstration (design §6.3): concurrent EVALs against a pool of locked VMs — the deployment shape a daemon actually uses. |
|
sharedvm
command
Command sharedvm is the single-shared-VM deployment mode (design §6.3): one Lua memory image, many goroutines — VM.Run serializes on the image lock (A9) and scripts observe each other's globals, exactly like Redis-classic single-state script execution.
|
Command sharedvm is the single-shared-VM deployment mode (design §6.3): one Lua memory image, many goroutines — VM.Run serializes on the image lock (A9) and scripts observe each other's globals, exactly like Redis-classic single-state script execution. |
|
Package host is the public Go API a pure-Go daemon (the Ultima Redis clone) imports to run untrusted Lua scripts: compile to wasm, execute on wazero against the embedded production runtime blob, exchange values with in-script host functions (the redis.call seam).
|
Package host is the public Go API a pure-Go daemon (the Ultima Redis clone) imports to run untrusted Lua scripts: compile to wasm, execute on wazero against the embedded production runtime blob, exchange values with in-script host functions (the redis.call seam). |
|
Package luafuzz is the M6e differential fuzzer: a deterministic Lua program generator (design doc §8.4 L5) plus an interruptible, chunk-resumable soak runner (m6 plan §4.5/D6).
|
Package luafuzz is the M6e differential fuzzer: a deterministic Lua program generator (design doc §8.4 L5) plus an interruptible, chunk-resumable soak runner (m6 plan §4.5/D6). |
|
Package luawasm is the Lua→wasm backend (design doc §4): FunctionProto trees from the glasm frontend become wasm modules that share linear memory with the C runtime and call down through the rt_* ABI.
|
Package luawasm is the Lua→wasm backend (design doc §4): FunctionProto trees from the glasm frontend become wasm modules that share linear memory with the C runtime and call down through the rt_* ABI. |
|
Lua pattern match functions for Go
|
Lua pattern match functions for Go |
|
Package testdiff is the differential testing harness of the Lua→wasm project (docs/Lua-Wasm-Design-and-Test-Plan.md §7–§8, milestone M1).
|
Package testdiff is the differential testing harness of the Lua→wasm project (docs/Lua-Wasm-Design-and-Test-Plan.md §7–§8, milestone M1). |
|
Package wasm is a minimal, dependency-free emitter for WebAssembly 1.0/2.0 core binary modules.
|
Package wasm is a minimal, dependency-free emitter for WebAssembly 1.0/2.0 core binary modules. |