fix(v1.0.2): Array grow from 0, Map/Set rehash, checked div/mod
ci / build (ubuntu) (push) Has been cancelled
ci / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled
ci / unit + fmt (push) Has been cancelled
ci / examples (push) Has been cancelled
ci / goldens + tools (push) Has been cancelled
ci / apps (push) Has been cancelled
ci / selfhost smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled

- Array_Push grows from cap 0 (same min as Insert) to avoid segfault
- Map/StringMap/Set: default min cap 8 and auto-rehash at ~50% load
- Integer / and % emit bux_div_i64 / bux_mod_i64 (panic instead of SIGFPE)
- Bump version to 1.0.2; stdlib golden regressions; fmt clean
This commit is contained in:
2026-07-29 00:03:22 +03:00
parent f21002d258
commit d8c21609fd
16 changed files with 296 additions and 37 deletions
+9
View File
@@ -256,6 +256,12 @@ proc emitExpr(be: var CBackend, node: HirNode): string =
of hBinary:
let left = be.emitExpr(node.binaryLeft)
let right = be.emitExpr(node.binaryRight)
# Checked integer / and % (float keeps raw C operators)
let isFloat = node.typ != nil and node.typ.kind in {tkFloat32, tkFloat64}
if node.binaryOp == tkSlash and not isFloat:
return &"bux_div_i64((int64_t)({left}), (int64_t)({right}))"
if node.binaryOp == tkPercent and not isFloat:
return &"bux_mod_i64((int64_t)({left}), (int64_t)({right}))"
let op = operatorToC(node.binaryOp)
return &"({left} {op} {right})"
@@ -658,6 +664,9 @@ proc emitModule*(be: var CBackend, module: HirModule): string =
be.emitLine("#include <stdbool.h>")
be.emitLine("#include <string.h>")
be.emitLine("")
be.emitLine("extern int64_t bux_div_i64(int64_t a, int64_t b);")
be.emitLine("extern int64_t bux_mod_i64(int64_t a, int64_t b);")
be.emitLine("")
# Pre-collect slice types so we can emit forward declarations early
let sliceTypes = collectSliceTypes(module)
+1 -1
View File
@@ -1350,7 +1350,7 @@ proc cmdDoc*(args: seq[string], opts: GlobalOptions): int =
return 0
proc cmdVersion*(args: seq[string], opts: GlobalOptions): int =
echo "bux 1.0.0 (bootstrap)"
echo "bux 1.0.2 (bootstrap)"
return 0
proc runCli*(args: seq[string]): int =
+10 -3
View File
@@ -106,14 +106,17 @@ proc emitInstr(be: var LirCBackend, instr: LirInstr) =
be.emitLine(&"{v(instr.dst)} = {v(instr.src)};")
# ── Arithmetic ──
of lirAdd, lirSub, lirMul, lirDiv, lirMod,
of lirDiv:
# Checked integer division (runtime panics on divisor 0 instead of SIGFPE).
be.emitLine(&"{v(instr.dst)} = bux_div_i64((int64_t)({v(instr.src)}), (int64_t)({v(instr.src2)}));")
of lirMod:
be.emitLine(&"{v(instr.dst)} = bux_mod_i64((int64_t)({v(instr.src)}), (int64_t)({v(instr.src2)}));")
of lirAdd, lirSub, lirMul,
lirAnd, lirOr, lirXor, lirShl, lirShr:
let op = case instr.kind
of lirAdd: "+"
of lirSub: "-"
of lirMul: "*"
of lirDiv: "/"
of lirMod: "%"
of lirAnd: "&"
of lirOr: "|"
of lirXor: "^"
@@ -629,6 +632,10 @@ proc emitModule*(be: var LirCBackend, builder: LirBuilder, module: HirModule): s
be.emitLine("#include <stdbool.h>")
be.emitLine("#include <string.h>")
be.emitLine("")
# Checked integer div/mod (rt/runtime*.c) — always available
be.emitLine("extern int64_t bux_div_i64(int64_t a, int64_t b);")
be.emitLine("extern int64_t bux_mod_i64(int64_t a, int64_t b);")
be.emitLine("")
# Forward struct declarations
for s in module.structs: