From 4b353c05aa9a62e4606fa34ea8c0e7b3757e35b3 Mon Sep 17 00:00:00 2001 From: Stanley Wirian Date: Fri, 8 Dec 2023 16:31:30 +1100 Subject: [PATCH 1/2] Fixed string concat to cstring conversion --- test-cases/execution/string_concat_to_cstring.exp | 1 + test-cases/execution/string_concat_to_cstring.in | 0 test-cases/execution/string_concat_to_cstring.wybe | 3 +++ wybelibs/wybe/string.wybe | 3 +-- 4 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 test-cases/execution/string_concat_to_cstring.exp create mode 100644 test-cases/execution/string_concat_to_cstring.in create mode 100644 test-cases/execution/string_concat_to_cstring.wybe diff --git a/test-cases/execution/string_concat_to_cstring.exp b/test-cases/execution/string_concat_to_cstring.exp new file mode 100644 index 000000000..de97a6dc4 --- /dev/null +++ b/test-cases/execution/string_concat_to_cstring.exp @@ -0,0 +1 @@ +012 diff --git a/test-cases/execution/string_concat_to_cstring.in b/test-cases/execution/string_concat_to_cstring.in new file mode 100644 index 000000000..e69de29bb diff --git a/test-cases/execution/string_concat_to_cstring.wybe b/test-cases/execution/string_concat_to_cstring.wybe new file mode 100644 index 000000000..337c8f46f --- /dev/null +++ b/test-cases/execution/string_concat_to_cstring.wybe @@ -0,0 +1,3 @@ +?str = ("0" ,, "1") ,, "2" + +!println(c_string(str)) diff --git a/wybelibs/wybe/string.wybe b/wybelibs/wybe/string.wybe index 13642eed8..789bbf04e 100644 --- a/wybelibs/wybe/string.wybe +++ b/wybelibs/wybe/string.wybe @@ -42,7 +42,7 @@ pub def c_string(s:_):c_string = str where { | else :: ?len = length(s) + 1 foreign lpvm alloc(len, ?str) - foreign lpvm mutate(str, ?str, len, true, len, 0, '\0') + foreign lpvm mutate(str, ?str, len-1, true, len, 0, '\0') ?offset = 0 pack(s, !str, len, !offset) } @@ -180,7 +180,6 @@ def pack(s:_, !raw:c_string, size:int, !offset:int) { | concat(?left, ?right) :: pack(left, !raw, size, !offset) pack(right, !raw, size, !offset) - incr(!offset) | slice(_, _) :: for ?c in s { foreign lpvm mutate(raw, ?raw, offset, true, size, 0, c) From 40bdee70e6039d84b885e034d7882243fa0d3ed3 Mon Sep 17 00:00:00 2001 From: Stanley Wirian Date: Fri, 8 Dec 2023 16:44:12 +1100 Subject: [PATCH 2/2] Minor stylistic adjustment --- wybelibs/wybe/string.wybe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wybelibs/wybe/string.wybe b/wybelibs/wybe/string.wybe index 789bbf04e..da9a73ecc 100644 --- a/wybelibs/wybe/string.wybe +++ b/wybelibs/wybe/string.wybe @@ -42,7 +42,7 @@ pub def c_string(s:_):c_string = str where { | else :: ?len = length(s) + 1 foreign lpvm alloc(len, ?str) - foreign lpvm mutate(str, ?str, len-1, true, len, 0, '\0') + foreign lpvm mutate(str, ?str, len - 1, true, len, 0, '\0') ?offset = 0 pack(s, !str, len, !offset) }