Merge branch 'master' into api-change
This commit is contained in:
commit
9f3fefd606
2
Makefile
2
Makefile
|
@ -65,7 +65,7 @@ test: test-contribs test-nostdlib
|
|||
test-contribs: bin/picrin $(CONTRIB_TESTS)
|
||||
|
||||
test-nostdlib:
|
||||
$(CC) -I extlib/benz/include -D'PIC_ENABLE_LIBC=0' -D'PIC_ENABLE_FLOAT=0' -D'PIC_ENABLE_STDIO=0' -nostdlib -fPIC -shared -std=c89 -ansi -pedantic -Wall -Wextra -o lib/libbenz.so $(BENZ_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
$(CC) -I extlib/benz/include -D'PIC_ENABLE_LIBC=0' -D'PIC_ENABLE_FLOAT=0' -D'PIC_ENABLE_STDIO=0' -nostdlib -fPIC -shared -std=c89 -pedantic -Wall -Wextra -Werror -o lib/libbenz.so $(BENZ_SRCS) etc/libc_polyfill.c -fno-stack-protector
|
||||
rm -f lib/libbenz.so
|
||||
|
||||
install: all
|
||||
|
|
|
@ -435,6 +435,7 @@ analyze_lambda(pic_state *pic, analyze_scope *up, pic_value form)
|
|||
pic_value rest = pic_undef_value();
|
||||
pic_vec *args, *locals, *captures;
|
||||
size_t i, j;
|
||||
khiter_t it;
|
||||
|
||||
formals = pic_list_ref(pic, form, 1);
|
||||
body = pic_list_ref(pic, form, 2);
|
||||
|
@ -455,16 +456,16 @@ analyze_lambda(pic_state *pic, analyze_scope *up, pic_value form)
|
|||
}
|
||||
|
||||
locals = pic_make_vec(pic, kh_size(&scope->locals));
|
||||
for (i = kh_begin(&scope->locals), j = 0; i < kh_end(&scope->locals); ++i) {
|
||||
if (kh_exist(&scope->locals, i)) {
|
||||
locals->data[j++] = pic_obj_value(kh_key(&scope->locals, i));
|
||||
for (it = kh_begin(&scope->locals), j = 0; it < kh_end(&scope->locals); ++it) {
|
||||
if (kh_exist(&scope->locals, it)) {
|
||||
locals->data[j++] = pic_obj_value(kh_key(&scope->locals, it));
|
||||
}
|
||||
}
|
||||
|
||||
captures = pic_make_vec(pic, kh_size(&scope->captures));
|
||||
for (i = kh_begin(&scope->captures), j = 0; i < kh_end(&scope->captures); ++i) {
|
||||
if (kh_exist(&scope->captures, i)) {
|
||||
captures->data[j++] = pic_obj_value(kh_key(&scope->captures, i));
|
||||
for (it = kh_begin(&scope->captures), j = 0; it < kh_end(&scope->captures); ++it) {
|
||||
if (kh_exist(&scope->captures, it)) {
|
||||
captures->data[j++] = pic_obj_value(kh_key(&scope->captures, it));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,19 +157,19 @@ pic_callcc(pic_state *pic, struct pic_proc *proc)
|
|||
static pic_value
|
||||
pic_va_values(pic_state *pic, size_t n, ...)
|
||||
{
|
||||
pic_value args[n];
|
||||
pic_vec *args = pic_make_vec(pic, n);
|
||||
va_list ap;
|
||||
size_t i = 0;
|
||||
|
||||
va_start(ap, n);
|
||||
|
||||
while (i < n) {
|
||||
args[i++] = va_arg(ap, pic_value);
|
||||
args->data[i++] = va_arg(ap, pic_value);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
||||
return pic_values(pic, n, args);
|
||||
return pic_values(pic, n, args->data);
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
@ -288,19 +288,19 @@ static pic_value
|
|||
pic_cont_call_with_values(pic_state *pic)
|
||||
{
|
||||
struct pic_proc *producer, *consumer;
|
||||
size_t argc;
|
||||
pic_vec *args;
|
||||
|
||||
pic_get_args(pic, "ll", &producer, &consumer);
|
||||
|
||||
pic_apply(pic, producer, pic_nil_value());
|
||||
|
||||
do {
|
||||
size_t argc = pic_receive(pic, 0, NULL);
|
||||
pic_value args[argc];
|
||||
argc = pic_receive(pic, 0, NULL);
|
||||
args = pic_make_vec(pic, argc);
|
||||
|
||||
pic_receive(pic, argc, args);
|
||||
pic_receive(pic, argc, args->data);
|
||||
|
||||
return pic_apply_trampoline(pic, consumer, argc, args);
|
||||
} while (0);
|
||||
return pic_apply_trampoline(pic, consumer, argc, args->data);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -155,42 +155,19 @@ static pic_value
|
|||
pic_dict_dictionary_map(pic_state *pic)
|
||||
{
|
||||
struct pic_proc *proc;
|
||||
size_t argc, i;
|
||||
pic_value *args;
|
||||
pic_value arg_list, ret = pic_nil_value();
|
||||
struct pic_dict *dict;
|
||||
khiter_t it;
|
||||
khash_t(dict) *kh;
|
||||
pic_value ret = pic_nil_value();
|
||||
|
||||
pic_get_args(pic, "l*", &proc, &argc, &args);
|
||||
pic_get_args(pic, "ld", &proc, &dict);
|
||||
|
||||
if (argc != 0) {
|
||||
khiter_t it[argc];
|
||||
khash_t(dict) *kh[argc];
|
||||
kh = &dict->hash;
|
||||
|
||||
for (i = 0; i < argc; ++i) {
|
||||
if (! pic_dict_p(args[i])) {
|
||||
pic_errorf(pic, "expected dict, but got %s", pic_type_repr(pic_type(args[i])));
|
||||
}
|
||||
kh[i] = &pic_dict_ptr(args[i])->hash;
|
||||
it[i] = kh_begin(kh[i]);
|
||||
for (it = kh_begin(kh); it != kh_end(kh); ++it) {
|
||||
if (kh_exist(kh, it)) {
|
||||
pic_push(pic, pic_apply1(pic, proc, pic_obj_value(kh_key(kh, it))), ret);
|
||||
}
|
||||
|
||||
do {
|
||||
arg_list = pic_nil_value();
|
||||
for (i = 0; i < argc; ++i) {
|
||||
while (it[i] != kh_end(kh[i])) { /* find next available */
|
||||
if (kh_exist(kh[i], it[i]))
|
||||
break;
|
||||
it[i]++;
|
||||
}
|
||||
if (it[i] == kh_end(kh[i])) {
|
||||
break;
|
||||
}
|
||||
pic_push(pic, pic_obj_value(kh_key(kh[i], it[i]++)), arg_list);
|
||||
}
|
||||
if (i != argc) {
|
||||
break;
|
||||
}
|
||||
pic_push(pic, pic_apply(pic, proc, pic_reverse(pic, arg_list)), ret);
|
||||
} while (1);
|
||||
}
|
||||
|
||||
return pic_reverse(pic, ret);
|
||||
|
@ -200,42 +177,18 @@ static pic_value
|
|||
pic_dict_dictionary_for_each(pic_state *pic)
|
||||
{
|
||||
struct pic_proc *proc;
|
||||
size_t argc, i;
|
||||
pic_value *args;
|
||||
pic_value arg_list;
|
||||
struct pic_dict *dict;
|
||||
khiter_t it;
|
||||
khash_t(dict) *kh;
|
||||
|
||||
pic_get_args(pic, "l*", &proc, &argc, &args);
|
||||
pic_get_args(pic, "ld", &proc, &dict);
|
||||
|
||||
if (argc != 0) {
|
||||
khiter_t it[argc];
|
||||
khash_t(dict) *kh[argc];
|
||||
kh = &dict->hash;
|
||||
|
||||
for (i = 0; i < argc; ++i) {
|
||||
if (! pic_dict_p(args[i])) {
|
||||
pic_errorf(pic, "expected dict, but got %s", pic_type_repr(pic_type(args[i])));
|
||||
}
|
||||
kh[i] = &pic_dict_ptr(args[i])->hash;
|
||||
it[i] = kh_begin(kh[i]);
|
||||
for (it = kh_begin(kh); it != kh_end(kh); ++it) {
|
||||
if (kh_exist(kh, it)) {
|
||||
pic_apply1(pic, proc, pic_obj_value(kh_key(kh, it)));
|
||||
}
|
||||
|
||||
do {
|
||||
arg_list = pic_nil_value();
|
||||
for (i = 0; i < argc; ++i) {
|
||||
while (it[i] != kh_end(kh[i])) { /* find next available */
|
||||
if (kh_exist(kh[i], it[i]))
|
||||
break;
|
||||
it[i]++;
|
||||
}
|
||||
if (it[i] == kh_end(kh[i])) {
|
||||
break;
|
||||
}
|
||||
pic_push(pic, pic_obj_value(kh_key(kh[i], it[i]++)), arg_list);
|
||||
}
|
||||
if (i != argc) {
|
||||
break;
|
||||
}
|
||||
pic_void(pic_apply(pic, proc, pic_reverse(pic, arg_list)));
|
||||
} while (1);
|
||||
}
|
||||
|
||||
return pic_undef_value();
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef struct pic_state pic_state;
|
|||
#include "picrin/read.h"
|
||||
#include "picrin/gc.h"
|
||||
|
||||
KHASH_DECLARE(s, const char *, pic_sym *);
|
||||
KHASH_DECLARE(s, const char *, pic_sym *)
|
||||
|
||||
typedef struct pic_checkpoint {
|
||||
PIC_OBJECT_HEADER
|
||||
|
|
|
@ -89,7 +89,7 @@ extern "C" {
|
|||
|
||||
#else
|
||||
|
||||
# define assert(v) 0
|
||||
# define assert(v) (void)0
|
||||
|
||||
PIC_INLINE int
|
||||
isspace(int c)
|
||||
|
|
|
@ -27,21 +27,7 @@
|
|||
#ifndef AC_KHASH_H
|
||||
#define AC_KHASH_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if UINT_MAX == 0xffffffffu
|
||||
typedef unsigned int khint32_t;
|
||||
#elif ULONG_MAX == 0xffffffffu
|
||||
typedef unsigned long khint32_t;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX == ULLONG_MAX
|
||||
typedef unsigned long khint64_t;
|
||||
#else
|
||||
typedef unsigned long long khint64_t;
|
||||
#endif
|
||||
|
||||
typedef khint32_t khint_t;
|
||||
typedef int khint_t;
|
||||
typedef khint_t khiter_t;
|
||||
|
||||
#define ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
|
||||
|
@ -78,7 +64,7 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key)
|
|||
#define KHASH_DECLARE(name, khkey_t, khval_t) \
|
||||
typedef struct { \
|
||||
khint_t n_buckets, size, n_occupied, upper_bound; \
|
||||
khint32_t *flags; \
|
||||
int *flags; \
|
||||
khkey_t *keys; \
|
||||
khval_t *vals; \
|
||||
} kh_##name##_t; \
|
||||
|
@ -105,7 +91,7 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key)
|
|||
void kh_clear_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h->flags) { \
|
||||
memset(h->flags, 0xaa, ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
|
||||
memset(h->flags, 0xaa, ac_fsize(h->n_buckets) * sizeof(int)); \
|
||||
h->size = h->n_occupied = 0; \
|
||||
} \
|
||||
} \
|
||||
|
@ -125,15 +111,15 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key)
|
|||
} \
|
||||
void kh_resize_##name(pic_state *pic, kh_##name##_t *h, khint_t new_n_buckets) \
|
||||
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
||||
khint32_t *new_flags = 0; \
|
||||
int *new_flags = 0; \
|
||||
khint_t j = 1; \
|
||||
{ \
|
||||
ac_roundup32(new_n_buckets); \
|
||||
if (new_n_buckets < 4) new_n_buckets = 4; \
|
||||
if (h->size >= ac_hash_upper(new_n_buckets)) j = 0; /* requested size is too small */ \
|
||||
else { /* hash table size to be changed (shrink or expand); rehash */ \
|
||||
new_flags = pic_malloc(pic, ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
memset(new_flags, 0xaa, ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
new_flags = pic_malloc(pic, ac_fsize(new_n_buckets) * sizeof(int)); \
|
||||
memset(new_flags, 0xaa, ac_fsize(new_n_buckets) * sizeof(int)); \
|
||||
if (h->n_buckets < new_n_buckets) { /* expand */ \
|
||||
h->keys = pic_realloc(pic, (void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (kh_is_map) { \
|
||||
|
@ -230,12 +216,10 @@ PIC_INLINE khint_t ac_Wang_hash(khint_t key)
|
|||
|
||||
/* --- BEGIN OF HASH FUNCTIONS --- */
|
||||
|
||||
#define kh_ptr_hash_func(key) (khint32_t)(long)(key)
|
||||
#define kh_ptr_hash_func(key) (int)(long)(key)
|
||||
#define kh_ptr_hash_equal(a, b) ((a) == (b))
|
||||
#define kh_int_hash_func(key) (khint32_t)(key)
|
||||
#define kh_int_hash_func(key) (int)(key)
|
||||
#define kh_int_hash_equal(a, b) ((a) == (b))
|
||||
#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
|
||||
#define kh_int64_hash_equal(a, b) ((a) == (b))
|
||||
#define kh_str_hash_func(key) ac_X31_hash_string(key)
|
||||
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)
|
||||
#define kh_int_hash_func2(k) ac_Wang_hash((khint_t)key)
|
||||
|
|
|
@ -611,7 +611,6 @@ pic_eqv_p(pic_value x, pic_value y)
|
|||
name(pic_state *pic, pic_value a, pic_value b) \
|
||||
{ \
|
||||
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||
double f; \
|
||||
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||
return pic_int_value(pic_int(a) op pic_int(b)); \
|
||||
} else { \
|
||||
|
|
|
@ -1046,14 +1046,15 @@ pic_value
|
|||
pic_apply_trampoline_list(pic_state *pic, struct pic_proc *proc, pic_value args)
|
||||
{
|
||||
size_t i, argc = pic_length(pic, args);
|
||||
pic_value val, it, argv[argc];
|
||||
pic_value val, it;
|
||||
pic_vec *argv = pic_make_vec(pic, argc);
|
||||
|
||||
i = 0;
|
||||
pic_for_each (val, args, it) {
|
||||
argv[i++] = val;
|
||||
argv->data[i++] = val;
|
||||
}
|
||||
|
||||
return pic_apply_trampoline(pic, proc, argc, argv);
|
||||
return pic_apply_trampoline(pic, proc, argc, argv->data);
|
||||
}
|
||||
|
||||
pic_value
|
||||
|
|
Loading…
Reference in New Issue