Skip to content

Commit cbc62bc

Browse files
committed
fix build
1 parent 3adc5ce commit cbc62bc

2 files changed

Lines changed: 23 additions & 42 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/lua/translation/LuaTranslator.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import de.peeeq.wurstscript.utils.Utils;
1313
import org.jetbrains.annotations.NotNull;
1414

15-
import java.nio.file.Files;
16-
import java.nio.file.Path;
17-
import java.nio.file.StandardOpenOption;
1815
import java.util.*;
1916
import java.util.stream.Stream;
2017

@@ -974,7 +971,7 @@ private int classDistance(ImClass from, ImClass to) {
974971
}
975972

976973
private void debugDispatchGroup(ImClass receiverClass, String key, Set<String> slotNames, List<ImMethod> groupMethods, ImMethod chosen) {
977-
if (!DEBUG_LUA_DISPATCH && !isSuspiciousGroup(slotNames, groupMethods, chosen)) {
974+
if (!DEBUG_LUA_DISPATCH) {
978975
return;
979976
}
980977
String chosenImpl = chosen != null && chosen.getImplementation() != null ? chosen.getImplementation().getName() : "null";
@@ -988,38 +985,12 @@ private void debugDispatchGroup(ImClass receiverClass, String key, Set<String> s
988985
}
989986
candidates.append(m.getName()).append("->").append(impl).append("@").append(classSortKey(m.attrClass()));
990987
}
991-
System.err.println("[LuaDispatch] class=" + classSortKey(receiverClass)
988+
String line = "[LuaDispatch] class=" + classSortKey(receiverClass)
992989
+ " key=" + key
993990
+ " slots=" + slotNames
994991
+ " chosen=" + chosenImpl
995-
+ " candidates=[" + candidates + "]");
996-
if (DEBUG_LUA_DISPATCH) {
997-
String line = "[LuaDispatch] class=" + classSortKey(receiverClass)
998-
+ " key=" + key
999-
+ " slots=" + slotNames
1000-
+ " chosen=" + chosenImpl
1001-
+ " candidates=[" + candidates + "]"
1002-
+ System.lineSeparator();
1003-
try {
1004-
Files.writeString(Path.of("C:/Users/Frotty/Documents/GitHub/WurstScript/lua-dispatch-debug.log"),
1005-
line, StandardOpenOption.CREATE, StandardOpenOption.APPEND);
1006-
} catch (Exception ignored) {
1007-
}
1008-
}
1009-
}
1010-
1011-
private boolean isSuspiciousGroup(Set<String> slotNames, List<ImMethod> groupMethods, ImMethod chosen) {
1012-
if (slotNames.size() > 1) {
1013-
return true;
1014-
}
1015-
boolean hasNonNoOp = false;
1016-
for (ImMethod m : groupMethods) {
1017-
if (!isNoOpImplementation(m) && m.getImplementation() != null) {
1018-
hasNonNoOp = true;
1019-
break;
1020-
}
1021-
}
1022-
return hasNonNoOp && isNoOpImplementation(chosen);
992+
+ " candidates=[" + candidates + "]";
993+
WLogger.trace(line);
1023994
}
1024995

1025996
private String methodSortKey(ImMethod m) {

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/LuaTranslationTests.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,16 @@ private List<String> subclassCreateClasses(String output, String baseName) {
141141
}
142142

143143
private String compileLuaWithRunArgs(String testName, boolean withStdLib, String... lines) {
144+
return compileLuaWithCUs(testName, withStdLib, Collections.emptyList(), lines);
145+
}
146+
147+
private String compileLuaWithCUs(String testName, boolean withStdLib, List<CU> extraCUs, String... lines) {
144148
RunArgs runArgs = new RunArgs().with("-lua", "-inline", "-localOptimizations", "-stacktraces");
145149
WurstGui gui = new WurstGuiCliImpl();
146150
WurstCompilerJassImpl compiler = new WurstCompilerJassImpl(null, gui, null, runArgs);
147-
List<CU> inputs = Collections.singletonList(new CU(testName + ".wurst", String.join("\n", lines)));
151+
List<CU> inputs = new ArrayList<>();
152+
inputs.addAll(extraCUs);
153+
inputs.add(new CU(testName + ".wurst", String.join("\n", lines)));
148154

149155
WurstModel model = parseFiles(Collections.emptyList(), inputs, withStdLib, compiler);
150156
assertNotNull("parse returned null model, errors = " + gui.getErrorList(), model);
@@ -2316,22 +2322,26 @@ public void wurstInternalNativesDoNotGetNilSafetyWrapper() throws IOException {
23162322
}
23172323

23182324
@Test
2319-
public void isLuaMagicConstantIsTrueInLuaMode() throws IOException {
2320-
// isLua must be inlined to true in Lua mode by GlobalsInliner,
2321-
// so backend-specific code paths can be selected at compile time.
2322-
test().testLua(true).withStdLib().lines(
2325+
public void isLuaMagicConstantIsTrueInLuaMode() {
2326+
// isLua must be replaced with true by LuaNativeLowering so the optimizer can
2327+
// prune Jass-only branches at compile time. This test does NOT use withStdLib()
2328+
// to avoid dependence on the stdlib version pin in StdLib.java.
2329+
CU magicFunctions = new CU("MagicFunctions.wurst",
2330+
"package MagicFunctions\npublic constant isLua = false\n");
2331+
String compiled = compileLuaWithCUs(
2332+
"LuaTranslationTests_isLuaMagicConstantIsTrueInLuaMode",
2333+
false,
2334+
Collections.singletonList(magicFunctions),
23232335
"package Test",
23242336
"import MagicFunctions",
2337+
"native print(string s)",
23252338
"init",
23262339
" if isLua",
23272340
" print(\"lua-path\")",
23282341
" else",
23292342
" print(\"jass-path\")"
23302343
);
2331-
String compiled = Files.toString(
2332-
new File("test-output/lua/LuaTranslationTests_isLuaMagicConstantIsTrueInLuaMode.lua"),
2333-
Charsets.UTF_8);
2334-
// After inlining, the raw isLua variable must not appear in Lua output
2344+
// After LuaNativeLowering, all reads of MagicFunctions_isLua must be inlined to true
23352345
assertFalse("MagicFunctions_isLua must be inlined away in Lua mode", compiled.contains("MagicFunctions_isLua"));
23362346
// The lua-path branch must be preserved
23372347
assertTrue("lua-path branch must be present", compiled.contains("lua-path"));

0 commit comments

Comments
 (0)