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")