Skip to content

Commit daecc28

Browse files
committed
more opts
1 parent 409cd5a commit daecc28

26 files changed

Lines changed: 387 additions & 187 deletions

de.peeeq.wurstscript/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ dependencies {
106106
implementation 'commons-lang:commons-lang:2.6'
107107
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
108108
implementation 'com.github.inwc3:jmpq3:29b55f2c32'
109-
implementation 'com.github.inwc3:wc3libs:bab65b961b'
109+
implementation 'com.github.inwc3:wc3libs:cc49c8e63c'
110110
implementation('com.github.wurstscript:wurstsetup:393cf5ea39') {
111111
exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit'
112112
exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit.ssh.apache'

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/CompiletimeFunctionRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private void executeCompiletimeFunction(ImFunction f) {
551551
if (!f.getBody().isEmpty()) {
552552
interpreter.getGlobalState().setLastStatement(f.getBody().get(0));
553553
}
554-
WLogger.debug("running " + functionFlag + " function " + f.getName());
554+
WLogger.debug(() -> "running " + functionFlag + " function " + f.getName());
555555
interpreter.runVoidFunc(f, null);
556556
successTests.add(f);
557557
} catch (TestSuccessException e) {

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,14 @@ public JassProg transformProgToJass() {
535535
}
536536

537537
beginPhase(13, "flatten");
538-
optimizer.removeGarbage();
538+
boolean garbageChanged = optimizer.removeGarbage();
539539
imProg.flatten(imTranslator);
540540

541541
// Re-run to avoid #883
542-
optimizer.removeGarbage();
543-
imProg.flatten(imTranslator);
542+
if (garbageChanged) {
543+
optimizer.removeGarbage();
544+
imProg.flatten(imTranslator);
545+
}
544546

545547
printDebugImProg("./test-output/im " + stage++ + "_afterremoveGarbage1.im");
546548
timeTaker.endPhase();
@@ -561,7 +563,7 @@ public JassProg transformProgToJass() {
561563
// translate flattened intermediate lang to jass:
562564

563565
beginPhase(14, "translate to jass");
564-
getImTranslator().calculateCallRelationsAndUsedVariables();
566+
getImTranslator().calculateCallRelationsAndReadVariables();
565567
ImToJassTranslator translator =
566568
new ImToJassTranslator(getImProg(), getImTranslator().getCalledFunctions(), getImTranslator().getMainFunc(), getImTranslator().getConfFunc());
567569
prog = translator.translate();
@@ -952,12 +954,14 @@ public LuaCompilationUnit transformProgToLua() {
952954

953955
printDebugImProg("./test-output/lua/im " + stage++ + "_afterlocalopts.im");
954956

955-
optimizer.removeGarbage();
957+
boolean garbageChanged = optimizer.removeGarbage();
956958
imProg.flatten(imTranslator);
957959

958960
// Re-run to avoid #883
959-
optimizer.removeGarbage();
960-
imProg.flatten(imTranslator);
961+
if (garbageChanged) {
962+
optimizer.removeGarbage();
963+
imProg.flatten(imTranslator);
964+
}
961965

962966
printDebugImProg("./test-output/lua/im " + stage++ + "_afterremoveGarbage1.im");
963967

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/JassInterpreter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static ILconst getDefaultValue(String type) {
6060

6161
public ILconst executeFunction(String name, ILconst... arguments) {
6262
if (trace) {
63-
WLogger.trace(name + "( " + Utils.join(arguments, ", ") + ")");
63+
WLogger.trace(() -> name + "( " + Utils.join(arguments, ", ") + ")");
6464
}
6565

6666
ExecutableJassFunction func = searchFunction(name);
@@ -99,13 +99,13 @@ ILconst executeJassFunction(JassFunction func, ILconst... arguments) {
9999
this.executeStatements(localVarMap, body);
100100
} catch (ReturnException e) {
101101
if (trace) {
102-
WLogger.trace("end function " + func.getName() + " returns " + e.getVal());
102+
WLogger.trace(() -> "end function " + func.getName() + " returns " + e.getVal());
103103
}
104104
return e.getVal();
105105
}
106106

107107
if (trace) {
108-
WLogger.trace("end function " + func.getName());
108+
WLogger.trace(() -> "end function " + func.getName());
109109
}
110110
return null;
111111
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/providers/ForceProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void DestroyForce(IlConstHandle force) {
4444
public void ForForce(IlConstHandle force, ILconstFuncRef funcRef) {
4545
// TODO take force param into account
4646
// For now this simply executes the supplied function.
47-
WLogger.trace("for force call");
4847
interpreter.runFuncRef(funcRef, null);
4948
}
5049
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/jassinterpreter/providers/GroupProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ public ILconst FirstOfGroup(IlConstHandle group) {
5252
}
5353

5454
public void ForGroup(IlConstHandle group, ILconstFuncRef funcRef) {
55-
WLogger.trace("for group call");
5655
LinkedHashSet<IlConstHandle> groupList = (LinkedHashSet<IlConstHandle>) group.getObj();
5756
groupList.forEach((IlConstHandle u) -> {
5857
enumUnitStack.push(u);
59-
WLogger.trace("for group call itr: " + funcRef.getFuncName());
6058
interpreter.runFuncRef(funcRef, null);
6159
enumUnitStack.pop();
6260
});

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/ConfigProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void refreshCacheAsync() {
143143
}
144144
})
145145
.exceptionally(e -> {
146-
WLogger.trace("Background config refresh failed (this is normal if client is busy): " + e.getMessage());
146+
WLogger.trace(() -> "Background config refresh failed (this is normal if client is busy): " + e.getMessage());
147147
return null;
148148
});
149149
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/ModelManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ private WurstCompilerJassImpl getCompiler(WurstGui gui) {
371371
}
372372

373373
private void updateModel(CompilationUnit cu, WurstGui gui) {
374-
WLogger.trace("update model with " + cu.getCuInfo().getFile());
375374
parseErrors.put(wFile(cu), new ArrayList<>(gui.getErrorsAndWarnings()));
376375

377376
WurstModel model2 = model;
@@ -534,7 +533,7 @@ private CompilationUnit replaceCompilationUnit(WFile filename, String contents,
534533
CompilationUnit existing = getCompilationUnit(filename);
535534
if (existing != null) {
536535
// no change
537-
WLogger.trace("CU " + filename + " was unchanged.");
536+
WLogger.trace(() -> "CU " + filename + " was unchanged.");
538537
return existing;
539538
}
540539
// Stale hash cache after remove/move; CU is gone, so reparse.
@@ -544,7 +543,7 @@ private CompilationUnit replaceCompilationUnit(WFile filename, String contents,
544543
}
545544
}
546545

547-
WLogger.trace("replace CU " + filename);
546+
WLogger.trace(() -> "replace CU " + filename);
548547
WurstGui gui = new WurstGuiLogger();
549548
WurstCompilerJassImpl c = getCompiler(gui);
550549
CompilationUnit cu = c.parse(filename.toString(), new StringReader(contents));

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/WLogger.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.ByteBuffer;
1515
import java.nio.channels.FileChannel;
1616
import java.util.Iterator;
17+
import java.util.function.Supplier;
1718

1819

1920
public abstract class WLogger {
@@ -28,6 +29,16 @@ public static void trace(String msg) {
2829
instance.trace(msg);
2930
}
3031

32+
public static void trace(String format, Object... args) {
33+
instance.trace(format, args);
34+
}
35+
36+
public static void trace(Supplier<String> msgSupplier) {
37+
if (instance.isTraceEnabled()) {
38+
instance.trace(msgSupplier.get());
39+
}
40+
}
41+
3142
public static void info(String msg) {
3243
instance.info(msg);
3344
}
@@ -36,6 +47,24 @@ public static void debug(String s) {
3647
instance.debug(s);
3748
}
3849

50+
public static void debug(String format, Object... args) {
51+
instance.debug(format, args);
52+
}
53+
54+
public static void debug(Supplier<String> msgSupplier) {
55+
if (instance.isDebugEnabled()) {
56+
instance.debug(msgSupplier.get());
57+
}
58+
}
59+
60+
public static boolean isTraceEnabled() {
61+
return instance.isTraceEnabled();
62+
}
63+
64+
public static boolean isDebugEnabled() {
65+
return instance.isDebugEnabled();
66+
}
67+
3968
public static void setLevel(Level level) {
4069
instance.setLevel(level);
4170
}

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/WLoggerDefault.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ public void trace(String msg) {
2222
logger.trace(msg);
2323
}
2424

25+
@Override
26+
public void trace(String format, Object... args) {
27+
logger.trace(format, args);
28+
}
29+
2530
@Override
2631
public void debug(String s) {
2732
logger.debug(s);
2833
}
2934

35+
@Override
36+
public void debug(String format, Object... args) {
37+
logger.debug(format, args);
38+
}
39+
3040
/**
3141
* (non-Javadoc)
3242
*
@@ -109,4 +119,14 @@ public void setLevel(Level level) {
109119
}
110120
}
111121

122+
@Override
123+
public boolean isTraceEnabled() {
124+
return logger.isTraceEnabled();
125+
}
126+
127+
@Override
128+
public boolean isDebugEnabled() {
129+
return logger.isDebugEnabled();
130+
}
131+
112132
}

0 commit comments

Comments
 (0)