Skip to content

Commit 7588a14

Browse files
authored
Add new startup wrappers, also fix #175 (#1098)
.exe files have been dropped in favor of .cmd files on windows, which can also be used as executable in PATH.
1 parent fdcd03d commit 7588a14

File tree

9 files changed

+138
-7
lines changed

9 files changed

+138
-7
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ jobs:
7272
generate_release_notes: true
7373
env:
7474
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+

Wurstpack/wurstscript/grill.exe

-1.56 MB
Binary file not shown.

Wurstpack/wurstscript/wurstscript

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
RUNTIME="$HOME/.wurst/wurst-runtime/bin/java"
5+
6+
# Resolve script dir (absolute)
7+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
JAR="$DIR/wurst-compiler/wurstscript.jar"
10+
if [[ ! -f "$JAR" ]]; then
11+
JAR="$DIR/../wurst-compiler/wurstscript.jar"
12+
fi
13+
14+
if [[ ! -f "$JAR" ]]; then
15+
echo "[wurstscript] ERROR: Missing jar. Searched:"
16+
echo " $DIR/wurst-compiler/wurstscript.jar"
17+
echo " $DIR/../wurst-compiler/wurstscript.jar"
18+
exit 2
19+
fi
20+
21+
if [[ ! -x "$RUNTIME" ]]; then
22+
echo "[wurstscript] ERROR: Bundled runtime not found or not executable at:"
23+
echo " $RUNTIME"
24+
echo "Please reinstall wurstscript via the VSCode extension."
25+
exit 3
26+
fi
27+
28+
exec "$RUNTIME" -jar "$JAR" "$@"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@echo off
2+
setlocal EnableExtensions
3+
4+
rem ---- shared slim runtime ----
5+
set "RUNTIME=%USERPROFILE%\.wurst\wurst-runtime\bin\java.exe"
6+
7+
rem script directory (trailing backslash)
8+
set "DIR=%~dp0"
9+
10+
if not exist "%RUNTIME%" (
11+
echo [wurstscript] ERROR: Runtime not found:
12+
echo(%RUNTIME%
13+
echo Reinstall Wurstscript via the VSCode extension.
14+
exit /b 1
15+
)
16+
17+
rem ---- fixed jar location(s), no wildcards ----
18+
set "JAR=%DIR%wurst-compiler\wurstscript.jar"
19+
if not exist "%JAR%" set "JAR=%DIR%..\wurst-compiler\wurstscript.jar"
20+
if not exist "%JAR%" (
21+
echo [wurstscript] ERROR: Missing jar:
22+
echo(%DIR%wurst-compiler\wurstscript.jar
23+
echo or
24+
echo(%DIR%..\wurst-compiler\wurstscript.jar
25+
exit /b 1
26+
)
27+
28+
rem Optional JVM flags via env var, e.g. set WURST_JAVA_OPTS=-Xmx1g
29+
"%RUNTIME%" %WURST_JAVA_OPTS% -jar "%JAR%" %*
30+
endlocal
-1.56 MB
Binary file not shown.

de.peeeq.wurstscript/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ buildscript {
88

99
plugins {
1010
id 'java'
11-
id 'application'
1211
id 'antlr'
1312
id 'eclipse'
1413
id 'idea'
@@ -27,9 +26,7 @@ import org.eclipse.jgit.lib.ObjectId
2726

2827
import java.util.regex.Pattern
2928

30-
application {
31-
mainClass = "de.peeeq.wurstio.Main"
32-
}
29+
ext.mainClassName = "de.peeeq.wurstio.Main"
3330

3431
version = "1.8.1.0"
3532

@@ -229,7 +226,9 @@ shadowJar {
229226
archiveBaseName.set('wurstscript')
230227
archiveClassifier.set('')
231228
archiveVersion.set('')
232-
manifest { attributes 'Main-Class': application.mainClass.get() }
229+
manifest {
230+
attributes 'Main-Class': mainClassName
231+
}
233232
}
234233

235234
def fatJar = shadowJar.archiveFile.map { it.asFile }

de.peeeq.wurstscript/deploy.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ tasks.register("assembleSlimCompilerDist", Copy) {
167167
}
168168
}
169169

170+
tasks.named("assembleSlimCompilerDist", Copy) { t ->
171+
if (os.isWindows()) {
172+
from("../Wurstpack/wurstscript/wurstscript.cmd") { into(".") }
173+
} else {
174+
from("../Wurstpack/wurstscript/wurstscript") {
175+
into(".")
176+
}
177+
}
178+
}
179+
170180
// 4a) Package ZIP on Windows
171181
tasks.register("packageSlimCompilerDistZip", Zip) {
172182
description = "Packages slim dist as a ZIP archive (Windows)."

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/validation/WurstValidator.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,51 @@ private void checkCall(StmtCall call) {
15681568
call.attrCallSignature().checkSignatureCompatibility(call.attrFunctionSignature(), funcName, call);
15691569
}
15701570

1571+
/** Error when a field in this class hides a field from a superclass. */
1572+
private void checkFieldShadowing(ClassDef c) {
1573+
// Iterate only the fields *declared* in this class:
1574+
for (NameLink nl : c.attrNameLinks().values()) {
1575+
NameDef def = nl.getDef();
1576+
// consider only variables that are declared in this class body
1577+
if (!(def instanceof GlobalVarDef)) continue;
1578+
if (nl.getDefinedIn() != c) continue; // not declared here
1579+
1580+
String name = def.getName();
1581+
1582+
// Look up all visible declarations of the same name in this class scope:
1583+
ImmutableCollection<DefLink> all = c.attrNameLinks().get(name);
1584+
for (DefLink other : all) {
1585+
if (!(other instanceof NameLink)) continue;
1586+
if (other.getDefinedIn() == c) continue; // skip "self" (duplicates in same class handled elsewhere)
1587+
NameDef od = other.getDef();
1588+
if (!(od instanceof GlobalVarDef)) continue;
1589+
1590+
// Is the other definition a superclass' field?
1591+
StructureDef owner = od.attrNearestStructureDef();
1592+
if (owner instanceof ClassDef) {
1593+
ClassDef superOwner = (ClassDef) owner;
1594+
if (isStrictSuperclassOf(superOwner, c)) {
1595+
// produce the requested error text
1596+
def.addError("Variable " + name + " in class " + c.getName()
1597+
+ " hides variable " + name + " from superclass " + superOwner.getName());
1598+
// one error per conflicting ancestor is enough
1599+
break;
1600+
}
1601+
}
1602+
}
1603+
}
1604+
}
15711605

1572-
// crude cap to avoid unbounded growth; tune as needed
1606+
private static boolean isStrictSuperclassOf(ClassDef sup, ClassDef sub) {
1607+
WurstTypeClass t = sub.attrTypC();
1608+
WurstTypeClass cur = (t != null) ? t.extendedClass() : null;
1609+
while (cur != null) {
1610+
ClassDef cd = cur.getClassDef();
1611+
if (cd == sup) return true;
1612+
cur = cur.extendedClass();
1613+
}
1614+
return false;
1615+
}
15731616

15741617
private static boolean isSubtypeCached(WurstType actual, WurstType expected, Annotation site) {
15751618
if (actual == expected) return true;
@@ -1796,12 +1839,15 @@ private void checkReturnInFunc(StmtReturn s, FunctionImplementation func) {
17961839

17971840
private void visit(ClassDef classDef) {
17981841
checkTypeName(classDef, classDef.getName());
1799-
if (!(classDef.getExtendedClass() instanceof NoTypeExpr) && !(classDef.getExtendedClass().attrTyp() instanceof WurstTypeClass)) {
1842+
if (!(classDef.getExtendedClass() instanceof NoTypeExpr)
1843+
&& !(classDef.getExtendedClass().attrTyp() instanceof WurstTypeClass)) {
18001844
classDef.getExtendedClass().addError("Classes may only extend other classes.");
18011845
}
18021846
if (classDef.isInnerClass() && !classDef.attrIsStatic()) {
18031847
classDef.addError("At the moment only static inner classes are supported.");
18041848
}
1849+
1850+
checkFieldShadowing(classDef);
18051851
}
18061852

18071853
private void checkTypeName(Element source, String name) {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,4 +1443,21 @@ public void minusRewrite() {
14431443
}
14441444

14451445

1446+
@Test
1447+
public void duplicateNameInClassHierachy() {
1448+
testAssertErrorsLines(false, "Variable x in class B hides variable x from superclass A",
1449+
"package test",
1450+
"native testSuccess()",
1451+
"class A",
1452+
" int x",
1453+
"class B extends A",
1454+
" int x",
1455+
"init",
1456+
" let b = new B()",
1457+
" if b != null",
1458+
" testSuccess()",
1459+
"endpackage");
1460+
}
1461+
1462+
14461463
}

0 commit comments

Comments
 (0)