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.
61 lines
2.6 KiB
Plaintext
61 lines
2.6 KiB
Plaintext
// Map_Remove / Map_Clear / Set_Remove
|
|
import Std::Io::{PrintLine, PrintInt};
|
|
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::Test::{Test_AssertTrue, Test_AssertFalse, Test_AssertEqInt, Test_Pass};
|
|
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};
|
|
|
|
func Main() -> int {
|
|
// --- Map ---
|
|
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_Len<int, int>(&m) as int, 2);
|
|
Test_AssertEqInt(Map_Get<int, int>(&m, 1), 100);
|
|
Test_AssertEqInt(Map_Get<int, int>(&m, 3), 300);
|
|
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);
|
|
|
|
// --- Set ---
|
|
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);
|
|
|
|
// --- Result helpers ---
|
|
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"));
|
|
|
|
// --- Option helpers ---
|
|
let some: Option<int> = Option_NewSome<int>(5);
|
|
let none: Option<int> = Option_NewNone<int>();
|
|
Test_AssertTrue(Option_IsSome<int>(some));
|
|
let o2: Option<int> = Option_Or<int>(none, some);
|
|
Test_AssertEqInt(Option_UnwrapOr<int>(o2, 0), 5);
|
|
|
|
PrintLine("map_remove: ok");
|
|
Test_Pass("map_remove + result helpers");
|
|
return 0;
|
|
}
|