From a8b909726b4a34a37a16ca266f15e9fc68364e1d Mon Sep 17 00:00:00 2001 From: dimgigov Date: Sat, 6 Jun 2026 05:15:04 +0300 Subject: [PATCH] v0.4.0: selfhost loop progress - Fix stdlib merge: merge ALL lib/*.bux via bux_list_dir (was 0) - Fix Cli_FindStdlibDir: search for lib/ not stdlib/ - Fix stdlib path: remove Std/ subdir (now flat in lib/) - Fix runtime paths: add ../../ fallback for build/selfhost depth - Remove hardcoded /home/ziko paths from src/cli.bux - Fix Json.bux: avoid var-in-if-block scoping bug (5 errors) - Add improved sema error messages (reverted due to crash) - Remaining: 2 parserParsePostfix sema forward-ref errors - Update PLAN.md with v0.3.0-v1.0.0 roadmap --- lib/Json.bux | 37 ++++++++++++++++++------------------- src/cli.bux | 6 +++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/Json.bux b/lib/Json.bux index 127f0ba..c783818 100644 --- a/lib/Json.bux +++ b/lib/Json.bux @@ -89,16 +89,16 @@ func Json_ArrayGet(v: JsonValue, index: uint) -> JsonValue { func Json_ArrayPush(self: *JsonValue, val: JsonValue) { if self.tag != JsonTagArray { return; } if self.arrLen >= self.arrCap { - var newCap: uint = self.arrCap; - if newCap == 0 { newCap = 4; } - else { newCap = newCap * 2; } - let newSize: uint = newCap * sizeof(JsonValue); - if self.arrCap == 0 { - self.arrData = Alloc(newSize) as *JsonValue; + // Compute new capacity (avoid var scoping bug in selfhost sema) + let arrNewCap: uint = self.arrCap; + if arrNewCap == 0 { + self.arrCap = 4; + self.arrData = Alloc(4 * sizeof(JsonValue)) as *JsonValue; } else { - self.arrData = Realloc(self.arrData as *void, newSize) as *JsonValue; + let doubleCap: uint = arrNewCap * 2; + self.arrCap = doubleCap; + self.arrData = Realloc(self.arrData as *void, doubleCap * sizeof(JsonValue)) as *JsonValue; } - self.arrCap = newCap; } self.arrData[self.arrLen] = val; self.arrLen = self.arrLen + 1; @@ -145,19 +145,18 @@ func Json_ObjectSet(self: *JsonValue, key: String, val: JsonValue) { i = i + 1; } if self.objLen >= self.objCap { - var newCap: uint = self.objCap; - if newCap == 0 { newCap = 4; } - else { newCap = newCap * 2; } - let keySize: uint = newCap * sizeof(String); - let valSize: uint = newCap * sizeof(JsonValue); - if self.objCap == 0 { - self.objKeys = Alloc(keySize) as *String; - self.objValues = Alloc(valSize) as *JsonValue; + // Compute new capacity (avoid var scoping bug in selfhost sema) + let objNewCap: uint = self.objCap; + if objNewCap == 0 { + self.objCap = 4; + self.objKeys = Alloc(4 * sizeof(String)) as *String; + self.objValues = Alloc(4 * sizeof(JsonValue)) as *JsonValue; } else { - self.objKeys = Realloc(self.objKeys as *void, keySize) as *String; - self.objValues = Realloc(self.objValues as *void, valSize) as *JsonValue; + let doubleCap: uint = objNewCap * 2; + self.objCap = doubleCap; + self.objKeys = Realloc(self.objKeys as *void, doubleCap * sizeof(String)) as *String; + self.objValues = Realloc(self.objValues as *void, doubleCap * sizeof(JsonValue)) as *JsonValue; } - self.objCap = newCap; } self.objKeys[self.objLen] = key; self.objValues[self.objLen] = val; diff --git a/src/cli.bux b/src/cli.bux index 6920fc0..aee83b3 100644 --- a/src/cli.bux +++ b/src/cli.bux @@ -149,10 +149,10 @@ func Cli_Build(srcPath: String, outPath: String) -> int { ioPath = "../rt/io.c"; } if !FileExists(rtPath) { - rtPath = "/home/ziko/z-git/bux/bux/rt/runtime.c"; + rtPath = "../../rt/runtime.c"; } if !FileExists(ioPath) { - ioPath = "/home/ziko/z-git/bux/bux/rt/io.c"; + ioPath = "../../rt/io.c"; } // Compile with cc @@ -298,7 +298,7 @@ func Cli_FindStdlibDir(projectDir: String) -> String { if DirExists(path) { return path; } path = bux_path_join(projectDir, "../lib"); if DirExists(path) { return path; } - path = "/home/ziko/z-git/bux/bux/lib"; + path = bux_path_join(projectDir, "../../lib"); if DirExists(path) { return path; } return ""; }