Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions base.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ var baseLibrary = []RegistryFunction{
return l.Top() // return all arguments
}
CheckAny(l, 1)
l.Remove(1) // remove condition
l.PushString("assertion failed!") // default message
l.SetTop(1) // leave only message (default if no other one)
return baseError(l) // call 'error'
l.Remove(1) // remove condition
l.PushString("assertion failed!") // default message
l.SetTop(1) // leave only message (default if no other one)
return baseError(l) // call 'error'
}},
{"collectgarbage", func(l *State) int {
switch opt, _ := OptString(l, 1, "collect"), OptInteger(l, 2, 0); opt {
Expand Down
17 changes: 8 additions & 9 deletions code.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ type function struct {
freeRegisterCount int
activeVariableCount int
firstLocal int
firstLabel int // Lua 5.4: first label index for this function (like C Lua's fs->firstlabel)
previousLine int // Lua 5.4: for relative line info encoding (per-function, like C Lua's FuncState)
iwthabs int // instructions without absolute line info
firstLabel int // Lua 5.4: first label index for this function (like C Lua's fs->firstlabel)
previousLine int // Lua 5.4: for relative line info encoding (per-function, like C Lua's FuncState)
iwthabs int // instructions without absolute line info
needClose bool // Lua 5.4: function has TBC variables (affects RETURN k-bit)
}

Expand Down Expand Up @@ -488,8 +488,8 @@ func (f *function) assertEqual(a, b interface{}) {

const (
lineInfoAbs = -0x80 // marker for absolute line info in lineInfo
limLineDiff = 0x80 // max absolute delta that fits in int8
maxIWthAbs = 128 // max instructions without absolute line info
limLineDiff = 0x80 // max absolute delta that fits in int8
maxIWthAbs = 128 // max instructions without absolute line info
)

func (f *function) encode(i instruction) int {
Expand Down Expand Up @@ -601,7 +601,7 @@ func (f *function) Jump() int {
return f.Concatenate(f.encodeJ(opJump, noJump), jumpPC)
}

func (f *function) JumpTo(target int) { f.PatchList(f.Jump(), target) }
func (f *function) JumpTo(target int) { f.PatchList(f.Jump(), target) }
func (f *function) ReturnNone() {
k := 0
if f.needClose {
Expand Down Expand Up @@ -1011,7 +1011,6 @@ func (f *function) ExpressionToValue(e exprDesc) exprDesc {
return f.DischargeVariables(e)
}


// exp2K tries to convert expression to a constant index in range.
// Returns (constant index, true) if successful, (0, false) otherwise.
func (f *function) exp2K(e exprDesc) (int, bool) {
Expand Down Expand Up @@ -1191,8 +1190,8 @@ func (f *function) Indexed(t, k exprDesc) exprDesc {
if t.kind == kindUpValue {
f.assert(f.isKstr(k))
r := makeExpression(kindIndexUp, 0)
r.table = t.info // upvalue index
r.index = k.info // string constant index
r.table = t.info // upvalue index
r.index = k.info // string constant index
return r
}
// table is in a register
Expand Down
12 changes: 6 additions & 6 deletions coroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var coroutineLibrary = []RegistryFunction{
co.hasError = false
// Reset call info to base (like C Lua)
co.callInfo = &co.baseCallInfo
co.errorFunction = 0 // clear any xpcall error handler
co.errorFunction = 0 // clear any xpcall error handler
co.status = threadStatusOK // temporarily OK so __close handlers can run
// Close TBC variables in protected mode with error chaining
closeErrVal := co.closeTBCProtected(0, nil)
Expand Down Expand Up @@ -47,9 +47,9 @@ var coroutineLibrary = []RegistryFunction{
{"create", func(l *State) int {
CheckType(l, 1, TypeFunction)
co := l.NewThread()
l.PushValue(1) // push function
XMove(l, co, 1) // move function to coroutine stack
return 1 // return the thread
l.PushValue(1) // push function
XMove(l, co, 1) // move function to coroutine stack
return 1 // return the thread
}},
{"resume", coroutineResume},
{"yield", func(l *State) int {
Expand Down Expand Up @@ -81,8 +81,8 @@ var coroutineLibrary = []RegistryFunction{
{"wrap", func(l *State) int {
CheckType(l, 1, TypeFunction)
l.NewThread()
l.PushValue(1) // push function
XMove(l, l.ToThread(-2), 1) // move function to coroutine stack
l.PushValue(1) // push function
XMove(l, l.ToThread(-2), 1) // move function to coroutine stack
l.PushGoClosure(coroutineWrapHelper, 1)
return 1
}},
Expand Down
24 changes: 13 additions & 11 deletions instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ var opNames = []string{
}

// Lua 5.4 instruction layout:
// iABC: op(7) | A(8) | k(1) | B(8) | C(8)
// iABx: op(7) | A(8) | Bx(17)
// iAsBx: op(7) | A(8) | sBx(17)
// iAx: op(7) | Ax(25)
// isJ: op(7) | sJ(25)
//
// iABC: op(7) | A(8) | k(1) | B(8) | C(8)
// iABx: op(7) | A(8) | Bx(17)
// iAsBx: op(7) | A(8) | sBx(17)
// iAx: op(7) | Ax(25)
// isJ: op(7) | sJ(25)
const (
sizeC = 8
sizeB = 8
Expand Down Expand Up @@ -312,12 +313,13 @@ func (i instruction) String() string {
}

// Lua 5.4 opmode format:
// bits 0-2: op mode (iABC=0, iABx=1, iAsBx=2, iAx=3, isJ=4)
// bit 3: instruction sets register A
// bit 4: operator is a test (next instruction must be a jump)
// bit 5: instruction uses 'L->top' set by previous instruction (when B == 0)
// bit 6: instruction sets 'L->top' for next instruction (when C == 0)
// bit 7: instruction is an MM instruction (call a metamethod)
//
// bits 0-2: op mode (iABC=0, iABx=1, iAsBx=2, iAx=3, isJ=4)
// bit 3: instruction sets register A
// bit 4: operator is a test (next instruction must be a jump)
// bit 5: instruction uses 'L->top' set by previous instruction (when B == 0)
// bit 6: instruction sets 'L->top' for next instruction (when C == 0)
// bit 7: instruction is an MM instruction (call a metamethod)
func opmode(mm, ot, it, t, a, m int) byte {
return byte(mm<<7 | ot<<6 | it<<5 | t<<4 | a<<3 | m)
}
Expand Down
8 changes: 4 additions & 4 deletions io.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ var ioLibrary = []RegistryFunction{
// iterator, file_stream, nil, file_stream (TBC)
forceOpen(l, CheckString(l, 1), "r")
l.Replace(1)
lines(l, true) // pushes iterator closure
l.PushValue(1) // push file stream as 2nd result
l.PushNil() // push nil as 3rd result
l.PushValue(1) // push file stream as 4th result (to-be-closed)
lines(l, true) // pushes iterator closure
l.PushValue(1) // push file stream as 2nd result
l.PushNil() // push nil as 3rd result
l.PushValue(1) // push file stream as 4th result (to-be-closed)
return 4
}},
{"open", func(l *State) int {
Expand Down
1 change: 0 additions & 1 deletion isolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,3 @@ func TestIsolateCallLine(t *testing.T) {
}
}
}

4 changes: 2 additions & 2 deletions lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ type Function func(state *State) int
type threadStatus byte

const (
threadStatusOK threadStatus = iota
threadStatusOK threadStatus = iota
threadStatusYield
threadStatusDead
)
Expand Down Expand Up @@ -722,7 +722,7 @@ func (l *State) finishOp() {
l.concat(total) // concat remaining (may yield again)
}
ci.frame[a] = l.stack[l.top-1] // move final result
l.top = ci.top // restore top
l.top = ci.top // restore top
case opClose, opReturn0, opReturn1:
// yielded closing variables — repeat instruction to close others
ci.savedPC--
Expand Down
8 changes: 4 additions & 4 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var tokens []string = []string{
type token struct {
t rune
n float64
i int64 // Lua 5.3: integer value
i int64 // Lua 5.3: integer value
s string
raw string // original source text for error messages (txtToken)
}
Expand All @@ -90,9 +90,9 @@ func (s *scanner) assert(cond bool) { s.l.assert(cond) }
func (s *scanner) syntaxError(message string) { s.scanError(message, s.t) }
func (s *scanner) errorExpected(t rune) { s.syntaxError(s.tokenToString(t) + " expected") }
func (s *scanner) numberError() { s.scanError("malformed number", tkNumber) }
func isNewLine(c rune) bool { return c == '\n' || c == '\r' }
func isDecimal(c rune) bool { return '0' <= c && c <= '9' }
func isAlpha(c rune) bool { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') }
func isNewLine(c rune) bool { return c == '\n' || c == '\r' }
func isDecimal(c rune) bool { return '0' <= c && c <= '9' }
func isAlpha(c rune) bool { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') }

func (s *scanner) tokenToString(t rune) string {
switch {
Expand Down
2 changes: 1 addition & 1 deletion string.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func scanFormat(l *State, fs string) string {
for i < len(fs) && strings.ContainsRune(allFlags, rune(fs[i])) {
i++
}
i++ // include the conversion specifier
i++ // include the conversion specifier
if i > 22 { // MAX_FORMAT - 10
Errorf(l, "invalid format (too long)")
}
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ type prototype struct {
constants []value
code []instruction
prototypes []prototype
lineInfo []int8 // Lua 5.4: relative line info
lineInfo []int8 // Lua 5.4: relative line info
absLineInfos []absLineInfo // Lua 5.4: absolute line info
localVariables []localVariable
upValues []upValueDesc
Expand Down
14 changes: 7 additions & 7 deletions undump.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type loadState struct {

// Lua 5.4 header: no IntSize/PointerSize fields
var header54 struct {
Signature [4]byte
Version, Format byte
Data [6]byte // LUAC_DATA: "\x19\x93\r\n\x1a\n"
InstructionSize byte
IntegerSize, NumberSize byte
TestInt int64 // LUAC_INT: 0x5678
TestNum float64 // LUAC_NUM: 370.5
Signature [4]byte
Version, Format byte
Data [6]byte // LUAC_DATA: "\x19\x93\r\n\x1a\n"
InstructionSize byte
IntegerSize, NumberSize byte
TestInt int64 // LUAC_INT: 0x5678
TestNum float64 // LUAC_NUM: 370.5
}

var (
Expand Down
3 changes: 1 addition & 2 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ func expectNext(ci *callInfo, expected opCode) instruction {
return i
}


func (l *State) executeSwitch() {
ci := l.callInfo
frame, closure, constants := newFrame(l, ci)
Expand Down Expand Up @@ -1512,7 +1511,7 @@ func (l *State) executeSwitch() {
}
} else {
count = uint64(iInit) - uint64(iLimit)
count /= uint64(-(iStep+1)) + 1
count /= uint64(-(iStep + 1)) + 1
}
frame[a+1] = int64(count) // store counter in place of limit
// ra stays as init (unchanged)
Expand Down
Loading