Skip to content

Commit

Permalink
Update marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Feb 24, 2024
1 parent 4fcf4b9 commit d9ec043
Show file tree
Hide file tree
Showing 103 changed files with 495 additions and 340 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
- name: Grant execute permission for gradlew
if: ${{ runner.os != 'Windows' }}
run: chmod +x gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build --no-daemon -x :samples:test
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Execute Gradle build
run: ./gradlew build --no-daemon -x :samples:test
- name: Upload build reports
if: ${{ runner.os == 'Linux' && matrix.java == '22-ea' && failure() }}
uses: actions/upload-artifact@v4
Expand Down
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
`java-platform`
`maven-publish`
signing
id("me.champeau.jmh") version "0.7.2" apply false
}

val projGroupId: String by project
Expand Down Expand Up @@ -127,7 +126,6 @@ artifactNameMap.forEach { (subprojectName, artifactName) ->
project(subprojectName) {
apply(plugin = "java-library")
apply(plugin = "idea")
apply(plugin = "me.champeau.jmh")

group = projGroupId
version = projVersion
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jdkEnablePreview=true
jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

overrunMarshalVersion=0.1.0-alpha.17-jdk22
overrunMarshalVersion=0.1.0-alpha.20-jdk22
overrunPlatformVersion=1.0.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package overrungl.glfw;

import org.jetbrains.annotations.Nullable;
import overrun.marshal.DirectAccess;
import overrun.marshal.Downcall;
import overrun.marshal.MemoryStack;
import overrun.marshal.Unmarshal;
Expand All @@ -40,7 +41,7 @@
* @author squid233
* @since 0.1.0
*/
public interface GLFW {
public interface GLFW extends DirectAccess {
/**
* The instance of GLFW.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for Unicode character callbacks.
Expand All @@ -37,15 +39,14 @@ public interface GLFWCharFun extends Upcall {
/**
* The type.
*/
Type<GLFWCharFun> TYPE = Upcall.type();
Type<GLFWCharFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT));

/**
* The function pointer type for Unicode character callbacks.
*
* @param window The window that received the event.
* @param codepoint The Unicode code point of the character.
*/
@Stub
void invoke(MemorySegment window, int codepoint);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for cursor enter/leave callbacks.
Expand All @@ -37,7 +39,7 @@ public interface GLFWCursorEnterFun extends Upcall {
/**
* The type.
*/
Type<GLFWCursorEnterFun> TYPE = Upcall.type();
Type<GLFWCursorEnterFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT));

/**
* The function pointer type for cursor enter/leave callbacks.
Expand All @@ -55,7 +57,6 @@ public interface GLFWCursorEnterFun extends Upcall {
* @param entered {@code true} if the cursor entered the window's content
* area, or {@code false} if it left it.
*/
@Stub
default void ninvoke(MemorySegment window, int entered) {
invoke(window, entered != GLFW.FALSE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for cursor position callbacks. A cursor
Expand All @@ -37,7 +39,7 @@ public interface GLFWCursorPosFun extends Upcall {
/**
* The type.
*/
Type<GLFWCursorPosFun> TYPE = Upcall.type();
Type<GLFWCursorPosFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE));

/**
* The function pointer type for cursor position callbacks.
Expand All @@ -46,7 +48,6 @@ public interface GLFWCursorPosFun extends Upcall {
* @param xpos The new cursor x-coordinate, relative to the left edge of the content area.
* @param ypos The new cursor y-coordinate, relative to the top edge of the content area.
*/
@Stub
void invoke(MemorySegment window, double xpos, double ypos);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

Expand All @@ -41,7 +42,7 @@ public interface GLFWDropFun extends Upcall {
/**
* The type.
*/
Type<GLFWDropFun> TYPE = Upcall.type();
Type<GLFWDropFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS));

/**
* The function pointer type for path drop callbacks.
Expand All @@ -58,7 +59,6 @@ public interface GLFWDropFun extends Upcall {
* @param pathCount The number of dropped paths.
* @param paths The UTF-8 encoded file and/or directory path names.
*/
@Stub
default void ninvoke(MemorySegment window, int pathCount, MemorySegment paths) {
invoke(window, Unmarshal.unmarshalAsStringArray(paths.reinterpret(ValueLayout.ADDRESS.scale(0L, pathCount))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

import overrun.marshal.Unmarshal;
import overrun.marshal.Upcall;
import overrun.marshal.gen.SizedSeg;
import overrungl.NativeType;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;

import static java.lang.foreign.ValueLayout.*;

/**
* This is the function pointer type for error callbacks. An error callback
* function has the following signature:
Expand All @@ -43,7 +46,7 @@ public interface GLFWErrorFun extends Upcall {
/**
* The type.
*/
Type<GLFWErrorFun> TYPE = Upcall.type();
Type<GLFWErrorFun> TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(JAVA_INT, ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, JAVA_BYTE))));

/**
* The function pointer type for error callbacks.
Expand All @@ -60,8 +63,7 @@ public interface GLFWErrorFun extends Upcall {
* Future releases may add more error codes.
* @param description A UTF-8 encoded string describing the error.
*/
@Stub
default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarshal.STR_SIZE) MemorySegment description) {
default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) {
invoke(errorCode, Unmarshal.unmarshalAsString(description));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for framebuffer size callbacks.
Expand All @@ -37,7 +39,7 @@ public interface GLFWFramebufferSizeFun extends Upcall {
/**
* The type.
*/
Type<GLFWFramebufferSizeFun> TYPE = Upcall.type();
Type<GLFWFramebufferSizeFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT));

