From 9291a4faf0ab82b1b64b3266eecd80e4cc69de0b Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sun, 14 Jan 2018 10:23:24 -0500 Subject: [PATCH] Make suit0 fully functional by adding push functoin to stl --- core/stl.c | 15 +++++++++++++++ dsttest/suite0.dst | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/stl.c b/core/stl.c index c5563f30..e3092f09 100644 --- a/core/stl.c +++ b/core/stl.c @@ -23,6 +23,20 @@ #include #include +int dst_stl_push(int32_t argn, Dst *argv, Dst *ret) { + if (argn != 2) { + *ret = dst_cstringv("expected 2 arguments"); + return 1; + } + if (!dst_checktype(argv[0], DST_ARRAY)) { + *ret = dst_cstringv("expected array"); + return 1; + } + dst_array_push(dst_unwrap_array(argv[0]), argv[1]); + *ret = argv[0]; + return 0; +} + int dst_stl_parse(int32_t argn, Dst *argv, Dst *ret) { const uint8_t *src; int32_t len; @@ -385,6 +399,7 @@ DST_DEFINE_COMPARATOR(notdescending, > 0) DST_DEFINE_COMPARATOR(notascending, < 0) static DstReg stl[] = { + {"push", dst_stl_push}, {"load-native", dst_load_native}, {"parse", dst_stl_parse}, {"compile", dst_stl_compile}, diff --git a/dsttest/suite0.dst b/dsttest/suite0.dst index 0e1777ba..5ff6d491 100644 --- a/dsttest/suite0.dst +++ b/dsttest/suite0.dst @@ -180,8 +180,7 @@ # Merge sort -(def empty? (fn [xs] (= 0 (length xs)))) - +# Impertiave merge sort merge (def merge (fn [xs ys] (def ret []) (def xlen (length xs)) @@ -207,6 +206,11 @@ (varset! j (+ j 1))) ret)) +(assert (apply <= (merge [1 3 5] [2 4 6])) "merge sort merge 1") +(assert (apply <= (merge [1 2 3] [4 5 6])) "merge sort merge 2") +(assert (apply <= (merge [1 3 5] [2 4 6 6 6 9])) "merge sort merge 3") +(assert (apply <= (merge '(1 3 5) [2 4 6 6 6 9])) "merge sort merge 4") + # Gensym tests (assert (not= (gensym) (gensym)) "two gensyms not equal")