MCPcopy
hub / github.com/yuin/gopher-lua / compileAssignStmt

Function compileAssignStmt

compile.go:783–814  ·  view source on GitHub ↗

}}}

(context *funcContext, stmt *ast.AssignStmt)

Source from the content-addressed store, hash-verified

781} // }}}
782
783func compileAssignStmt(context *funcContext, stmt *ast.AssignStmt) { // {{{
784 code := context.Code
785 lennames := len(stmt.Lhs)
786 reg, acs := compileAssignStmtLeft(context, stmt)
787 reg, acs = compileAssignStmtRight(context, stmt, reg, acs)
788
789 for i := lennames - 1; i >= 0; i-- {
790 ex := stmt.Lhs[i]
791 switch acs[i].ec.ctype {
792 case ecLocal:
793 if acs[i].needmove {
794 code.AddABC(OP_MOVE, context.FindLocalVar(ex.(*ast.IdentExpr).Value), reg, 0, sline(ex))
795 reg -= 1
796 }
797 case ecGlobal:
798 code.AddABx(OP_SETGLOBAL, reg, context.ConstIndex(LString(ex.(*ast.IdentExpr).Value)), sline(ex))
799 reg -= 1
800 case ecUpvalue:
801 code.AddABC(OP_SETUPVAL, reg, context.Upvalues.RegisterUnique(ex.(*ast.IdentExpr).Value), 0, sline(ex))
802 reg -= 1
803 case ecTable:
804 opcode := OP_SETTABLE
805 if acs[i].keyks {
806 opcode = OP_SETTABLEKS
807 }
808 code.AddABC(opcode, acs[i].ec.reg, acs[i].keyrk, acs[i].valuerk, sline(ex))
809 if !opIsK(acs[i].valuerk) {
810 reg -= 1
811 }
812 }
813 }
814} // }}}
815
816func compileRegAssignment(context *funcContext, names []string, exprs []ast.Expr, reg int, nvars int, line int) { // {{{
817 lennames := len(names)

Callers 2

compileStmtFunction · 0.85
compileFuncDefStmtFunction · 0.85

Calls 10

compileAssignStmtLeftFunction · 0.85
compileAssignStmtRightFunction · 0.85
slineFunction · 0.85
LStringTypeAlias · 0.85
opIsKFunction · 0.85
AddABCMethod · 0.80
FindLocalVarMethod · 0.80
AddABxMethod · 0.80
ConstIndexMethod · 0.80
RegisterUniqueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…