Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ private void handleLExprReads(ImLExpr expr) {
if (expr instanceof ImVarAccess) {
// Write only, skip
} else if (expr instanceof ImMemberAccess) {
((ImMemberAccess) expr).getReceiver().accept(this);
ImMemberAccess memberAccess = (ImMemberAccess) expr;
memberAccess.getReceiver().accept(this);
memberAccess.getIndexes().accept(this);
} else if (expr instanceof ImVarArrayAccess) {
((ImVarArrayAccess) expr).getIndexes().accept(this);
} else if (expr instanceof ImTupleSelection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ public void tuplesAreScalarizedWithoutLuaAllocations() throws IOException {
assertFalse("tuple arrays must be split into scalar arrays", compiled.contains("__wurst_arrIndex("));
}

@Test
public void tupleMemberArrayAssignmentCapturesIndex() throws IOException {
test().testLua(true).luaOnly(false).executeProg().lines(
"package Test",
"native testSuccess()",
"tuple pair(int first, int second)",
"constant SIZE = 10",
"class Container",
" pair array[SIZE] values",
" int used",
" function add(pair value)",
" values[used] = value",
" used++",
"init",
" let container = new Container()",
" container.add(pair(1, 2))",
" if container.used == 1 and container.values[0] == pair(1, 2)",
" testSuccess()"
);

String compiled = compiledLua("tupleMemberArrayAssignmentCapturesIndex");
assertTrue("tuple member-array index must be captured into a declared Lua local",
compiled.contains("local tuple_lvalue_index = 0"));
assertTrue("tuple member-array index capture must survive dead-store elimination",
compiled.contains("tuple_lvalue_index = Container_used_storage[this]"));
}

@Test
public void optimizedTupleCommonPathIsOnlyScalarCode() {
String compiled = compileOptimizedLua(
Expand Down
Loading