/**
* The function pointer type for framebuffer size callbacks.
Expand All @@ -46,7 +48,6 @@ public interface GLFWFramebufferSizeFun extends Upcall {
* @param width The new width, in pixels, of the framebuffer.
* @param height The new height, in pixels, of the framebuffer.
*/
@Stub
void invoke(MemorySegment window, int width, int height);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public final class GLFWGamepadState extends Struct {
* The states of each <a href="https://www.glfw.org/docs/latest/group__gamepad__buttons.html">gamepad button</a>,
* {@link GLFW#PRESS} or {@link GLFW#RELEASE}.
*/
public final StructHandleSizedByteArray buttons = StructHandleSizedByteArray.of(this, "buttons");
public static final StructHandleSizedByteArray buttons = StructHandleSizedByteArray.of(LAYOUT, "buttons");
/**
* The states of each <a href="https://www.glfw.org/docs/latest/group__gamepad__axes.html">gamepad axis</a>,
* in the range -1.0 to 1.0 inclusive.
*/
public final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(this, "axes");
public static final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(LAYOUT, "axes");

/**
* Creates a struct with the given layout.
Expand Down Expand Up @@ -97,7 +97,7 @@ public GLFWGamepadState(SegmentAllocator allocator) {
* @return the state, {@code PRESS} or {@code RELEASE}
*/
public boolean button(int index) {
return buttons.get(index) == GLFW.PRESS;
return buttons.get(this, index) == GLFW.PRESS;
}

/**
Expand All @@ -107,6 +107,6 @@ public boolean button(int index) {
* @return the state, in the range -1.0 to 1.0 inclusive
*/
public float axe(int index) {
return axes.get(index);
return axes.get(this, index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ public final class GLFWGammaRamp extends Struct {
/**
* An array of value describing the response of the red channel.
*/
public final StructHandle.Array<short[]> red = StructHandle.ofArray(this, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
public static final StructHandle.Array<short[]> red = StructHandle.ofArray(LAYOUT, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
/**
* An array of value describing the response of the green channel.
*/
public final StructHandle.Array<short[]> green = StructHandle.ofArray(this, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
public static final StructHandle.Array<short[]> green = StructHandle.ofArray(LAYOUT, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
/**
* An array of value describing the response of the blue channel.
*/
public final StructHandle.Array<short[]> blue = StructHandle.ofArray(this, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
public static final StructHandle.Array<short[]> blue = StructHandle.ofArray(LAYOUT, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray);
/**
* The number of elements in each array.
*/
public final StructHandle.Int size = StructHandle.ofInt(this, "size");
public static final StructHandle.Int size = StructHandle.ofInt(LAYOUT, "size");

/**
* Creates a struct with the given layout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public final class GLFWImage extends Struct {
/**
* The width, in pixels, of this image.
*/
public final StructHandle.Int width = StructHandle.ofInt(this, "width");
public static final StructHandle.Int width = StructHandle.ofInt(LAYOUT, "width");
/**
* The height, in pixels, of this image.
*/
public final StructHandle.Int height = StructHandle.ofInt(this, "height");
public static final StructHandle.Int height = StructHandle.ofInt(LAYOUT, "height");
/**
* The pixel data address of this image, arranged left-to-right, top-to-bottom.
*/
public final StructHandle.Address pixels = StructHandle.ofAddress(this, "pixels");
public static final StructHandle.Address pixels = StructHandle.ofAddress(LAYOUT, "pixels");

/**
* Creates a struct with the given layout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for joystick configuration callbacks.
Expand All @@ -37,7 +39,7 @@ public interface GLFWJoystickFun extends Upcall {
/**
* The type.
*/
Type<GLFWJoystickFun> TYPE = Upcall.type();
Type<GLFWJoystickFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT));

/**
* The function pointer type for joystick configuration callbacks.
Expand All @@ -46,7 +48,6 @@ public interface GLFWJoystickFun extends Upcall {
* @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future
* releases may add more events.
*/
@Stub
void invoke(int jid, int event);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.Upcall;

import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* This is the function pointer type for keyboard key callbacks. A keyboard
Expand All @@ -37,7 +39,7 @@ public interface GLFWKeyFun extends Upcall {
/**
* The type.
*/
Type<GLFWKeyFun> TYPE = Upcall.type();
Type<GLFWKeyFun> TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT));

/**
* The function pointer type for keyboard key callbacks.
Expand All @@ -50,7 +52,6 @@ public interface GLFWKeyFun extends Upcall {
* @param mods Bit field describing which <a href="https://www.glfw.org/docs/latest/group__mods.html">modifier keys</a>
* were held down.
*/
@Stub
void invoke(MemorySegment window, int key, int scancode, int action, int mods);

@Override
Expand Down
Loading

0 comments on commit d9ec043

Please sign in to comment.