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

Function compileIfStmt

compile.go:913–930  ·  view source on GitHub ↗

}}}

(context *funcContext, stmt *ast.IfStmt)

Source from the content-addressed store, hash-verified

911} // }}}
912
913func compileIfStmt(context *funcContext, stmt *ast.IfStmt) { // {{{
914 thenlabel := context.NewLabel()
915 elselabel := context.NewLabel()
916 endlabel := context.NewLabel()
917
918 compileBranchCondition(context, context.RegTop(), stmt.Condition, thenlabel, elselabel, false)
919 context.SetLabelPc(thenlabel, context.Code.LastPC())
920 compileBlock(context, stmt.Then)
921 if len(stmt.Else) > 0 {
922 context.Code.AddASbx(OP_JMP, 0, endlabel, sline(stmt))
923 }
924 context.SetLabelPc(elselabel, context.Code.LastPC())
925 if len(stmt.Else) > 0 {
926 compileBlock(context, stmt.Else)
927 context.SetLabelPc(endlabel, context.Code.LastPC())
928 }
929
930} // }}}
931
932func compileBranchCondition(context *funcContext, reg int, expr ast.Expr, thenlabel, elselabel int, hasnextcond bool) { // {{{
933 // TODO folding constants?

Callers 1

compileStmtFunction · 0.85

Calls 8

compileBranchConditionFunction · 0.85
compileBlockFunction · 0.85
slineFunction · 0.85
NewLabelMethod · 0.80
RegTopMethod · 0.80
SetLabelPcMethod · 0.80
LastPCMethod · 0.80
AddASbxMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…