Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 6e473d2

Browse files
authored
Merge pull request #8 from QuantumVoxel/updates/graalvm-23
Fix Native Image crash
2 parents 0b749c3 + 2dd3c31 commit 6e473d2

5 files changed

Lines changed: 49 additions & 38 deletions

File tree

.github/workflows/build-native-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
- name: Checkout Repository
1717
uses: actions/checkout@v4
1818

19-
- name: Set up GraalVM JDK 23
19+
- name: Set up GraalVM JDK 21
2020
uses: graalvm/setup-graalvm@v1
2121
with:
2222
distribution: 'graalvm'
23-
java-version: '23'
23+
java-version: '21'
2424

2525
- name: Grant execute permission for Gradle (Linux & macOS)
2626
if: runner.os != 'Windows'

.github/workflows/build-native.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: graalvm/setup-graalvm@v1
1919
with:
2020
distribution: 'graalvm'
21-
java-version: '23'
21+
java-version: '21'
2222

2323
- name: Grant execute permission for Gradle
2424
run: chmod +x gradlew

common/src/main/kotlin/dev/ultreon/quantum/scripting/function/VirtualFunction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ object VirtualFunctions {
101101
val last = commonResources["scripts"]?.asDir()?.get(name)?.asLeaf()?.last()
102102
val text = last?.text
103103
return@register QFuncInterpreter(context.paramValues)
104-
.interpretAsync(
104+
.interpret(
105105
text ?: run {
106106
logger.error("Script not found: $name")
107107
return@register null

common/src/main/kotlin/dev/ultreon/quantum/scripting/qfunc/QFuncInterpreter.kt

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,26 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
5151
fun interpret(
5252
code: String,
5353
callContext: CallContext,
54-
completion: () -> Unit = {},
55-
error: (Throwable) -> Unit = {}
56-
) {
57-
val lexer = QFuncLexer(code, "<dynamic>")
54+
filename: String = "<dynamic>"
55+
): ContextValue<*>? {
56+
val lexer = QFuncLexer(code, filename)
5857
val parser = QFuncParser(lexer)
5958

6059
this@QFuncInterpreter.inputParameters =
6160
callContext.paramValues + ("core" to ContextValue(ContextType.core, CoreUtils))
6261
this@QFuncInterpreter.context = MainDispatcher
6362

6463
try {
65-
runBlocking { visit(parser.file ?: return@runBlocking) }
66-
completion()
64+
return runBlocking { visit(parser.file ?: return@runBlocking null) as? ContextValue<*> }
6765
} catch (e: QFuncSyntaxError) {
6866
logger.error(e.toString())
69-
error(e)
67+
} catch (e: QFuncParserException) {
68+
logger.error("Error parsing: " + e.message)
69+
} catch (e: Exception) {
70+
logger.error(e.toString() + "\n" + e.stackTraceToString())
7071
}
72+
73+
return null
7174
}
7275

7376
suspend fun interpretAsync(
@@ -234,6 +237,7 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
234237
throw QFuncInterpreterException("Cannot NOT non-boolean value", tree.filename, tree.line, tree.column)
235238
}
236239
}
240+
237241
QFuncTokenType.SUB -> {
238242
when (value) {
239243
is Int -> return ContextValue(ContextType.int, -value)
@@ -243,6 +247,7 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
243247
else -> throw QFuncInterpreterException("Cannot SUB non-number value", tree.filename, tree.line, tree.column)
244248
}
245249
}
250+
246251
QFuncTokenType.ADD -> {
247252
when (value) {
248253
is Int -> return ContextValue(ContextType.int, abs(value))
@@ -252,31 +257,50 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
252257
else -> throw QFuncInterpreterException("Cannot ADD non-number value", tree.filename, tree.line, tree.column)
253258
}
254259
}
260+
255261
QFuncTokenType.INCREMENT -> {
256262
when (value) {
257263
is Int -> return ContextValue(ContextType.int, value + 1)
258264
is Long -> return ContextValue(ContextType.long, value + 1)
259265
is Float -> return ContextValue(ContextType.float, value + 1)
260266
is Double -> return ContextValue(ContextType.double, value + 1)
261-
else -> throw QFuncInterpreterException("Cannot INCREMENT non-number value", tree.filename, tree.line, tree.column)
267+
else -> throw QFuncInterpreterException(
268+
"Cannot INCREMENT non-number value",
269+
tree.filename,
270+
tree.line,
271+
tree.column
272+
)
262273
}
263274
}
275+
264276
QFuncTokenType.DECREMENT -> {
265277
when (value) {
266278
is Int -> return ContextValue(ContextType.int, value - 1)
267279
is Long -> return ContextValue(ContextType.long, value - 1)
268280
is Float -> return ContextValue(ContextType.float, value - 1)
269281
is Double -> return ContextValue(ContextType.double, value - 1)
270-
else -> throw QFuncInterpreterException("Cannot DECREMENT non-number value", tree.filename, tree.line, tree.column)
282+
else -> throw QFuncInterpreterException(
283+
"Cannot DECREMENT non-number value",
284+
tree.filename,
285+
tree.line,
286+
tree.column
287+
)
271288
}
272289
}
290+
273291
QFuncTokenType.BITWISE_NOT -> {
274292
when (value) {
275293
is Int -> return ContextValue(ContextType.int, value.inv())
276294
is Long -> return ContextValue(ContextType.long, value.inv())
277-
else -> throw QFuncInterpreterException("Cannot BITWISE_NOT non-number or non-integer value", tree.filename, tree.line, tree.column)
295+
else -> throw QFuncInterpreterException(
296+
"Cannot BITWISE_NOT non-number or non-integer value",
297+
tree.filename,
298+
tree.line,
299+
tree.column
300+
)
278301
}
279302
}
303+
280304
else -> throw QFuncInterpreterException("Unknown operator: ${tree.type}", tree.filename, tree.line, tree.column)
281305
}
282306
}
@@ -446,7 +470,12 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
446470
throw QFuncInterpreterException("Not a function", tree.filename, tree.line, tree.column)
447471
}
448472
} catch (e: Exception) {
449-
throw QFuncInterpreterException("Error calling function: ${e.message}", tree.filename, tree.line, tree.column)
473+
throw QFuncInterpreterException(
474+
"Error calling function: ${e.message}",
475+
tree.filename,
476+
tree.line,
477+
tree.column
478+
)
450479
}
451480
}
452481
}
@@ -567,16 +596,7 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
567596
break
568597
}
569598

