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

Function compileTableExpr

compile.go:1350–1419  ·  view source on GitHub ↗

}}}

(context *funcContext, reg int, ex *ast.TableExpr, ec *expcontext)

Source from the content-addressed store, hash-verified

1348} // }}}
1349
1350func compileTableExpr(context *funcContext, reg int, ex *ast.TableExpr, ec *expcontext) { // {{{
1351 code := context.Code
1352 /*
1353 tablereg := savereg(ec, reg)
1354 if tablereg == reg {
1355 reg += 1
1356 }
1357 */
1358 tablereg := reg
1359 reg++
1360 code.AddABC(OP_NEWTABLE, tablereg, 0, 0, sline(ex))
1361 tablepc := code.LastPC()
1362 regbase := reg
1363
1364 arraycount := 0
1365 lastvararg := false
1366 for i, field := range ex.Fields {
1367 islast := i == len(ex.Fields)-1
1368 if field.Key == nil {
1369 if islast && isVarArgReturnExpr(field.Value) {
1370 reg += compileExpr(context, reg, field.Value, ecnone(-2))
1371 lastvararg = true
1372 } else {
1373 reg += compileExpr(context, reg, field.Value, ecnone(0))
1374 arraycount += 1
1375 }
1376 } else {
1377 regorg := reg
1378 b := reg
1379 compileExprWithKMVPropagation(context, field.Key, &reg, &b)
1380 c := reg
1381 compileExprWithKMVPropagation(context, field.Value, &reg, &c)
1382 opcode := OP_SETTABLE
1383 if _, ok := field.Key.(*ast.StringExpr); ok {
1384 opcode = OP_SETTABLEKS
1385 }
1386 code.AddABC(opcode, tablereg, b, c, sline(ex))
1387 reg = regorg
1388 }
1389 flush := arraycount % FieldsPerFlush
1390 if (arraycount != 0 && (flush == 0 || islast)) || lastvararg {
1391 reg = regbase
1392 num := flush
1393 if num == 0 {
1394 num = FieldsPerFlush
1395 }
1396 c := (arraycount-1)/FieldsPerFlush + 1
1397 b := num
1398 if islast && isVarArgReturnExpr(field.Value) {
1399 b = 0
1400 }
1401 line := field.Value
1402 if field.Key != nil {
1403 line = field.Key
1404 }
1405 if c > 511 {
1406 c = 0
1407 }

Callers 1

compileExprFunction · 0.85

Calls 12

slineFunction · 0.85
isVarArgReturnExprFunction · 0.85
compileExprFunction · 0.85
ecnoneFunction · 0.85
int2FbFunction · 0.85
shouldmoveFunction · 0.85
AddABCMethod · 0.80
LastPCMethod · 0.80
AddMethod · 0.80
SetBMethod · 0.80
SetCMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…