Read bounded C text in Ziran and bring Ziran tests up to date
AppTextFromCString reached a C host for work the app's own Ziran code already does, so every test that touched text had to stub it in C. It now reads the bounded buffer directly and the C export forwards to it. Tests failed on current Kryon and Ziran: Kryon geometry imports Ziran's math module, which several test scripts did not put on the module path, enum members now need their using declaration, and the device policy test lacked the font metric host its text measurement reaches.
This commit is contained in:
1 parent
68a4976fff
commit
3dd1755e90
12 files changed
+49
-18
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in new issue
Block a user