diff --git a/base.go b/base.go index e93132c..7916ae0 100644 --- a/base.go +++ b/base.go @@ -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 { diff --git a/code.go b/code.go index 4a14ad1..231275e 100644 --- a/code.go +++ b/code.go @@ -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) } @@ -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 { @@ -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 { @@ -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) { @@ -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 diff --git a/coroutine.go b/coroutine.go index dd3f8f7..454fa6f 100644 --- a/coroutine.go +++ b/coroutine.go @@ -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) @@ -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 { @@ -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 }}, diff --git a/instructions.go b/instructions.go index 0799d1b..8f3ded4 100644 --- a/instructions.go +++ b/instructions.go @@ -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 @@ -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) } diff --git a/io.go b/io.go index 7a0c9b8..c9c6a50 100644 --- a/io.go +++ b/io.go @@ -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 { diff --git a/isolate_test.go b/isolate_test.go index 553b096..7c11b8e 100644 --- a/isolate_test.go +++ b/isolate_test.go @@ -393,4 +393,3 @@ func TestIsolateCallLine(t *testing.T) { } } } - diff --git a/lua.go b/lua.go index 7f4639e..ee9922e 100644 --- a/lua.go +++ b/lua.go @@ -211,7 +211,7 @@ type Function func(state *State) int type threadStatus byte const ( - threadStatusOK threadStatus = iota + threadStatusOK threadStatus = iota threadStatusYield threadStatusDead ) @@ -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-- diff --git a/scanner.go b/scanner.go index 16592fc..a72ea91 100644 --- a/scanner.go +++ b/scanner.go @@ -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) } @@ -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 { diff --git a/string.go b/string.go index 1a3f632..6da6fe3 100644 --- a/string.go +++ b/string.go @@ -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)") } diff --git a/types.go b/types.go index b206491..fd8fa02 100644 --- a/types.go +++ b/types.go @@ -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 diff --git a/undump.go b/undump.go index 86f2d10..5654f73 100644 --- a/undump.go +++ b/undump.go @@ -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 ( diff --git a/vm.go b/vm.go index 329f571..b1c68e3 100644 --- a/vm.go +++ b/vm.go @@ -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) @@ -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)