From 8bb99c6f8119430347a931b09682f1ff4efe30ae Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 27 Feb 2025 15:42:38 +0100 Subject: [PATCH] Fixes to examples and MSVC compilation. --- resources/examples/contextfree/cleanup.c3 | 2 +- resources/examples/contextfree/dynscope.c3 | 2 +- resources/examples/contextfree/guess_number.c3 | 2 +- resources/examples/ls.c3 | 4 ++-- resources/examples/notworking/madlibs.c3 | 4 ++-- resources/examples/plus_minus.c3 | 4 ++-- src/build/libraries.c | 2 +- test/test_suite/expressions/enum_ct_sub.c3t | 3 --- test/test_suite/macros/vasplat_function_call.c3 | 7 ++++--- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/resources/examples/contextfree/cleanup.c3 b/resources/examples/contextfree/cleanup.c3 index 64a978d70..b7aaf2702 100644 --- a/resources/examples/contextfree/cleanup.c3 +++ b/resources/examples/contextfree/cleanup.c3 @@ -47,7 +47,7 @@ fn Resource! prep_out(String out_name, String[] prep_names) fn void main() { - Resource writer = prep_out("out", String[] { "a", "b"})!!; + Resource writer = prep_out("out", (String[]) { "a", "b"})!!; defer writer.deinit(); io::printn("use out"); } \ No newline at end of file diff --git a/resources/examples/contextfree/dynscope.c3 b/resources/examples/contextfree/dynscope.c3 index 356a56ecc..e031215a0 100644 --- a/resources/examples/contextfree/dynscope.c3 +++ b/resources/examples/contextfree/dynscope.c3 @@ -27,6 +27,6 @@ fn void main() { long val1 = perform("something"); long val2 = @with_mode("faster", perform, "reliable"); - long val3 = perform(String[] {"something"}); + long val3 = perform((String[]){"something"}); io::printfn("%d %d %d", val1, val2, val3); } diff --git a/resources/examples/contextfree/guess_number.c3 b/resources/examples/contextfree/guess_number.c3 index 81df037cc..ecd623526 100644 --- a/resources/examples/contextfree/guess_number.c3 +++ b/resources/examples/contextfree/guess_number.c3 @@ -22,7 +22,7 @@ int err_count = 0; fn int! ask_guess(int high) { io::printf("Guess a number between 1 and %d: ", high); - String text = io::readline() ?? InputResult.FAILED_TO_READ?!; + String text = io::treadline() ?? InputResult.FAILED_TO_READ?!; return text.to_int() ?? InputResult.NOT_AN_INT?; } diff --git a/resources/examples/ls.c3 b/resources/examples/ls.c3 index 0a3902852..e0323e298 100644 --- a/resources/examples/ls.c3 +++ b/resources/examples/ls.c3 @@ -2,8 +2,8 @@ import std::io; fn void main() { - Path path = path::new_cwd()!!; - foreach (i, p : path::new_ls(path)!!) + Path path = path::cwd(mem)!!; + foreach (i, p : path::ls(mem, path)!!) { io::printfn("%02d %s", i, p.str_view()); } diff --git a/resources/examples/notworking/madlibs.c3 b/resources/examples/notworking/madlibs.c3 index 8bbd9b4a3..5b8f5f2c5 100644 --- a/resources/examples/notworking/madlibs.c3 +++ b/resources/examples/notworking/madlibs.c3 @@ -5,7 +5,7 @@ fn void main() { printn("Enter a story template, terminated by an empty line:"); String story = ""; - while (try String line = stdin().readline().strip()) + while (try String line = stdin().readline(mem).strip()) { story = story.append(line); @@ -21,7 +21,7 @@ fn void main() { VarString s = match.string; printf("Enter a value for '%s': ", s[1..^2]); - String word = stdin().readline().strip()!; + String word = stdin().readline(mem).strip()!; story = story.replace(s, word); } diff --git a/resources/examples/plus_minus.c3 b/resources/examples/plus_minus.c3 index 6dc65190f..61ffabb80 100644 --- a/resources/examples/plus_minus.c3 +++ b/resources/examples/plus_minus.c3 @@ -13,9 +13,9 @@ fault TokenResult fn void main(String[] args) { // Grab a string from stdin - String s = io::readline()!!; + String s = io::readline(mem)!!; // Delete it at scope end [defer] - defer s.free(); + defer free(s); // Copy the slice, which doesn't change the underlying data. String numbers = s; diff --git a/src/build/libraries.c b/src/build/libraries.c index 401e5ccfc..4fc16fbcf 100644 --- a/src/build/libraries.c +++ b/src/build/libraries.c @@ -40,7 +40,7 @@ const char *manifest_target_keys[][2] = { const int manifest_target_keys_count = ELEMENTLEN(manifest_target_keys); -const char *manifest_deprecated_target_keys[] = { }; +const char *manifest_deprecated_target_keys[] = { "none" }; const int manifest_deprecated_target_key_count = ELEMENTLEN(manifest_deprecated_target_keys); diff --git a/test/test_suite/expressions/enum_ct_sub.c3t b/test/test_suite/expressions/enum_ct_sub.c3t index 50deb9772..9a20d46c8 100644 --- a/test/test_suite/expressions/enum_ct_sub.c3t +++ b/test/test_suite/expressions/enum_ct_sub.c3t @@ -6,9 +6,6 @@ enum Foo : char distinct Abc = int; fn void main() { - $assert (Foo.ABC - Foo.BCD) == 255; - char c = Foo.ABC - Foo.BCD; - $assert $typeof(Foo.ABC - Foo.BCD).typeid == char.typeid; $assert Foo.BCD - 1 == Foo.ABC; $assert Foo.ABC + 1 == Foo.BCD; $assert $typeof(Foo.BCD - 1).typeid == Foo.typeid; diff --git a/test/test_suite/macros/vasplat_function_call.c3 b/test/test_suite/macros/vasplat_function_call.c3 index b95ea8d26..3af15b33e 100644 --- a/test/test_suite/macros/vasplat_function_call.c3 +++ b/test/test_suite/macros/vasplat_function_call.c3 @@ -1,7 +1,7 @@ import std; def IList = List{int}; -fn IList new() +fn IList IList.newAbc(&self) { IList l; l.init(mem, $vasplat); // #error: can only be used inside @@ -11,8 +11,9 @@ fn IList new() fn void main() { - IList a = new(123, 123, 123, 123, 123, 123, 123, 134); + IList x; + IList a = x.newAbc(123, 123, 123, 123, 123, 123, 123, 134); a.push(567); io::printfn("%s", a[0]); -} \ No newline at end of file +}