fixed all the optimizer bugs

This commit is contained in:
IonutParau 2025-07-12 11:27:59 +02:00
parent faa67f417d
commit 1bf8604433
3 changed files with 26 additions and 15 deletions

View File

@ -14,6 +14,10 @@ fn addEngineSources(b: *std.Build, opts: LibBuildOpts) *std.Build.Module {
.target = opts.target,
.optimize = opts.optimize,
.single_threaded = true,
.sanitize_c = true,
.valgrind = true,
.stack_check = true,
.stack_protector = true,
});
dataMod.addCSourceFiles(.{
@ -62,10 +66,17 @@ const LuaVersion = enum {
// For the test architecture, we specify the target Lua version we so desire.
// This can be checked for with Lua's _VERSION
fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVersion) !void {
fn compileTheRightLua(b: *std.Build, target: std.Build.ResolvedTarget, version: LuaVersion) !*std.Build.Step.Compile {
const alloc = b.allocator;
const dirName = @tagName(version);
const c = b.addObject(.{
.name = "lua",
.link_libc = true,
.optimize = .ReleaseSafe,
.target = target,
});
const rootPath = try std.mem.join(alloc, std.fs.path.sep_str, &.{ "foreign", dirName });
c.addIncludePath(b.path(rootPath));
@ -90,13 +101,8 @@ fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVer
.root = b.path(rootPath),
.files = files.items,
});
}
fn getSharedEngineName(os: std.Target.Os.Tag) []const u8 {
if (os == .windows) {
return "neonucleusdll";
} else {
return "neonucleus";
}
return c;
}
pub fn build(b: *std.Build) void {
@ -125,7 +131,7 @@ pub fn build(b: *std.Build) void {
});
const engineShared = b.addSharedLibrary(.{
.name = getSharedEngineName(os),
.name = if(os == .windows) "neonucleusdll" else "neonucleus",
.root_module = engineMod,
});
@ -167,9 +173,10 @@ pub fn build(b: *std.Build) void {
if(opts.bit32) "-DNN_BIT32" else "",
},
});
compileTheRightLua(b, emulator, luaVer) catch unreachable;
const l = compileTheRightLua(b, target, luaVer) catch unreachable;
// forces us to link in everything too
emulator.addObject(l);
emulator.linkLibrary(engineStatic);
const emulatorStep = b.step("emulator", "Builds the emulator");

View File

@ -164,9 +164,9 @@ void nni_gpu_get(nni_gpu *gpu, void *_, nn_component *component, nn_computer *co
nn_unicode_codepointToChar(chr, pxl.codepoint, &l);
// TODO: gosh darn palettes
nn_return(computer, nn_values_cstring(chr));
nn_return(computer, nn_values_integer(pxl.fg));
nn_return(computer, nn_values_integer(pxl.bg));
nn_return_string(computer, chr, l);
nn_return_integer(computer, pxl.fg);
nn_return_integer(computer, pxl.bg);
}
void nni_gpu_getScreen(nni_gpu *gpu, void *_, nn_component *component, nn_computer *computer) {

View File

@ -673,7 +673,11 @@ testLuaArch *testLuaArch_setup(nn_computer *computer, void *_) {
lua_setfield(L, LUA_REGISTRYINDEX, "archPtr");
s->L = L;
testLuaArch_loadEnv(L);
assert(luaL_loadbufferx(L, testLuaSandbox, strlen(testLuaSandbox), "=machine.lua", "t") == LUA_OK);
if(luaL_loadbufferx(L, testLuaSandbox, strlen(testLuaSandbox), "=machine.lua", "t") != LUA_OK) {
lua_close(L);
nn_dealloc(alloc, s, sizeof(testLuaArch));
return NULL;
}
return s;
}
@ -703,7 +707,7 @@ void testLuaArch_tick(nn_computer *computer, testLuaArch *arch, void *_) {
} else {
const char *s = lua_tostring(arch->L, -1);
nn_setError(computer, s);
lua_pop(arch->L, 1);
lua_pop(arch->L, ret);
}
}