diff --git a/src/app/host_services.zi b/src/app/host_services.zi index 4f5a7b947..f646c71e5 100644 --- a/src/app/host_services.zi +++ b/src/app/host_services.zi @@ -1,4 +1,5 @@ // App process services, with typed native calls at the operating system boundary. +#import, file "text_buffers.zi"; #import "byte_text_linux" #import "c_string" @@ -68,16 +69,10 @@ HostAppendLocale :: (value: *u8, used: s32) -> s32 { return at } +// C callers of the app's bounded text helper. #program_export app_text_from_cstring :: (data: *u8, capacity: s32) -> string { - if data == null || capacity <= 0 { - return "" - } - length: s32 = 0 - while length < capacity && data[length] != cast(u8)0 { - length += 1 - } - return TextFromBytes(BytesFromPointer(data, cast(u64)length)) + return AppTextFromCString(data, capacity) } #program_export diff --git a/src/app/text_buffers.zi b/src/app/text_buffers.zi index 8a424fea7..f4e59c968 100644 --- a/src/app/text_buffers.zi +++ b/src/app/text_buffers.zi @@ -1,3 +1,4 @@ +#import "byte_text_linux" c :: #system_library "c"; FrameTextCapacity :: 16384 @@ -7,9 +8,6 @@ FrameTextStore :: struct { used: s32 } -// Borrow text from an app-owned, bounded NUL-terminated buffer. The caller -// keeps the buffer alive while the returned string is in use. -app_text_from_cstring_host :: (data: *u8, capacity: s32) -> string #foreign c "app_text_from_cstring"; app_append_text_host :: (dst: *u8, dst_size: s64, src: string) #foreign c "app_append_text"; // C ABI callers still share these bounded text operations during the Ziran @@ -54,12 +52,18 @@ AppendTextToBuffer :: (dst: *u8, dst_size: s64, src: string) { dst[index] = cast(u8)0 } +// Borrow text from an app-owned, bounded NUL-terminated buffer. The caller +// keeps the buffer alive while the returned string is in use. #program_export AppTextFromCString :: (data: *u8, capacity: s32) -> string { if data == null || capacity <= 0 { return "" } - return app_text_from_cstring_host(data, capacity) + length: s32 = 0 + while length < capacity && data[length] != cast(u8)0 { + length += 1 + } + return TextFromBytes(BytesFromPointer(data, cast(u64)length)) } // Copy borrowed text into caller-owned, NUL-terminated byte storage. diff --git a/tests/device_policy_behavior.zi b/tests/device_policy_behavior.zi index e1d033dce..3bf2ffb31 100644 --- a/tests/device_policy_behavior.zi +++ b/tests/device_policy_behavior.zi @@ -1,6 +1,11 @@ #import, file "../src/app/device_policy.zi"; #import, file "../src/app/app_types.zi"; +using AppOrientationMode; + +using AppThemeMode; +using AppThemeSource; + #program_export Answer :: () -> s32 { if ThemeModeForSource(cast(AppThemeMode)APP_THEME_DARK, diff --git a/tests/device_policy_zi_test.sh b/tests/device_policy_zi_test.sh index d536b79a3..ddddb94bc 100644 --- a/tests/device_policy_zi_test.sh +++ b/tests/device_policy_zi_test.sh @@ -9,14 +9,17 @@ source=$root/tests/device_policy_behavior.zi mkdir -p "$work/ir" "$work/c" "$bin/zi2zir" --root "$root/tests" --module-path "$root/src" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$work/ir" "$source" "$bin/zi2zib" bundle --root "$root/tests" \ --module-path "$root/src" --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ --entry device_policy_behavior:Answer \ -o "$work/source.zib" "$source" "$bin/zi2zib" bundle --root "$work/ir" --module-path "$work/ir" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ --entry device_policy_behavior:Answer \ -o "$work/saved.zib" "$work/ir/device_policy_behavior.zir" [ "$(env -u DISPLAY -u WAYLAND_DISPLAY "$bin/zi2zib" run "$work/source.zib")" = 42 ] @@ -25,9 +28,21 @@ cmp "$work/source.zib" "$work/saved.zib" "$bin/zi2c" --no-main --root "$root/tests" \ --module-path "$root/src" --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$work/c" "$source" cat > "$work/c/main.c" <<'C' #include "device_policy_behavior.h" +/* Device policy reaches text measurement; fixed-width glyphs suffice. */ +int32_t MeasureGlyphWidth(String value, int32_t font, String typeface) +{ + (void)typeface; + return (int32_t)(value.length * (size_t)font / 2); +} +int32_t MeasureGlyphLineHeight(int32_t font, String typeface) +{ + (void)typeface; + return font; +} int main(void) { return Answer() == 42 ? 0 : 1; } C "${CC:-cc}" -std=c11 -DZIRAN_BOUNDS_CHECK \ diff --git a/tests/exercise_types_behavior.zi b/tests/exercise_types_behavior.zi index cf4651caa..45c690e98 100644 --- a/tests/exercise_types_behavior.zi +++ b/tests/exercise_types_behavior.zi @@ -1,5 +1,7 @@ #import, file "../src/app/exercise_types.zi"; +using ExerciseType; + #program_export Answer :: () -> s32 { if EXERCISE_WIM_HOF != 0 || EXERCISE_MEDITATION != 1 || diff --git a/tests/habit_calendar_zi_test.sh b/tests/habit_calendar_zi_test.sh index 368c0edd8..cde87f13d 100644 --- a/tests/habit_calendar_zi_test.sh +++ b/tests/habit_calendar_zi_test.sh @@ -10,9 +10,9 @@ trap 'rm -rf "$work"' EXIT HUP INT TERM source=$root/tests/habit_calendar_behavior.zi "$bin/zi2zir" --root "$root/tests" --module-path "$root/src" \ - --module-path "$ui" -o "$work/ir" "$source" + --module-path "$ui" --module-path "$root/build/packages/ziran/std" -o "$work/ir" "$source" "$bin/zi2zib" bundle --root "$root/tests" --module-path "$root/src" \ - --module-path "$ui" --entry habit_calendar_behavior:CalendarAnswer \ + --module-path "$ui" --module-path "$root/build/packages/ziran/std" --entry habit_calendar_behavior:CalendarAnswer \ -o "$work/source.zib" "$source" "$bin/zi2zib" bundle --root "$work/ir" \ --entry habit_calendar_behavior:CalendarAnswer \ @@ -22,7 +22,7 @@ test "$("$bin/zi2zib" run "$work/source.zib")" = 42 test "$("$bin/zi2zib" run "$work/saved.zib")" = 42 "$bin/zi2c" --no-main --root "$root/tests" --module-path "$root/src" \ - --module-path "$ui" -o "$work/c" "$source" + --module-path "$ui" --module-path "$root/build/packages/ziran/std" -o "$work/c" "$source" cat > "$work/c/main.c" <<'C' #include "habit_calendar_behavior.h" int main(void) { return Answer() == 42 && CalendarAnswer() == 42 ? 0 : 1; } diff --git a/tests/metrics_zi_test.sh b/tests/metrics_zi_test.sh index efc980ef0..e6e1311a8 100644 --- a/tests/metrics_zi_test.sh +++ b/tests/metrics_zi_test.sh @@ -6,7 +6,8 @@ bin=${1:-"$root/build/ziran-toolchain/bin"} work=$root/build/metrics-zi-test mkdir -p "$work/c" "$bin/zi2c" --no-main --root "$root/tests" --module-path "$root/src" \ - --module-path "$root/build/packages/kryon/src/ui" -o "$work/c" \ + --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" -o "$work/c" \ "$root/tests/metrics_link_behavior.zi" "${CC:-cc}" -std=c11 -DZIRAN_BOUNDS_CHECK -ffunction-sections \ -fdata-sections -Wl,--gc-sections \ diff --git a/tests/navigation_routes_zi_test.sh b/tests/navigation_routes_zi_test.sh index b79b78fd3..4e9f18dff 100644 --- a/tests/navigation_routes_zi_test.sh +++ b/tests/navigation_routes_zi_test.sh @@ -10,6 +10,7 @@ include=${ZIRAN_INCLUDE:-"$root/build/packages/ziran/include"} mkdir -p "$work/ir" "$bin/zi2zir" --root "$root/tests" --module-path "$root/src" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$work/ir" "$source" for input in source saved; do @@ -28,6 +29,7 @@ for input in source saved; do "$bin/zi2zib" bundle --root "$module_root" \ --module-path "$module_path" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ --entry navigation_routes_behavior:Answer \ -o "$output/navigation_routes.zib" "$file" [ "$("$bin/zi2zib" run "$output/navigation_routes.zib")" = 42 ] @@ -35,6 +37,7 @@ for input in source saved; do "$bin/zi2c" --no-main --root "$module_root" \ --module-path "$module_path" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$output/c" "$file" cat > "$output/c/main.c" <<'C' #include "navigation_routes_behavior.h" @@ -51,6 +54,7 @@ C "$bin/zi2cpp" --no-main --root "$module_root" \ --module-path "$module_path" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$output/cpp" "$file" cat > "$output/cpp/main.cpp" <<'CPP' #include "navigation_routes_behavior.hpp" @@ -67,6 +71,7 @@ CPP "$bin/zi2go" --no-main --root "$module_root" \ --module-path "$module_path" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$output/go" "$file" cat > "$output/go/navigation_routes_behavior_test.go" <<'GO' package ziran diff --git a/tests/route_catalog_zi_test.sh b/tests/route_catalog_zi_test.sh index cc5e12fec..0cead3cf0 100644 --- a/tests/route_catalog_zi_test.sh +++ b/tests/route_catalog_zi_test.sh @@ -10,7 +10,7 @@ ui=${KRYON_UI_DIR:-$root/build/packages/kryon/src/ui} mkdir -p "$work/ir" "$bin/zi2zir" --root "$root/tests" --module-path "$root/src" \ - --module-path "$ui" -o "$work/ir" "$source" + --module-path "$ui" --module-path "$root/build/packages/ziran/std" -o "$work/ir" "$source" for input in source saved; do if [ "$input" = source ]; then diff --git a/tests/scroll_input_zi_test.sh b/tests/scroll_input_zi_test.sh index ec9474a74..98e02c957 100644 --- a/tests/scroll_input_zi_test.sh +++ b/tests/scroll_input_zi_test.sh @@ -9,7 +9,7 @@ ui=${KRYON_UI_DIR:-$root/build/packages/kryon/src/ui} mkdir -p "$work/ir" "$bin/zi2zir" --root "$root/tests" --module-path "$root/src" \ - --module-path "$ui" \ + --module-path "$ui" --module-path "$root/build/packages/ziran/std" \ -o "$work/ir" "$source" for input in source saved; do if test "$input" = source; then @@ -26,6 +26,7 @@ for input in source saved; do mkdir -p "$work/$input" "$bin/zi2zib" bundle --root "$module_root" \ --module-path "$module_path" --module-path "$kryon_path" \ + --module-path "$root/build/packages/ziran/std" \ --entry scroll_input_behavior:Answer \ -o "$work/$input/scroll_input.zib" "$file" test "$("$bin/zi2zib" run "$work/$input/scroll_input.zib")" = 42 diff --git a/tests/statistics_date_zi_test.sh b/tests/statistics_date_zi_test.sh index 2c42f0838..6eaf533b3 100755 --- a/tests/statistics_date_zi_test.sh +++ b/tests/statistics_date_zi_test.sh @@ -10,6 +10,7 @@ source=$root/tests/statistics_date_behavior.zi "$bin/ziran" bundle --root "$root" \ --module-path "$root/src" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ --entry statistics_date_behavior:Answer \ -o "$work/date.zib" "$source" test "$("$bin/ziran" run "$work/date.zib")" = 42 @@ -17,6 +18,7 @@ test "$("$bin/ziran" run "$work/date.zib")" = 42 "$bin/zi2c" --no-main --root "$root" \ --module-path "$root/src" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$work/c" "$source" cat > "$work/c/main.c" <<'C' #include "statistics_date_behavior.h" diff --git a/tests/sync_safety_zi_test.sh b/tests/sync_safety_zi_test.sh index 34994cd5c..09c048a53 100644 --- a/tests/sync_safety_zi_test.sh +++ b/tests/sync_safety_zi_test.sh @@ -68,6 +68,7 @@ cmp "$work/source/safety.zib" "$work/saved/safety.zib" "$bin/zi2c" --no-main --root "$root/src" \ --module-path "$root/build/packages/kryon/src/ui" \ + --module-path "$root/build/packages/ziran/std" \ -o "$work/native" "$root/src/app/sync_safety.zi" "${CC:-cc}" -std=c11 -DZIRAN_BOUNDS_CHECK \ -ffunction-sections -fdata-sections -Wl,--gc-sections \