use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.
the class CInterfaceTutorial method javaEntryPoint4.
@CEntryPoint(name = "java_entry_point4")
protected static void javaEntryPoint4(@SuppressWarnings("unused") IsolateThread thread, SUData sudata) {
int i = 0;
UnsignedWord u = sudata.getUB1Unsigned();
SignedWord s = sudata.getSB1Signed();
i = sudata.getUB1();
System.out.println(" getUB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
System.out.println(" getUB1Unsigned() = " + u.rawValue() + (u.rawValue() < 0 ? "<" : ">=") + " 0");
i = sudata.getSB1();
System.out.println(" getSB1() = " + i + (i < 0 ? "<" : ">=") + " 0");
System.out.println(" getSB1Signed() = " + s.rawValue() + (s.rawValue() < 0 ? "<" : ">=") + " 0");
System.out.println("(byte) 245 = " + ((byte) 245));
System.out.println("(byte) 245 & 0xFF = " + (((byte) 245) & 0xFF));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual(220) = " + sudata.getUB1Unsigned().aboveOrEqual(220));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual(245) = " + sudata.getUB1Unsigned().aboveOrEqual(245));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)220) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 220));
System.out.println("sudata.getUB1Unsigned().aboveOrEqual((byte)245) = " + sudata.getUB1Unsigned().aboveOrEqual((byte) 245));
System.out.println("sudata.getUB1() && 0xFF > 220 = " + ((sudata.getUB1() & 0xFF) > 220));
System.out.println("sudata.getUB1() && 0xFF > 245 = " + ((sudata.getUB1() & 0xFF) > 245));
}
use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.
the class CInterfaceTutorial method javaEntryPoint2.
@CEntryPoint(name = "java_entry_point2")
protected static void javaEntryPoint2(@SuppressWarnings("unused") IsolateThread thread, Substruct1 s1, Substruct2 s2) {
System.out.println("*** In Java, demonstrating inheritance with @CStruct class");
CCharPointer tp1 = s1.typePtr();
CCharPointer tp2 = s2.header().typePtr();
System.out.println("tp1 = 0x" + Long.toHexString(tp1.rawValue()) + " tp2 = 0x" + Long.toHexString(tp2.rawValue()));
System.out.println("&s1.header = 0x" + Long.toHexString(s1.header().rawValue()) + " &s2.header = 0x" + Long.toHexString(s2.header().rawValue()));
System.out.println("s1.f1 = " + s1.f1() + " s2.f2 = " + s2.f1());
System.out.println("&s1.f1 = 0x" + Long.toHexString(s1.addressOff1().rawValue()));
System.out.println("*&s1.f1 = " + s1.addressOff1().read());
System.out.println("offset_of(s1.f1) = " + s1.offsetOff1());
System.out.println("s1.header.type = " + s1.type() + " ((Header) s2).type = " + s2.header().type());
System.out.println("*** In Java, demonstrating @CFieldOffset");
System.out.println("offset_of(s1.header) = " + Substruct1.offsetOfHeader());
System.out.println("offset_of(s2.header) = " + s2.offsetOfHeader());
System.out.println("offset_of(s2.f1) = " + s2.offsetOff1().rawValue());
/*
* Accessing elements of an array of struct. Say that s1 is the first element of subdata_t
* s[10].
*/
// ps1 = &s[0]
Substruct1 ps1 = s1.addressOf(0);
// ps2 = &s[1]
Substruct1 ps2 = s1.addressOf(1);
long s = ps2.rawValue() - ps1.rawValue();
System.out.print("sizeof(s1) =" + SizeOf.get(Substruct1.class));
System.out.print(" s1 = 0x" + Long.toHexString(s1.rawValue()));
System.out.print(" ps1 = 0x" + Long.toHexString(ps1.rawValue()));
System.out.println(" ps2 = 0x" + Long.toHexString(ps2.rawValue()));
System.out.println(" ps2 - ps1 " + (s == SizeOf.get(Substruct1.class) ? "=" : "!=") + " sizeof(substruct1)");
}
use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.
the class PolyglotNativeAPI method polyglot_get_callback_info.
@CEntryPoint(name = "polyglot_get_callback_info")
public static PolyglotStatus polyglot_get_callback_info(IsolateThread isolate_thread, PolyglotCallbackInfo callback_info, SizeTPointer argc, PolyglotValuePointerPointer argv, WordPointer data) {
return withHandledErrors(() -> {
PolyglotCallbackInfoInternal callbackInfo = fetchHandle(callback_info);
UnsignedWord numberOfArguments = WordFactory.unsigned(callbackInfo.arguments.length);
UnsignedWord bufferSize = argc.read();
UnsignedWord size = bufferSize.belowThan(numberOfArguments) ? bufferSize : numberOfArguments;
argc.write(size);
for (UnsignedWord i = WordFactory.zero(); i.belowThan(size); i = i.add(1)) {
int index = (int) i.rawValue();
ObjectHandle argument = callbackInfo.arguments[index];
argv.write(index, argument);
}
data.write(callbackInfo.data);
});
}
use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.
the class PolyglotNativeAPI method polyglot_value_as_int64.
@CEntryPoint(name = "polyglot_value_as_int64")
public static PolyglotStatus polyglot_value_as_int64(IsolateThread isolate_thread, PolyglotValuePointer value, CLongPointer result) {
return withHandledErrors(() -> {
Value valueObject = fetchHandle(value);
result.write(valueObject.asLong());
});
}
use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.
the class PolyglotNativeAPI method polyglot_value_as_float.
@CEntryPoint(name = "polyglot_value_as_float")
public static PolyglotStatus polyglot_value_as_float(IsolateThread isolate_thread, PolyglotValuePointer value, CFloatPointer result) {
return withHandledErrors(() -> {
Value dataObject = fetchHandle(value);
result.write(dataObject.asFloat());
});
}
Aggregations