diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java index 2578664f3..6f404664f 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/WurstCompilerJassImpl.java @@ -47,6 +47,9 @@ import java.util.function.Function; import static de.peeeq.wurstio.CompiletimeFunctionRunner.FunctionFlagToRun.CompiletimeFunctions; +import static de.peeeq.wurstscript.WurstOperator.PLUS; +import static de.peeeq.wurstscript.translation.imtranslation.FunctionFlagEnum.IS_EXTERN; +import static de.peeeq.wurstscript.translation.imtranslation.FunctionFlagEnum.IS_NATIVE; public class WurstCompilerJassImpl implements WurstCompiler { @@ -111,7 +114,7 @@ public void runCompiletime(WurstProjectConfigData projectConfigData, boolean isP // TODO run optimizations later? gui.sendProgress("Running compiletime functions"); CompiletimeFunctionRunner ctr = new CompiletimeFunctionRunner(imTranslator, getImProg(), getMapFile(), getMapfileMpqEditor(), gui, - CompiletimeFunctions, projectConfigData, isProd, cache); + CompiletimeFunctions, projectConfigData, isProd, cache); ctr.setInjectObjects(runArgs.isInjectObjects()); ctr.setOutputStream(new PrintStream(System.err)); ctr.run(); @@ -119,7 +122,7 @@ public void runCompiletime(WurstProjectConfigData projectConfigData, boolean isP if (gui.getErrorCount() > 0) { CompileError compileError = gui - .getErrorList().get(0); + .getErrorList().get(0); throw new RequestFailedException(MessageType.Error, "Could not compile project (error in running compiletime functions/expressions): ", compileError); } @@ -205,7 +208,6 @@ public static ImmutableList checkDependencyFile(File depFile, WurstGui gui } - // import wurst folder if it exists Optional l_mapFile = mapFile; if (l_mapFile.isPresent()) { @@ -290,7 +292,7 @@ public static void addDependenciesFromFolder(File projectFolder, Collection FileUtils.sameFile(f, depFile))) { + && dependencies.stream().noneMatch(f -> FileUtils.sameFile(f, depFile))) { dependencies.add(depFile); } } @@ -352,7 +354,7 @@ private void resolveImport(Function addCompilationUnit, S // ignore this package } else { imp.addError("The import '" + imp.getPackagename() + "' could not be resolved.\n" + "Available packages: " - + Utils.join(getLibs().keySet(), ", ")); + + Utils.join(getLibs().keySet(), ", ")); } } } else { @@ -542,13 +544,12 @@ public JassProg transformProgToJass() { } - // translate flattened intermediate lang to jass: beginPhase(14, "translate to jass"); getImTranslator().calculateCallRelationsAndUsedVariables(); ImToJassTranslator translator = - new ImToJassTranslator(getImProg(), getImTranslator().getCalledFunctions(), getImTranslator().getMainFunc(), getImTranslator().getConfFunc()); + new ImToJassTranslator(getImProg(), getImTranslator().getCalledFunctions(), getImTranslator().getMainFunc(), getImTranslator().getConfFunc()); prog = translator.translate(); if (errorHandler.getErrorCount() > 0) { prog = null; @@ -569,17 +570,22 @@ private void addJassHotCodeReloadCode() { // add call to JHCR_Init_init in main stmts.add(callExtern(trace, CallType.EXECUTE, "JHCR_Init_init")); - ImFunction statusFunc = findFunction("JHCR_API_GetLastStatus", trace.attrErrorPos()); - ImFunctionCall jhcrStatusCall = JassIm.ImFunctionCall(trace, statusFunc, JassIm.ImTypeArguments(), JassIm.ImExprs(), false, CallType.NORMAL); + ImFunction statusFunction = JassIm.ImFunction(trace, "JHCR_API_GetLastStatus", JassIm.ImTypeVars(), + JassIm.ImVars(), JassIm.ImSimpleType("integer"), JassIm.ImVars(), JassIm.ImStmts(JassIm.ImReturn(trace, JassIm.ImIntVal(0))), + List.of()); + + imProg.getFunctions().add(statusFunction); + + ImFunctionCall jhcrStatusCall = JassIm.ImFunctionCall(trace, statusFunction, JassIm.ImTypeArguments(), JassIm.ImExprs(), false, CallType.NORMAL); ImFunction I2S = findNative("I2S", trace.attrErrorPos()); ImFunctionCall statusCall = JassIm.ImFunctionCall(trace, I2S, JassIm.ImTypeArguments(), JassIm.ImExprs(jhcrStatusCall), false, CallType.NORMAL); // add reload trigger for pressing escape ImStmts reloadBody = JassIm.ImStmts( - callExtern(trace, CallType.EXECUTE, "JHCR_Init_parse") -// callExtern(trace, CallType.NORMAL, "BJDebugMsg", JassIm.ImOperatorCall(PLUS, JassIm.ImExprs(JassIm.ImStringVal("Code reloaded, status: "), statusCall)) - ); + callExtern(trace, CallType.EXECUTE, "JHCR_Init_parse"), + callExtern(trace, CallType.NORMAL, "BJDebugMsg", JassIm.ImOperatorCall(PLUS, JassIm.ImExprs(JassIm.ImStringVal("Code reloaded, status: "), statusCall))) + ); ImFunction jhcr_reload = JassIm.ImFunction(trace, "jhcr_reload_on_escape", JassIm.ImTypeVars(), JassIm.ImVars(), JassIm.ImVoid(), JassIm.ImVars(), reloadBody, Collections.emptyList()); @@ -588,9 +594,9 @@ private void addJassHotCodeReloadCode() { // TriggerRegisterPlayerEventEndCinematic(trig, Player(0)) stmts.add(JassIm.ImSet(trace, JassIm.ImVarAccess(trig), callExtern(trace, CallType.NORMAL, "CreateTrigger"))); stmts.add(callExtern(trace, CallType.NORMAL, "TriggerRegisterPlayerEventEndCinematic", JassIm.ImVarAccess(trig), - callExtern(trace, CallType.NORMAL, "Player", JassIm.ImIntVal(0)))); + callExtern(trace, CallType.NORMAL, "Player", JassIm.ImIntVal(0)))); stmts.add(callExtern(trace, CallType.NORMAL, "TriggerAddAction", JassIm.ImVarAccess(trig), - JassIm.ImFuncRef(trace, jhcr_reload))); + JassIm.ImFuncRef(trace, jhcr_reload))); mainFunc.getBody().addAll(0, stmts); } @@ -620,7 +626,7 @@ private ImFunction findFunction(String funcName, WPos trace) { @NotNull private ImFunctionCall callExtern(Element trace, CallType callType, String functionName, ImExpr... arguments) { - ImFunction jhcrinit = JassIm.ImFunction(trace, functionName, JassIm.ImTypeVars(), JassIm.ImVars(), JassIm.ImVoid(), JassIm.ImVars(), JassIm.ImStmts(), Collections.singletonList(FunctionFlagEnum.IS_EXTERN)); + ImFunction jhcrinit = JassIm.ImFunction(trace, functionName, JassIm.ImTypeVars(), JassIm.ImVars(), JassIm.ImVoid(), JassIm.ImVars(), JassIm.ImStmts(), Collections.singletonList(IS_EXTERN)); return JassIm.ImFunctionCall(trace, jhcrinit, JassIm.ImTypeArguments(), JassIm.ImExprs(arguments), true, callType); } @@ -660,7 +666,7 @@ private void beginPhase(int phase, String description) { } private void printDebugImProg(String debugFile) { - if (!errorHandler.isUnitTestMode() ) { + if (!errorHandler.isUnitTestMode()) { // output only in unit test mode return; } @@ -715,8 +721,8 @@ private CompilationUnit processMap(File file) { // the war3map.j file was generated by wurst // this should not be the case, as we will get duplicate function errors in this case throw new AbortCompilationException( - "Map was not saved correctly. Please try saving the map again.\n\n" + "This usually happens if you change the name of the map or \n" - + "if you have used the test-map-button without saving the map first."); + "Map was not saved correctly. Please try saving the map again.\n\n" + "This usually happens if you change the name of the map or \n" + + "if you have used the test-map-button without saving the map first."); } // move file to wurst directory diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java index 2a8df5f2f..f0bdc6198 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java @@ -459,14 +459,15 @@ private W3InstallationData getBestW3InstallationData() throws RequestFailedExcep return new W3InstallationData(Optional.empty(), Optional.empty()); } if (wc3Path.isPresent() && StringUtils.isNotBlank(wc3Path.get())) { - W3InstallationData w3data = new W3InstallationData(langServer, new File(wc3Path.get()), this instanceof RunMap); + W3InstallationData w3data = new W3InstallationData(langServer, new File(wc3Path.get()), + this instanceof RunMap && !runArgs.isHotReload()); if (w3data.getWc3PatchVersion().isEmpty()) { throw new RequestFailedException(MessageType.Error, "Could not find Warcraft III installation at specified path: " + wc3Path); } return w3data; } else { - return new W3InstallationData(langServer, this instanceof RunMap); + return new W3InstallationData(langServer, this instanceof RunMap && !runArgs.isHotReload()); } }