Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LFunction: remove IsG #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions _state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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 ""
}

Expand Down
12 changes: 6 additions & 6 deletions _vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions baselib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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 ""
}

Expand Down
2 changes: 1 addition & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading