diff --git a/buildSrc/src/main/kotlin/luau.jextract.gradle.kts b/buildSrc/src/main/kotlin/luau.jextract.gradle.kts index 66fab357..d3a36fd9 100644 --- a/buildSrc/src/main/kotlin/luau.jextract.gradle.kts +++ b/buildSrc/src/main/kotlin/luau.jextract.gradle.kts @@ -58,6 +58,7 @@ tasks.named("jextract") { "lua_rawgetfield", "lua_rawget", "lua_rawgeti", "lua_getinfo", "lua_setuserdatametatable", "lua_pcall", "lua_call", "lua_tolstringatom", "lua_namecallatom", + "lua_debugtrace" ) typedefs.addAll("lua_Alloc", "lua_CFunction", "lua_Destructor", "lua_Continuation") structs.addAll("lua_Callbacks", "lua_Debug") @@ -73,7 +74,7 @@ tasks.named("jextract") { "luaopen_utf8", "luaopen_math", "luaopen_debug", "luaopen_vector", "luaL_openlibs", "luaL_optboolean", - "luaL_sandbox", "luaL_sandboxthread", + "luaL_sandbox", "luaL_sandboxthread" ) } @@ -110,6 +111,7 @@ tasks.named("jextract") { "luaW_lessthan", "luaLW_checkboolean", "luaLW_checkudata", "luaW_assertconf_log", "luaW_assertconf_dump", + "luaW_interrupt_preempt_handler" ) } } diff --git a/native/luau b/native/luau index ccc532dd..9471fac4 160000 --- a/native/luau +++ b/native/luau @@ -1 +1 @@ -Subproject commit ccc532ddd1b2698e8297f347e77aa82f3916eeb8 +Subproject commit 9471fac46bbbcbf907e53aaca02ecde605aebe3e diff --git a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_CompileOptions.java b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_CompileOptions.java index b66d0ec9..ce1d25af 100644 --- a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_CompileOptions.java +++ b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_CompileOptions.java @@ -72,7 +72,7 @@ public static final GroupLayout layout() { return optimizationLevel$LAYOUT; } - private static final long optimizationLevel$OFFSET = 0; + private static final long optimizationLevel$OFFSET = $LAYOUT.byteOffset(groupElement("optimizationLevel")); /** * Offset for field: @@ -116,7 +116,7 @@ public static void optimizationLevel(MemorySegment struct, int fieldValue) { return debugLevel$LAYOUT; } - private static final long debugLevel$OFFSET = 4; + private static final long debugLevel$OFFSET = $LAYOUT.byteOffset(groupElement("debugLevel")); /** * Offset for field: @@ -160,7 +160,7 @@ public static void debugLevel(MemorySegment struct, int fieldValue) { return typeInfoLevel$LAYOUT; } - private static final long typeInfoLevel$OFFSET = 8; + private static final long typeInfoLevel$OFFSET = $LAYOUT.byteOffset(groupElement("typeInfoLevel")); /** * Offset for field: @@ -204,7 +204,7 @@ public static void typeInfoLevel(MemorySegment struct, int fieldValue) { return coverageLevel$LAYOUT; } - private static final long coverageLevel$OFFSET = 12; + private static final long coverageLevel$OFFSET = $LAYOUT.byteOffset(groupElement("coverageLevel")); /** * Offset for field: @@ -248,7 +248,7 @@ public static void coverageLevel(MemorySegment struct, int fieldValue) { return vectorLib$LAYOUT; } - private static final long vectorLib$OFFSET = 16; + private static final long vectorLib$OFFSET = $LAYOUT.byteOffset(groupElement("vectorLib")); /** * Offset for field: @@ -292,7 +292,7 @@ public static void vectorLib(MemorySegment struct, MemorySegment fieldValue) { return vectorCtor$LAYOUT; } - private static final long vectorCtor$OFFSET = 24; + private static final long vectorCtor$OFFSET = $LAYOUT.byteOffset(groupElement("vectorCtor")); /** * Offset for field: @@ -336,7 +336,7 @@ public static void vectorCtor(MemorySegment struct, MemorySegment fieldValue) { return vectorType$LAYOUT; } - private static final long vectorType$OFFSET = 32; + private static final long vectorType$OFFSET = $LAYOUT.byteOffset(groupElement("vectorType")); /** * Offset for field: @@ -380,7 +380,7 @@ public static void vectorType(MemorySegment struct, MemorySegment fieldValue) { return mutableGlobals$LAYOUT; } - private static final long mutableGlobals$OFFSET = 40; + private static final long mutableGlobals$OFFSET = $LAYOUT.byteOffset(groupElement("mutableGlobals")); /** * Offset for field: @@ -424,7 +424,7 @@ public static void mutableGlobals(MemorySegment struct, MemorySegment fieldValue return userdataTypes$LAYOUT; } - private static final long userdataTypes$OFFSET = 48; + private static final long userdataTypes$OFFSET = $LAYOUT.byteOffset(groupElement("userdataTypes")); /** * Offset for field: @@ -468,7 +468,7 @@ public static void userdataTypes(MemorySegment struct, MemorySegment fieldValue) return librariesWithKnownMembers$LAYOUT; } - private static final long librariesWithKnownMembers$OFFSET = 56; + private static final long librariesWithKnownMembers$OFFSET = $LAYOUT.byteOffset(groupElement("librariesWithKnownMembers")); /** * Offset for field: @@ -512,7 +512,7 @@ public static void librariesWithKnownMembers(MemorySegment struct, MemorySegment return libraryMemberTypeCb$LAYOUT; } - private static final long libraryMemberTypeCb$OFFSET = 64; + private static final long libraryMemberTypeCb$OFFSET = $LAYOUT.byteOffset(groupElement("libraryMemberTypeCb")); /** * Offset for field: @@ -556,7 +556,7 @@ public static void libraryMemberTypeCb(MemorySegment struct, MemorySegment field return libraryMemberConstantCb$LAYOUT; } - private static final long libraryMemberConstantCb$OFFSET = 72; + private static final long libraryMemberConstantCb$OFFSET = $LAYOUT.byteOffset(groupElement("libraryMemberConstantCb")); /** * Offset for field: @@ -600,7 +600,7 @@ public static void libraryMemberConstantCb(MemorySegment struct, MemorySegment f return disabledBuiltins$LAYOUT; } - private static final long disabledBuiltins$OFFSET = 80; + private static final long disabledBuiltins$OFFSET = $LAYOUT.byteOffset(groupElement("disabledBuiltins")); /** * Offset for field: diff --git a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberConstantCallback.java b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberConstantCallback.java index 640c7874..01e8ede8 100644 --- a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberConstantCallback.java +++ b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberConstantCallback.java @@ -17,9 +17,9 @@ * typedef void (*lua_LibraryMemberConstantCallback)(const char *, const char *, lua_CompileConstant *) * } */ -public class lua_LibraryMemberConstantCallback { +public final class lua_LibraryMemberConstantCallback { - lua_LibraryMemberConstantCallback() { + private lua_LibraryMemberConstantCallback() { // Should not be called directly } @@ -58,9 +58,11 @@ public static MemorySegment allocate(lua_LibraryMemberConstantCallback.Function /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment library, MemorySegment member, MemorySegment constant) { + public static void invoke(MemorySegment funcPtr, MemorySegment library, MemorySegment member, MemorySegment constant) { try { DOWN$MH.invokeExact(funcPtr, library, member, constant); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberTypeCallback.java b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberTypeCallback.java index 68fb372c..3b35e487 100644 --- a/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberTypeCallback.java +++ b/src/generated/java/net/hollowcube/luau/internal/compiler/lua_LibraryMemberTypeCallback.java @@ -17,9 +17,9 @@ * typedef int (*lua_LibraryMemberTypeCallback)(const char *, const char *) * } */ -public class lua_LibraryMemberTypeCallback { +public final class lua_LibraryMemberTypeCallback { - lua_LibraryMemberTypeCallback() { + private lua_LibraryMemberTypeCallback() { // Should not be called directly } @@ -58,9 +58,11 @@ public static MemorySegment allocate(lua_LibraryMemberTypeCallback.Function fi, /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static int invoke(MemorySegment funcPtr,MemorySegment library, MemorySegment member) { + public static int invoke(MemorySegment funcPtr, MemorySegment library, MemorySegment member) { try { return (int) DOWN$MH.invokeExact(funcPtr, library, member); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h$shared.java b/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h$shared.java new file mode 100644 index 00000000..42d4e82b --- /dev/null +++ b/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h$shared.java @@ -0,0 +1,63 @@ +// Generated by jextract + +package net.hollowcube.luau.internal.compiler; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class luacode_h$shared { + + luacode_h$shared() { + // Should not be called directly + } + + public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR)); + public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} + diff --git a/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h.java b/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h.java index 27046c46..60700e47 100644 --- a/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h.java +++ b/src/generated/java/net/hollowcube/luau/internal/compiler/luacode_h.java @@ -12,62 +12,17 @@ import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.MemoryLayout.PathElement.*; -public class luacode_h { +public class luacode_h extends luacode_h$shared { luacode_h() { // Should not be called directly } static final Arena LIBRARY_ARENA = Arena.ofAuto(); - static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); - - static void traceDowncall(String name, Object... args) { - String traceArgs = Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")); - System.out.printf("%s(%s)\n", name, traceArgs); - } - - static MemorySegment findOrThrow(String symbol) { - return SYMBOL_LOOKUP.find(symbol) - .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); - } catch (ReflectiveOperationException ex) { - throw new AssertionError(ex); - } - } - - static MemoryLayout align(MemoryLayout layout, long align) { - return switch (layout) { - case PaddingLayout p -> p; - case ValueLayout v -> v.withByteAlignment(align); - case GroupLayout g -> { - MemoryLayout[] alignedMembers = g.memberLayouts().stream() - .map(m -> align(m, align)).toArray(MemoryLayout[]::new); - yield g instanceof StructLayout ? - MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); - } - case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); - }; - } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() .or(Linker.nativeLinker().defaultLookup()); - public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; - public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; - public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; - public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; - public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; - public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; - public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; - public static final AddressLayout C_POINTER = ValueLayout.ADDRESS - .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); - public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; private static class luau_compile { public static final FunctionDescriptor DESC = FunctionDescriptor.of( @@ -78,7 +33,7 @@ private static class luau_compile { luacode_h.C_POINTER ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_compile"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_compile"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -125,6 +80,8 @@ public static MemorySegment luau_compile(MemorySegment source, long size, Memory traceDowncall("luau_compile", source, size, options, outsize); } return (MemorySegment)mh$.invokeExact(source, size, options, outsize); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -135,7 +92,7 @@ private static class luau_set_compile_constant_nil { luacode_h.C_POINTER ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_set_compile_constant_nil"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_set_compile_constant_nil"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -182,6 +139,8 @@ public static void luau_set_compile_constant_nil(MemorySegment constant) { traceDowncall("luau_set_compile_constant_nil", constant); } mh$.invokeExact(constant); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -193,7 +152,7 @@ private static class luau_set_compile_constant_boolean { luacode_h.C_INT ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_set_compile_constant_boolean"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_set_compile_constant_boolean"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -240,6 +199,8 @@ public static void luau_set_compile_constant_boolean(MemorySegment constant, int traceDowncall("luau_set_compile_constant_boolean", constant, b); } mh$.invokeExact(constant, b); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -251,7 +212,7 @@ private static class luau_set_compile_constant_number { luacode_h.C_DOUBLE ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_set_compile_constant_number"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_set_compile_constant_number"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -298,6 +259,8 @@ public static void luau_set_compile_constant_number(MemorySegment constant, doub traceDowncall("luau_set_compile_constant_number", constant, n); } mh$.invokeExact(constant, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -312,7 +275,7 @@ private static class luau_set_compile_constant_vector { luacode_h.C_FLOAT ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_set_compile_constant_vector"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_set_compile_constant_vector"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -359,6 +322,8 @@ public static void luau_set_compile_constant_vector(MemorySegment constant, floa traceDowncall("luau_set_compile_constant_vector", constant, x, y, z, w); } mh$.invokeExact(constant, x, y, z, w); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -371,7 +336,7 @@ private static class luau_set_compile_constant_string { luacode_h.C_LONG ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_set_compile_constant_string"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_set_compile_constant_string"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -418,6 +383,8 @@ public static void luau_set_compile_constant_string(MemorySegment constant, Memo traceDowncall("luau_set_compile_constant_string", constant, s, l); } mh$.invokeExact(constant, s, l); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -428,7 +395,7 @@ private static class luau_ext_free { luacode_h.C_POINTER ); - public static final MemorySegment ADDR = luacode_h.findOrThrow("luau_ext_free"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_ext_free"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -475,6 +442,8 @@ public static void luau_ext_free(MemorySegment bytecode) { traceDowncall("luau_ext_free", bytecode); } mh$.invokeExact(bytecode); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/luaW_newuserdatadtor$dtor.java b/src/generated/java/net/hollowcube/luau/internal/vm/luaW_newuserdatadtor$dtor.java index 084ba93a..3f633b17 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/luaW_newuserdatadtor$dtor.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/luaW_newuserdatadtor$dtor.java @@ -17,9 +17,9 @@ * void (*dtor)(void *) * } */ -public class luaW_newuserdatadtor$dtor { +public final class luaW_newuserdatadtor$dtor { - luaW_newuserdatadtor$dtor() { + private luaW_newuserdatadtor$dtor() { // Should not be called directly } @@ -56,9 +56,11 @@ public static MemorySegment allocate(luaW_newuserdatadtor$dtor.Function fi, Aren /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0) { try { DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Alloc.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Alloc.java index 82daa266..55166845 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Alloc.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Alloc.java @@ -17,9 +17,9 @@ * typedef void *(*lua_Alloc)(void *, void *, size_t, size_t) * } */ -public class lua_Alloc { +public final class lua_Alloc { - lua_Alloc() { + private lua_Alloc() { // Should not be called directly } @@ -60,9 +60,11 @@ public static MemorySegment allocate(lua_Alloc.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static MemorySegment invoke(MemorySegment funcPtr,MemorySegment ud, MemorySegment ptr, long osize, long nsize) { + public static MemorySegment invoke(MemorySegment funcPtr, MemorySegment ud, MemorySegment ptr, long osize, long nsize) { try { return (MemorySegment) DOWN$MH.invokeExact(funcPtr, ud, ptr, osize, nsize); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_CFunction.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_CFunction.java index 069dc237..02f0b1c7 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_CFunction.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_CFunction.java @@ -17,9 +17,9 @@ * typedef int (*lua_CFunction)(lua_State *) * } */ -public class lua_CFunction { +public final class lua_CFunction { - lua_CFunction() { + private lua_CFunction() { // Should not be called directly } @@ -57,9 +57,11 @@ public static MemorySegment allocate(lua_CFunction.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static int invoke(MemorySegment funcPtr,MemorySegment L) { + public static int invoke(MemorySegment funcPtr, MemorySegment L) { try { return (int) DOWN$MH.invokeExact(funcPtr, L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Callbacks.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Callbacks.java index afde8bcc..a8435299 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Callbacks.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Callbacks.java @@ -17,6 +17,7 @@ * struct lua_Callbacks { * void *userdata; * void (*interrupt)(lua_State *, int); + * int (*preempt)(lua_State *, int); * void (*panic)(lua_State *, int); * void (*userthread)(lua_State *, lua_State *); * int16_t (*useratom)(const char *, size_t); @@ -37,6 +38,7 @@ public class lua_Callbacks { private static final GroupLayout $LAYOUT = MemoryLayout.structLayout( lua_h.C_POINTER.withName("userdata"), lua_h.C_POINTER.withName("interrupt"), + lua_h.C_POINTER.withName("preempt"), lua_h.C_POINTER.withName("panic"), lua_h.C_POINTER.withName("userthread"), lua_h.C_POINTER.withName("useratom"), @@ -66,7 +68,7 @@ public static final GroupLayout layout() { return userdata$LAYOUT; } - private static final long userdata$OFFSET = 0; + private static final long userdata$OFFSET = $LAYOUT.byteOffset(groupElement("userdata")); /** * Offset for field: @@ -103,9 +105,9 @@ public static void userdata(MemorySegment struct, MemorySegment fieldValue) { * void (*interrupt)(lua_State *, int) * } */ - public static class interrupt { + public final static class interrupt { - interrupt() { + private interrupt() { // Should not be called directly } @@ -143,9 +145,11 @@ public static MemorySegment allocate(interrupt.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, int _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -164,7 +168,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { return interrupt$LAYOUT; } - private static final long interrupt$OFFSET = 8; + private static final long interrupt$OFFSET = $LAYOUT.byteOffset(groupElement("interrupt")); /** * Offset for field: @@ -196,14 +200,115 @@ public static void interrupt(MemorySegment struct, MemorySegment fieldValue) { struct.set(interrupt$LAYOUT, interrupt$OFFSET, fieldValue); } + /** + * {@snippet lang=c : + * int (*preempt)(lua_State *, int) + * } + */ + public final static class preempt { + + private preempt() { + // Should not be called directly + } + + /** + * The function pointer signature, expressed as a functional interface + */ + public interface Function { + int apply(MemorySegment _x0, int _x1); + } + + private static final FunctionDescriptor $DESC = FunctionDescriptor.of( + lua_h.C_INT, + lua_h.C_POINTER, + lua_h.C_INT + ); + + /** + * The descriptor of this function pointer + */ + public static FunctionDescriptor descriptor() { + return $DESC; + } + + private static final MethodHandle UP$MH = lua_h.upcallHandle(preempt.Function.class, "apply", $DESC); + + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(preempt.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); + } + + private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ + public static int invoke(MemorySegment funcPtr, MemorySegment _x0, int _x1) { + try { + return (int) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + } + + private static final AddressLayout preempt$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("preempt")); + + /** + * Layout for field: + * {@snippet lang=c : + * int (*preempt)(lua_State *, int) + * } + */ + public static final AddressLayout preempt$layout() { + return preempt$LAYOUT; + } + + private static final long preempt$OFFSET = $LAYOUT.byteOffset(groupElement("preempt")); + + /** + * Offset for field: + * {@snippet lang=c : + * int (*preempt)(lua_State *, int) + * } + */ + public static final long preempt$offset() { + return preempt$OFFSET; + } + + /** + * Getter for field: + * {@snippet lang=c : + * int (*preempt)(lua_State *, int) + * } + */ + public static MemorySegment preempt(MemorySegment struct) { + return struct.get(preempt$LAYOUT, preempt$OFFSET); + } + + /** + * Setter for field: + * {@snippet lang=c : + * int (*preempt)(lua_State *, int) + * } + */ + public static void preempt(MemorySegment struct, MemorySegment fieldValue) { + struct.set(preempt$LAYOUT, preempt$OFFSET, fieldValue); + } + /** * {@snippet lang=c : * void (*panic)(lua_State *, int) * } */ - public static class panic { + public final static class panic { - panic() { + private panic() { // Should not be called directly } @@ -241,9 +346,11 @@ public static MemorySegment allocate(panic.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, int _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -262,7 +369,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, int _x1) { return panic$LAYOUT; } - private static final long panic$OFFSET = 16; + private static final long panic$OFFSET = $LAYOUT.byteOffset(groupElement("panic")); /** * Offset for field: @@ -299,9 +406,9 @@ public static void panic(MemorySegment struct, MemorySegment fieldValue) { * void (*userthread)(lua_State *, lua_State *) * } */ - public static class userthread { + public final static class userthread { - userthread() { + private userthread() { // Should not be called directly } @@ -339,9 +446,11 @@ public static MemorySegment allocate(userthread.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -360,7 +469,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment return userthread$LAYOUT; } - private static final long userthread$OFFSET = 24; + private static final long userthread$OFFSET = $LAYOUT.byteOffset(groupElement("userthread")); /** * Offset for field: @@ -397,9 +506,9 @@ public static void userthread(MemorySegment struct, MemorySegment fieldValue) { * int16_t (*useratom)(const char *, size_t) * } */ - public static class useratom { + public final static class useratom { - useratom() { + private useratom() { // Should not be called directly } @@ -438,9 +547,11 @@ public static MemorySegment allocate(useratom.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static short invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1) { + public static short invoke(MemorySegment funcPtr, MemorySegment _x0, long _x1) { try { return (short) DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -459,7 +570,7 @@ public static short invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1) { return useratom$LAYOUT; } - private static final long useratom$OFFSET = 32; + private static final long useratom$OFFSET = $LAYOUT.byteOffset(groupElement("useratom")); /** * Offset for field: @@ -496,9 +607,9 @@ public static void useratom(MemorySegment struct, MemorySegment fieldValue) { * void (*debugbreak)(lua_State *, lua_Debug *) * } */ - public static class debugbreak { + public final static class debugbreak { - debugbreak() { + private debugbreak() { // Should not be called directly } @@ -536,9 +647,11 @@ public static MemorySegment allocate(debugbreak.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -557,7 +670,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment return debugbreak$LAYOUT; } - private static final long debugbreak$OFFSET = 40; + private static final long debugbreak$OFFSET = $LAYOUT.byteOffset(groupElement("debugbreak")); /** * Offset for field: @@ -594,9 +707,9 @@ public static void debugbreak(MemorySegment struct, MemorySegment fieldValue) { * void (*debugstep)(lua_State *, lua_Debug *) * } */ - public static class debugstep { + public final static class debugstep { - debugstep() { + private debugstep() { // Should not be called directly } @@ -634,9 +747,11 @@ public static MemorySegment allocate(debugstep.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -655,7 +770,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment return debugstep$LAYOUT; } - private static final long debugstep$OFFSET = 48; + private static final long debugstep$OFFSET = $LAYOUT.byteOffset(groupElement("debugstep")); /** * Offset for field: @@ -692,9 +807,9 @@ public static void debugstep(MemorySegment struct, MemorySegment fieldValue) { * void (*debuginterrupt)(lua_State *, lua_Debug *) * } */ - public static class debuginterrupt { + public final static class debuginterrupt { - debuginterrupt() { + private debuginterrupt() { // Should not be called directly } @@ -732,9 +847,11 @@ public static MemorySegment allocate(debuginterrupt.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment _x1) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, MemorySegment _x1) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -753,7 +870,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, MemorySegment return debuginterrupt$LAYOUT; } - private static final long debuginterrupt$OFFSET = 56; + private static final long debuginterrupt$OFFSET = $LAYOUT.byteOffset(groupElement("debuginterrupt")); /** * Offset for field: @@ -790,9 +907,9 @@ public static void debuginterrupt(MemorySegment struct, MemorySegment fieldValue * void (*debugprotectederror)(lua_State *) * } */ - public static class debugprotectederror { + public final static class debugprotectederror { - debugprotectederror() { + private debugprotectederror() { // Should not be called directly } @@ -829,9 +946,11 @@ public static MemorySegment allocate(debugprotectederror.Function fi, Arena aren /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0) { try { DOWN$MH.invokeExact(funcPtr, _x0); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -850,7 +969,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0) { return debugprotectederror$LAYOUT; } - private static final long debugprotectederror$OFFSET = 64; + private static final long debugprotectederror$OFFSET = $LAYOUT.byteOffset(groupElement("debugprotectederror")); /** * Offset for field: @@ -887,9 +1006,9 @@ public static void debugprotectederror(MemorySegment struct, MemorySegment field * void (*onallocate)(lua_State *, size_t, size_t) * } */ - public static class onallocate { + public final static class onallocate { - onallocate() { + private onallocate() { // Should not be called directly } @@ -928,9 +1047,11 @@ public static MemorySegment allocate(onallocate.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1, long _x2) { + public static void invoke(MemorySegment funcPtr, MemorySegment _x0, long _x1, long _x2) { try { DOWN$MH.invokeExact(funcPtr, _x0, _x1, _x2); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -949,7 +1070,7 @@ public static void invoke(MemorySegment funcPtr,MemorySegment _x0, long _x1, lon return onallocate$LAYOUT; } - private static final long onallocate$OFFSET = 72; + private static final long onallocate$OFFSET = $LAYOUT.byteOffset(groupElement("onallocate")); /** * Offset for field: diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Continuation.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Continuation.java index d24bd1aa..fe3a4983 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Continuation.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Continuation.java @@ -17,9 +17,9 @@ * typedef int (*lua_Continuation)(lua_State *, int) * } */ -public class lua_Continuation { +public final class lua_Continuation { - lua_Continuation() { + private lua_Continuation() { // Should not be called directly } @@ -58,9 +58,11 @@ public static MemorySegment allocate(lua_Continuation.Function fi, Arena arena) /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static int invoke(MemorySegment funcPtr,MemorySegment L, int status) { + public static int invoke(MemorySegment funcPtr, MemorySegment L, int status) { try { return (int) DOWN$MH.invokeExact(funcPtr, L, status); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Debug.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Debug.java index c5fc52c1..5987dd05 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Debug.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Debug.java @@ -69,7 +69,7 @@ public static final GroupLayout layout() { return name$LAYOUT; } - private static final long name$OFFSET = 0; + private static final long name$OFFSET = $LAYOUT.byteOffset(groupElement("name")); /** * Offset for field: @@ -113,7 +113,7 @@ public static void name(MemorySegment struct, MemorySegment fieldValue) { return what$LAYOUT; } - private static final long what$OFFSET = 8; + private static final long what$OFFSET = $LAYOUT.byteOffset(groupElement("what")); /** * Offset for field: @@ -157,7 +157,7 @@ public static void what(MemorySegment struct, MemorySegment fieldValue) { return source$LAYOUT; } - private static final long source$OFFSET = 16; + private static final long source$OFFSET = $LAYOUT.byteOffset(groupElement("source")); /** * Offset for field: @@ -201,7 +201,7 @@ public static void source(MemorySegment struct, MemorySegment fieldValue) { return short_src$LAYOUT; } - private static final long short_src$OFFSET = 24; + private static final long short_src$OFFSET = $LAYOUT.byteOffset(groupElement("short_src")); /** * Offset for field: @@ -245,7 +245,7 @@ public static void short_src(MemorySegment struct, MemorySegment fieldValue) { return linedefined$LAYOUT; } - private static final long linedefined$OFFSET = 32; + private static final long linedefined$OFFSET = $LAYOUT.byteOffset(groupElement("linedefined")); /** * Offset for field: @@ -289,7 +289,7 @@ public static void linedefined(MemorySegment struct, int fieldValue) { return currentline$LAYOUT; } - private static final long currentline$OFFSET = 36; + private static final long currentline$OFFSET = $LAYOUT.byteOffset(groupElement("currentline")); /** * Offset for field: @@ -333,7 +333,7 @@ public static void currentline(MemorySegment struct, int fieldValue) { return nupvals$LAYOUT; } - private static final long nupvals$OFFSET = 40; + private static final long nupvals$OFFSET = $LAYOUT.byteOffset(groupElement("nupvals")); /** * Offset for field: @@ -377,7 +377,7 @@ public static void nupvals(MemorySegment struct, byte fieldValue) { return nparams$LAYOUT; } - private static final long nparams$OFFSET = 41; + private static final long nparams$OFFSET = $LAYOUT.byteOffset(groupElement("nparams")); /** * Offset for field: @@ -421,7 +421,7 @@ public static void nparams(MemorySegment struct, byte fieldValue) { return isvararg$LAYOUT; } - private static final long isvararg$OFFSET = 42; + private static final long isvararg$OFFSET = $LAYOUT.byteOffset(groupElement("isvararg")); /** * Offset for field: @@ -465,7 +465,7 @@ public static void isvararg(MemorySegment struct, byte fieldValue) { return userdata$LAYOUT; } - private static final long userdata$OFFSET = 48; + private static final long userdata$OFFSET = $LAYOUT.byteOffset(groupElement("userdata")); /** * Offset for field: @@ -509,7 +509,7 @@ public static void userdata(MemorySegment struct, MemorySegment fieldValue) { return ssbuf$LAYOUT; } - private static final long ssbuf$OFFSET = 56; + private static final long ssbuf$OFFSET = $LAYOUT.byteOffset(groupElement("ssbuf")); /** * Offset for field: @@ -561,7 +561,7 @@ public static void ssbuf(MemorySegment struct, MemorySegment fieldValue) { * } */ public static byte ssbuf(MemorySegment struct, long index0) { - return (byte)ssbuf$ELEM_HANDLE.get(struct, 0L, index0); + return (byte)ssbuf$ELEM_HANDLE.get(struct, ssbuf$OFFSET, index0); } /** @@ -571,7 +571,7 @@ public static byte ssbuf(MemorySegment struct, long index0) { * } */ public static void ssbuf(MemorySegment struct, long index0, byte fieldValue) { - ssbuf$ELEM_HANDLE.set(struct, 0L, index0, fieldValue); + ssbuf$ELEM_HANDLE.set(struct, ssbuf$OFFSET, index0, fieldValue); } /** diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Destructor.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Destructor.java index ea3f498d..41801ec0 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_Destructor.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_Destructor.java @@ -17,9 +17,9 @@ * typedef void (*lua_Destructor)(lua_State *, void *) * } */ -public class lua_Destructor { +public final class lua_Destructor { - lua_Destructor() { + private lua_Destructor() { // Should not be called directly } @@ -57,9 +57,11 @@ public static MemorySegment allocate(lua_Destructor.Function fi, Arena arena) { /** * Invoke the upcall stub {@code funcPtr}, with given parameters */ - public static void invoke(MemorySegment funcPtr,MemorySegment L, MemorySegment userdata) { + public static void invoke(MemorySegment funcPtr, MemorySegment L, MemorySegment userdata) { try { DOWN$MH.invokeExact(funcPtr, L, userdata); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_h$shared.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_h$shared.java new file mode 100644 index 00000000..b6532bda --- /dev/null +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_h$shared.java @@ -0,0 +1,63 @@ +// Generated by jextract + +package net.hollowcube.luau.internal.vm; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class lua_h$shared { + + lua_h$shared() { + // Should not be called directly + } + + public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR)); + public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} + diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lua_h.java b/src/generated/java/net/hollowcube/luau/internal/vm/lua_h.java index 663d1d7d..ba7c9c2a 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lua_h.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lua_h.java @@ -12,62 +12,17 @@ import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.MemoryLayout.PathElement.*; -public class lua_h { +public class lua_h extends lua_h$shared { lua_h() { // Should not be called directly } static final Arena LIBRARY_ARENA = Arena.ofAuto(); - static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); - - static void traceDowncall(String name, Object... args) { - String traceArgs = Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")); - System.out.printf("%s(%s)\n", name, traceArgs); - } - - static MemorySegment findOrThrow(String symbol) { - return SYMBOL_LOOKUP.find(symbol) - .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); - } catch (ReflectiveOperationException ex) { - throw new AssertionError(ex); - } - } - - static MemoryLayout align(MemoryLayout layout, long align) { - return switch (layout) { - case PaddingLayout p -> p; - case ValueLayout v -> v.withByteAlignment(align); - case GroupLayout g -> { - MemoryLayout[] alignedMembers = g.memberLayouts().stream() - .map(m -> align(m, align)).toArray(MemoryLayout[]::new); - yield g instanceof StructLayout ? - MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); - } - case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); - }; - } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() .or(Linker.nativeLinker().defaultLookup()); - public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; - public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; - public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; - public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; - public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; - public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; - public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; - public static final AddressLayout C_POINTER = ValueLayout.ADDRESS - .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); - public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; private static final int LUA_UTAG_LIMIT = (int)128L; /** * {@snippet lang=c : @@ -101,7 +56,7 @@ private static class lua_close { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_close"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_close"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -148,6 +103,8 @@ public static void lua_close(MemorySegment L) { traceDowncall("lua_close", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -159,7 +116,7 @@ private static class lua_mainthread { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_mainthread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_mainthread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -206,6 +163,8 @@ public static MemorySegment lua_mainthread(MemorySegment L) { traceDowncall("lua_mainthread", L); } return (MemorySegment)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -217,7 +176,7 @@ private static class lua_isthreadreset { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isthreadreset"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isthreadreset"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -264,6 +223,8 @@ public static int lua_isthreadreset(MemorySegment L) { traceDowncall("lua_isthreadreset", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -276,7 +237,7 @@ private static class lua_absindex { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_absindex"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_absindex"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -323,6 +284,8 @@ public static int lua_absindex(MemorySegment L, int idx) { traceDowncall("lua_absindex", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -334,7 +297,7 @@ private static class lua_gettop { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_gettop"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_gettop"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -381,6 +344,8 @@ public static int lua_gettop(MemorySegment L) { traceDowncall("lua_gettop", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -392,7 +357,7 @@ private static class lua_settop { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_settop"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_settop"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -439,6 +404,8 @@ public static void lua_settop(MemorySegment L, int idx) { traceDowncall("lua_settop", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -450,7 +417,7 @@ private static class lua_pushvalue { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushvalue"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushvalue"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -497,6 +464,8 @@ public static void lua_pushvalue(MemorySegment L, int idx) { traceDowncall("lua_pushvalue", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -508,7 +477,7 @@ private static class lua_remove { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_remove"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_remove"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -555,6 +524,8 @@ public static void lua_remove(MemorySegment L, int idx) { traceDowncall("lua_remove", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -566,7 +537,7 @@ private static class lua_insert { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_insert"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_insert"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -613,6 +584,8 @@ public static void lua_insert(MemorySegment L, int idx) { traceDowncall("lua_insert", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -624,7 +597,7 @@ private static class lua_replace { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_replace"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_replace"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -671,6 +644,8 @@ public static void lua_replace(MemorySegment L, int idx) { traceDowncall("lua_replace", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -683,7 +658,7 @@ private static class lua_checkstack { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_checkstack"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_checkstack"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -730,6 +705,8 @@ public static int lua_checkstack(MemorySegment L, int sz) { traceDowncall("lua_checkstack", L, sz); } return (int)mh$.invokeExact(L, sz); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -741,7 +718,7 @@ private static class lua_rawcheckstack { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawcheckstack"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawcheckstack"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -788,6 +765,8 @@ public static void lua_rawcheckstack(MemorySegment L, int sz) { traceDowncall("lua_rawcheckstack", L, sz); } mh$.invokeExact(L, sz); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -800,7 +779,7 @@ private static class lua_isnumber { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isnumber"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isnumber"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -847,6 +826,8 @@ public static int lua_isnumber(MemorySegment L, int idx) { traceDowncall("lua_isnumber", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -859,7 +840,7 @@ private static class lua_isstring { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isstring"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isstring"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -906,6 +887,8 @@ public static int lua_isstring(MemorySegment L, int idx) { traceDowncall("lua_isstring", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -918,7 +901,7 @@ private static class lua_iscfunction { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_iscfunction"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_iscfunction"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -965,6 +948,8 @@ public static int lua_iscfunction(MemorySegment L, int idx) { traceDowncall("lua_iscfunction", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -977,7 +962,7 @@ private static class lua_isLfunction { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isLfunction"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isLfunction"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1024,6 +1009,8 @@ public static int lua_isLfunction(MemorySegment L, int idx) { traceDowncall("lua_isLfunction", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1036,7 +1023,7 @@ private static class lua_isuserdata { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isuserdata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isuserdata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1083,6 +1070,8 @@ public static int lua_isuserdata(MemorySegment L, int idx) { traceDowncall("lua_isuserdata", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1095,7 +1084,7 @@ private static class lua_type { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_type"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_type"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1142,6 +1131,8 @@ public static int lua_type(MemorySegment L, int idx) { traceDowncall("lua_type", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1155,7 +1146,7 @@ private static class lua_rawequal { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawequal"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawequal"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1202,6 +1193,8 @@ public static int lua_rawequal(MemorySegment L, int idx1, int idx2) { traceDowncall("lua_rawequal", L, idx1, idx2); } return (int)mh$.invokeExact(L, idx1, idx2); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1215,7 +1208,7 @@ private static class lua_tonumberx { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tonumberx"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tonumberx"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1262,6 +1255,8 @@ public static double lua_tonumberx(MemorySegment L, int idx, MemorySegment isnum traceDowncall("lua_tonumberx", L, idx, isnum); } return (double)mh$.invokeExact(L, idx, isnum); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1275,7 +1270,7 @@ private static class lua_tointegerx { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tointegerx"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tointegerx"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1322,6 +1317,8 @@ public static int lua_tointegerx(MemorySegment L, int idx, MemorySegment isnum) traceDowncall("lua_tointegerx", L, idx, isnum); } return (int)mh$.invokeExact(L, idx, isnum); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1335,7 +1332,7 @@ private static class lua_tounsignedx { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tounsignedx"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tounsignedx"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1382,6 +1379,8 @@ public static int lua_tounsignedx(MemorySegment L, int idx, MemorySegment isnum) traceDowncall("lua_tounsignedx", L, idx, isnum); } return (int)mh$.invokeExact(L, idx, isnum); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1394,7 +1393,7 @@ private static class lua_tovector { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tovector"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tovector"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1441,6 +1440,8 @@ public static MemorySegment lua_tovector(MemorySegment L, int idx) { traceDowncall("lua_tovector", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1453,7 +1454,7 @@ private static class lua_toboolean { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_toboolean"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_toboolean"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1500,6 +1501,8 @@ public static int lua_toboolean(MemorySegment L, int idx) { traceDowncall("lua_toboolean", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1514,7 +1517,7 @@ private static class lua_tolstringatom { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tolstringatom"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tolstringatom"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1561,6 +1564,8 @@ public static MemorySegment lua_tolstringatom(MemorySegment L, int idx, MemorySe traceDowncall("lua_tolstringatom", L, idx, len, atom); } return (MemorySegment)mh$.invokeExact(L, idx, len, atom); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1573,7 +1578,7 @@ private static class lua_namecallatom { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_namecallatom"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_namecallatom"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1620,6 +1625,8 @@ public static MemorySegment lua_namecallatom(MemorySegment L, MemorySegment atom traceDowncall("lua_namecallatom", L, atom); } return (MemorySegment)mh$.invokeExact(L, atom); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1632,7 +1639,7 @@ private static class lua_tocfunction { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tocfunction"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tocfunction"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1679,6 +1686,8 @@ public static MemorySegment lua_tocfunction(MemorySegment L, int idx) { traceDowncall("lua_tocfunction", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1691,7 +1700,7 @@ private static class lua_tolightuserdata { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tolightuserdata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tolightuserdata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1738,6 +1747,8 @@ public static MemorySegment lua_tolightuserdata(MemorySegment L, int idx) { traceDowncall("lua_tolightuserdata", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1751,7 +1762,7 @@ private static class lua_tolightuserdatatagged { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tolightuserdatatagged"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tolightuserdatatagged"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1798,6 +1809,8 @@ public static MemorySegment lua_tolightuserdatatagged(MemorySegment L, int idx, traceDowncall("lua_tolightuserdatatagged", L, idx, tag); } return (MemorySegment)mh$.invokeExact(L, idx, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1810,7 +1823,7 @@ private static class lua_touserdata { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_touserdata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_touserdata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1857,6 +1870,8 @@ public static MemorySegment lua_touserdata(MemorySegment L, int idx) { traceDowncall("lua_touserdata", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1870,7 +1885,7 @@ private static class lua_touserdatatagged { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_touserdatatagged"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_touserdatatagged"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1917,6 +1932,8 @@ public static MemorySegment lua_touserdatatagged(MemorySegment L, int idx, int t traceDowncall("lua_touserdatatagged", L, idx, tag); } return (MemorySegment)mh$.invokeExact(L, idx, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1929,7 +1946,7 @@ private static class lua_userdatatag { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_userdatatag"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_userdatatag"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1976,6 +1993,8 @@ public static int lua_userdatatag(MemorySegment L, int idx) { traceDowncall("lua_userdatatag", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1988,7 +2007,7 @@ private static class lua_lightuserdatatag { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_lightuserdatatag"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_lightuserdatatag"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2035,6 +2054,8 @@ public static int lua_lightuserdatatag(MemorySegment L, int idx) { traceDowncall("lua_lightuserdatatag", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2047,7 +2068,7 @@ private static class lua_tothread { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tothread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tothread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2094,6 +2115,8 @@ public static MemorySegment lua_tothread(MemorySegment L, int idx) { traceDowncall("lua_tothread", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2107,7 +2130,7 @@ private static class lua_tobuffer { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_tobuffer"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_tobuffer"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2154,6 +2177,8 @@ public static MemorySegment lua_tobuffer(MemorySegment L, int idx, MemorySegment traceDowncall("lua_tobuffer", L, idx, len); } return (MemorySegment)mh$.invokeExact(L, idx, len); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2166,7 +2191,7 @@ private static class lua_topointer { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_topointer"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_topointer"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2213,6 +2238,8 @@ public static MemorySegment lua_topointer(MemorySegment L, int idx) { traceDowncall("lua_topointer", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2223,7 +2250,7 @@ private static class lua_pushnil { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushnil"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushnil"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2270,6 +2297,8 @@ public static void lua_pushnil(MemorySegment L) { traceDowncall("lua_pushnil", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2281,7 +2310,7 @@ private static class lua_pushnumber { lua_h.C_DOUBLE ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushnumber"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushnumber"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2328,6 +2357,8 @@ public static void lua_pushnumber(MemorySegment L, double n) { traceDowncall("lua_pushnumber", L, n); } mh$.invokeExact(L, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2339,7 +2370,7 @@ private static class lua_pushinteger { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushinteger"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushinteger"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2386,6 +2417,8 @@ public static void lua_pushinteger(MemorySegment L, int n) { traceDowncall("lua_pushinteger", L, n); } mh$.invokeExact(L, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2397,7 +2430,7 @@ private static class lua_pushunsigned { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushunsigned"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushunsigned"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2444,6 +2477,8 @@ public static void lua_pushunsigned(MemorySegment L, int n) { traceDowncall("lua_pushunsigned", L, n); } mh$.invokeExact(L, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2457,7 +2492,7 @@ private static class lua_pushvector { lua_h.C_FLOAT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushvector"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushvector"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2504,6 +2539,8 @@ public static void lua_pushvector(MemorySegment L, float x, float y, float z) { traceDowncall("lua_pushvector", L, x, y, z); } mh$.invokeExact(L, x, y, z); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2515,7 +2552,7 @@ private static class lua_pushboolean { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushboolean"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushboolean"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2562,6 +2599,8 @@ public static void lua_pushboolean(MemorySegment L, int b) { traceDowncall("lua_pushboolean", L, b); } mh$.invokeExact(L, b); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2573,7 +2612,7 @@ private static class lua_pushthread { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushthread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushthread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2620,6 +2659,8 @@ public static int lua_pushthread(MemorySegment L) { traceDowncall("lua_pushthread", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2632,7 +2673,7 @@ private static class lua_pushlightuserdatatagged { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pushlightuserdatatagged"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pushlightuserdatatagged"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2679,6 +2720,8 @@ public static void lua_pushlightuserdatatagged(MemorySegment L, MemorySegment p, traceDowncall("lua_pushlightuserdatatagged", L, p, tag); } mh$.invokeExact(L, p, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2692,7 +2735,7 @@ private static class lua_rawgetfield { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawgetfield"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawgetfield"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2739,6 +2782,8 @@ public static int lua_rawgetfield(MemorySegment L, int idx, MemorySegment k) { traceDowncall("lua_rawgetfield", L, idx, k); } return (int)mh$.invokeExact(L, idx, k); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2751,7 +2796,7 @@ private static class lua_rawget { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawget"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawget"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2798,6 +2843,8 @@ public static int lua_rawget(MemorySegment L, int idx) { traceDowncall("lua_rawget", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2811,7 +2858,7 @@ private static class lua_rawgeti { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawgeti"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawgeti"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2858,6 +2905,8 @@ public static int lua_rawgeti(MemorySegment L, int idx, int n) { traceDowncall("lua_rawgeti", L, idx, n); } return (int)mh$.invokeExact(L, idx, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2870,7 +2919,7 @@ private static class lua_setreadonly { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setreadonly"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setreadonly"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2917,6 +2966,8 @@ public static void lua_setreadonly(MemorySegment L, int idx, int enabled) { traceDowncall("lua_setreadonly", L, idx, enabled); } mh$.invokeExact(L, idx, enabled); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2929,7 +2980,7 @@ private static class lua_getreadonly { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getreadonly"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getreadonly"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2976,6 +3027,8 @@ public static int lua_getreadonly(MemorySegment L, int idx) { traceDowncall("lua_getreadonly", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2988,7 +3041,7 @@ private static class lua_getmetatable { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getmetatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getmetatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3035,6 +3088,8 @@ public static int lua_getmetatable(MemorySegment L, int objindex) { traceDowncall("lua_getmetatable", L, objindex); } return (int)mh$.invokeExact(L, objindex); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3050,7 +3105,7 @@ private static class luau_load { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("luau_load"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_load"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3097,6 +3152,8 @@ public static int luau_load(MemorySegment L, MemorySegment chunkname, MemorySegm traceDowncall("luau_load", L, chunkname, data, size, env); } return (int)mh$.invokeExact(L, chunkname, data, size, env); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3109,7 +3166,7 @@ private static class lua_call { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_call"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_call"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3156,6 +3213,8 @@ public static void lua_call(MemorySegment L, int nargs, int nresults) { traceDowncall("lua_call", L, nargs, nresults); } mh$.invokeExact(L, nargs, nresults); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3170,7 +3229,7 @@ private static class lua_pcall { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_pcall"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_pcall"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3217,6 +3276,8 @@ public static int lua_pcall(MemorySegment L, int nargs, int nresults, int errfun traceDowncall("lua_pcall", L, nargs, nresults, errfunc); } return (int)mh$.invokeExact(L, nargs, nresults, errfunc); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3230,7 +3291,7 @@ private static class lua_resume { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_resume"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_resume"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3277,6 +3338,8 @@ public static int lua_resume(MemorySegment L, MemorySegment from, int narg) { traceDowncall("lua_resume", L, from, narg); } return (int)mh$.invokeExact(L, from, narg); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3289,7 +3352,7 @@ private static class lua_resumeerror { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_resumeerror"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_resumeerror"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3336,6 +3399,8 @@ public static int lua_resumeerror(MemorySegment L, MemorySegment from) { traceDowncall("lua_resumeerror", L, from); } return (int)mh$.invokeExact(L, from); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3347,7 +3412,7 @@ private static class lua_status { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_status"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_status"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3394,6 +3459,8 @@ public static int lua_status(MemorySegment L) { traceDowncall("lua_status", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3405,7 +3472,7 @@ private static class lua_isyieldable { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_isyieldable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_isyieldable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3452,6 +3519,8 @@ public static int lua_isyieldable(MemorySegment L) { traceDowncall("lua_isyieldable", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3463,7 +3532,7 @@ private static class lua_getthreaddata { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getthreaddata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getthreaddata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3510,6 +3579,8 @@ public static MemorySegment lua_getthreaddata(MemorySegment L) { traceDowncall("lua_getthreaddata", L); } return (MemorySegment)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3521,7 +3592,7 @@ private static class lua_setthreaddata { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setthreaddata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setthreaddata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3568,6 +3639,8 @@ public static void lua_setthreaddata(MemorySegment L, MemorySegment data) { traceDowncall("lua_setthreaddata", L, data); } mh$.invokeExact(L, data); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3580,7 +3653,7 @@ private static class lua_costatus { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_costatus"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_costatus"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3627,6 +3700,8 @@ public static int lua_costatus(MemorySegment L, MemorySegment co) { traceDowncall("lua_costatus", L, co); } return (int)mh$.invokeExact(L, co); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3640,7 +3715,7 @@ private static class lua_gc { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_gc"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_gc"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3687,6 +3762,8 @@ public static int lua_gc(MemorySegment L, int what, int data) { traceDowncall("lua_gc", L, what, data); } return (int)mh$.invokeExact(L, what, data); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3698,7 +3775,7 @@ private static class lua_setmemcat { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setmemcat"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setmemcat"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3745,6 +3822,8 @@ public static void lua_setmemcat(MemorySegment L, int category) { traceDowncall("lua_setmemcat", L, category); } mh$.invokeExact(L, category); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3757,7 +3836,7 @@ private static class lua_totalbytes { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_totalbytes"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_totalbytes"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3804,6 +3883,8 @@ public static long lua_totalbytes(MemorySegment L, int category) { traceDowncall("lua_totalbytes", L, category); } return (long)mh$.invokeExact(L, category); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3817,7 +3898,7 @@ private static class lua_rawiter { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_rawiter"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_rawiter"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3864,6 +3945,8 @@ public static int lua_rawiter(MemorySegment L, int idx, int iter) { traceDowncall("lua_rawiter", L, idx, iter); } return (int)mh$.invokeExact(L, idx, iter); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3876,7 +3959,7 @@ private static class lua_setuserdatatag { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setuserdatatag"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setuserdatatag"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3923,6 +4006,8 @@ public static void lua_setuserdatatag(MemorySegment L, int idx, int tag) { traceDowncall("lua_setuserdatatag", L, idx, tag); } mh$.invokeExact(L, idx, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3935,7 +4020,7 @@ private static class lua_setuserdatadtor { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setuserdatadtor"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setuserdatadtor"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -3982,6 +4067,8 @@ public static void lua_setuserdatadtor(MemorySegment L, int tag, MemorySegment d traceDowncall("lua_setuserdatadtor", L, tag, dtor); } mh$.invokeExact(L, tag, dtor); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -3993,7 +4080,7 @@ private static class lua_setuserdatametatable { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_setuserdatametatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_setuserdatametatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4040,6 +4127,8 @@ public static void lua_setuserdatametatable(MemorySegment L, int tag) { traceDowncall("lua_setuserdatametatable", L, tag); } mh$.invokeExact(L, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4051,7 +4140,7 @@ private static class lua_getuserdatametatable { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getuserdatametatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getuserdatametatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4098,6 +4187,8 @@ public static void lua_getuserdatametatable(MemorySegment L, int tag) { traceDowncall("lua_getuserdatametatable", L, tag); } mh$.invokeExact(L, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4110,7 +4201,7 @@ private static class lua_getlightuserdataname { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getlightuserdataname"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getlightuserdataname"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4157,6 +4248,8 @@ public static MemorySegment lua_getlightuserdataname(MemorySegment L, int tag) { traceDowncall("lua_getlightuserdataname", L, tag); } return (MemorySegment)mh$.invokeExact(L, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4169,7 +4262,7 @@ private static class lua_ref { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_ref"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_ref"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4216,6 +4309,8 @@ public static int lua_ref(MemorySegment L, int idx) { traceDowncall("lua_ref", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4227,7 +4322,7 @@ private static class lua_unref { lua_h.C_INT ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_unref"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_unref"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4274,6 +4369,8 @@ public static void lua_unref(MemorySegment L, int ref) { traceDowncall("lua_unref", L, ref); } mh$.invokeExact(L, ref); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4288,7 +4385,7 @@ private static class lua_getinfo { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_getinfo"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_getinfo"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4335,6 +4432,68 @@ public static int lua_getinfo(MemorySegment L, int level, MemorySegment what, Me traceDowncall("lua_getinfo", L, level, what, ar); } return (int)mh$.invokeExact(L, level, what, ar); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class lua_debugtrace { + public static final FunctionDescriptor DESC = FunctionDescriptor.of( + lua_h.C_POINTER, + lua_h.C_POINTER + ); + + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_debugtrace"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern const char *lua_debugtrace(lua_State *L) + * } + */ + public static FunctionDescriptor lua_debugtrace$descriptor() { + return lua_debugtrace.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern const char *lua_debugtrace(lua_State *L) + * } + */ + public static MethodHandle lua_debugtrace$handle() { + return lua_debugtrace.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * extern const char *lua_debugtrace(lua_State *L) + * } + */ + public static MemorySegment lua_debugtrace$address() { + return lua_debugtrace.ADDR; + } + + /** + * {@snippet lang=c : + * extern const char *lua_debugtrace(lua_State *L) + * } + */ + public static MemorySegment lua_debugtrace(MemorySegment L) { + var mh$ = lua_debugtrace.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("lua_debugtrace", L); + } + return (MemorySegment)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -4346,7 +4505,7 @@ private static class lua_callbacks { lua_h.C_POINTER ); - public static final MemorySegment ADDR = lua_h.findOrThrow("lua_callbacks"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_callbacks"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -4393,6 +4552,8 @@ public static MemorySegment lua_callbacks(MemorySegment L) { traceDowncall("lua_callbacks", L); } return (MemorySegment)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h$shared.java b/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h$shared.java new file mode 100644 index 00000000..057f4779 --- /dev/null +++ b/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h$shared.java @@ -0,0 +1,63 @@ +// Generated by jextract + +package net.hollowcube.luau.internal.vm; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class luacodegen_h$shared { + + luacodegen_h$shared() { + // Should not be called directly + } + + public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR)); + public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} + diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h.java b/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h.java index 1004ee85..b200b154 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/luacodegen_h.java @@ -12,68 +12,23 @@ import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.MemoryLayout.PathElement.*; -public class luacodegen_h { +public class luacodegen_h extends luacodegen_h$shared { luacodegen_h() { // Should not be called directly } static final Arena LIBRARY_ARENA = Arena.ofAuto(); - static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); - - static void traceDowncall(String name, Object... args) { - String traceArgs = Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")); - System.out.printf("%s(%s)\n", name, traceArgs); - } - - static MemorySegment findOrThrow(String symbol) { - return SYMBOL_LOOKUP.find(symbol) - .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); - } catch (ReflectiveOperationException ex) { - throw new AssertionError(ex); - } - } - - static MemoryLayout align(MemoryLayout layout, long align) { - return switch (layout) { - case PaddingLayout p -> p; - case ValueLayout v -> v.withByteAlignment(align); - case GroupLayout g -> { - MemoryLayout[] alignedMembers = g.memberLayouts().stream() - .map(m -> align(m, align)).toArray(MemoryLayout[]::new); - yield g instanceof StructLayout ? - MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); - } - case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); - }; - } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() .or(Linker.nativeLinker().defaultLookup()); - public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; - public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; - public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; - public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; - public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; - public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; - public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; - public static final AddressLayout C_POINTER = ValueLayout.ADDRESS - .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); - public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; private static class luau_codegen_supported { public static final FunctionDescriptor DESC = FunctionDescriptor.of( luacodegen_h.C_INT ); - public static final MemorySegment ADDR = luacodegen_h.findOrThrow("luau_codegen_supported"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_codegen_supported"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -120,6 +75,8 @@ public static int luau_codegen_supported() { traceDowncall("luau_codegen_supported"); } return (int)mh$.invokeExact(); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -130,7 +87,7 @@ private static class luau_codegen_create { luacodegen_h.C_POINTER ); - public static final MemorySegment ADDR = luacodegen_h.findOrThrow("luau_codegen_create"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_codegen_create"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -177,6 +134,8 @@ public static void luau_codegen_create(MemorySegment L) { traceDowncall("luau_codegen_create", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -188,7 +147,7 @@ private static class luau_codegen_compile { luacodegen_h.C_INT ); - public static final MemorySegment ADDR = luacodegen_h.findOrThrow("luau_codegen_compile"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luau_codegen_compile"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -235,6 +194,8 @@ public static void luau_codegen_compile(MemorySegment L, int idx) { traceDowncall("luau_codegen_compile", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h$shared.java b/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h$shared.java new file mode 100644 index 00000000..d9df6664 --- /dev/null +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h$shared.java @@ -0,0 +1,63 @@ +// Generated by jextract + +package net.hollowcube.luau.internal.vm; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class lualib_h$shared { + + lualib_h$shared() { + // Should not be called directly + } + + public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR)); + public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} + diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h.java b/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h.java index e837502e..50efb069 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/lualib_h.java @@ -12,62 +12,17 @@ import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.MemoryLayout.PathElement.*; -public class lualib_h { +public class lualib_h extends lualib_h$shared { lualib_h() { // Should not be called directly } static final Arena LIBRARY_ARENA = Arena.ofAuto(); - static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); - - static void traceDowncall(String name, Object... args) { - String traceArgs = Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")); - System.out.printf("%s(%s)\n", name, traceArgs); - } - - static MemorySegment findOrThrow(String symbol) { - return SYMBOL_LOOKUP.find(symbol) - .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); - } catch (ReflectiveOperationException ex) { - throw new AssertionError(ex); - } - } - - static MemoryLayout align(MemoryLayout layout, long align) { - return switch (layout) { - case PaddingLayout p -> p; - case ValueLayout v -> v.withByteAlignment(align); - case GroupLayout g -> { - MemoryLayout[] alignedMembers = g.memberLayouts().stream() - .map(m -> align(m, align)).toArray(MemoryLayout[]::new); - yield g instanceof StructLayout ? - MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); - } - case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); - }; - } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() .or(Linker.nativeLinker().defaultLookup()); - public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; - public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; - public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; - public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; - public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; - public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; - public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; - public static final AddressLayout C_POINTER = ValueLayout.ADDRESS - .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); - public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; private static class luaL_optboolean { public static final FunctionDescriptor DESC = FunctionDescriptor.of( @@ -77,7 +32,7 @@ private static class luaL_optboolean { lualib_h.C_INT ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaL_optboolean"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaL_optboolean"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -124,6 +79,8 @@ public static int luaL_optboolean(MemorySegment L, int narg, int def) { traceDowncall("luaL_optboolean", L, narg, def); } return (int)mh$.invokeExact(L, narg, def); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -135,7 +92,7 @@ private static class luaopen_base { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_base"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_base"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -182,6 +139,8 @@ public static int luaopen_base(MemorySegment L) { traceDowncall("luaopen_base", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -193,7 +152,7 @@ private static class luaopen_coroutine { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_coroutine"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_coroutine"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -240,6 +199,8 @@ public static int luaopen_coroutine(MemorySegment L) { traceDowncall("luaopen_coroutine", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -251,7 +212,7 @@ private static class luaopen_table { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_table"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_table"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -298,6 +259,8 @@ public static int luaopen_table(MemorySegment L) { traceDowncall("luaopen_table", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -309,7 +272,7 @@ private static class luaopen_os { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_os"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_os"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -356,6 +319,8 @@ public static int luaopen_os(MemorySegment L) { traceDowncall("luaopen_os", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -367,7 +332,7 @@ private static class luaopen_string { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_string"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_string"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -414,6 +379,8 @@ public static int luaopen_string(MemorySegment L) { traceDowncall("luaopen_string", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -425,7 +392,7 @@ private static class luaopen_bit32 { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_bit32"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_bit32"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -472,6 +439,8 @@ public static int luaopen_bit32(MemorySegment L) { traceDowncall("luaopen_bit32", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -483,7 +452,7 @@ private static class luaopen_buffer { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_buffer"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_buffer"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -530,6 +499,8 @@ public static int luaopen_buffer(MemorySegment L) { traceDowncall("luaopen_buffer", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -541,7 +512,7 @@ private static class luaopen_utf8 { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_utf8"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_utf8"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -588,6 +559,8 @@ public static int luaopen_utf8(MemorySegment L) { traceDowncall("luaopen_utf8", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -599,7 +572,7 @@ private static class luaopen_math { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_math"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_math"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -646,6 +619,8 @@ public static int luaopen_math(MemorySegment L) { traceDowncall("luaopen_math", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -657,7 +632,7 @@ private static class luaopen_debug { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_debug"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_debug"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -704,6 +679,8 @@ public static int luaopen_debug(MemorySegment L) { traceDowncall("luaopen_debug", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -715,7 +692,7 @@ private static class luaopen_vector { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaopen_vector"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaopen_vector"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -762,6 +739,8 @@ public static int luaopen_vector(MemorySegment L) { traceDowncall("luaopen_vector", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -772,7 +751,7 @@ private static class luaL_openlibs { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaL_openlibs"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaL_openlibs"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -819,6 +798,8 @@ public static void luaL_openlibs(MemorySegment L) { traceDowncall("luaL_openlibs", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -829,7 +810,7 @@ private static class luaL_sandbox { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaL_sandbox"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaL_sandbox"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -876,6 +857,8 @@ public static void luaL_sandbox(MemorySegment L) { traceDowncall("luaL_sandbox", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -886,7 +869,7 @@ private static class luaL_sandboxthread { lualib_h.C_POINTER ); - public static final MemorySegment ADDR = lualib_h.findOrThrow("luaL_sandboxthread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaL_sandboxthread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -933,6 +916,8 @@ public static void luaL_sandboxthread(MemorySegment L) { traceDowncall("luaL_sandboxthread", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h$shared.java b/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h$shared.java new file mode 100644 index 00000000..f0438805 --- /dev/null +++ b/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h$shared.java @@ -0,0 +1,63 @@ +// Generated by jextract + +package net.hollowcube.luau.internal.vm; + +import java.lang.invoke.*; +import java.lang.foreign.*; +import java.nio.ByteOrder; +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import static java.lang.foreign.ValueLayout.*; +import static java.lang.foreign.MemoryLayout.PathElement.*; + +public class luawrap_h$shared { + + luawrap_h$shared() { + // Should not be called directly + } + + public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); + public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); + public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); + public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); + public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); + public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); + public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR)); + public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); + + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); + + static void traceDowncall(String name, Object... args) { + String traceArgs = Arrays.stream(args) + .map(Object::toString) + .collect(Collectors.joining(", ")); + System.out.printf("%s(%s)\n", name, traceArgs); + } + + static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { + try { + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); + } catch (ReflectiveOperationException ex) { + throw new AssertionError(ex); + } + } + + static MemoryLayout align(MemoryLayout layout, long align) { + return switch (layout) { + case PaddingLayout p -> p; + case ValueLayout v -> v.withByteAlignment(align); + case GroupLayout g -> { + MemoryLayout[] alignedMembers = g.memberLayouts().stream() + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); + yield g instanceof StructLayout ? + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); + } + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); + }; + } +} + diff --git a/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h.java b/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h.java index 296ff1a7..97874a57 100644 --- a/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h.java +++ b/src/generated/java/net/hollowcube/luau/internal/vm/luawrap_h.java @@ -12,62 +12,17 @@ import static java.lang.foreign.ValueLayout.*; import static java.lang.foreign.MemoryLayout.PathElement.*; -public class luawrap_h { +public class luawrap_h extends luawrap_h$shared { luawrap_h() { // Should not be called directly } static final Arena LIBRARY_ARENA = Arena.ofAuto(); - static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); - - static void traceDowncall(String name, Object... args) { - String traceArgs = Arrays.stream(args) - .map(Object::toString) - .collect(Collectors.joining(", ")); - System.out.printf("%s(%s)\n", name, traceArgs); - } - - static MemorySegment findOrThrow(String symbol) { - return SYMBOL_LOOKUP.find(symbol) - .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); - } - - static MethodHandle upcallHandle(Class fi, String name, FunctionDescriptor fdesc) { - try { - return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); - } catch (ReflectiveOperationException ex) { - throw new AssertionError(ex); - } - } - - static MemoryLayout align(MemoryLayout layout, long align) { - return switch (layout) { - case PaddingLayout p -> p; - case ValueLayout v -> v.withByteAlignment(align); - case GroupLayout g -> { - MemoryLayout[] alignedMembers = g.memberLayouts().stream() - .map(m -> align(m, align)).toArray(MemoryLayout[]::new); - yield g instanceof StructLayout ? - MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); - } - case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); - }; - } static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() .or(Linker.nativeLinker().defaultLookup()); - public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; - public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; - public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; - public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; - public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; - public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; - public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; - public static final AddressLayout C_POINTER = ValueLayout.ADDRESS - .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); - public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; private static class lua_xmove { public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( @@ -76,7 +31,7 @@ private static class lua_xmove { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("lua_xmove"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_xmove"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -123,6 +78,8 @@ public static void lua_xmove(MemorySegment from, MemorySegment to, int n) { traceDowncall("lua_xmove", from, to, n); } mh$.invokeExact(from, to, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -135,7 +92,7 @@ private static class lua_xpush { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("lua_xpush"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("lua_xpush"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -182,6 +139,8 @@ public static void lua_xpush(MemorySegment from, MemorySegment to, int idx) { traceDowncall("lua_xpush", from, to, idx); } mh$.invokeExact(from, to, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -193,7 +152,7 @@ private static class luaW_getstatus { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_getstatus"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_getstatus"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -240,6 +199,8 @@ public static int luaW_getstatus(MemorySegment L) { traceDowncall("luaW_getstatus", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -253,7 +214,7 @@ public static int luaW_getstatus(MemorySegment L) { */ public static class luaW_assertconf_log { private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.ofVoid( ); - private static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_assertconf_log"); + private static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_assertconf_log"); private final MethodHandle handle; private final FunctionDescriptor descriptor; @@ -305,7 +266,7 @@ public void apply(Object... x0) { if (TRACE_DOWNCALLS) { traceDowncall("luaW_assertconf_log", x0); } - spreader.invokeExact(x0); + spreader.invokeExact(x0); } catch(IllegalArgumentException | ClassCastException ex$) { throw ex$; // rethrow IAE from passing wrong number/type of args } catch (Throwable ex$) { @@ -322,7 +283,7 @@ public void apply(Object... x0) { */ public static class luaW_assertconf_dump { private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.ofVoid( ); - private static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_assertconf_dump"); + private static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_assertconf_dump"); private final MethodHandle handle; private final FunctionDescriptor descriptor; @@ -374,7 +335,7 @@ public void apply(Object... x0) { if (TRACE_DOWNCALLS) { traceDowncall("luaW_assertconf_dump", x0); } - spreader.invokeExact(x0); + spreader.invokeExact(x0); } catch(IllegalArgumentException | ClassCastException ex$) { throw ex$; // rethrow IAE from passing wrong number/type of args } catch (Throwable ex$) { @@ -389,7 +350,7 @@ private static class luaW_newstate { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newstate"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newstate"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -436,6 +397,8 @@ public static MemorySegment luaW_newstate(MemorySegment f) { traceDowncall("luaW_newstate", f); } return (MemorySegment)mh$.invokeExact(f); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -447,7 +410,7 @@ private static class luaW_newthread { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newthread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newthread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -494,6 +457,8 @@ public static MemorySegment luaW_newthread(MemorySegment L) { traceDowncall("luaW_newthread", L); } return (MemorySegment)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -504,7 +469,7 @@ private static class luaW_resetthread { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_resetthread"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_resetthread"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -551,6 +516,8 @@ public static void luaW_resetthread(MemorySegment L) { traceDowncall("luaW_resetthread", L); } mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -564,7 +531,7 @@ private static class luaW_equal { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_equal"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_equal"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -611,6 +578,8 @@ public static int luaW_equal(MemorySegment L, int idx1, int idx2) { traceDowncall("luaW_equal", L, idx1, idx2); } return (int)mh$.invokeExact(L, idx1, idx2); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -624,7 +593,7 @@ private static class luaW_lessthan { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_lessthan"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_lessthan"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -671,6 +640,8 @@ public static int luaW_lessthan(MemorySegment L, int idx1, int idx2) { traceDowncall("luaW_lessthan", L, idx1, idx2); } return (int)mh$.invokeExact(L, idx1, idx2); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -684,7 +655,7 @@ private static class luaW_tolstring { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_tolstring"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_tolstring"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -731,6 +702,8 @@ public static MemorySegment luaW_tolstring(MemorySegment L, int idx, MemorySegme traceDowncall("luaW_tolstring", L, idx, len); } return (MemorySegment)mh$.invokeExact(L, idx, len); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -743,7 +716,7 @@ private static class luaW_objlen { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_objlen"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_objlen"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -790,6 +763,8 @@ public static int luaW_objlen(MemorySegment L, int idx) { traceDowncall("luaW_objlen", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -802,7 +777,7 @@ private static class luaW_pushlstring { luawrap_h.C_LONG ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_pushlstring"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_pushlstring"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -849,6 +824,8 @@ public static void luaW_pushlstring(MemorySegment L, MemorySegment s, long l) { traceDowncall("luaW_pushlstring", L, s, l); } mh$.invokeExact(L, s, l); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -863,7 +840,7 @@ private static class luaW_pushcclosurek { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_pushcclosurek"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_pushcclosurek"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -910,6 +887,8 @@ public static void luaW_pushcclosurek(MemorySegment L, MemorySegment fn, MemoryS traceDowncall("luaW_pushcclosurek", L, fn, debugname, nup, cont); } mh$.invokeExact(L, fn, debugname, nup, cont); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -923,7 +902,7 @@ private static class luaW_newuserdatatagged { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newuserdatatagged"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newuserdatatagged"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -970,6 +949,8 @@ public static MemorySegment luaW_newuserdatatagged(MemorySegment L, long sz, int traceDowncall("luaW_newuserdatatagged", L, sz, tag); } return (MemorySegment)mh$.invokeExact(L, sz, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -983,7 +964,7 @@ private static class luaW_newuserdatataggedwithmetatable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newuserdatataggedwithmetatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newuserdatataggedwithmetatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1030,6 +1011,8 @@ public static MemorySegment luaW_newuserdatataggedwithmetatable(MemorySegment L, traceDowncall("luaW_newuserdatataggedwithmetatable", L, sz, tag); } return (MemorySegment)mh$.invokeExact(L, sz, tag); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1043,7 +1026,7 @@ private static class luaW_newuserdatadtor { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newuserdatadtor"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newuserdatadtor"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1090,6 +1073,8 @@ public static MemorySegment luaW_newuserdatadtor(MemorySegment L, long sz, Memor traceDowncall("luaW_newuserdatadtor", L, sz, dtor); } return (MemorySegment)mh$.invokeExact(L, sz, dtor); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1102,7 +1087,7 @@ private static class luaW_newbuffer { luawrap_h.C_LONG ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_newbuffer"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_newbuffer"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1149,6 +1134,8 @@ public static MemorySegment luaW_newbuffer(MemorySegment L, long sz) { traceDowncall("luaW_newbuffer", L, sz); } return (MemorySegment)mh$.invokeExact(L, sz); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1161,7 +1148,7 @@ private static class luaW_gettable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_gettable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_gettable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1208,6 +1195,8 @@ public static int luaW_gettable(MemorySegment L, int idx) { traceDowncall("luaW_gettable", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1221,7 +1210,7 @@ private static class luaW_getfield { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_getfield"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_getfield"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1268,6 +1257,8 @@ public static int luaW_getfield(MemorySegment L, int idx, MemorySegment k) { traceDowncall("luaW_getfield", L, idx, k); } return (int)mh$.invokeExact(L, idx, k); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1280,7 +1271,7 @@ private static class luaW_createtable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_createtable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_createtable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1327,6 +1318,8 @@ public static void luaW_createtable(MemorySegment L, int narr, int nrec) { traceDowncall("luaW_createtable", L, narr, nrec); } mh$.invokeExact(L, narr, nrec); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1338,7 +1331,7 @@ private static class luaW_settable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_settable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_settable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1385,6 +1378,8 @@ public static void luaW_settable(MemorySegment L, int idx) { traceDowncall("luaW_settable", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1397,7 +1392,7 @@ private static class luaW_setfield { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_setfield"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_setfield"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1444,6 +1439,8 @@ public static void luaW_setfield(MemorySegment L, int idx, MemorySegment k) { traceDowncall("luaW_setfield", L, idx, k); } mh$.invokeExact(L, idx, k); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1456,7 +1453,7 @@ private static class luaW_rawsetfield { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_rawsetfield"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_rawsetfield"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1503,6 +1500,8 @@ public static void luaW_rawsetfield(MemorySegment L, int idx, MemorySegment k) { traceDowncall("luaW_rawsetfield", L, idx, k); } mh$.invokeExact(L, idx, k); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1514,7 +1513,7 @@ private static class luaW_rawset { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_rawset"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_rawset"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1561,6 +1560,8 @@ public static void luaW_rawset(MemorySegment L, int idx) { traceDowncall("luaW_rawset", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1573,7 +1574,7 @@ private static class luaW_rawseti { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_rawseti"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_rawseti"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1620,6 +1621,8 @@ public static void luaW_rawseti(MemorySegment L, int idx, int n) { traceDowncall("luaW_rawseti", L, idx, n); } mh$.invokeExact(L, idx, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1632,7 +1635,7 @@ private static class luaW_setmetatable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_setmetatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_setmetatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1679,6 +1682,8 @@ public static int luaW_setmetatable(MemorySegment L, int objindex) { traceDowncall("luaW_setmetatable", L, objindex); } return (int)mh$.invokeExact(L, objindex); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1691,7 +1696,7 @@ private static class luaW_yield { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_yield"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_yield"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1738,6 +1743,8 @@ public static int luaW_yield(MemorySegment L, int nresults) { traceDowncall("luaW_yield", L, nresults); } return (int)mh$.invokeExact(L, nresults); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1749,7 +1756,7 @@ private static class luaW_break { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_break"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_break"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1796,6 +1803,8 @@ public static int luaW_break(MemorySegment L) { traceDowncall("luaW_break", L); } return (int)mh$.invokeExact(L); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1808,7 +1817,7 @@ private static class luaW_next { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_next"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_next"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1855,6 +1864,8 @@ public static int luaW_next(MemorySegment L, int idx) { traceDowncall("luaW_next", L, idx); } return (int)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1866,7 +1877,7 @@ private static class luaW_concat { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_concat"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_concat"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1913,6 +1924,8 @@ public static void luaW_concat(MemorySegment L, int n) { traceDowncall("luaW_concat", L, n); } mh$.invokeExact(L, n); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1925,7 +1938,7 @@ private static class luaW_setlightuserdataname { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_setlightuserdataname"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_setlightuserdataname"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -1972,6 +1985,8 @@ public static void luaW_setlightuserdataname(MemorySegment L, int tag, MemorySeg traceDowncall("luaW_setlightuserdataname", L, tag, name); } mh$.invokeExact(L, tag, name); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -1983,7 +1998,7 @@ private static class luaW_clonefunction { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_clonefunction"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_clonefunction"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2030,6 +2045,8 @@ public static void luaW_clonefunction(MemorySegment L, int idx) { traceDowncall("luaW_clonefunction", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2041,7 +2058,7 @@ private static class luaW_cleartable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_cleartable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_cleartable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2088,6 +2105,8 @@ public static void luaW_cleartable(MemorySegment L, int idx) { traceDowncall("luaW_cleartable", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2099,7 +2118,7 @@ private static class luaW_clonetable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaW_clonetable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_clonetable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2146,6 +2165,8 @@ public static void luaW_clonetable(MemorySegment L, int idx) { traceDowncall("luaW_clonetable", L, idx); } mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2158,7 +2179,7 @@ private static class luaLW_newmetatable { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_newmetatable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_newmetatable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2205,6 +2226,8 @@ public static int luaLW_newmetatable(MemorySegment L, MemorySegment tname) { traceDowncall("luaLW_newmetatable", L, tname); } return (int)mh$.invokeExact(L, tname); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2218,7 +2241,7 @@ private static class luaLW_tolstring { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_tolstring"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_tolstring"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2265,6 +2288,8 @@ public static MemorySegment luaLW_tolstring(MemorySegment L, int idx, MemorySegm traceDowncall("luaLW_tolstring", L, idx, len); } return (MemorySegment)mh$.invokeExact(L, idx, len); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2279,7 +2304,7 @@ private static class luaLW_findtable { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_findtable"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_findtable"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2326,6 +2351,8 @@ public static MemorySegment luaLW_findtable(MemorySegment L, int idx, MemorySegm traceDowncall("luaLW_findtable", L, idx, fname, szhint); } return (MemorySegment)mh$.invokeExact(L, idx, fname, szhint); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2338,7 +2365,7 @@ private static class luaLW_typename { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_typename"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_typename"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2385,6 +2412,8 @@ public static MemorySegment luaLW_typename(MemorySegment L, int idx) { traceDowncall("luaLW_typename", L, idx); } return (MemorySegment)mh$.invokeExact(L, idx); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2397,7 +2426,7 @@ private static class luaLW_typeerror { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_typeerror"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_typeerror"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2444,6 +2473,8 @@ public static void luaLW_typeerror(MemorySegment L, int narg, MemorySegment tnam traceDowncall("luaLW_typeerror", L, narg, tname); } mh$.invokeExact(L, narg, tname); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2456,7 +2487,7 @@ private static class luaLW_argerror { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_argerror"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_argerror"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2503,6 +2534,8 @@ public static void luaLW_argerror(MemorySegment L, int narg, MemorySegment extra traceDowncall("luaLW_argerror", L, narg, extramsg); } mh$.invokeExact(L, narg, extramsg); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2515,7 +2548,7 @@ private static class luaLW_checkboolean { luawrap_h.C_INT ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_checkboolean"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_checkboolean"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2562,6 +2595,8 @@ public static int luaLW_checkboolean(MemorySegment L, int narg) { traceDowncall("luaLW_checkboolean", L, narg); } return (int)mh$.invokeExact(L, narg); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } @@ -2575,7 +2610,7 @@ private static class luaLW_checkudata { luawrap_h.C_POINTER ); - public static final MemorySegment ADDR = luawrap_h.findOrThrow("luaLW_checkudata"); + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaLW_checkudata"); public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); } @@ -2622,6 +2657,68 @@ public static MemorySegment luaLW_checkudata(MemorySegment L, int ud, MemorySegm traceDowncall("luaLW_checkudata", L, ud, tname); } return (MemorySegment)mh$.invokeExact(L, ud, tname); + } catch (Error | RuntimeException ex) { + throw ex; + } catch (Throwable ex$) { + throw new AssertionError("should not reach here", ex$); + } + } + + private static class luaW_interrupt_preempt_handler { + public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid( + luawrap_h.C_POINTER, + luawrap_h.C_INT + ); + + public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("luaW_interrupt_preempt_handler"); + + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); + } + + /** + * Function descriptor for: + * {@snippet lang=c : + * extern void luaW_interrupt_preempt_handler(lua_State *L, int gc) + * } + */ + public static FunctionDescriptor luaW_interrupt_preempt_handler$descriptor() { + return luaW_interrupt_preempt_handler.DESC; + } + + /** + * Downcall method handle for: + * {@snippet lang=c : + * extern void luaW_interrupt_preempt_handler(lua_State *L, int gc) + * } + */ + public static MethodHandle luaW_interrupt_preempt_handler$handle() { + return luaW_interrupt_preempt_handler.HANDLE; + } + + /** + * Address for: + * {@snippet lang=c : + * extern void luaW_interrupt_preempt_handler(lua_State *L, int gc) + * } + */ + public static MemorySegment luaW_interrupt_preempt_handler$address() { + return luaW_interrupt_preempt_handler.ADDR; + } + + /** + * {@snippet lang=c : + * extern void luaW_interrupt_preempt_handler(lua_State *L, int gc) + * } + */ + public static void luaW_interrupt_preempt_handler(MemorySegment L, int gc) { + var mh$ = luaW_interrupt_preempt_handler.HANDLE; + try { + if (TRACE_DOWNCALLS) { + traceDowncall("luaW_interrupt_preempt_handler", L, gc); + } + mh$.invokeExact(L, gc); + } catch (Error | RuntimeException ex) { + throw ex; } catch (Throwable ex$) { throw new AssertionError("should not reach here", ex$); } diff --git a/src/main/java/net/hollowcube/luau/LuaCallbacks.java b/src/main/java/net/hollowcube/luau/LuaCallbacks.java index dacb5812..1c4e9013 100644 --- a/src/main/java/net/hollowcube/luau/LuaCallbacks.java +++ b/src/main/java/net/hollowcube/luau/LuaCallbacks.java @@ -34,6 +34,33 @@ static Interrupt allocate(Handler handler, Arena arena) { void interrupt(@Nullable Interrupt handler); void interrupt(MemorySegment functionAddress); + sealed interface Preempt permits LuaCallbacksImpl.PreemptImpl { + + enum PreemptType { + NONE(0), YIELD(-1), ERROR(-2); + + final int value; + + PreemptType(int value) {this.value = value;} + + public int value() { return value; } + } + + @FunctionalInterface + interface Handler { + PreemptType preempt(LuaState state, int gc); + } + + static Preempt allocate(Preempt.Handler handler, Arena arena) { + return new LuaCallbacksImpl.PreemptImpl(handler, arena); + } + } + + /// gets called at safepoints (loop back edges, call/ret, gc) if set AND + /// interrupt() is set to luaW_interrupt_preempt_handler + void preempt(@Nullable LuaCallbacks.Preempt handler); + void preempt(MemorySegment functionAddress); + sealed interface UserAtom permits LuaCallbacksImpl.UserAtomImpl { @FunctionalInterface interface Handler { diff --git a/src/main/java/net/hollowcube/luau/LuaCallbacksImpl.java b/src/main/java/net/hollowcube/luau/LuaCallbacksImpl.java index 1afa0a48..094a7f5f 100644 --- a/src/main/java/net/hollowcube/luau/LuaCallbacksImpl.java +++ b/src/main/java/net/hollowcube/luau/LuaCallbacksImpl.java @@ -1,6 +1,7 @@ package net.hollowcube.luau; import net.hollowcube.luau.internal.vm.lua_Callbacks; +import net.hollowcube.luau.internal.vm.luawrap_h; import net.hollowcube.luau.util.GlobalRef; import org.jetbrains.annotations.Nullable; @@ -31,6 +32,30 @@ public void interrupt(MemorySegment functionAddress) { lua_Callbacks.interrupt(callbacks, functionAddress); } + record PreemptImpl(MemorySegment handle) implements Preempt { + public PreemptImpl(Handler handler, Arena arena) { + final lua_Callbacks.preempt.Function f = (L, gc) -> + handler.preempt(new LuaStateImpl(L), gc).value(); + + this(lua_Callbacks.preempt.allocate(f, arena)); + } + } + + @Override + public void preempt(MemorySegment functionAddress) { + lua_Callbacks.interrupt(callbacks, luawrap_h.luaW_interrupt_preempt_handler$address()); + lua_Callbacks.preempt(callbacks, functionAddress); + } + + @Override + public void preempt(@Nullable LuaCallbacks.Preempt handler) { + final MemorySegment handle = handler != null + ? ((PreemptImpl) handler).handle + : MemorySegment.NULL; + + preempt(handle); + } + record UserAtomImpl(MemorySegment handle) implements UserAtom { public UserAtomImpl(Handler handler, Arena arena) { final lua_Callbacks.useratom.Function f = (str, len) -> {