d517c62380
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: generic enum support (parser, lowering, codegen — both selfhost + bootstrap)
- enum Result<T,E> { Ok(T), Err(E) } parsing + monomorphization
- tag constant mangling in monomorphized function bodies
- data field access (l-value + r-value) for generated enum instances
- multiple concrete instances in same file
- HIR walker for enum reference mangling (selfhost + bootstrap)
- feat: stdlib Result<T,E> and Option<T> made truly generic
- breaking: explicit type args required (Result<int, String>)
- fix: 'is' operator — lowering to hBinary tag comparison + C backend fallback
- fix: Type_Eq structural comparison (inner types for pointer/slice/tuple)
- fix: hardcoded limit diagnostics (>8 params/variants/captures now emit errors)
- docs: Iter<T> safety warning for dangling pointer
- docs: IMPROVEMENTS.md — comprehensive plan and changelog
- test: generic_enum example added to EXAMPLES
All tests pass (0 FAIL). Selfhost loop deterministic.
68 lines
2.6 KiB
Plaintext
68 lines
2.6 KiB
Plaintext
// Stdlib golden: Map / Set / Result / Option helpers
|
|
import Std::Io::{PrintLine};
|
|
import Std::Map::{
|
|
Map, Map_New, Map_Set, Map_Get, Map_Has, Map_Remove, Map_Clear,
|
|
Map_Len, Map_IsEmpty, Map_Free
|
|
};
|
|
import Std::Set::{
|
|
Set, Set_New, Set_Add, Set_Has, Set_Remove, Set_Len, Set_IsEmpty, Set_Free
|
|
};
|
|
import Std::Result::{
|
|
Result, Result_NewOk, Result_NewErr, Result_IsOk, Result_IsErr,
|
|
Result_UnwrapOr, Result_Or, Result_UnwrapErr
|
|
};
|
|
import Std::Option::{
|
|
Option, Option_NewSome, Option_NewNone, Option_IsSome, Option_Or, Option_UnwrapOr
|
|
};
|
|
import Std::String::{String_Eq};
|
|
import Std::Test::{
|
|
Test_AssertTrue, Test_AssertFalse, Test_AssertEqInt, Test_Pass
|
|
};
|
|
|
|
func Main() -> int {
|
|
var m: Map<int, int> = Map_New<int, int>(16);
|
|
Map_Set<int, int>(&m, 1, 100);
|
|
Map_Set<int, int>(&m, 2, 200);
|
|
Map_Set<int, int>(&m, 3, 300);
|
|
Test_AssertEqInt(Map_Len<int, int>(&m) as int, 3);
|
|
Test_AssertTrue(Map_Has<int, int>(&m, 2));
|
|
Test_AssertTrue(Map_Remove<int, int>(&m, 2));
|
|
Test_AssertFalse(Map_Has<int, int>(&m, 2));
|
|
Test_AssertEqInt(Map_Get<int, int>(&m, 1), 100);
|
|
Test_AssertFalse(Map_Remove<int, int>(&m, 99));
|
|
Map_Clear<int, int>(&m);
|
|
Test_AssertTrue(Map_IsEmpty<int, int>(&m));
|
|
Map_Free<int, int>(&m);
|
|
|
|
var s: Set<int> = Set_New<int>(16);
|
|
Set_Add<int>(&s, 10);
|
|
Set_Add<int>(&s, 20);
|
|
Set_Add<int>(&s, 30);
|
|
Test_AssertTrue(Set_Remove<int>(&s, 20));
|
|
Test_AssertFalse(Set_Has<int>(&s, 20));
|
|
Test_AssertTrue(Set_Has<int>(&s, 10));
|
|
Test_AssertEqInt(Set_Len<int>(&s) as int, 2);
|
|
Test_AssertFalse(Set_IsEmpty<int>(&s));
|
|
Set_Free<int>(&s);
|
|
|
|
let ok: Result<int, String> = Result_NewOk<int, String>(42);
|
|
let err: Result<int, String> = Result_NewErr<int, String>("boom");
|
|
Test_AssertTrue(Result_IsOk<int, String>(ok));
|
|
Test_AssertTrue(Result_IsErr<int, String>(err));
|
|
Test_AssertEqInt(Result_UnwrapOr<int, String>(err, -1), -1);
|
|
let recovered: Result<int, String> = Result_Or<int, String>(err, Result_NewOk<int, String>(7));
|
|
Test_AssertEqInt(Result_UnwrapOr<int, String>(recovered, 0), 7);
|
|
Test_AssertTrue(String_Eq(Result_UnwrapErr<int, String>(err), "boom"));
|
|
|
|
let some: Option<int> = Option_NewSome<int>(5);
|
|
let none: Option<int> = Option_NewNone<int>();
|
|
Test_AssertTrue(Option_IsSome<int>(some));
|
|
Test_AssertEqInt(Option_UnwrapOr<int>(none, 9), 9);
|
|
let filled: Option<int> = Option_Or<int>(none, Option_NewSome<int>(3));
|
|
Test_AssertEqInt(Option_UnwrapOr<int>(filled, 0), 3);
|
|
|
|
PrintLine("stdlib_collections: ok");
|
|
Test_Pass("stdlib_collections");
|
|
return 0;
|
|
}
|