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

Function compileAssignStmtRight

compile.go:723–781  ·  view source on GitHub ↗

}}}

(context *funcContext, stmt *ast.AssignStmt, reg int, acs []*assigncontext)

Source from the content-addressed store, hash-verified

721} // }}}
722
723func compileAssignStmtRight(context *funcContext, stmt *ast.AssignStmt, reg int, acs []*assigncontext) (int, []*assigncontext) { // {{{
724 lennames := len(stmt.Lhs)
725 lenexprs := len(stmt.Rhs)
726 namesassigned := 0
727
728 for namesassigned < lennames {
729 ac := acs[namesassigned]
730 ec := ac.ec
731 var expr ast.Expr = nil
732 if namesassigned >= lenexprs {
733 expr = &ast.NilExpr{}
734 expr.SetLine(sline(stmt.Lhs[namesassigned]))
735 expr.SetLastLine(eline(stmt.Lhs[namesassigned]))
736 } else if isVarArgReturnExpr(stmt.Rhs[namesassigned]) && (lenexprs-namesassigned-1) <= 0 {
737 varargopt := lennames - namesassigned - 1
738 regstart := reg
739 reginc := compileExpr(context, reg, stmt.Rhs[namesassigned], ecnone(varargopt))
740 reg += reginc
741 for i := namesassigned; i < namesassigned+int(reginc); i++ {
742 acs[i].needmove = true
743 if acs[i].ec.ctype == ecTable {
744 acs[i].valuerk = regstart + (i - namesassigned)
745 }
746 }
747 namesassigned = lennames
748 continue
749 }
750
751 if expr == nil {
752 expr = stmt.Rhs[namesassigned]
753 }
754 idx := reg
755 reginc := compileExpr(context, reg, expr, ec)
756 if ec.ctype == ecTable {
757 if _, ok := expr.(*ast.LogicalOpExpr); !ok {
758 context.Code.PropagateKMV(context.RegTop(), &ac.valuerk, &reg, reginc)
759 } else {
760 ac.valuerk = idx
761 reg += reginc
762 }
763 } else {
764 ac.needmove = reginc != 0
765 reg += reginc
766 }
767 namesassigned += 1
768 }
769
770 rightreg := reg - 1
771
772 // extra right exprs
773 for i := namesassigned; i < lenexprs; i++ {
774 varargopt := -1
775 if i != lenexprs-1 {
776 varargopt = 0
777 }
778 reg += compileExpr(context, reg, stmt.Rhs[i], ecnone(varargopt))
779 }
780 return rightreg, acs

Callers 1

compileAssignStmtFunction · 0.85

Calls 9

slineFunction · 0.85
elineFunction · 0.85
isVarArgReturnExprFunction · 0.85
compileExprFunction · 0.85
ecnoneFunction · 0.85
PropagateKMVMethod · 0.80
RegTopMethod · 0.80
SetLineMethod · 0.65
SetLastLineMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…