From 5ef0923d372368e411e4852697ad97527dfe92fd Mon Sep 17 00:00:00 2001 From: IMXEren <96839938+IMXEren@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:09:07 +0530 Subject: [PATCH] datatype99: add package (#4545) * datatype99: add package * datatype99: test against older version * datatype99: improve test * datatype99: use c11 flag * Update xmake.lua --------- Co-authored-by: ruki --- packages/d/datatype99/xmake.lua | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/d/datatype99/xmake.lua diff --git a/packages/d/datatype99/xmake.lua b/packages/d/datatype99/xmake.lua new file mode 100644 index 000000000..c530078a3 --- /dev/null +++ b/packages/d/datatype99/xmake.lua @@ -0,0 +1,41 @@ +package("datatype99") + set_kind("library", { headeronly = true }) + set_homepage("https://github.com/Hirrolot/datatype99") + set_description("Algebraic data types for C99") + set_license("MIT") + + add_urls("https://github.com/Hirrolot/datatype99/archive/refs/tags/v$(version).tar.gz", + "https://github.com/Hirrolot/datatype99.git") + + add_versions("1.6.3", "0ddc138eac8db19fa22c482d9a2ec107ff622fd7ce61bb0b1eefb4d8f522e01e") + add_versions("1.6.4", "f8488decc7ab035e3af77ee62e64fc678d5cb57831457f7270efe003e63d6f09") + + add_deps("metalang99") + + on_install(function(package) + os.cp("*.h", package:installdir("include")) + end) + + on_test(function(package) + assert(package:check_csnippets({test = [[ + #include + datatype( + BinaryTree, + (Leaf, int), + (Node, BinaryTree *, int, BinaryTree *) + ); + int sum(const BinaryTree *tree) { + match(*tree) { + of(Leaf, x) return *x; + of(Node, lhs, x, rhs) return sum(*lhs) + *x + sum(*rhs); + } + return -1; + } + void test() { + BinaryTree leaf5 = Leaf(5); + BinaryTree leaf7 = Leaf(7); + BinaryTree node = Node(&leaf5, 123, &leaf7); + assert(sum(&node) == 135); + } + ]]}, { configs = { languages = "c11" }, includes = "datatype99.h" })) + end)