Skip to content

Commit 4bf0ff0

Browse files
authored
Minor changes (#1184)
* Update README.markdown * macos support * fix class management jass bug, ignore utf BOM
1 parent dfbfeb2 commit 4bf0ff0

9 files changed

Lines changed: 125 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,27 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
# Emit a wider matrix on master pushes (adds macOS), narrow on PRs (saves minutes)
15+
setup:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
matrix: ${{ steps.set-matrix.outputs.matrix }}
19+
steps:
20+
- id: set-matrix
21+
shell: bash
22+
run: |
23+
if [[ "${{ github.event_name }}" == "push" ]]; then
24+
echo 'matrix={"include":[{"os":"ubuntu-latest"},{"os":"windows-latest"},{"os":"macos-13"},{"os":"macos-14"}]}' >> "$GITHUB_OUTPUT"
25+
else
26+
echo 'matrix={"include":[{"os":"ubuntu-latest"},{"os":"windows-latest"}]}' >> "$GITHUB_OUTPUT"
27+
fi
28+
1429
build:
1530
name: Gradle build on ${{ matrix.os }}
31+
needs: setup
1632
strategy:
1733
fail-fast: false
18-
matrix:
19-
os: [ubuntu-latest, windows-latest]
34+
matrix: ${{ fromJson(needs.setup.outputs.matrix) }}
2035
runs-on: ${{ matrix.os }}
2136
permissions:
2237
contents: read
@@ -147,14 +162,14 @@ jobs:
147162
mkdir -p upload
148163
find artifacts -type f -name '*.zip' -print0 | xargs -0 -I{} cp "{}" upload/
149164
150-
- name: Verify we have both platform zips
165+
- name: Verify we have all platform zips
151166
shell: bash
152167
run: |
153168
shopt -s nullglob
154169
zips=(upload/*.zip)
155170
echo "Found ${#zips[@]} zip(s):"; ls -alh upload
156-
if (( ${#zips[@]} < 2 )); then
157-
echo "ERROR: expected at least Win + Linux zips."
171+
if (( ${#zips[@]} < 4 )); then
172+
echo "ERROR: expected Win + Linux + macOS x64 + macOS arm64 zips (got ${#zips[@]})."
158173
exit 1
159174
fi
160175

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ Checksums/testmd5.txt
5656
downloads/
5757
WurstSetup/proguard.map
5858
de.peeeq.wurstscript/output.txt
59+
/HelperScripts/gamedata
60+
/HelperScripts/.gradle

README.markdown

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
Wurstscript is a delicious programming language which compiles to Jass or Lua code that is used to power WarCraft III maps.
44

55
[![Build](https://github.com/wurstscript/WurstScript/actions/workflows/build.yml/badge.svg)](https://github.com/wurstscript/WurstScript/actions/workflows/build.yml)
6-
[![Release](https://github.com/wurstscript/WurstScript/actions/workflows/release.yml/badge.svg)](https://github.com/wurstscript/WurstScript/actions/workflows/release.yml)
76
[![GitHub issues](https://img.shields.io/github/issues/wurstscript/WurstScript.svg)]()
87
[![GitHub pull requests](https://img.shields.io/github/issues-pr/wurstscript/WurstScript.svg)]()
98
[![Coverage Status](https://coveralls.io/repos/github/wurstscript/WurstScript/badge.svg?branch=master)](https://coveralls.io/github/wurstscript/WurstScript?branch=master)

de.peeeq.wurstscript/build.gradle

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,21 @@ shadowJar {
292292
}
293293

294294
def fatJar = shadowJar.archiveFile.map { it.asFile }
295+
def wurstUserDir = "${System.properties['user.home']}/.wurst"
296+
def wurstCompilerDir = "${wurstUserDir}/wurst-compiler"
297+
298+
tasks.register('delete_legacy_userdir_compiler_jar', Delete) {
299+
delete "${wurstUserDir}/wurstscript.jar"
300+
}
295301

296302
tasks.register('make_for_userdir', Copy) {
297-
dependsOn 'shadowJar', 'make_for_userdir_wurst_compiler'
303+
dependsOn 'shadowJar', 'delete_legacy_userdir_compiler_jar'
298304
from fatJar
299-
into "${System.properties['user.home']}/.wurst/"
305+
into wurstCompilerDir
300306
}
301307

302-
tasks.register('make_for_userdir_wurst_compiler', Copy) {
303-
dependsOn 'shadowJar'
304-
from fatJar
305-
into "${System.properties['user.home']}/.wurst/wurst-compiler/"
308+
tasks.register('make_for_userdir_wurst_compiler') {
309+
dependsOn 'make_for_userdir'
306310
}
307311

308312
tasks.register('make_for_wurstpack', Copy) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ public JassProg transformProgToJass() {
394394
// eliminate
395395
beginPhase(2, "Eliminate generics");
396396
new EliminateGenerics(imTranslator2, imProg2).transform();
397+
imTranslator2.clearStaleClassManagementVars();
397398
printDebugImProg("./test-output/im " + stage++ + "_genericsEliminated.im");
398399
timeTaker.endPhase();
399400
// eliminate classes

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/parser/AntlrTokenPipeline.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Result<TS, P, T> run(
3838
) throws IOException {
3939

4040
CharStream input = CharStreams.fromReader(reader);
41+
if (input.LA(1) == '\uFEFF') {
42+
input.consume();
43+
}
4144

4245
TS tokenSource = tokenSourceFactory.create(input);
4346
if (installLexerListener != null) {

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/ImTranslator.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,23 @@ public Map<ImClass, ClassManagementVars> getClassManagementVars() {
21022102
return classManagementVars;
21032103
}
21042104

2105+
public void clearStaleClassManagementVars() {
2106+
if (classManagementVars == null) {
2107+
return;
2108+
}
2109+
if (classManagementVars.keySet().stream().anyMatch(c -> !imProg.getClasses().contains(c))
2110+
|| classManagementVars.values().stream().anyMatch(this::hasStaleClassManagementVars)) {
2111+
classManagementVars = null;
2112+
}
2113+
}
2114+
2115+
private boolean hasStaleClassManagementVars(ClassManagementVars vars) {
2116+
return !imProg.getGlobals().contains(vars.free)
2117+
|| !imProg.getGlobals().contains(vars.freeCount)
2118+
|| !imProg.getGlobals().contains(vars.maxIndex)
2119+
|| !imProg.getGlobals().contains(vars.typeId);
2120+
}
2121+
21052122
private Partitions<ImClass> buildClassPartitions() {
21062123
Partitions<ImClass> p = new Partitions<>();
21072124
for (ImClass c : imProg.getClasses()) {

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,67 @@ public void classes_method() throws IOException {
4747
testAssertOkFile(new File(TEST_DIR + "Classes_method.wurst"), true);
4848
}
4949

50+
@Test
51+
public void jassKeepsTypeIdGlobalsWhenDestroyGuardReadsThem() throws IOException {
52+
testAssertOkLines(false,
53+
"package test",
54+
" class Reference<T>",
55+
" T value",
56+
"",
57+
" init",
58+
" let r = new Reference<int>",
59+
" destroy r",
60+
"endpackage"
61+
);
62+
63+
String opt = Files.readString(new File(TEST_OUTPUT_PATH + "ClassesTests_jassKeepsTypeIdGlobalsWhenDestroyGuardReadsThem_opt.j").toPath(), StandardCharsets.UTF_8);
64+
assertTrue(opt.contains("integer array Reference_nextFree"),
65+
"Expected generated Jass to keep the Reference_nextFree global declaration.\n" + opt);
66+
assertTrue(opt.contains("integer Reference_firstFree=0"),
67+
"Expected generated Jass to keep the Reference_firstFree global declaration.\n" + opt);
68+
assertTrue(opt.contains("integer Reference_maxIndex=0"),
69+
"Expected generated Jass to keep the Reference_maxIndex global declaration.\n" + opt);
70+
assertTrue(opt.contains("integer array Reference_typeId"),
71+
"Expected generated Jass to keep the Reference_typeId global declaration.\n" + opt);
72+
assertTrue(opt.contains("Reference_typeId[obj]"),
73+
"Expected generated Jass to still reference Reference_typeId in destroy/dispatch logic.");
74+
assertTrue(opt.contains("Reference_nextFree[Reference_firstFree]"),
75+
"Expected generated Jass to still reference the recycle stack globals.");
76+
}
77+
78+
@Test
79+
public void jassNewGenericsRebuildsClassManagementVarsAfterCompiletime() throws IOException {
80+
test()
81+
.runCompiletimeFunctions(true)
82+
.executeProg(false)
83+
.lines(
84+
"package test",
85+
" class Reference<T:>",
86+
" T val",
87+
" construct(T val)",
88+
" this.val = val",
89+
"",
90+
" class Box",
91+
"",
92+
" constant compiletimeRef = new Reference<int>(0)",
93+
"",
94+
" init",
95+
" let r = new Reference<int>(1)",
96+
" destroy r",
97+
" let s = new Reference<bool>(true)",
98+
" destroy s",
99+
"endpackage"
100+
);
101+
102+
String opt = Files.readString(new File(TEST_OUTPUT_PATH + "ClassesTests_jassNewGenericsRebuildsClassManagementVarsAfterCompiletime_opt.j").toPath(), StandardCharsets.UTF_8);
103+
assertTrue(opt.contains("integer array Reference_integer__typeId"),
104+
"Expected generated Jass to declare integer-specialized class-management globals.\n" + opt);
105+
assertTrue(opt.contains("integer array Reference_boolean__typeId"),
106+
"Expected generated Jass to declare boolean-specialized class-management globals.\n" + opt);
107+
assertFalse(opt.contains("Reference_typeId["),
108+
"Expected specialized generic lifecycle code not to reference undeclared raw Reference_typeId.");
109+
}
110+
50111
@Test
51112
public void dispatchNarrowingUsesStaticReceiverTypeInJass() throws IOException {
52113
testAssertOkLines(true,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ public void testStringNullCheckStaysNull() throws IOException {
380380
);
381381
}
382382

383+
@Test
384+
public void jassFileWithUtf8Bom() {
385+
testJurstWithJass(false, false,
386+
"\uFEFFglobals\nendglobals\n",
387+
Utils.string(
388+
"package test",
389+
"endpackage",
390+
"")
391+
);
392+
}
393+
383394
private void testJurstWithJass(boolean executeProg, boolean withStdLib, String jass, String jurst) {
384395
Map<String, String> inputs = ImmutableMap.of(
385396
"example.j", jass,

0 commit comments

Comments
 (0)