add test code to NativeBindings.java

This commit is contained in:
2026-05-25 22:41:17 -03:00
parent ad9176d909
commit 560cce77e8
2 changed files with 48 additions and 3 deletions

View File

@@ -1,19 +1,63 @@
package org.neoflock.NeoNucleus;
import java.util.UUID;
public class NativeBindings {
static {
System.loadLibrary("neonucleusjni");
}
public static void main(String[] args) {
//nn_Context ctx = nn_initContext();
nn_EEPROM eeprom = new nn_EEPROM(100, 200, 300, 400, 0, 0, 0, 0);
/*nn_EEPROM eeprom = new nn_EEPROM(100, 200, 300, 400, 0, 0, 0, 0);
eeprom.allocate();
System.out.println("we live");
eeprom.free();
System.out.println("about to double free");
eeprom.free();
eeprom.free();*/
nn_Context ctx = nn_initContext();
nn_initPalettes();
nn_Universe universe = nn_createUniverse(ctx);
nn_Architecture arch = getLuaArch();
nn_EEPROM eeprom = new nn_EEPROM(2048, 2048, 1, 1, 1, 1, 1, 1);
nn_Component eepromCard = ncl_createEEPROM(universe, UUID.randomUUID().toString(), eeprom, "error('amog us')", false);
nn_Computer computer = nn_createComputer(universe, UUID.randomUUID().toString(), 4096, 100, 100);
nn_setCallBudget(computer, 0);
nn_setArchitecture(computer, arch);
nn_addSupportedArchitecture(computer, arch);
nn_Exit e = nn_tick(computer);
if (e != nn_Exit.NN_OK) {
System.out.println("NN tick error: " + nn_getError(computer));
return;
}
e = nn_tickSynchronized(computer);
if (e != nn_Exit.NN_OK) {
System.out.println("NN synchronized tick error: " + nn_getError(computer));
return;
}
nn_ComputerState state = nn_getComputerState(computer);
/*if(state == nn_Exit.NN_POWEROFF) break;
if(state == nn_Exit.NN_CRASHED) {
System.out.println("error: %s\n", nn_getError(c));
return;
}
if(state == nn_Exit.NN_CHARCH) {
System.out.println("new arch: %s\n", nn_getDesiredArchitecture(c).name);
return;
}
if(state == nn_Exit.NN_BLACKOUT) {
System.out.println("out of energy\n");
goto cleanup;
}
if(state == nn_Exit.NN_RESTART) {
System.out.println("restart requested\n");
nn_stopComputer(computer);
//ncl_resetScreen(nn_getComponentState(screen));
nn_addIdleTime(computer, 1);
continue;
}*/
//System.out.println(ctx.ptr);
}
public static native nn_Architecture getLuaArch();
public static native nn_Context nn_initContext();
public static native void nn_initPalettes();
// nn_Universe *nn_createUniverse(nn_Context *ctx, void *userdata)

View File

@@ -2,6 +2,7 @@
#include <iostream>
#include "neonucleus.h"
#include "ncomplib.h"
#include <jni.h>
#include "carbon.hpp"
@@ -161,7 +162,7 @@ JNIEXPORT jobject JNICALL Java_org_neoflock_NeoNucleus_NativeBindings_nn_1create
(JNIEnv * env, jclass, jobject universe, jstring address, jlong totalMemory, jlong maxComponents, jlong maxDevices) {
nn_Universe* nnUni = (nn_Universe*) Carbon::PointerBacked::GetPointer(env, universe);
NULLPTR_CHECK(nnUni, nn_Universe);
const char * addr = env->GetStringUTFChars(address, NULL);
// TODO: computer jni userdata lol
nn_Computer* computer = nn_createComputer(nnUni, NULL, addr, totalMemory, maxComponents, maxDevices);