feat: macros (multi-rep, hygiene), Drop field-move, lean multi-OS CI
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

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.
This commit is contained in:
2026-07-20 17:19:46 +03:00
parent 6f2a3b1d88
commit fe3b1e8b6a
41 changed files with 5281 additions and 141 deletions
+78
View File
@@ -0,0 +1,78 @@
// Session 63 — multi-rep patterns, compound/zipped rep, nested template $(…)*
import Std::Io::{PrintLine};
import Std::String::{String_FromInt};
// Compound rep: $( $a:expr , $b:expr ),* → parallel lists, zip in template
macro! add_pairs {
( $($a:expr, $b:expr),* ) => {
var __acc: int = 0;
$( __acc = __acc + ($a + $b); )*
__acc
}
}
// Multi-rep groups separated by `;` in the call
// sum_n!(1,2; 10,20,30) → sum first group + sum second group
macro! sum_groups {
( $($x:expr),* ; $($y:expr),* ) => {
var __s: int = 0;
$( __s = __s + $x; )*
$( __s = __s + $y; )*
__s
}
}
// Nested template: outer over $x, inner body uses current $x once
// (same-list nested MacroRep expands once when bound as single)
macro! double_each_sum {
( $($x:expr),* ) => {
var __t: int = 0;
$(
$( __t = __t + $x; )*
$( __t = __t + $x; )*
)*
__t
}
}
// Prefix fixed + trailing rep still works
macro! named_sum {
( $label:ident, $($n:expr),* ) => {
var __u: int = 0;
$( __u = __u + $n; )*
__u
}
}
func Main() -> int {
let p: int = add_pairs!(1, 10, 2, 20);
// (1+10)+(2+20) = 33
let g: int = sum_groups!(1, 2; 10, 20, 30);
// 1+2+10+20+30 = 63
let d: int = double_each_sum!(3, 4);
// (3+3)+(4+4) = 14
let n: int = named_sum!(ignored, 5, 6, 7);
// 18
PrintLine(String_FromInt(p));
PrintLine(String_FromInt(g));
PrintLine(String_FromInt(d));
PrintLine(String_FromInt(n));
if p != 33 {
PrintLine("FAIL add_pairs");
return 1;
}
if g != 63 {
PrintLine("FAIL sum_groups");
return 1;
}
if d != 14 {
PrintLine("FAIL double_each_sum");
return 1;
}
if n != 18 {
PrintLine("FAIL named_sum");
return 1;
}
PrintLine("PASS macro_nested");
return 0;
}