Files
sx/examples/0029-basic-scoping.sx
agra 12bf61a9fc std: restructure step 3 — ffi/ moves, build.sx, math dir spelling, fixtures
- objc.sx, objc_block.sx (from std/) + sdl3/opengl/raylib/stb/stb_truetype/
  wasm vendor bindings (from modules/ root) -> modules/ffi/
- std/uikit.sx deleted: platform/uikit.sx already declares UIApplicationMain
  and imports objc; '#framework "UIKit"' cannot live in a file imported on
  macOS targets (unconditional link directive, UIKit is iOS-only), so the
  three iOS-only examples carry the 3-line glue inline. 1607/1608/1616 also
  un-rotted (dead ns_string -> 'xx "..."' Into conversions, callconv(.c)
  msgSend fn-ptrs) — all three build for ios-sim/ios again.
- math/math.sx -> math/scalar.sx; one spelling '#import "modules/math"'
  everywhere (4 pinned IR snapshots regenerated: dir import adds Vec2/Mat4
  to the type tables).
- compiler.sx -> build.sx (imports, CLAUDE.md bundling table, specs.md).
- testpkg/ + test_c.sx -> tests/fixtures/ (resolve CWD-relative from repo
  root, same as vendors/).
- library-internal imports use full modules/... paths (std.sx tail,
  platform/bundle.sx, fixtures).
2026-06-11 08:37:22 +03:00

80 lines
1.7 KiB
Plaintext

#import "modules/std.sx";
#import "modules/math";
#import "modules/build.sx";
#import "modules/std/test.sx";
pkg :: #import "tests/fixtures/testpkg";
main :: () {
// ========================================================
// 6. SCOPING & DEFER
// ========================================================
print("=== 6. Scoping ===\n");
// Scope block with shadowing
sv := 100;
{
sv := 200;
print("inner: {}\n", sv);
}
print("outer: {}\n", sv);
// Shadow with different type
st_v := 42;
print("shadow-type: {}\n", st_v);
{
st_v := 3.14;
print("shadow-type: {}\n", st_v);
}
// Nested scopes (3 levels)
nv := 1;
{
nv := 2;
{
nv := 3;
print("nest3: {}\n", nv);
}
print("nest2: {}\n", nv);
}
print("nest1: {}\n", nv);
// Scope isolation
{ iso := 100; print("scope-isolate: {}\n", iso); }
// Reuse name after scope exit
sr := 1;
print("scope-reuse: {}\n", sr);
{ sr := 2; print("scope-reuse: {}\n", sr); }
print("scope-reuse: {}\n", sr);
// Multiple defers (LIFO order)
{
defer print("defer-c\n");
defer print("defer-b\n");
defer print("defer-a\n");
}
// Four defers
{
defer print("d1\n");
defer print("d2\n");
defer print("d3\n");
defer print("d4\n");
}
// Defer in nested scopes
{
defer print("outer-defer\n");
{
defer print("inner-defer\n");
}
}
// Defer in if block
if true {
defer print("defer-in-if: deferred\n");
print("defer-in-if: body\n");
}
}