native_drive_compile.sleela
impl/tests/native_drive/native_drive_compile.sleela · 37 line(s) · sleela
#sleela 3.0
class Callback {
static int receive(int value) { return value + 1; }
}
class NativeDriveCompile {
// Bytecode fallback for nativeCall(module, "fallback", 7): the plugin
// exports no "fallback", so the VM must run this method (7 * 3 = 21).
static int fallback(int value) {
return value * 3;
}
static int check() {
int module = nativeOpen("@NATIVE_PLUGIN_PATH@");
int nativeResult = nativeCall(module, "twice", 21);
int fallbackResult = nativeCall(module, "fallback", 7);
int callbackResult = nativeCall(module, "call_sleela", 41);
String sample = "Aé😀Z";
int utf16Length = nativeCall(module, "utf16_length", sample);
int unitA = nativeCall(module, "utf16_char_at", sample, 0);
int unitEAcute = nativeCall(module, "utf16_char_at", sample, 1);
int highSurrogate = nativeCall(module, "utf16_char_at", sample, 2);
int lowSurrogate = nativeCall(module, "utf16_char_at", sample, 3);
int unitZ = nativeCall(module, "utf16_char_at", sample, 4);
nativeClose(module);
if (utf16Length != 5 || unitA != 0x0041 || unitEAcute != 0x00e9 ||
highSurrogate != 0xd83d || lowSurrogate != 0xde00 || unitZ != 0x005a)
return -1;
return nativeResult + fallbackResult + callbackResult;
}
// Syntax 3.0 requires void main; the smoke harness selects check() as
// its entry with slvm_find_func() so it can assert the returned value.
static void main() {
int result = check();
}
}