1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

Make suit0 fully functional by adding push functoin to stl

This commit is contained in:
bakpakin 2018-01-14 10:23:24 -05:00
parent f5b29b85ba
commit 9291a4faf0
2 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,20 @@
#include <dst/dst.h>
#include <dst/dststl.h>
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},

View File

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