From a7e4dda360a23785b6de7d3827ea86d9482ffb34 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 26 Jul 2022 02:10:18 +0200 Subject: [PATCH] Added examples. --- .../contextfree}/boolerr.c3 | 0 resources/examples/contextfree/dynscope.c3 | 28 +++++++++++++++++++ .../{ => contextfree}/guess_number.c3 | 0 resources/examples/contextfree/multi.c3 | 27 ++++++++++++++++++ 4 files changed, 55 insertions(+) rename resources/{testfragments => examples/contextfree}/boolerr.c3 (100%) create mode 100644 resources/examples/contextfree/dynscope.c3 rename resources/examples/{ => contextfree}/guess_number.c3 (100%) create mode 100644 resources/examples/contextfree/multi.c3 diff --git a/resources/testfragments/boolerr.c3 b/resources/examples/contextfree/boolerr.c3 similarity index 100% rename from resources/testfragments/boolerr.c3 rename to resources/examples/contextfree/boolerr.c3 diff --git a/resources/examples/contextfree/dynscope.c3 b/resources/examples/contextfree/dynscope.c3 new file mode 100644 index 000000000..c12ed9931 --- /dev/null +++ b/resources/examples/contextfree/dynscope.c3 @@ -0,0 +1,28 @@ +module foo; +import std::io; + +tlocal char[] context_user = "safe"; + +macro long perform(task) +{ + io::printf("%s: %s\n", context_user, task); + return task.len; +} + +macro @with_mode(char[] user, #action, arg) +{ + @scope(context_user) + { + context_user = user; + return #action(arg); + }; +} + +fn void main() +{ + long result = perform("something!"); + result += @with_mode("faster", perform, "reliable"); + result += perform(char[][] {"again", "more"}); + result += perform(int[<2>] { 56, 99 }); + io::printf("Result: %d\n", result); +} \ No newline at end of file diff --git a/resources/examples/guess_number.c3 b/resources/examples/contextfree/guess_number.c3 similarity index 100% rename from resources/examples/guess_number.c3 rename to resources/examples/contextfree/guess_number.c3 diff --git a/resources/examples/contextfree/multi.c3 b/resources/examples/contextfree/multi.c3 new file mode 100644 index 000000000..002556270 --- /dev/null +++ b/resources/examples/contextfree/multi.c3 @@ -0,0 +1,27 @@ +module test; +import std::io; + +fn void main() +{ + /* + Here's a comment. + /* + And a nested comment. + */ + */ + char[] text = ` + function hello() { + console.log("name`"\t"`age"); + } + + hello(); + `; + io::println(text); + + // Binary + const DATA = x"4749463839610100010080" + x"0100ffffff00000021f904" + x"010a0001002c0000000001" + x"0001000002024c01003b"; + io::printf("%d\n", DATA.len); +} \ No newline at end of file