mirror of
https://github.com/janet-lang/janet
synced 2025-04-20 17:53:14 +00:00
refactor(c-api): backfit the changes in the API functions on the places they are used
This commit is contained in:
parent
3f4f71cf87
commit
5991e48d6d
@ -26,8 +26,6 @@
|
||||
#include "tests.h"
|
||||
|
||||
int array_test() {
|
||||
|
||||
int i;
|
||||
JanetArray *array1, *array2;
|
||||
|
||||
array1 = janet_array(10);
|
||||
@ -53,7 +51,7 @@ int array_test() {
|
||||
janet_array_push(array2, janet_cstringv("six"));
|
||||
janet_array_push(array2, janet_cstringv("seven"));
|
||||
|
||||
for (i = 0; i < array2->count; i++) {
|
||||
for (size_t i = 0; i < array2->count; i++) {
|
||||
assert(janet_equals(array1->data[i], array2->data[i]));
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,6 @@
|
||||
#include "tests.h"
|
||||
|
||||
int buffer_test() {
|
||||
|
||||
int i;
|
||||
JanetBuffer *buffer1, *buffer2;
|
||||
|
||||
buffer1 = janet_buffer(100);
|
||||
@ -54,7 +52,7 @@ int buffer_test() {
|
||||
assert(buffer1->capacity >= buffer1->count);
|
||||
assert(buffer2->capacity >= buffer2->count);
|
||||
|
||||
for (i = 0; i < buffer1->count; i++) {
|
||||
for (size_t i = 0; i < buffer1->count; i++) {
|
||||
assert(buffer1->data[i] == buffer2->data[i]);
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ JANET_CORE_FN(cfun_array_push,
|
||||
"Push all the elements of xs to the end of an array. Modifies the input array and returns it.") {
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetArray *array = janet_getarray(argv, 0);
|
||||
if (JANET_INTMAX_INT64 - argc + 1 <= array->count) {
|
||||
if ((size_t) JANET_INTMAX_INT64 - argc + 1 <= array->count) {
|
||||
janet_panic("array overflow");
|
||||
}
|
||||
size_t newcount = array->count - 1 + argc;
|
||||
@ -248,10 +248,9 @@ JANET_CORE_FN(cfun_array_concat,
|
||||
"which must be an array. If any of the parts are arrays or tuples, their elements will "
|
||||
"be inserted into the array. Otherwise, each part in `parts` will be appended to `arr` in order. "
|
||||
"Return the modified array `arr`.") {
|
||||
size_t i;
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetArray *array = janet_getarray(argv, 0);
|
||||
for (i = 1; i < argc; i++) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
switch (janet_type(argv[i])) {
|
||||
default:
|
||||
janet_array_push(array, argv[i]);
|
||||
@ -284,15 +283,15 @@ JANET_CORE_FN(cfun_array_insert,
|
||||
size_t chunksize, restsize;
|
||||
janet_arity(argc, 2, -1);
|
||||
JanetArray *array = janet_getarray(argv, 0);
|
||||
size_t at = janet_getinteger(argv, 1);
|
||||
int32_t at = janet_getinteger(argv, 1);
|
||||
if (at < 0) {
|
||||
at = array->count + at + 1;
|
||||
}
|
||||
if (at < 0 || at > array->count)
|
||||
if (at < 0 || (size_t) at > array->count)
|
||||
janet_panicf("insertion index %d out of range [0,%d]", at, array->count);
|
||||
chunksize = (argc - 2) * sizeof(Janet);
|
||||
restsize = (array->count - at) * sizeof(Janet);
|
||||
if (JANET_INTMAX_INT64 - (argc - 2) < array->count) {
|
||||
if ((size_t) JANET_INTMAX_INT64 - (argc - 2) < array->count) {
|
||||
janet_panic("array overflow");
|
||||
}
|
||||
janet_array_ensure(array, array->count + argc - 2, 2);
|
||||
@ -314,15 +313,15 @@ JANET_CORE_FN(cfun_array_remove,
|
||||
"Returns the array.") {
|
||||
janet_arity(argc, 2, 3);
|
||||
JanetArray *array = janet_getarray(argv, 0);
|
||||
size_t at = janet_getinteger(argv, 1);
|
||||
int32_t at = janet_getinteger(argv, 1);
|
||||
size_t n = 1;
|
||||
if (at < 0) {
|
||||
at = array->count + at;
|
||||
}
|
||||
if (at < 0 || at > array->count)
|
||||
if (at < 0 || (size_t) at > array->count)
|
||||
janet_panicf("removal index %d out of range [0,%d]", at, array->count);
|
||||
if (argc == 3) {
|
||||
n = janet_getinteger(argv, 2);
|
||||
n = janet_getsize(argv, 2);
|
||||
if (n < 0)
|
||||
janet_panicf("expected non-negative integer for argument n, got %v", argv[2]);
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ static int32_t doarg_1(
|
||||
case JANET_TUPLE: {
|
||||
const Janet *t = janet_unwrap_tuple(x);
|
||||
if (argtype == JANET_OAT_TYPE) {
|
||||
int32_t i = 0;
|
||||
size_t i = 0;
|
||||
ret = 0;
|
||||
for (i = 0; i < janet_tuple_length(t); i++) {
|
||||
ret |= doarg_1(a, JANET_OAT_SIMPLETYPE, t[i]);
|
||||
@ -492,7 +492,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
|
||||
JanetAssembler a;
|
||||
Janet s = source;
|
||||
JanetFuncDef *def;
|
||||
int32_t count, i;
|
||||
size_t count, i;
|
||||
const Janet *arr;
|
||||
Janet x;
|
||||
(void) flags;
|
||||
@ -578,8 +578,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
|
||||
Janet v = arr[i];
|
||||
if (janet_checktype(v, JANET_TUPLE)) {
|
||||
const Janet *t = janet_unwrap_tuple(v);
|
||||
int32_t j;
|
||||
for (j = 0; j < janet_tuple_length(t); j++) {
|
||||
for (size_t j = 0; j < janet_tuple_length(t); j++) {
|
||||
if (!janet_checktype(t[j], JANET_SYMBOL))
|
||||
janet_asm_error(&a, "slot names must be symbols");
|
||||
janet_table_put(&a.slots, t[j], janet_wrap_integer(i));
|
||||
@ -615,8 +614,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
|
||||
x = janet_get1(s, janet_ckeywordv("defs"));
|
||||
}
|
||||
if (janet_indexed_view(x, &arr, &count)) {
|
||||
int32_t i;
|
||||
for (i = 0; i < count; i++) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
JanetAssembleResult subres;
|
||||
Janet subname;
|
||||
int32_t newlen;
|
||||
@ -701,7 +699,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
|
||||
/* Check for source mapping */
|
||||
x = janet_get1(s, janet_ckeywordv("sourcemap"));
|
||||
if (janet_indexed_view(x, &arr, &count)) {
|
||||
janet_asm_assert(&a, count == def->bytecode_length, "sourcemap must have the same length as the bytecode");
|
||||
janet_asm_assert(&a, count == (size_t) def->bytecode_length, "sourcemap must have the same length as the bytecode");
|
||||
def->sourcemap = janet_malloc(sizeof(JanetSourceMapping) * (size_t) count);
|
||||
if (NULL == def->sourcemap) {
|
||||
JANET_OUT_OF_MEMORY;
|
||||
@ -775,7 +773,7 @@ static JanetAssembleResult janet_asm1(JanetAssembler *parent, Janet source, int
|
||||
if (def->environments_length) {
|
||||
def->environments = janet_realloc(def->environments, def->environments_length * sizeof(int32_t));
|
||||
}
|
||||
for (int32_t i = 0; i < count; i++) {
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
if (!janet_checkint(arr[i])) {
|
||||
janet_asm_error(&a, "expected integer");
|
||||
}
|
||||
|
@ -226,9 +226,8 @@ JANET_CORE_FN(cfun_buffer_frombytes,
|
||||
"(buffer/from-bytes & byte-vals)",
|
||||
"Creates a buffer from integer parameters with byte values. All integers "
|
||||
"will be coerced to the range of 1 byte 0-255.") {
|
||||
size_t i;
|
||||
JanetBuffer *buffer = janet_buffer(argc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
for (int32_t i = 0; i < argc; i++) {
|
||||
size_t c = janet_getsize(argv, i);
|
||||
buffer->data[i] = c & 0xFF;
|
||||
}
|
||||
@ -275,10 +274,9 @@ JANET_CORE_FN(cfun_buffer_u8,
|
||||
"(buffer/push-byte buffer & xs)",
|
||||
"Append bytes to a buffer. Will expand the buffer as necessary. "
|
||||
"Returns the modified buffer. Will throw an error if the buffer overflows.") {
|
||||
size_t i;
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||
for (i = 1; i < argc; i++) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
janet_buffer_push_u8(buffer, (uint8_t)(janet_getinteger(argv, i) & 0xFF));
|
||||
}
|
||||
return argv[0];
|
||||
@ -289,10 +287,9 @@ JANET_CORE_FN(cfun_buffer_word,
|
||||
"Append machine words to a buffer. The 4 bytes of the integer are appended "
|
||||
"in twos complement, little endian order, unsigned for all x. Returns the modified buffer. Will "
|
||||
"throw an error if the buffer overflows.") {
|
||||
size_t i;
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||
for (i = 1; i < argc; i++) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
double number = janet_getnumber(argv, i);
|
||||
uint32_t word = (uint32_t) number;
|
||||
if (word != number)
|
||||
@ -308,10 +305,9 @@ JANET_CORE_FN(cfun_buffer_chars,
|
||||
"Will accept any of strings, keywords, symbols, and buffers. "
|
||||
"Returns the modified buffer. "
|
||||
"Will throw an error if the buffer overflows.") {
|
||||
size_t i;
|
||||
janet_arity(argc, 1, -1);
|
||||
JanetBuffer *buffer = janet_getbuffer(argv, 0);
|
||||
for (i = 1; i < argc; i++) {
|
||||
for (int32_t i = 1; i < argc; i++) {
|
||||
JanetByteView view = janet_getbytes(argv, i);
|
||||
if (view.bytes == buffer->data) {
|
||||
janet_buffer_ensure(buffer, buffer->count + view.len, 2);
|
||||
@ -553,7 +549,7 @@ static void bitloc(int32_t argc, Janet *argv, JanetBuffer **b, size_t *index, in
|
||||
int64_t bitindex = (int64_t) x;
|
||||
int64_t byteindex = bitindex >> 3;
|
||||
int which_bit = bitindex & 7;
|
||||
if (bitindex != x || bitindex < 0 || byteindex >= buffer->count)
|
||||
if (bitindex != x || bitindex < 0 || (size_t) byteindex >= buffer->count)
|
||||
janet_panicf("invalid bit index %v", argv[1]);
|
||||
*b = buffer;
|
||||
*index = (size_t) byteindex;
|
||||
|
@ -138,7 +138,7 @@ type janet_opt##name(const Janet *argv, int32_t argc, int32_t n, type dflt) { \
|
||||
}
|
||||
|
||||
#define DEFINE_OPTLEN(name, NAME, type) \
|
||||
type janet_opt##name(const Janet *argv, int32_t argc, int32_t n, int32_t dflt_len) { \
|
||||
type janet_opt##name(const Janet *argv, int32_t argc, int32_t n, size_t dflt_len) { \
|
||||
if (n >= argc || janet_checktype(argv[n], JANET_NIL)) {\
|
||||
return janet_##name(dflt_len); \
|
||||
}\
|
||||
|
@ -718,12 +718,12 @@ JANET_CORE_FN(janet_core_memcmp,
|
||||
janet_arity(argc, 2, 5);
|
||||
JanetByteView a = janet_getbytes(argv, 0);
|
||||
JanetByteView b = janet_getbytes(argv, 1);
|
||||
int32_t len = janet_optnat(argv, argc, 2, a.len < b.len ? a.len : b.len);
|
||||
int32_t offset_a = janet_optnat(argv, argc, 3, 0);
|
||||
int32_t offset_b = janet_optnat(argv, argc, 4, 0);
|
||||
size_t len = janet_optsize(argv, argc, 2, a.len < b.len ? a.len : b.len);
|
||||
size_t offset_a = janet_optsize(argv, argc, 3, 0);
|
||||
size_t offset_b = janet_optsize(argv, argc, 4, 0);
|
||||
if (offset_a + len > a.len) janet_panicf("invalid offset-a: %d", offset_a);
|
||||
if (offset_b + len > b.len) janet_panicf("invalid offset-b: %d", offset_b);
|
||||
return janet_wrap_integer(memcmp(a.bytes + offset_a, b.bytes + offset_b, (size_t) len));
|
||||
return janet_wrap_integer(memcmp(a.bytes + offset_a, b.bytes + offset_b, len));
|
||||
}
|
||||
|
||||
typedef struct SandboxOption {
|
||||
@ -1339,7 +1339,7 @@ JanetTable *janet_core_env(JanetTable *replacements) {
|
||||
janet_resolve(env, janet_csymbol("make-image-dict"), &midv);
|
||||
JanetTable *lid = janet_unwrap_table(lidv);
|
||||
JanetTable *mid = janet_unwrap_table(midv);
|
||||
for (int32_t i = 0; i < lid->capacity; i++) {
|
||||
for (size_t i = 0; i < lid->capacity; i++) {
|
||||
const JanetKV *kv = lid->data + i;
|
||||
if (!janet_checktype(kv->key, JANET_NIL)) {
|
||||
janet_table_put(mid, kv->value, kv->key);
|
||||
@ -1357,7 +1357,7 @@ JanetTable *janet_core_lookup_table(JanetTable *replacements) {
|
||||
|
||||
/* Add replacements */
|
||||
if (replacements != NULL) {
|
||||
for (int32_t i = 0; i < replacements->capacity; i++) {
|
||||
for (size_t i = 0; i < replacements->capacity; i++) {
|
||||
JanetKV kv = replacements->data[i];
|
||||
if (!janet_checktype(kv.key, JANET_NIL)) {
|
||||
janet_table_put(dict, kv.key, kv.value);
|
||||
|
@ -1011,7 +1011,7 @@ JANET_CORE_FN(cfun_channel_pop,
|
||||
|
||||
static void chan_unlock_args(const Janet *argv, int32_t n) {
|
||||
for (int32_t i = 0; i < n; i++) {
|
||||
int32_t len;
|
||||
size_t len;
|
||||
const Janet *data;
|
||||
JanetChannel *chan;
|
||||
if (janet_indexed_view(argv[i], &data, &len) && len == 2) {
|
||||
@ -1036,7 +1036,7 @@ JANET_CORE_FN(cfun_channel_choice,
|
||||
"channel was closed while waiting, or that the channel was already "
|
||||
"closed.") {
|
||||
janet_arity(argc, 1, -1);
|
||||
int32_t len;
|
||||
size_t len;
|
||||
const Janet *data;
|
||||
|
||||
/* Check channels for immediate reads and writes */
|
||||
@ -3185,7 +3185,7 @@ JANET_CORE_FN(janet_cfun_ev_all_tasks,
|
||||
janet_fixarity(argc, 0);
|
||||
(void) argv;
|
||||
JanetArray *array = janet_array(janet_vm.active_tasks.count);
|
||||
for (int32_t i = 0; i < janet_vm.active_tasks.capacity; i++) {
|
||||
for (size_t i = 0; i < janet_vm.active_tasks.capacity; i++) {
|
||||
if (!janet_checktype(janet_vm.active_tasks.data[i].key, JANET_NIL)) {
|
||||
janet_array_push(array, janet_vm.active_tasks.data[i].key);
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ static JanetFFIStruct *build_struct_type(int32_t argc, const Janet *argv) {
|
||||
st->fields[i].offset = st->size;
|
||||
st->size += (uint32_t) el_size;
|
||||
} else {
|
||||
if (el_align > st->align) st->align = (uint32_t) el_align;
|
||||
if (el_align > (size_t) st->align) st->align = (uint32_t) el_align;
|
||||
st->fields[i].offset = (uint32_t)(((st->size + el_align - 1) / el_align) * el_align);
|
||||
st->size = (uint32_t)(el_size + st->fields[i].offset);
|
||||
}
|
||||
@ -518,11 +518,11 @@ static void janet_ffi_write_one(void *to, const Janet *argv, int32_t n, JanetFFI
|
||||
el_type.array_count = -1;
|
||||
size_t el_size = type_size(el_type);
|
||||
JanetView els = janet_getindexed(argv, n);
|
||||
if (els.len != type.array_count) {
|
||||
if (els.len != (size_t) type.array_count) {
|
||||
janet_panicf("bad array length, expected %d, got %d", type.array_count, els.len);
|
||||
}
|
||||
char *cursor = to;
|
||||
for (int32_t i = 0; i < els.len; i++) {
|
||||
for (size_t i = 0; i < els.len; i++) {
|
||||
janet_ffi_write_one(cursor, els.items, i, el_type, recur - 1);
|
||||
cursor += el_size;
|
||||
}
|
||||
@ -541,7 +541,7 @@ static void janet_ffi_write_one(void *to, const Janet *argv, int32_t n, JanetFFI
|
||||
janet_panicf("wrong number of fields in struct, expected %d, got %d",
|
||||
(int32_t) st->field_count, els.len);
|
||||
}
|
||||
for (int32_t i = 0; i < els.len; i++) {
|
||||
for (size_t i = 0; i < els.len; i++) {
|
||||
JanetFFIType tp = st->fields[i].type;
|
||||
janet_ffi_write_one((char *) to + st->fields[i].offset, els.items, i, tp, recur - 1);
|
||||
}
|
||||
@ -1385,10 +1385,10 @@ JANET_CORE_FN(cfun_ffi_buffer_write,
|
||||
janet_sandbox_assert(JANET_SANDBOX_FFI_USE);
|
||||
janet_arity(argc, 2, 4);
|
||||
JanetFFIType type = decode_ffi_type(argv[0]);
|
||||
uint32_t el_size = (uint32_t) type_size(type);
|
||||
size_t el_size = type_size(type);
|
||||
JanetBuffer *buffer = janet_optbuffer(argv, argc, 2, el_size);
|
||||
int32_t index = janet_optnat(argv, argc, 3, 0);
|
||||
int32_t old_count = buffer->count;
|
||||
size_t index = janet_optsize(argv, argc, 3, 0);
|
||||
size_t old_count = buffer->count;
|
||||
if (index > old_count) janet_panic("index out of bounds");
|
||||
buffer->count = index;
|
||||
janet_buffer_extra(buffer, el_size);
|
||||
|
@ -69,7 +69,7 @@ static JanetFiber *fiber_alloc(size_t capacity) {
|
||||
|
||||
/* Create a new fiber with argn values on the stack by reusing a fiber. */
|
||||
JanetFiber *janet_fiber_reset(JanetFiber *fiber, JanetFunction *callee, int32_t argc, const Janet *argv) {
|
||||
int32_t newstacktop;
|
||||
size_t newstacktop;
|
||||
fiber_reset(fiber);
|
||||
if (argc) {
|
||||
newstacktop = fiber->stacktop + argc;
|
||||
@ -147,7 +147,7 @@ void janet_fiber_push(JanetFiber *fiber, Janet x) {
|
||||
/* Push 2 values on the next stack frame */
|
||||
void janet_fiber_push2(JanetFiber *fiber, Janet x, Janet y) {
|
||||
if (fiber->stacktop >= INT32_MAX - 1) janet_panic("stack overflow");
|
||||
int32_t newtop = fiber->stacktop + 2;
|
||||
size_t newtop = fiber->stacktop + 2;
|
||||
if (newtop > fiber->capacity) {
|
||||
janet_fiber_grow(fiber, newtop);
|
||||
}
|
||||
@ -159,7 +159,7 @@ void janet_fiber_push2(JanetFiber *fiber, Janet x, Janet y) {
|
||||
/* Push 3 values on the next stack frame */
|
||||
void janet_fiber_push3(JanetFiber *fiber, Janet x, Janet y, Janet z) {
|
||||
if (fiber->stacktop >= INT32_MAX - 2) janet_panic("stack overflow");
|
||||
int32_t newtop = fiber->stacktop + 3;
|
||||
size_t newtop = fiber->stacktop + 3;
|
||||
if (newtop > fiber->capacity) {
|
||||
janet_fiber_grow(fiber, newtop);
|
||||
}
|
||||
@ -171,8 +171,8 @@ void janet_fiber_push3(JanetFiber *fiber, Janet x, Janet y, Janet z) {
|
||||
|
||||
/* Push an array on the next stack frame */
|
||||
void janet_fiber_pushn(JanetFiber *fiber, const Janet *arr, int32_t n) {
|
||||
if (fiber->stacktop > INT32_MAX - n) janet_panic("stack overflow");
|
||||
int32_t newtop = fiber->stacktop + n;
|
||||
if (fiber->stacktop > (size_t) INT32_MAX - n) janet_panic("stack overflow");
|
||||
size_t newtop = fiber->stacktop + n;
|
||||
if (newtop > fiber->capacity) {
|
||||
janet_fiber_grow(fiber, newtop);
|
||||
}
|
||||
@ -194,12 +194,12 @@ static Janet make_struct_n(const Janet *args, size_t n) {
|
||||
int janet_fiber_funcframe(JanetFiber *fiber, JanetFunction *func) {
|
||||
JanetStackFrame *newframe;
|
||||
|
||||
int32_t i;
|
||||
int32_t oldtop = fiber->stacktop;
|
||||
int32_t oldframe = fiber->frame;
|
||||
int32_t nextframe = fiber->stackstart;
|
||||
int32_t nextstacktop = nextframe + func->def->slotcount + JANET_FRAME_SIZE;
|
||||
int32_t next_arity = fiber->stacktop - fiber->stackstart;
|
||||
size_t i;
|
||||
size_t oldtop = fiber->stacktop;
|
||||
size_t oldframe = fiber->frame;
|
||||
size_t nextframe = fiber->stackstart;
|
||||
size_t nextstacktop = nextframe + func->def->slotcount + JANET_FRAME_SIZE;
|
||||
int32_t next_arity = (int32_t) fiber->stacktop - fiber->stackstart;
|
||||
|
||||
/* Check strict arity before messing with state */
|
||||
if (next_arity < func->def->min_arity) return 1;
|
||||
@ -230,7 +230,7 @@ int janet_fiber_funcframe(JanetFiber *fiber, JanetFunction *func) {
|
||||
|
||||
/* Check varargs */
|
||||
if (func->def->flags & JANET_FUNCDEF_FLAG_VARARG) {
|
||||
int32_t tuplehead = fiber->frame + func->def->arity;
|
||||
size_t tuplehead = fiber->frame + (size_t) func->def->arity;
|
||||
int st = func->def->flags & JANET_FUNCDEF_FLAG_STRUCTARG;
|
||||
if (tuplehead >= oldtop) {
|
||||
fiber->data[tuplehead] = st
|
||||
@ -331,11 +331,11 @@ void janet_env_maybe_detach(JanetFuncEnv *env) {
|
||||
|
||||
/* Create a tail frame for a function */
|
||||
int janet_fiber_funcframe_tail(JanetFiber *fiber, JanetFunction *func) {
|
||||
int32_t i;
|
||||
int32_t nextframetop = fiber->frame + func->def->slotcount;
|
||||
int32_t nextstacktop = nextframetop + JANET_FRAME_SIZE;
|
||||
int32_t next_arity = fiber->stacktop - fiber->stackstart;
|
||||
int32_t stacksize;
|
||||
size_t i;
|
||||
size_t nextframetop = fiber->frame + func->def->slotcount;
|
||||
size_t nextstacktop = nextframetop + JANET_FRAME_SIZE;
|
||||
int32_t next_arity = (int32_t) fiber->stacktop - fiber->stackstart;
|
||||
size_t stacksize;
|
||||
|
||||
/* Check strict arity before messing with state */
|
||||
if (next_arity < func->def->min_arity) return 1;
|
||||
@ -359,7 +359,7 @@ int janet_fiber_funcframe_tail(JanetFiber *fiber, JanetFunction *func) {
|
||||
|
||||
/* Check varargs */
|
||||
if (func->def->flags & JANET_FUNCDEF_FLAG_VARARG) {
|
||||
int32_t tuplehead = fiber->stackstart + func->def->arity;
|
||||
size_t tuplehead = fiber->stackstart + (size_t) func->def->arity;
|
||||
int st = func->def->flags & JANET_FUNCDEF_FLAG_STRUCTARG;
|
||||
if (tuplehead >= fiber->stacktop) {
|
||||
if (tuplehead >= fiber->capacity) janet_fiber_setcapacity(fiber, 2 * (tuplehead + 1));
|
||||
@ -403,9 +403,9 @@ int janet_fiber_funcframe_tail(JanetFiber *fiber, JanetFunction *func) {
|
||||
void janet_fiber_cframe(JanetFiber *fiber, JanetCFunction cfun) {
|
||||
JanetStackFrame *newframe;
|
||||
|
||||
int32_t oldframe = fiber->frame;
|
||||
int32_t nextframe = fiber->stackstart;
|
||||
int32_t nextstacktop = fiber->stacktop + JANET_FRAME_SIZE;
|
||||
size_t oldframe = fiber->frame;
|
||||
size_t nextframe = fiber->stackstart;
|
||||
size_t nextstacktop = fiber->stacktop + JANET_FRAME_SIZE;
|
||||
|
||||
if (fiber->capacity < nextstacktop) {
|
||||
janet_fiber_setcapacity(fiber, 2 * nextstacktop);
|
||||
@ -519,11 +519,10 @@ JANET_CORE_FN(cfun_fiber_new,
|
||||
fiber->env = janet_gettable(argv, 2);
|
||||
}
|
||||
if (argc >= 2) {
|
||||
int32_t i;
|
||||
JanetByteView view = janet_getbytes(argv, 1);
|
||||
fiber->flags = JANET_FIBER_RESUME_NO_USEVAL | JANET_FIBER_RESUME_NO_SKIP;
|
||||
janet_fiber_set_status(fiber, JANET_STATUS_NEW);
|
||||
for (i = 0; i < view.len; i++) {
|
||||
for (size_t i = 0; i < view.len; i++) {
|
||||
if (view.bytes[i] >= '0' && view.bytes[i] <= '9') {
|
||||
fiber->flags |= JANET_FIBER_MASK_USERN(view.bytes[i] - '0');
|
||||
} else {
|
||||
|
@ -70,7 +70,7 @@
|
||||
|
||||
#define janet_stack_frame(s) ((JanetStackFrame *)((s) - JANET_FRAME_SIZE))
|
||||
#define janet_fiber_frame(f) janet_stack_frame((f)->data + (f)->frame)
|
||||
void janet_fiber_setcapacity(JanetFiber *fiber, int32_t n);
|
||||
void janet_fiber_setcapacity(JanetFiber *fiber, size_t n);
|
||||
void janet_fiber_push(JanetFiber *fiber, Janet x);
|
||||
void janet_fiber_push2(JanetFiber *fiber, Janet x, Janet y);
|
||||
void janet_fiber_push3(JanetFiber *fiber, Janet x, Janet y, Janet z);
|
||||
|
@ -481,7 +481,7 @@ void janet_sweep() {
|
||||
#ifdef JANET_EV
|
||||
/* Sweep threaded abstract types for references to decrement */
|
||||
JanetKV *items = janet_vm.threaded_abstracts.data;
|
||||
for (int32_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
|
||||
for (size_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
|
||||
if (janet_checktype(items[i].key, JANET_ABSTRACT)) {
|
||||
|
||||
/* If item was not visited during the mark phase, then this
|
||||
@ -665,7 +665,7 @@ int janet_gcunrootall(Janet root) {
|
||||
void janet_clear_memory(void) {
|
||||
#ifdef JANET_EV
|
||||
JanetKV *items = janet_vm.threaded_abstracts.data;
|
||||
for (int32_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
|
||||
for (size_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
|
||||
if (janet_checktype(items[i].key, JANET_ABSTRACT)) {
|
||||
void *abst = janet_unwrap_abstract(items[i].key);
|
||||
if (0 == janet_abstract_decref(abst)) {
|
||||
|
@ -204,11 +204,11 @@ JANET_CORE_FN(cfun_io_fread,
|
||||
} else {
|
||||
buffer = janet_getbuffer(argv, 2);
|
||||
}
|
||||
int32_t bufstart = buffer->count;
|
||||
size_t bufstart = buffer->count;
|
||||
if (janet_checktype(argv[1], JANET_KEYWORD)) {
|
||||
const uint8_t *sym = janet_unwrap_keyword(argv[1]);
|
||||
if (!janet_cstrcmp(sym, "all")) {
|
||||
int32_t sizeBefore;
|
||||
size_t sizeBefore;
|
||||
do {
|
||||
sizeBefore = buffer->count;
|
||||
read_chunk(iof, buffer, 4096);
|
||||
|
@ -96,7 +96,7 @@ static Janet entry_getval(Janet env_entry) {
|
||||
/* Merge values from an environment into an existing lookup table. */
|
||||
void janet_env_lookup_into(JanetTable *renv, JanetTable *env, const char *prefix, int recurse) {
|
||||
while (env) {
|
||||
for (int32_t i = 0; i < env->capacity; i++) {
|
||||
for (size_t i = 0; i < env->capacity; i++) {
|
||||
if (janet_checktype(env->data[i].key, JANET_SYMBOL)) {
|
||||
if (prefix) {
|
||||
int32_t prelen = (int32_t) strlen(prefix);
|
||||
@ -566,12 +566,11 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
|
||||
return;
|
||||
}
|
||||
case JANET_ARRAY: {
|
||||
int32_t i;
|
||||
JanetArray *a = janet_unwrap_array(x);
|
||||
MARK_SEEN();
|
||||
pushbyte(st, LB_ARRAY);
|
||||
pushint(st, a->count);
|
||||
for (i = 0; i < a->count; i++)
|
||||
for (size_t i = 0; i < a->count; i++)
|
||||
marshal_one(st, a->data[i], flags + 1);
|
||||
return;
|
||||
}
|
||||
@ -596,7 +595,7 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
|
||||
pushint(st, t->count);
|
||||
if (t->proto)
|
||||
marshal_one(st, janet_wrap_table(t->proto), flags + 1);
|
||||
for (int32_t i = 0; i < t->capacity; i++) {
|
||||
for (size_t i = 0; i < t->capacity; i++) {
|
||||
if (janet_checktype(t->data[i].key, JANET_NIL))
|
||||
continue;
|
||||
marshal_one(st, t->data[i].key, flags + 1);
|
||||
@ -612,7 +611,7 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
|
||||
pushint(st, count);
|
||||
if (janet_struct_proto(struct_))
|
||||
marshal_one(st, janet_wrap_struct(janet_struct_proto(struct_)), flags + 1);
|
||||
for (int32_t i = 0; i < janet_struct_capacity(struct_); i++) {
|
||||
for (size_t i = 0; i < janet_struct_capacity(struct_); i++) {
|
||||
if (janet_checktype(struct_[i].key, JANET_NIL))
|
||||
continue;
|
||||
marshal_one(st, struct_[i].key, flags + 1);
|
||||
@ -1094,7 +1093,7 @@ static const uint8_t *unmarshal_one_fiber(
|
||||
if (!fiber->data) {
|
||||
JANET_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < fiber->capacity; i++) {
|
||||
for (size_t i = 0; i < fiber->capacity; i++) {
|
||||
fiber->data[i] = janet_wrap_nil();
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ static EnvBlock os_execute_env(int32_t argc, const Janet *argv) {
|
||||
#else
|
||||
char **envp = janet_smalloc(sizeof(char *) * ((size_t)dict.len + 1));
|
||||
int32_t j = 0;
|
||||
for (int32_t i = 0; i < dict.cap; i++) {
|
||||
for (size_t i = 0; i < dict.cap; i++) {
|
||||
const JanetKV *kv = dict.kvs + i;
|
||||
if (!janet_checktype(kv->key, JANET_STRING)) continue;
|
||||
if (!janet_checktype(kv->value, JANET_STRING)) continue;
|
||||
@ -1247,7 +1247,7 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, JanetExecuteMode mode) {
|
||||
int status = 0;
|
||||
|
||||
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
|
||||
for (int32_t i = 0; i < exargs.len; i++)
|
||||
for (size_t i = 0; i < exargs.len; i++)
|
||||
child_argv[i] = janet_getcstring(exargs.items, i);
|
||||
child_argv[exargs.len] = NULL;
|
||||
/* Coerce to form that works for spawn. I'm fairly confident no implementation
|
||||
|
@ -920,13 +920,13 @@ JANET_CORE_FN(cfun_parse_consume,
|
||||
JanetParser *p = janet_getabstract(argv, 0, &janet_parser_type);
|
||||
JanetByteView view = janet_getbytes(argv, 1);
|
||||
if (argc == 3) {
|
||||
int32_t offset = janet_getinteger(argv, 2);
|
||||
size_t offset = janet_getsize(argv, 2);
|
||||
if (offset < 0 || offset > view.len)
|
||||
janet_panicf("invalid offset %d out of range [0,%d]", offset, view.len);
|
||||
view.len -= offset;
|
||||
view.bytes += offset;
|
||||
}
|
||||
int32_t i;
|
||||
size_t i;
|
||||
for (i = 0; i < view.len; i++) {
|
||||
janet_parser_consume(p, view.bytes[i]);
|
||||
switch (janet_parser_status(p)) {
|
||||
@ -934,10 +934,10 @@ JANET_CORE_FN(cfun_parse_consume,
|
||||
case JANET_PARSE_PENDING:
|
||||
break;
|
||||
default:
|
||||
return janet_wrap_integer(i + 1);
|
||||
return janet_wrap_size(i + 1);
|
||||
}
|
||||
}
|
||||
return janet_wrap_integer(i);
|
||||
return janet_wrap_size(i);
|
||||
}
|
||||
|
||||
JANET_CORE_FN(cfun_parse_eof,
|
||||
|
@ -597,7 +597,7 @@ tail:
|
||||
case RULE_ERROR: {
|
||||
int oldmode = s->mode;
|
||||
s->mode = PEG_MODE_NORMAL;
|
||||
int32_t old_cap = s->captures->count;
|
||||
size_t old_cap = s->captures->count;
|
||||
down1(s);
|
||||
const uint8_t *result = peg_rule(s, s->bytecode + rule[1], text);
|
||||
up1(s);
|
||||
@ -925,7 +925,7 @@ static void spec_set(Builder *b, int32_t argc, const Janet *argv) {
|
||||
Reserve r = reserve(b, 9);
|
||||
const uint8_t *str = peg_getset(b, argv[0]);
|
||||
uint32_t bitmap[8] = {0};
|
||||
for (int32_t i = 0; i < janet_string_length(str); i++)
|
||||
for (size_t i = 0; i < janet_string_length(str); i++)
|
||||
bitmap_set(bitmap, str[i]);
|
||||
emit_rule(r, RULE_SET, 8, bitmap);
|
||||
}
|
||||
@ -1384,7 +1384,7 @@ static uint32_t peg_compile1(Builder *b, Janet peg) {
|
||||
/* Build grammar table */
|
||||
const JanetKV *st = janet_unwrap_struct(peg);
|
||||
JanetTable *new_grammar = janet_table(2 * janet_struct_capacity(st));
|
||||
for (int32_t i = 0; i < janet_struct_capacity(st); i++) {
|
||||
for (size_t i = 0; i < janet_struct_capacity(st); i++) {
|
||||
if (janet_checktype(st[i].key, JANET_KEYWORD)) {
|
||||
janet_table_put(new_grammar, st[i].key, st[i].value);
|
||||
}
|
||||
@ -1805,7 +1805,7 @@ JANET_CORE_FN(cfun_peg_find,
|
||||
"(peg/find peg text &opt start & args)",
|
||||
"Find first index where the peg matches in text. Returns an integer, or nil if not found.") {
|
||||
PegCall c = peg_cfun_init(argc, argv, 0);
|
||||
for (int32_t i = c.start; i < c.bytes.len; i++) {
|
||||
for (size_t i = c.start; i < c.bytes.len; i++) {
|
||||
peg_call_reset(&c);
|
||||
if (peg_rule(&c.s, c.s.bytecode, c.bytes.bytes + i))
|
||||
return janet_wrap_integer(i);
|
||||
@ -1818,7 +1818,7 @@ JANET_CORE_FN(cfun_peg_find_all,
|
||||
"Find all indexes where the peg matches in text. Returns an array of integers.") {
|
||||
PegCall c = peg_cfun_init(argc, argv, 0);
|
||||
JanetArray *ret = janet_array(0);
|
||||
for (int32_t i = c.start; i < c.bytes.len; i++) {
|
||||
for (size_t i = c.start; i < c.bytes.len; i++) {
|
||||
peg_call_reset(&c);
|
||||
if (peg_rule(&c.s, c.s.bytecode, c.bytes.bytes + i))
|
||||
janet_array_push(ret, janet_wrap_integer(i));
|
||||
@ -1829,8 +1829,8 @@ JANET_CORE_FN(cfun_peg_find_all,
|
||||
static Janet cfun_peg_replace_generic(int32_t argc, Janet *argv, int only_one) {
|
||||
PegCall c = peg_cfun_init(argc, argv, 1);
|
||||
JanetBuffer *ret = janet_buffer(0);
|
||||
int32_t trail = 0;
|
||||
for (int32_t i = c.start; i < c.bytes.len;) {
|
||||
size_t trail = 0;
|
||||
for (size_t i = c.start; i < c.bytes.len;) {
|
||||
peg_call_reset(&c);
|
||||
const uint8_t *result = peg_rule(&c.s, c.s.bytecode, c.bytes.bytes + i);
|
||||
if (NULL != result) {
|
||||
@ -1838,7 +1838,7 @@ static Janet cfun_peg_replace_generic(int32_t argc, Janet *argv, int only_one) {
|
||||
janet_buffer_push_bytes(ret, c.bytes.bytes + trail, (i - trail));
|
||||
trail = i;
|
||||
}
|
||||
int32_t nexti = (int32_t)(result - c.bytes.bytes);
|
||||
size_t nexti = (size_t)(result - c.bytes.bytes);
|
||||
JanetByteView subst = janet_text_substitution(&c.subst, c.bytes.bytes + i, nexti - i, c.s.captures);
|
||||
janet_buffer_push_bytes(ret, subst.bytes, subst.len);
|
||||
trail = nexti;
|
||||
|
@ -391,7 +391,7 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) {
|
||||
JanetTuple t = janet_unwrap_tuple(x);
|
||||
int isb = janet_tuple_flag(t) & JANET_TUPLE_FLAG_BRACKETCTOR;
|
||||
janet_buffer_push_u8(S->buffer, isb ? '[' : '(');
|
||||
for (int32_t i = 0; i < janet_tuple_length(t); i++) {
|
||||
for (size_t i = 0; i < janet_tuple_length(t); i++) {
|
||||
if (i) janet_buffer_push_u8(S->buffer, ' ');
|
||||
if (print_jdn_one(S, t[i], depth - 1)) return 1;
|
||||
}
|
||||
@ -402,7 +402,7 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) {
|
||||
janet_table_put(&S->seen, x, janet_wrap_true());
|
||||
JanetArray *a = janet_unwrap_array(x);
|
||||
janet_buffer_push_cstring(S->buffer, "@[");
|
||||
for (int32_t i = 0; i < a->count; i++) {
|
||||
for (size_t i = 0; i < a->count; i++) {
|
||||
if (i) janet_buffer_push_u8(S->buffer, ' ');
|
||||
if (print_jdn_one(S, a->data[i], depth - 1)) return 1;
|
||||
}
|
||||
@ -414,7 +414,7 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) {
|
||||
JanetTable *tab = janet_unwrap_table(x);
|
||||
janet_buffer_push_cstring(S->buffer, "@{");
|
||||
int isFirst = 1;
|
||||
for (int32_t i = 0; i < tab->capacity; i++) {
|
||||
for (size_t i = 0; i < tab->capacity; i++) {
|
||||
const JanetKV *kv = tab->data + i;
|
||||
if (janet_checktype(kv->key, JANET_NIL)) continue;
|
||||
if (!isFirst) janet_buffer_push_u8(S->buffer, ' ');
|
||||
@ -430,7 +430,7 @@ static int print_jdn_one(struct pretty *S, Janet x, int depth) {
|
||||
JanetStruct st = janet_unwrap_struct(x);
|
||||
janet_buffer_push_u8(S->buffer, '{');
|
||||
int isFirst = 1;
|
||||
for (int32_t i = 0; i < janet_struct_capacity(st); i++) {
|
||||
for (size_t i = 0; i < janet_struct_capacity(st); i++) {
|
||||
const JanetKV *kv = st + i;
|
||||
if (janet_checktype(kv->key, JANET_NIL)) continue;
|
||||
if (!isFirst) janet_buffer_push_u8(S->buffer, ' ');
|
||||
|
@ -30,7 +30,7 @@
|
||||
int janet_dobytes(JanetTable *env, const uint8_t *bytes, size_t len, const char *sourcePath, Janet *out) {
|
||||
JanetParser parser;
|
||||
int errflags = 0, done = 0;
|
||||
int32_t index = 0;
|
||||
size_t index = 0;
|
||||
Janet ret = janet_wrap_nil();
|
||||
JanetFiber *fiber = NULL;
|
||||
const uint8_t *where = sourcePath ? janet_cstring(sourcePath) : NULL;
|
||||
|
@ -96,9 +96,8 @@ static JanetSlot quasiquote(JanetFopts opts, Janet x, int depth, int level) {
|
||||
: JOP_MAKE_TUPLE);
|
||||
}
|
||||
case JANET_ARRAY: {
|
||||
int32_t i;
|
||||
JanetArray *array = janet_unwrap_array(x);
|
||||
for (i = 0; i < array->count; i++)
|
||||
for (size_t i = 0; i < array->count; i++)
|
||||
janet_v_push(slots, quasiquote(subopts, array->data[i], depth - 1, level));
|
||||
return qq_slots(opts, slots, JOP_MAKE_ARRAY);
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ const uint8_t *janet_cstring(const char *str) {
|
||||
/* Knuth Morris Pratt Algorithm */
|
||||
|
||||
struct kmp_state {
|
||||
int32_t i;
|
||||
int32_t j;
|
||||
size_t i;
|
||||
size_t j;
|
||||
size_t textlen;
|
||||
size_t patlen;
|
||||
int32_t *lookup;
|
||||
@ -121,7 +121,8 @@ static void kmp_init(
|
||||
s->patlen = patlen;
|
||||
/* Init state machine */
|
||||
{
|
||||
int32_t i, j;
|
||||
size_t i;
|
||||
int32_t j;
|
||||
for (i = 1, j = 0; i < patlen; i++) {
|
||||
while (j && pat[j] != pat[i]) j = lookup[j - 1];
|
||||
if (pat[j] == pat[i]) j++;
|
||||
@ -140,8 +141,8 @@ static void kmp_seti(struct kmp_state *state, int32_t i) {
|
||||
}
|
||||
|
||||
static int32_t kmp_next(struct kmp_state *state) {
|
||||
int32_t i = state->i;
|
||||
int32_t j = state->j;
|
||||
size_t i = state->i;
|
||||
size_t j = state->j;
|
||||
size_t textlen = state->textlen;
|
||||
size_t patlen = state->patlen;
|
||||
const uint8_t *text = state->text;
|
||||
@ -270,7 +271,7 @@ JANET_CORE_FN(cfun_string_asciiupper,
|
||||
janet_fixarity(argc, 1);
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
uint8_t *buf = janet_string_begin(view.len);
|
||||
for (int32_t i = 0; i < view.len; i++) {
|
||||
for (size_t i = 0; i < view.len; i++) {
|
||||
uint8_t c = view.bytes[i];
|
||||
if (c >= 97 && c <= 122) {
|
||||
buf[i] = c - 32;
|
||||
@ -287,7 +288,7 @@ JANET_CORE_FN(cfun_string_reverse,
|
||||
janet_fixarity(argc, 1);
|
||||
JanetByteView view = janet_getbytes(argv, 0);
|
||||
uint8_t *buf = janet_string_begin(view.len);
|
||||
int32_t i, j;
|
||||
size_t i, j;
|
||||
for (i = 0, j = view.len - 1; i < view.len; i++, j--) {
|
||||
buf[i] = view.bytes[j];
|
||||
}
|
||||
@ -474,13 +475,13 @@ JANET_CORE_FN(cfun_string_checkset,
|
||||
JanetByteView set = janet_getbytes(argv, 0);
|
||||
JanetByteView str = janet_getbytes(argv, 1);
|
||||
/* Populate set */
|
||||
for (int32_t i = 0; i < set.len; i++) {
|
||||
for (size_t i = 0; i < set.len; i++) {
|
||||
int index = set.bytes[i] >> 5;
|
||||
uint32_t mask = 1 << (set.bytes[i] & 0x1F);
|
||||
bitset[index] |= mask;
|
||||
}
|
||||
/* Check set */
|
||||
for (int32_t i = 0; i < str.len; i++) {
|
||||
for (size_t i = 0; i < str.len; i++) {
|
||||
int index = str.bytes[i] >> 5;
|
||||
uint32_t mask = 1 << (str.bytes[i] & 0x1F);
|
||||
if (!(bitset[index] & mask)) {
|
||||
|
@ -54,7 +54,7 @@ const JanetKV *janet_struct_find(const JanetKV *st, Janet key) {
|
||||
for (i = index; i < cap; i++)
|
||||
if (janet_checktype(st[i].key, JANET_NIL) || janet_equals(st[i].key, key))
|
||||
return st + i;
|
||||
for (i = 0; i < index; i++)
|
||||
for (i = 0; i < (size_t) index; i++)
|
||||
if (janet_checktype(st[i].key, JANET_NIL) || janet_equals(st[i].key, key))
|
||||
return st + i;
|
||||
return NULL;
|
||||
@ -77,7 +77,7 @@ void janet_struct_put_ext(JanetKV *st, Janet key, Janet value, int replace) {
|
||||
if (janet_checktype(key, JANET_NIL) || janet_checktype(value, JANET_NIL)) return;
|
||||
if (janet_checktype(key, JANET_NUMBER) && isnan(janet_unwrap_number(key))) return;
|
||||
/* Avoid extra items */
|
||||
if (janet_struct_hash(st) == janet_struct_length(st)) return;
|
||||
if ((size_t) janet_struct_hash(st) == janet_struct_length(st)) return;
|
||||
for (dist = 0, j = 0; j < 4; j += 2)
|
||||
for (i = bounds[j]; i < bounds[j + 1]; i++, dist++) {
|
||||
int status;
|
||||
@ -138,7 +138,7 @@ void janet_struct_put(JanetKV *st, Janet key, Janet value) {
|
||||
|
||||
/* Finish building a struct */
|
||||
const JanetKV *janet_struct_end(JanetKV *st) {
|
||||
if (janet_struct_hash(st) != janet_struct_length(st)) {
|
||||
if ((size_t) janet_struct_hash(st) != janet_struct_length(st)) {
|
||||
/* Error building struct, probably duplicate values. We need to rebuild
|
||||
* the struct using only the values that went in. The second creation should always
|
||||
* succeed. */
|
||||
|
@ -302,7 +302,7 @@ const JanetKV *janet_dict_find(const JanetKV *buckets, size_t cap, Janet key) {
|
||||
}
|
||||
}
|
||||
/* Lower half */
|
||||
for (i = 0; i < index; i++) {
|
||||
for (i = 0; i < (size_t) index; i++) {
|
||||
const JanetKV *kv = buckets + i;
|
||||
if (janet_checktype(kv->key, JANET_NIL)) {
|
||||
if (janet_checktype(kv->value, JANET_NIL)) {
|
||||
@ -847,21 +847,21 @@ JanetTable *janet_get_core_table(const char *name) {
|
||||
}
|
||||
|
||||
/* Sort keys of a dictionary type */
|
||||
int32_t janet_sorted_keys(const JanetKV *dict, int32_t cap, int32_t *index_buffer) {
|
||||
int32_t janet_sorted_keys(const JanetKV *dict, size_t cap, int32_t *index_buffer) {
|
||||
|
||||
/* First, put populated indices into index_buffer */
|
||||
int32_t next_index = 0;
|
||||
for (int32_t i = 0; i < cap; i++) {
|
||||
size_t next_index = 0;
|
||||
for (size_t i = 0; i < cap; i++) {
|
||||
if (!janet_checktype(dict[i].key, JANET_NIL)) {
|
||||
index_buffer[next_index++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Next, sort those (simple insertion sort here for now) */
|
||||
for (int32_t i = 1; i < next_index; i++) {
|
||||
for (size_t i = 1; i < next_index; i++) {
|
||||
int32_t index_to_insert = index_buffer[i];
|
||||
Janet lhs = dict[index_to_insert].key;
|
||||
for (int32_t j = i - 1; j >= 0; j--) {
|
||||
for (size_t j = i - 1; j >= 0; j--) {
|
||||
index_buffer[j + 1] = index_buffer[j];
|
||||
Janet rhs = dict[index_buffer[j]].key;
|
||||
if (janet_compare(lhs, rhs) >= 0) {
|
||||
|
@ -997,7 +997,7 @@ static JanetSignal run_vm(JanetFiber *fiber, Janet in) {
|
||||
|
||||
VM_OP(JOP_PUSH_ARRAY) {
|
||||
const Janet *vals;
|
||||
int32_t len;
|
||||
size_t len;
|
||||
if (janet_indexed_view(stack[D], &vals, &len)) {
|
||||
janet_fiber_pushn(fiber, vals, len);
|
||||
} else {
|
||||
|
@ -924,11 +924,11 @@ struct JanetGCObject {
|
||||
struct JanetFiber {
|
||||
JanetGCObject gc; /* GC Object stuff */
|
||||
int32_t flags; /* More flags */
|
||||
int32_t frame; /* Index of the stack frame */
|
||||
int32_t stackstart; /* Beginning of next args */
|
||||
int32_t stacktop; /* Top of stack. Where values are pushed and popped from. */
|
||||
size_t frame; /* Index of the stack frame */
|
||||
size_t stackstart; /* Beginning of next args */
|
||||
size_t stacktop; /* Top of stack. Where values are pushed and popped from. */
|
||||
size_t capacity; /* How big is the stack memory */
|
||||
int32_t maxstack; /* Arbitrary defined limit for stack overflow */
|
||||
size_t maxstack; /* Arbitrary defined limit for stack overflow */
|
||||
JanetTable *env; /* Dynamic bindings table (usually current environment). */
|
||||
Janet *data; /* Dynamically resized stack memory */
|
||||
JanetFiber *child; /* Keep linked list of fibers for restarting pending fibers */
|
||||
@ -1658,7 +1658,7 @@ JANET_API JanetString janet_string(const uint8_t *buf, size_t len);
|
||||
JANET_API JanetString janet_cstring(const char *cstring);
|
||||
JANET_API int janet_string_compare(JanetString lhs, JanetString rhs);
|
||||
JANET_API int janet_string_equal(JanetString lhs, JanetString rhs);
|
||||
JANET_API int janet_string_equalconst(JanetString lhs, const uint8_t *rhs, size_t rlen, size_t rhash);
|
||||
JANET_API int janet_string_equalconst(JanetString lhs, const uint8_t *rhs, size_t rlen, int32_t rhash);
|
||||
JANET_API JanetString janet_description(Janet x);
|
||||
JANET_API JanetString janet_to_string(Janet x);
|
||||
JANET_API void janet_to_string_b(JanetBuffer *buffer, Janet x);
|
||||
@ -1808,13 +1808,13 @@ JANET_API Janet janet_getindex(Janet ds, size_t index);
|
||||
JANET_API size_t janet_length(Janet x);
|
||||
JANET_API Janet janet_lengthv(Janet x);
|
||||
JANET_API void janet_put(Janet ds, Janet key, Janet value);
|
||||
JANET_API void janet_putindex(Janet ds, int32_t index, Janet value);
|
||||
JANET_API void janet_putindex(Janet ds, size_t index, Janet value);
|
||||
#define janet_flag_at(F, I) ((F) & ((1ULL) << (I)))
|
||||
JANET_API Janet janet_wrap_number_safe(double x);
|
||||
JANET_API int janet_keyeq(Janet x, const char *cstring);
|
||||
JANET_API int janet_streq(Janet x, const char *cstring);
|
||||
JANET_API int janet_symeq(Janet x, const char *cstring);
|
||||
JANET_API int32_t janet_sorted_keys(const JanetKV *dict, int32_t cap, int32_t *index_buffer);
|
||||
JANET_API int32_t janet_sorted_keys(const JanetKV *dict, size_t cap, int32_t *index_buffer);
|
||||
|
||||
/* VM functions */
|
||||
JANET_API int janet_init(void);
|
||||
@ -2051,9 +2051,9 @@ JANET_API size_t janet_optsize(const Janet *argv, int32_t argc, int32_t n, size_
|
||||
JANET_API JanetAbstract janet_optabstract(const Janet *argv, int32_t argc, int32_t n, const JanetAbstractType *at, JanetAbstract dflt);
|
||||
|
||||
/* Mutable optional types specify a size default, and construct a new value if none is provided */
|
||||
JANET_API JanetBuffer *janet_optbuffer(const Janet *argv, int32_t argc, int32_t n, int32_t dflt_len);
|
||||
JANET_API JanetTable *janet_opttable(const Janet *argv, int32_t argc, int32_t n, int32_t dflt_len);
|
||||
JANET_API JanetArray *janet_optarray(const Janet *argv, int32_t argc, int32_t n, int32_t dflt_len);
|
||||
JANET_API JanetBuffer *janet_optbuffer(const Janet *argv, int32_t argc, int32_t n, size_t dflt_len);
|
||||
JANET_API JanetTable *janet_opttable(const Janet *argv, int32_t argc, int32_t n, size_t dflt_len);
|
||||
JANET_API JanetArray *janet_optarray(const Janet *argv, int32_t argc, int32_t n, size_t dflt_len);
|
||||
|
||||
JANET_API Janet janet_dyn(const char *name);
|
||||
JANET_API void janet_setdyn(const char *name, Janet value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user