7ee6a73ea4
Add standard library modules: - Std::String: strlen, strcmp, concat, copy, starts_with wrappers - Std::Map: linear-probing hash map with String keys, int values Add error handling: - Result and Option algebraic enum examples - ? try operator for automatic error propagation in HIR lowering Compiler bugfixes: - Fix sizeof() for user-defined structs (new hSizeOf HIR node) - Fix HIR type lowering for char8, bool8, int8, uint8, etc. - Fix let statement lowering for pointer types (*char8 → int* bug) - Fix PrintInt ABI mismatch (int64_t → int in io.c) - Fix Makefile test bug (_test_tmp_pkg already exists) Documentation: - Rewrite README.md with features, examples, project structure - Add docs/LanguageRef.md — complete language reference - Add docs/Stdlib.md — standard library documentation - Add docs/BuildAndTest.md — build and test guide New examples: strings, map, result_option, try_operator (13 total)
45 lines
973 B
Plaintext
45 lines
973 B
Plaintext
// Map - Hash map with String keys and int values
|
|
import Std::Io::{PrintLine, PrintInt};
|
|
import Std::Map::{Map, Map_New, Map_Set, Map_Get, Map_Has, Map_Len};
|
|
|
|
func Main() -> int {
|
|
let m: Map = Map_New(16);
|
|
|
|
PrintLine("Map operations:");
|
|
|
|
Map_Set(&m, "one", 1);
|
|
Map_Set(&m, "two", 2);
|
|
Map_Set(&m, "three", 3);
|
|
|
|
PrintLine("Length:");
|
|
PrintInt(Map_Len(&m));
|
|
PrintLine("");
|
|
|
|
PrintLine("Get 'one':");
|
|
PrintInt(Map_Get(&m, "one"));
|
|
PrintLine("");
|
|
|
|
PrintLine("Get 'two':");
|
|
PrintInt(Map_Get(&m, "two"));
|
|
PrintLine("");
|
|
|
|
PrintLine("Get 'three':");
|
|
PrintInt(Map_Get(&m, "three"));
|
|
PrintLine("");
|
|
|
|
Map_Set(&m, "two", 22);
|
|
PrintLine("Updated 'two':");
|
|
PrintInt(Map_Get(&m, "two"));
|
|
PrintLine("");
|
|
|
|
if Map_Has(&m, "one") {
|
|
PrintLine("Has 'one': yes");
|
|
}
|
|
|
|
if !Map_Has(&m, "four") {
|
|
PrintLine("Has 'four': no");
|
|
}
|
|
|
|
return 0;
|
|
}
|