Files
bux-lang/examples/c_precedence.bux
T
dimgigov fe3b1e8b6a
ci / build (ubuntu) (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 / macos smoke (push) Has been cancelled
ci / windows smoke (push) Has been cancelled
ci / CI gate (push) Has been cancelled
selfhost-loop / bootstrap determinism (push) Has been cancelled
feat: macros (multi-rep, hygiene), Drop field-move, lean multi-OS CI
Sessions 56–69: declarative macro! with rep/zip/literal/block and
unhygienic var $name binders; partial field-move skip Drop; @[Release]
polish; LSP type hierarchy; CI Nim cache + lean macOS + Windows smoke.
2026-07-20 17:19:46 +03:00

54 lines
1.3 KiB
Plaintext

// C precedence safety: Bux AST must survive C codegen without rewrite.
// Mul(Add(a,b), c) must stay (a+b)*c, not a+b*c.
import Std::Io::{PrintLine};
import Std::String::{String_FromInt};
func MulSum(a: int, b: int, c: int) -> int {
// AST: (a+b)*c → 9 for (1,2,3); wrong C emit gives 1+2*3=7
return (a + b) * c;
}
func SubDiv(a: int, b: int, c: int) -> int {
// AST: (a-b)/c → 3 for (10,4,2); wrong C emit gives 10-4/2=8
return (a - b) / c;
}
func ShiftSum(a: int, b: int) -> int {
// (a+b)<<1 → 6 for (1,2)
return (a + b) << 1;
}
func Mix(a: int, b: int, c: int, d: int) -> int {
// ((a+b)*c)-d → 7 for (1,2,3,2)
return (a + b) * c - d;
}
func Main() -> int {
let m: int = MulSum(1, 2, 3);
let s: int = SubDiv(10, 4, 2);
let sh: int = ShiftSum(1, 2);
let x: int = Mix(1, 2, 3, 2);
PrintLine(String_FromInt(m));
PrintLine(String_FromInt(s));
PrintLine(String_FromInt(sh));
PrintLine(String_FromInt(x));
if m != 9 {
PrintLine("FAIL MulSum");
return 1;
}
if s != 3 {
PrintLine("FAIL SubDiv");
return 1;
}
if sh != 6 {
PrintLine("FAIL ShiftSum");
return 1;
}
if x != 7 {
PrintLine("FAIL Mix");
return 1;
}
PrintLine("PASS c_precedence");
return 0;
}