From 6d2594db2da8214c9968bce036a85d5020270c17 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Mon, 30 Jun 2025 13:08:52 +0200 Subject: [PATCH] test id generation with macros --- test/test_idgen.c3 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/test_idgen.c3 diff --git a/test/test_idgen.c3 b/test/test_idgen.c3 new file mode 100644 index 0000000..d4709d5 --- /dev/null +++ b/test/test_idgen.c3 @@ -0,0 +1,30 @@ +import std::io; + +alias Id = uint; + +fn void foo_ex(Id id) +{ + io::printfn("id = %d", id); +} + + +macro Id @compute_id(...) +{ + Id id = (Id)$$LINE.hash() ^ (Id)@str_hash($$FILE); + $for var $i = 0; $i < $vacount; $i++: + id ^= (Id)$vaconst[$i].hash(); + $endfor + return id; +} + +macro foo(...) => foo_ex(@compute_id($vasplat)); + +fn int main() +{ + foo_ex(1234); + foo(); + foo(); + foo(); + + return 0; +} \ No newline at end of file