570-
try {
571-
visit(tree.body)
572-
} catch (e: QFuncInterpreterException) {
573-
logger.error("Error in while loop at ${tree.filename}:${tree.line}:${tree.column}", e)
574-
throw e
575-
} catch (e: Break) {
576-
break
577-
} catch (e: Continue) {
578-
continue
579-
}
599+
visit(tree.body)
580600
}
581601

582602
return null
@@ -594,18 +614,9 @@ class QFuncInterpreter(private var inputParameters: Map<String, ContextValue<*>?
594614
}
595615

596616
for (item in iterable) {
597-
try {
598-
this.loopValues.push(ContextValue(ContextType[(item!!)::class] as ContextType<*>, item))
599-
visit(tree.body)
600-
this.loopValues.pop()
601-
} catch (e: QFuncInterpreterException) {
602-
logger.error("Error in for loop at ${tree.filename}:${tree.line}:${tree.column}", e)
603-
throw e
604-
} catch (e: Break) {
605-
break
606-
} catch (e: Continue) {
607-
continue
608-
}
617+
this.loopValues.push(ContextValue(ContextType[(item!!)::class] as ContextType<*>, item))
618+
visit(tree.body)
619+
this.loopValues.pop()
609620
}
610621

611622
return null

lwjgl3/nativeimage.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ project(":lwjgl3") {
2020
sharedLibrary = false
2121
resources.autodetect()
2222
javaLauncher = javaToolchains.launcherFor {
23-
languageVersion = JavaLanguageVersion.of(23)
23+
languageVersion = JavaLanguageVersion.of(21)
2424
}
2525

2626
if (System.getProperty("os.name").containsIgnoreCase("windows")) {

0 commit comments

Comments
 (0)