mirror of
https://github.com/janet-lang/janet
synced 2025-04-29 14:13:23 +00:00
Make suit0 fully functional by adding push functoin to stl
This commit is contained in:
parent
f5b29b85ba
commit
9291a4faf0
15
core/stl.c
15
core/stl.c
@ -23,6 +23,20 @@
|
|||||||
#include <dst/dst.h>
|
#include <dst/dst.h>
|
||||||
#include <dst/dststl.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) {
|
int dst_stl_parse(int32_t argn, Dst *argv, Dst *ret) {
|
||||||
const uint8_t *src;
|
const uint8_t *src;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
@ -385,6 +399,7 @@ DST_DEFINE_COMPARATOR(notdescending, > 0)
|
|||||||
DST_DEFINE_COMPARATOR(notascending, < 0)
|
DST_DEFINE_COMPARATOR(notascending, < 0)
|
||||||
|
|
||||||
static DstReg stl[] = {
|
static DstReg stl[] = {
|
||||||
|
{"push", dst_stl_push},
|
||||||
{"load-native", dst_load_native},
|
{"load-native", dst_load_native},
|
||||||
{"parse", dst_stl_parse},
|
{"parse", dst_stl_parse},
|
||||||
{"compile", dst_stl_compile},
|
{"compile", dst_stl_compile},
|
||||||
|
@ -180,8 +180,7 @@
|
|||||||
|
|
||||||
# Merge sort
|
# Merge sort
|
||||||
|
|
||||||
(def empty? (fn [xs] (= 0 (length xs))))
|
# Impertiave merge sort merge
|
||||||
|
|
||||||
(def merge (fn [xs ys]
|
(def merge (fn [xs ys]
|
||||||
(def ret [])
|
(def ret [])
|
||||||
(def xlen (length xs))
|
(def xlen (length xs))
|
||||||
@ -207,6 +206,11 @@
|
|||||||
(varset! j (+ j 1)))
|
(varset! j (+ j 1)))
|
||||||
ret))
|
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
|
# Gensym tests
|
||||||
|
|
||||||
(assert (not= (gensym) (gensym)) "two gensyms not equal")
|
(assert (not= (gensym) (gensym)) "two gensyms not equal")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user