diff --git a/_state.go b/_state.go index 6e9febfb..b14202f6 100644 --- a/_state.go +++ b/_state.go @@ -615,7 +615,7 @@ func (ls *LState) printCallStack() { if frame == nil { break } - if frame.Fn.IsG { + if frame.Fn.IsG() { println("IsG:", true, "Frame:", frame, "Fn:", frame.Fn) } else { println("IsG:", false, "Frame:", frame, "Fn:", frame.Fn, "pc:", frame.Pc) @@ -626,7 +626,7 @@ func (ls *LState) printCallStack() { func (ls *LState) closeAllUpvalues() { // +inline-start for cf := ls.currentFrame; cf != nil; cf = cf.Parent { - if !cf.Fn.IsG { + if !cf.Fn.IsG() { ls.closeUpvalues(cf.LocalBase) } } @@ -653,7 +653,7 @@ func (ls *LState) raiseError(level int, format string, args ...interface{}) { func (ls *LState) findLocal(frame *callFrame, no int) string { fn := frame.Fn - if !fn.IsG { + if !fn.IsG() { if name, ok := fn.LocalName(no, frame.Pc-1); ok { return name } @@ -700,7 +700,7 @@ func (ls *LState) stackTrace(level int) string { for dbg, ok := ls.GetStack(i); ok; dbg, ok = ls.GetStack(i) { cf := dbg.frame buf = append(buf, fmt.Sprintf("\t%v in %v", ls.Where(i), ls.formattedFrameFuncName(cf))) - if !cf.Fn.IsG && cf.TailCall > 0 { + if !cf.Fn.IsG() && cf.TailCall > 0 { for tc := cf.TailCall; tc > 0; tc-- { buf = append(buf, "\t(tailcall): ?") i++ @@ -746,19 +746,19 @@ func (ls *LState) frameFuncName(fr *callFrame) (string, bool) { return "corountine", true } } - if !frame.Fn.IsG { + if !frame.Fn.IsG() { pc := frame.Pc - 1 for _, call := range frame.Fn.Proto.DbgCalls { if call.Pc == pc { name := call.Name - if (name == "?" || fr.TailCall > 0) && !fr.Fn.IsG { + if (name == "?" || fr.TailCall > 0) && !fr.Fn.IsG() { name = fmt.Sprintf("<%v:%v>", fr.Fn.Proto.SourceName, fr.Fn.Proto.LineDefined) } return name, false } } } - if !fr.Fn.IsG { + if !fr.Fn.IsG() { return fmt.Sprintf("<%v:%v>", fr.Fn.Proto.SourceName, fr.Fn.Proto.LineDefined), false } return "(anonymous)", false @@ -934,7 +934,7 @@ func (ls *LState) metaCall(lvalue LValue) (*LFunction, bool) { } func (ls *LState) initCallFrame(cf *callFrame) { // +inline-start - if cf.Fn.IsG { + if cf.Fn.IsG() { ls.reg.SetTop(cf.LocalBase + cf.NArgs) } else { proto := cf.Fn.Proto @@ -1549,20 +1549,20 @@ func (ls *LState) GetInfo(what string, dbg *Debug, fn LValue) (LValue, error) { case 'S': if dbg.frame != nil && dbg.frame.Parent == nil { dbg.What = "main" - } else if f.IsG { + } else if f.IsG() { dbg.What = "G" } else if dbg.frame != nil && dbg.frame.TailCall > 0 { dbg.What = "tail" } else { dbg.What = "Lua" } - if !f.IsG { + if !f.IsG() { dbg.Source = f.Proto.SourceName dbg.LineDefined = f.Proto.LineDefined dbg.LastLineDefined = f.Proto.LastLineDefined } case 'l': - if !f.IsG && dbg.frame != nil { + if !f.IsG() && dbg.frame != nil { if dbg.frame.Pc > 0 { dbg.CurrentLine = f.Proto.DbgSourcePositions[dbg.frame.Pc-1] } @@ -1591,7 +1591,7 @@ func (ls *LState) GetStack(level int) (*Debug, bool) { frame := ls.currentFrame for ; level > 0 && frame != nil; frame = frame.Parent { level-- - if !frame.Fn.IsG { + if !frame.Fn.IsG() { level -= frame.TailCall } } @@ -1622,7 +1622,7 @@ func (ls *LState) SetLocal(dbg *Debug, no int, lv LValue) string { } func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue) { - if fn.IsG { + if fn.IsG() { return "", LNil } @@ -1634,7 +1634,7 @@ func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue) { } func (ls *LState) SetUpvalue(fn *LFunction, no int, lv LValue) string { - if fn.IsG { + if fn.IsG() { return "" } diff --git a/_vm.go b/_vm.go index ee2be040..82d5484b 100644 --- a/_vm.go +++ b/_vm.go @@ -15,7 +15,7 @@ func mainLoop(L *LState, baseframe *callFrame) { } L.currentFrame = L.stack.Last() - if L.currentFrame.Fn.IsG { + if L.currentFrame.Fn.IsG() { callGFunction(L, false) return } @@ -39,7 +39,7 @@ func mainLoopWithContext(L *LState, baseframe *callFrame) { } L.currentFrame = L.stack.Last() - if L.currentFrame.Fn.IsG { + if L.currentFrame.Fn.IsG() { callGFunction(L, false) return } @@ -579,7 +579,7 @@ func init() { callable, meta = L.metaCall(lv) } // +inline-call L.pushCallFrame callFrame{Fn:callable,Pc:0,Base:RA,LocalBase:RA+1,ReturnBase:RA,NArgs:nargs,NRet:nret,Parent:cf,TailCall:0} lv meta - if callable.IsG && callGFunction(L, false) { + if callable.IsG() && callGFunction(L, false) { return 1 } return 0 @@ -608,7 +608,7 @@ func init() { L.RaiseError("attempt to call a non-function object") } // +inline-call L.closeUpvalues lbase - if callable.IsG { + if callable.IsG() { luaframe := cf L.pushCallFrame(callFrame{ Fn: callable, @@ -624,7 +624,7 @@ func init() { if callGFunction(L, true) { return 1 } - if L.currentFrame == nil || L.currentFrame.Fn.IsG || luaframe == baseframe { + if L.currentFrame == nil || L.currentFrame.Fn.IsG() || luaframe == baseframe { return 1 } } else { @@ -674,7 +674,7 @@ func init() { islast := baseframe == L.stack.Pop() || L.stack.IsEmpty() // +inline-call copyReturnValues L cf.ReturnBase RA n B L.currentFrame = L.stack.Last() - if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG { + if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG() { return 1 } return 0 diff --git a/baselib.go b/baselib.go index aa2c08a9..5d98f314 100644 --- a/baselib.go +++ b/baselib.go @@ -97,7 +97,7 @@ func baseGetFEnv(L *LState) int { } if fn, ok := value.(*LFunction); ok { - if !fn.IsG { + if !fn.IsG() { L.Push(fn.Env) } else { L.Push(L.G.Global) @@ -114,7 +114,7 @@ func baseGetFEnv(L *LState) int { for i := 0; i < level && cf != nil; i++ { cf = cf.Parent } - if cf == nil || cf.Fn.IsG { + if cf == nil || cf.Fn.IsG() { L.Push(L.G.Global) } else { L.Push(cf.Fn.Env) @@ -351,7 +351,7 @@ func baseSetFEnv(L *LState) int { env := L.CheckTable(2) if fn, ok := value.(*LFunction); ok { - if fn.IsG { + if fn.IsG() { L.RaiseError("cannot change the environment of given object") } else { fn.Env = env @@ -371,7 +371,7 @@ func baseSetFEnv(L *LState) int { for i := 0; i < level && cf != nil; i++ { cf = cf.Parent } - if cf == nil || cf.Fn.IsG { + if cf == nil || cf.Fn.IsG() { L.RaiseError("cannot change the environment of given object") } else { cf.Fn.Env = env @@ -506,7 +506,7 @@ func loModule(L *LState) int { caller := L.currentFrame.Parent if caller == nil { L.RaiseError("no calling stack.") - } else if caller.Fn.IsG { + } else if caller.Fn.IsG() { L.RaiseError("module() can not be called from GFunctions.") } L.SetFEnv(caller.Fn, tb) diff --git a/function.go b/function.go index 169e5407..1340291a 100644 --- a/function.go +++ b/function.go @@ -154,7 +154,6 @@ func (fp *FunctionProto) str(level int, count int) string { func newLFunctionL(proto *FunctionProto, env *LTable, nupvalue int) *LFunction { return &LFunction{ - IsG: false, Env: env, Proto: proto, @@ -165,7 +164,6 @@ func newLFunctionL(proto *FunctionProto, env *LTable, nupvalue int) *LFunction { func newLFunctionG(gfunc LGFunction, env *LTable, nupvalue int) *LFunction { return &LFunction{ - IsG: true, Env: env, Proto: nil, @@ -175,7 +173,7 @@ func newLFunctionG(gfunc LGFunction, env *LTable, nupvalue int) *LFunction { } func (fn *LFunction) LocalName(regno, pc int) (string, bool) { - if fn.IsG { + if fn.IsG() { return "", false } p := fn.Proto diff --git a/state.go b/state.go index 292f93b4..79cca372 100644 --- a/state.go +++ b/state.go @@ -715,7 +715,7 @@ func (ls *LState) printCallStack() { if frame == nil { break } - if frame.Fn.IsG { + if frame.Fn.IsG() { println("IsG:", true, "Frame:", frame, "Fn:", frame.Fn) } else { println("IsG:", false, "Frame:", frame, "Fn:", frame.Fn, "pc:", frame.Pc) @@ -726,7 +726,7 @@ func (ls *LState) printCallStack() { func (ls *LState) closeAllUpvalues() { // +inline-start for cf := ls.currentFrame; cf != nil; cf = cf.Parent { - if !cf.Fn.IsG { + if !cf.Fn.IsG() { ls.closeUpvalues(cf.LocalBase) } } @@ -753,7 +753,7 @@ func (ls *LState) raiseError(level int, format string, args ...interface{}) { func (ls *LState) findLocal(frame *callFrame, no int) string { fn := frame.Fn - if !fn.IsG { + if !fn.IsG() { if name, ok := fn.LocalName(no, frame.Pc-1); ok { return name } @@ -800,7 +800,7 @@ func (ls *LState) stackTrace(level int) string { for dbg, ok := ls.GetStack(i); ok; dbg, ok = ls.GetStack(i) { cf := dbg.frame buf = append(buf, fmt.Sprintf("\t%v in %v", ls.Where(i), ls.formattedFrameFuncName(cf))) - if !cf.Fn.IsG && cf.TailCall > 0 { + if !cf.Fn.IsG() && cf.TailCall > 0 { for tc := cf.TailCall; tc > 0; tc-- { buf = append(buf, "\t(tailcall): ?") i++ @@ -846,19 +846,19 @@ func (ls *LState) frameFuncName(fr *callFrame) (string, bool) { return "corountine", true } } - if !frame.Fn.IsG { + if !frame.Fn.IsG() { pc := frame.Pc - 1 for _, call := range frame.Fn.Proto.DbgCalls { if call.Pc == pc { name := call.Name - if (name == "?" || fr.TailCall > 0) && !fr.Fn.IsG { + if (name == "?" || fr.TailCall > 0) && !fr.Fn.IsG() { name = fmt.Sprintf("<%v:%v>", fr.Fn.Proto.SourceName, fr.Fn.Proto.LineDefined) } return name, false } } } - if !fr.Fn.IsG { + if !fr.Fn.IsG() { return fmt.Sprintf("<%v:%v>", fr.Fn.Proto.SourceName, fr.Fn.Proto.LineDefined), false } return "(anonymous)", false @@ -1034,7 +1034,7 @@ func (ls *LState) metaCall(lvalue LValue) (*LFunction, bool) { } func (ls *LState) initCallFrame(cf *callFrame) { // +inline-start - if cf.Fn.IsG { + if cf.Fn.IsG() { ls.reg.SetTop(cf.LocalBase + cf.NArgs) } else { proto := cf.Fn.Proto @@ -1146,7 +1146,7 @@ func (ls *LState) pushCallFrame(cf callFrame, fn LValue, meta bool) { // +inline // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go' { cf := newcf - if cf.Fn.IsG { + if cf.Fn.IsG() { ls.reg.SetTop(cf.LocalBase + cf.NArgs) } else { proto := cf.Fn.Proto @@ -1762,20 +1762,20 @@ func (ls *LState) GetInfo(what string, dbg *Debug, fn LValue) (LValue, error) { case 'S': if dbg.frame != nil && dbg.frame.Parent == nil { dbg.What = "main" - } else if f.IsG { + } else if f.IsG() { dbg.What = "G" } else if dbg.frame != nil && dbg.frame.TailCall > 0 { dbg.What = "tail" } else { dbg.What = "Lua" } - if !f.IsG { + if !f.IsG() { dbg.Source = f.Proto.SourceName dbg.LineDefined = f.Proto.LineDefined dbg.LastLineDefined = f.Proto.LastLineDefined } case 'l': - if !f.IsG && dbg.frame != nil { + if !f.IsG() && dbg.frame != nil { if dbg.frame.Pc > 0 { dbg.CurrentLine = f.Proto.DbgSourcePositions[dbg.frame.Pc-1] } @@ -1804,7 +1804,7 @@ func (ls *LState) GetStack(level int) (*Debug, bool) { frame := ls.currentFrame for ; level > 0 && frame != nil; frame = frame.Parent { level-- - if !frame.Fn.IsG { + if !frame.Fn.IsG() { level -= frame.TailCall } } @@ -1835,7 +1835,7 @@ func (ls *LState) SetLocal(dbg *Debug, no int, lv LValue) string { } func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue) { - if fn.IsG { + if fn.IsG() { return "", LNil } @@ -1847,7 +1847,7 @@ func (ls *LState) GetUpvalue(fn *LFunction, no int) (string, LValue) { } func (ls *LState) SetUpvalue(fn *LFunction, no int, lv LValue) string { - if fn.IsG { + if fn.IsG() { return "" } diff --git a/value.go b/value.go index 4156e9d5..fc83dac1 100644 --- a/value.go +++ b/value.go @@ -154,7 +154,6 @@ func (tb *LTable) String() string { return fmt.Sprintf("table: %p", tb) } func (tb *LTable) Type() LValueType { return LTTable } type LFunction struct { - IsG bool Env *LTable Proto *FunctionProto GFunction LGFunction @@ -164,6 +163,7 @@ type LGFunction func(*LState) int func (fn *LFunction) String() string { return fmt.Sprintf("function: %p", fn) } func (fn *LFunction) Type() LValueType { return LTFunction } +func (fn *LFunction) IsG() bool { return fn.GFunction != nil } type Global struct { MainThread *LState diff --git a/vm.go b/vm.go index 97335a75..02c61532 100644 --- a/vm.go +++ b/vm.go @@ -19,7 +19,7 @@ func mainLoop(L *LState, baseframe *callFrame) { } L.currentFrame = L.stack.Last() - if L.currentFrame.Fn.IsG { + if L.currentFrame.Fn.IsG() { callGFunction(L, false) return } @@ -43,7 +43,7 @@ func mainLoopWithContext(L *LState, baseframe *callFrame) { } L.currentFrame = L.stack.Last() - if L.currentFrame.Fn.IsG { + if L.currentFrame.Fn.IsG() { callGFunction(L, false) return } @@ -1209,7 +1209,7 @@ func init() { // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go' { cf := newcf - if cf.Fn.IsG { + if cf.Fn.IsG() { ls.reg.SetTop(cf.LocalBase + cf.NArgs) } else { proto := cf.Fn.Proto @@ -1305,7 +1305,7 @@ func init() { } ls.currentFrame = newcf } - if callable.IsG && callGFunction(L, false) { + if callable.IsG() && callGFunction(L, false) { return 1 } return 0 @@ -1353,7 +1353,7 @@ func init() { } } } - if callable.IsG { + if callable.IsG() { luaframe := cf L.pushCallFrame(callFrame{ Fn: callable, @@ -1369,7 +1369,7 @@ func init() { if callGFunction(L, true) { return 1 } - if L.currentFrame == nil || L.currentFrame.Fn.IsG || luaframe == baseframe { + if L.currentFrame == nil || L.currentFrame.Fn.IsG() || luaframe == baseframe { return 1 } } else { @@ -1391,7 +1391,7 @@ func init() { // source function is 'func (ls *LState) initCallFrame(cf *callFrame) ' in '_state.go' { ls := L - if cf.Fn.IsG { + if cf.Fn.IsG() { ls.reg.SetTop(cf.LocalBase + cf.NArgs) } else { proto := cf.Fn.Proto @@ -1784,7 +1784,7 @@ func init() { } } L.currentFrame = L.stack.Last() - if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG { + if islast || L.currentFrame == nil || L.currentFrame.Fn.IsG() { return 1 } return 0