Skip to content

Commit

Permalink
Remove string template
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jul 31, 2024
1 parent ffe2f01 commit effce51
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 84 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Import as a Gradle dependency:

```groovy
dependencies {
implementation("io.github.over-run:marshal:0.1.0-alpha.26-jdk22")
implementation("io.github.over-run:marshal:0.1.0-alpha.27-jdk22")
}
```

Expand Down
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ allprojects {
dependencies {
// add your dependencies
compileOnly("org.jetbrains:annotations:24.1.0")
testImplementation(platform("org.junit:junit-bom:5.10.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.3")
}

tasks.withType<Test> {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ projGroupId=io.github.over-run
projArtifactId=marshal
# The project name should only contain lowercase letters, numbers and hyphen.
projName=marshal
projVersion=0.1.0-alpha.26-jdk22
projVersion=0.1.0-alpha.27-jdk22
projDesc=Marshaler of native libraries
# Uncomment them if you want to publish to maven repository.
projUrl=https://github.com/Over-Run/marshal
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
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.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
144 changes: 77 additions & 67 deletions src/main/java/overrun/marshal/Downcall.java

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/main/java/overrun/marshal/DowncallOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.internal.DowncallOptions;

import java.lang.foreign.FunctionDescriptor;
import java.lang.invoke.MethodHandle;
import java.util.Map;
import java.util.function.UnaryOperator;

/**
* Downcall option.
Expand All @@ -28,8 +30,7 @@
* @since 0.1.0
*/
public sealed interface DowncallOption
permits DowncallOptions.Descriptors,
DowncallOptions.TargetClass {
permits DowncallOptions.Descriptors, DowncallOptions.TargetClass, DowncallOptions.Transform {
/**
* Specifies the target class.
*
Expand All @@ -49,4 +50,14 @@ static DowncallOption targetClass(Class<?> aClass) {
static DowncallOption descriptors(Map<String, FunctionDescriptor> descriptorMap) {
return new DowncallOptions.Descriptors(descriptorMap);
}

/**
* Specifies the method handle transformer.
*
* @param transform the transforming function
* @return the option instance
*/
static DowncallOption transform(UnaryOperator<MethodHandle> transform) {
return new DowncallOptions.Transform(transform);
}
}
2 changes: 1 addition & 1 deletion src/main/java/overrun/marshal/MemoryStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static MemoryStack create(MemorySegment segment) {

private void frameOverflow() {
if (DEBUG) {
Configurations.apiLog(STR."[WARNING] Out of frame stack space (\{frames.length}) in thread: \{Thread.currentThread()}");
Configurations.apiLog("[WARNING] Out of frame stack space (" + frames.length + ") in thread: " + Thread.currentThread());
}
frames = Arrays.copyOf(frames, frames.length * 3 / 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static ProcessorType fromClass(Class<?> aClass) {
if (CEnum.class.isAssignableFrom(aClass)) return ProcessorType.CEnum.INSTANCE;
if (Upcall.class.isAssignableFrom(aClass)) return ProcessorType.Upcall.INSTANCE;
if (aClass.isArray()) return new ProcessorType.Array(fromClass(aClass.componentType()));
return Objects.requireNonNull(map.get(aClass), STR."Cannot find processor type of \{aClass}");
return Objects.requireNonNull(map.get(aClass), "Cannot find processor type of " + aClass);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/overrun/marshal/internal/DowncallOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import overrun.marshal.DowncallOption;

import java.lang.foreign.FunctionDescriptor;
import java.lang.invoke.MethodHandle;
import java.util.Map;
import java.util.function.UnaryOperator;

/**
* Downcall options.
Expand Down Expand Up @@ -47,4 +49,12 @@ public record TargetClass(Class<?> aClass) implements DowncallOption {

public record Descriptors(Map<String, FunctionDescriptor> descriptorMap) implements DowncallOption {
}

/**
* specify method handle transform
*
* @param operator the transform function
*/
public record Transform(UnaryOperator<MethodHandle> operator) implements DowncallOption {
}
}
12 changes: 6 additions & 6 deletions src/main/java/overrun/marshal/struct/StructAllocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ private static byte[] buildBytecode(MethodHandles.Lookup lookup, StructLayout la
final var results = findValueLayout(memberLayout);

for (FindResult result : results) {
final String methodName = STR."\{name}\{result.appendName()}";
final String methodName = name + result.appendName();
final int indexCount = result.indexCount();
final ClassDesc returnDesc = ClassDesc.ofDescriptor(result.layout().carrier().descriptorString());
final TypeKind returnKind = TypeKind.from(returnDesc);

// var handle
final String vhName = STR."_VH_\{methodName}";
final String vhName = "_VH_" + methodName;
classBuilder.withField(vhName, CD_VarHandle, Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC);

// getter
Expand Down Expand Up @@ -319,7 +319,7 @@ private static byte[] buildBytecode(MethodHandles.Lookup lookup, StructLayout la
final TypeKind returnKind = TypeKind.from(returnDesc);

// var handle
final String vhName = STR."_VH_\{name}";
final String vhName = "_VH_" + name;
classBuilder.withField(vhName, CD_VarHandle, Modifier.PRIVATE | Modifier.FINAL | Modifier.STATIC);

// getter
Expand Down Expand Up @@ -381,7 +381,7 @@ private static byte[] buildBytecode(MethodHandles.Lookup lookup, StructLayout la
i++;
}
codeBuilder.invokeinterface(CD_StructLayout, "varHandle", MTD_VarHandle_MemoryLayout_PathElementArray)
.putstatic(cd_thisClass, STR."_VH_\{name}\{result.appendName()}", CD_VarHandle);
.putstatic(cd_thisClass, "_VH_" + name + result.appendName(), CD_VarHandle);
}
}
case ValueLayout valueLayout -> {
Expand All @@ -397,7 +397,7 @@ private static byte[] buildBytecode(MethodHandles.Lookup lookup, StructLayout la
.invokestatic(CD_MemoryLayout_PathElement, "groupElement", MTD_MemoryLayout_PathElement_String, true)
.aastore()
.invokeinterface(CD_StructLayout, "varHandle", MTD_VarHandle_MemoryLayout_PathElementArray)
.putstatic(cd_thisClass, STR."_VH_\{name}", CD_VarHandle);
.putstatic(cd_thisClass, "_VH_" + name, CD_VarHandle);
}
case PaddingLayout _ -> {
}
Expand Down Expand Up @@ -430,7 +430,7 @@ private int indexCount() {
public String appendName() {
return elems.stream()
.filter(elem -> elem instanceof GroupElem)
.map(elem -> STR."$\{((GroupElem) elem).name}")
.map(elem -> "$" + ((GroupElem) elem).name)
.collect(Collectors.joining());
}
}
Expand Down

0 comments on commit effce51

Please sign in to comment.