From 63c971db19492312ef04d6dce115e5ff08424c5f Mon Sep 17 00:00:00 2001 From: Stanley Wirian <67956410+wnats@users.noreply.github.com> Date: Fri, 8 Dec 2023 20:21:30 +1100 Subject: [PATCH] Fixed string concat to cstring conversion (#427) * Fixed string concat to cstring conversion * Minor stylistic adjustment --- 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..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, 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)