MCPcopy Index your code
hub / github.com/yuin/gopher-lua / compileNumberForStmt

Function compileNumberForStmt

compile.go:1050–1090  ·  view source on GitHub ↗

}}}

(context *funcContext, stmt *ast.NumberForStmt)

Source from the content-addressed store, hash-verified

1048} // }}}
1049
1050func compileNumberForStmt(context *funcContext, stmt *ast.NumberForStmt) { // {{{
1051 code := context.Code
1052 endlabel := context.NewLabel()
1053 ec := &expcontext{}
1054
1055 context.EnterBlock(endlabel, stmt)
1056 reg := context.RegTop()
1057 rindex := context.RegisterLocalVar("(for index)")
1058 ecupdate(ec, ecLocal, rindex, 0)
1059 compileExpr(context, reg, stmt.Init, ec)
1060
1061 reg = context.RegTop()
1062 rlimit := context.RegisterLocalVar("(for limit)")
1063 ecupdate(ec, ecLocal, rlimit, 0)
1064 compileExpr(context, reg, stmt.Limit, ec)
1065
1066 reg = context.RegTop()
1067 rstep := context.RegisterLocalVar("(for step)")
1068 if stmt.Step == nil {
1069 stmt.Step = &ast.NumberExpr{Value: "1"}
1070 stmt.Step.SetLine(sline(stmt.Init))
1071 }
1072 ecupdate(ec, ecLocal, rstep, 0)
1073 compileExpr(context, reg, stmt.Step, ec)
1074
1075 code.AddASbx(OP_FORPREP, rindex, 0, sline(stmt))
1076
1077 context.RegisterLocalVar(stmt.Name)
1078
1079 bodypc := code.LastPC()
1080 compileChunk(context, stmt.Stmts, false)
1081
1082 context.LeaveBlock()
1083
1084 flpc := code.LastPC()
1085 code.AddASbx(OP_FORLOOP, rindex, bodypc-(flpc+1), sline(stmt))
1086
1087 context.SetLabelPc(endlabel, code.LastPC())
1088 code.SetSbx(bodypc, flpc-bodypc)
1089
1090} // }}}
1091
1092func compileGenericForStmt(context *funcContext, stmt *ast.GenericForStmt) { // {{{
1093 code := context.Code

Callers 1

compileStmtFunction · 0.85

Calls 14

ecupdateFunction · 0.85
compileExprFunction · 0.85
slineFunction · 0.85
compileChunkFunction · 0.85
NewLabelMethod · 0.80
EnterBlockMethod · 0.80
RegTopMethod · 0.80
RegisterLocalVarMethod · 0.80
AddASbxMethod · 0.80
LastPCMethod · 0.80
LeaveBlockMethod · 0.80
SetLabelPcMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…