test: split 50-smoke.sx into per-section examples + add errors smoke
Break the monolithic examples/50-smoke.sx into 30 focused per-section examples,
filed into their category blocks (basic/types/comptime/memory/protocols/ffi),
each carrying only the top-level decls its section references (the protocols
section keeps the full preamble — its deps flow through UFCS method calls that
name-based extraction can't see). Outputs verified identical to the original
section blocks.
Add examples/1036-errors-failable-smoke.sx — an end-to-end error-handling example
(the E5.4 work): named + inferred error sets consumed via destructure, try (in
helpers), catch (bare-expr / match-body / diverging / no-binding), or
value-terminator, onfail+defer interleave, and error.X value + {} tag
interpolation.
Remove examples/50-smoke.sx. Suite: 324 passed, 0 failed.
This commit is contained in:
83
examples/0608-comptime-comptime.sx
Normal file
83
examples/0608-comptime-comptime.sx
Normal file
@@ -0,0 +1,83 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/math/math.sx";
|
||||
#import "modules/compiler.sx";
|
||||
#import "modules/test.sx";
|
||||
pkg :: #import "modules/testpkg";
|
||||
|
||||
add :: (a: s32, b: s32) -> s32 { a + b; }
|
||||
|
||||
mul :: (a: s32, b: s32) -> s32 { a * b; }
|
||||
|
||||
// #run compile-time constants
|
||||
CT_VAL :: #run add(10, 15);
|
||||
|
||||
CT_MUL :: #run mul(6, 7);
|
||||
|
||||
CT_CHAIN :: #run add(CT_VAL, 5);
|
||||
|
||||
// #run compile-time optional tests
|
||||
|
||||
// #run compile-time optional tests
|
||||
ct_opt_coalesce :: () -> s32 {
|
||||
x: ?s32 = 42;
|
||||
y: ?s32 = null;
|
||||
return (x ?? 0) + (y ?? 99);
|
||||
}
|
||||
|
||||
ct_opt_unwrap :: () -> s32 {
|
||||
x: ?s32 = 77;
|
||||
return x!;
|
||||
}
|
||||
|
||||
ct_opt_guard :: () -> s32 {
|
||||
x: ?s32 = 10;
|
||||
if x == null { return -1; }
|
||||
return x;
|
||||
}
|
||||
|
||||
CT_OPT_COALESCE :: #run ct_opt_coalesce();
|
||||
|
||||
CT_OPT_UNWRAP :: #run ct_opt_unwrap();
|
||||
|
||||
CT_OPT_GUARD :: #run ct_opt_guard();
|
||||
|
||||
// #insert helpers
|
||||
|
||||
// #insert helpers
|
||||
gen_code :: () -> string {
|
||||
return "print(\"insert-ok\\n\");";
|
||||
}
|
||||
|
||||
gen_val :: () -> string {
|
||||
return "print(\"insert-gen: {}\\n\", 42);";
|
||||
}
|
||||
|
||||
// --- Error handling (failable functions: sets, raise/try/catch/or/onfail) ---
|
||||
|
||||
main :: () {
|
||||
|
||||
// ========================================================
|
||||
// 8. COMPILE-TIME
|
||||
// ========================================================
|
||||
print("=== 8. Comptime ===\n");
|
||||
|
||||
// #run constant
|
||||
print("run-const: {}\n", CT_VAL);
|
||||
|
||||
// #run with expression
|
||||
print("run-expr: {}\n", CT_MUL);
|
||||
|
||||
// #run chained dependency
|
||||
print("run-chain: {}\n", CT_CHAIN);
|
||||
|
||||
// #run comptime optionals
|
||||
print("ct-opt-coalesce: {}\n", CT_OPT_COALESCE); // ct-opt-coalesce: 141
|
||||
print("ct-opt-unwrap: {}\n", CT_OPT_UNWRAP); // ct-opt-unwrap: 77
|
||||
print("ct-opt-guard: {}\n", CT_OPT_GUARD); // ct-opt-guard: 10
|
||||
|
||||
// #insert with function
|
||||
#insert gen_code();
|
||||
|
||||
// #insert additional
|
||||
#insert gen_val();
|
||||
}
|
||||
Reference in New Issue
Block a user