Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JHCR support update #1089

Merged
merged 1 commit into from
Jan 24, 2024
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 @@ -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 {

Expand Down Expand Up @@ -111,15 +114,15 @@ 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();
}

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);
}

Expand Down Expand Up @@ -205,7 +208,6 @@ public static ImmutableList<File> checkDependencyFile(File depFile, WurstGui gui
}



// import wurst folder if it exists
Optional<File> l_mapFile = mapFile;
if (l_mapFile.isPresent()) {
Expand Down Expand Up @@ -290,7 +292,7 @@ public static void addDependenciesFromFolder(File projectFolder, Collection<File
if (depProjects != null) {
for (File depFile : depProjects) {
if (depFile.isDirectory()
&& dependencies.stream().noneMatch(f -> FileUtils.sameFile(f, depFile))) {
&& dependencies.stream().noneMatch(f -> FileUtils.sameFile(f, depFile))) {
dependencies.add(depFile);
}
}
Expand Down Expand Up @@ -352,7 +354,7 @@ private void resolveImport(Function<File, CompilationUnit> 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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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());


Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down