From 1bf86044338dc38a332dbeaa8d64ba46e24e7e05 Mon Sep 17 00:00:00 2001 From: IonutParau Date: Sat, 12 Jul 2025 11:27:59 +0200 Subject: [PATCH] fixed all the optimizer bugs --- build.zig | 27 +++++++++++++++++---------- src/components/gpu.c | 6 +++--- src/testLuaArch.c | 8 ++++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/build.zig b/build.zig index 1013a0c..303d58d 100644 --- a/build.zig +++ b/build.zig @@ -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"); diff --git a/src/components/gpu.c b/src/components/gpu.c index 5cf1296..abf0f89 100644 --- a/src/components/gpu.c +++ b/src/components/gpu.c @@ -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) { diff --git a/src/testLuaArch.c b/src/testLuaArch.c index adedc62..667058b 100644 --- a/src/testLuaArch.c +++ b/src/testLuaArch.c @@ -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); } }