unification uses of int and size_t. use size_t for every variable that
can possibly be used as an array index.
This commit is contained in:
parent
223c531a3c
commit
8ae55bd9b6
|
@ -151,7 +151,7 @@ struct pic_string *pic_str_new_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
struct pic_vector *pic_vec_new(pic_state *, size_t);
|
struct pic_vector *pic_vec_new(pic_state *, size_t);
|
||||||
struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value);
|
struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value);
|
||||||
void pic_vec_extend_ip(pic_state *, struct pic_vector *, int);
|
void pic_vec_extend_ip(pic_state *, struct pic_vector *, size_t);
|
||||||
|
|
||||||
int pic_parse_file(pic_state *, FILE *file, pic_value *);
|
int pic_parse_file(pic_state *, FILE *file, pic_value *);
|
||||||
int pic_parse_cstr(pic_state *, const char *, pic_value *);
|
int pic_parse_cstr(pic_state *, const char *, pic_value *);
|
||||||
|
|
|
@ -12,13 +12,13 @@ extern "C" {
|
||||||
struct pic_blob {
|
struct pic_blob {
|
||||||
PIC_OBJECT_HEADER
|
PIC_OBJECT_HEADER
|
||||||
char *data;
|
char *data;
|
||||||
int len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB)
|
#define pic_blob_p(v) (pic_type(v) == PIC_TT_BLOB)
|
||||||
#define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v))
|
#define pic_blob_ptr(v) ((struct pic_blob *)pic_ptr(v))
|
||||||
|
|
||||||
struct pic_blob *pic_blob_new(pic_state *, char *, int len);
|
struct pic_blob *pic_blob_new(pic_state *, char *, size_t len);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct parser_control {
|
||||||
bool incomp;
|
bool incomp;
|
||||||
int yynerrs;
|
int yynerrs;
|
||||||
struct pic_vector *yy_arena;
|
struct pic_vector *yy_arena;
|
||||||
int yy_arena_idx;
|
size_t yy_arena_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "picrin/blob.h"
|
#include "picrin/blob.h"
|
||||||
|
|
||||||
struct pic_blob *
|
struct pic_blob *
|
||||||
pic_blob_new(pic_state *pic, char *dat, int len)
|
pic_blob_new(pic_state *pic, char *dat, size_t len)
|
||||||
{
|
{
|
||||||
struct pic_blob *bv;
|
struct pic_blob *bv;
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,10 @@ new_irep(pic_state *pic)
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_sym *
|
static pic_sym *
|
||||||
analyze_args(pic_state *pic, pic_value args, bool *varg, size_t *argc, size_t *localc)
|
analyze_args(pic_state *pic, pic_value args, bool *varg, int *argc, int *localc)
|
||||||
{
|
{
|
||||||
pic_sym *syms = (pic_sym *)pic_alloc(pic, sizeof(pic_sym));
|
pic_sym *syms = (pic_sym *)pic_alloc(pic, sizeof(pic_sym));
|
||||||
size_t i = 1, l = 0;
|
int i = 1, l = 0;
|
||||||
pic_value v;
|
pic_value v;
|
||||||
|
|
||||||
*varg = false;
|
*varg = false;
|
||||||
|
@ -78,7 +78,7 @@ static bool
|
||||||
valid_formal(pic_state *pic, pic_value formal)
|
valid_formal(pic_state *pic, pic_value formal)
|
||||||
{
|
{
|
||||||
bool varg;
|
bool varg;
|
||||||
size_t argc, localc;
|
int argc, localc;
|
||||||
pic_sym *syms;
|
pic_sym *syms;
|
||||||
|
|
||||||
syms = analyze_args(pic, formal, &varg, &argc, &localc);
|
syms = analyze_args(pic, formal, &varg, &argc, &localc);
|
||||||
|
@ -94,7 +94,7 @@ valid_formal(pic_state *pic, pic_value formal)
|
||||||
typedef struct analyze_scope {
|
typedef struct analyze_scope {
|
||||||
/* rest args variable is counted by localc */
|
/* rest args variable is counted by localc */
|
||||||
bool varg;
|
bool varg;
|
||||||
size_t argc, localc;
|
int argc, localc;
|
||||||
/* if variable v is captured, then xh_get(var_tbl, v) == 1 */
|
/* if variable v is captured, then xh_get(var_tbl, v) == 1 */
|
||||||
struct xhash *var_tbl;
|
struct xhash *var_tbl;
|
||||||
pic_sym *vars;
|
pic_sym *vars;
|
||||||
|
@ -665,7 +665,7 @@ pic_analyze(pic_state *pic, pic_value obj)
|
||||||
typedef struct resolver_scope {
|
typedef struct resolver_scope {
|
||||||
int depth;
|
int depth;
|
||||||
bool varg;
|
bool varg;
|
||||||
size_t argc, localc;
|
int argc, localc;
|
||||||
struct xhash *cvs, *lvs;
|
struct xhash *cvs, *lvs;
|
||||||
unsigned cv_num;
|
unsigned cv_num;
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ resolve_gref(resolver_state *state, pic_sym sym)
|
||||||
pic_state *pic = state->pic;
|
pic_state *pic = state->pic;
|
||||||
const char *name = pic_symbol_name(pic, sym);
|
const char *name = pic_symbol_name(pic, sym);
|
||||||
struct xh_entry *e;
|
struct xh_entry *e;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
if ((e = xh_get(pic->global_tbl, name))) {
|
if ((e = xh_get(pic->global_tbl, name))) {
|
||||||
i = e->val;
|
i = e->val;
|
||||||
|
@ -911,7 +911,7 @@ pic_resolve(pic_state *pic, pic_value obj)
|
||||||
typedef struct codegen_context {
|
typedef struct codegen_context {
|
||||||
bool varg;
|
bool varg;
|
||||||
/* rest args variable is counted by localc */
|
/* rest args variable is counted by localc */
|
||||||
size_t argc, localc;
|
int argc, localc;
|
||||||
/* closed variable table */
|
/* closed variable table */
|
||||||
unsigned *cv_tbl, cv_num;
|
unsigned *cv_tbl, cv_num;
|
||||||
/* actual bit code sequence */
|
/* actual bit code sequence */
|
||||||
|
|
20
src/gc.c
20
src/gc.c
|
@ -342,7 +342,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PIC_TT_VECTOR: {
|
case PIC_TT_VECTOR: {
|
||||||
int i;
|
size_t i;
|
||||||
for (i = 0; i < ((struct pic_vector *)obj)->len; ++i) {
|
for (i = 0; i < ((struct pic_vector *)obj)->len; ++i) {
|
||||||
gc_mark(pic, ((struct pic_vector *)obj)->data[i]);
|
gc_mark(pic, ((struct pic_vector *)obj)->data[i]);
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,8 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
struct pic_cont *cont = (struct pic_cont *)obj;
|
struct pic_cont *cont = (struct pic_cont *)obj;
|
||||||
pic_value *stack;
|
pic_value *stack;
|
||||||
pic_callinfo *ci;
|
pic_callinfo *ci;
|
||||||
int i;
|
size_t i;
|
||||||
|
int j;
|
||||||
|
|
||||||
/* block */
|
/* block */
|
||||||
gc_mark_block(pic, cont->blk);
|
gc_mark_block(pic, cont->blk);
|
||||||
|
@ -378,8 +379,8 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* arena */
|
/* arena */
|
||||||
for (i = 0; i < cont->arena_idx; ++i) {
|
for (j = 0; j < cont->arena_idx; ++j) {
|
||||||
gc_mark_object(pic, cont->arena[i]);
|
gc_mark_object(pic, cont->arena[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
gc_mark(pic, cont->result);
|
gc_mark(pic, cont->result);
|
||||||
|
@ -403,7 +404,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
gc_mark_object(pic, (struct pic_object *)senv->up);
|
gc_mark_object(pic, (struct pic_object *)senv->up);
|
||||||
}
|
}
|
||||||
if (senv->stx) {
|
if (senv->stx) {
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < senv->xlen; ++i) {
|
for (i = 0; i < senv->xlen; ++i) {
|
||||||
gc_mark_object(pic, (struct pic_object *)senv->stx[i]);
|
gc_mark_object(pic, (struct pic_object *)senv->stx[i]);
|
||||||
|
@ -433,7 +434,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
case PIC_TT_IREP: {
|
case PIC_TT_IREP: {
|
||||||
struct pic_irep *irep = (struct pic_irep *)obj;
|
struct pic_irep *irep = (struct pic_irep *)obj;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < irep->ilen; ++i) {
|
for (i = 0; i < irep->ilen; ++i) {
|
||||||
gc_mark_object(pic, (struct pic_object *)irep->irep[i]);
|
gc_mark_object(pic, (struct pic_object *)irep->irep[i]);
|
||||||
|
@ -472,7 +473,8 @@ gc_mark_phase(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_value *stack;
|
pic_value *stack;
|
||||||
pic_callinfo *ci;
|
pic_callinfo *ci;
|
||||||
int i;
|
size_t i;
|
||||||
|
int j;
|
||||||
|
|
||||||
/* block */
|
/* block */
|
||||||
gc_mark_block(pic, pic->blk);
|
gc_mark_block(pic, pic->blk);
|
||||||
|
@ -495,8 +497,8 @@ gc_mark_phase(pic_state *pic)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* arena */
|
/* arena */
|
||||||
for (i = 0; i < pic->arena_idx; ++i) {
|
for (j = 0; j < pic->arena_idx; ++j) {
|
||||||
gc_mark_object(pic, pic->arena[i]);
|
gc_mark_object(pic, pic->arena[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
|
|
|
@ -200,7 +200,7 @@ pic_import(pic_state *pic, pic_value spec)
|
||||||
xh_put(pic->lib->senv->tbl, it.e->key, it.e->val);
|
xh_put(pic->lib->senv->tbl, it.e->key, it.e->val);
|
||||||
}
|
}
|
||||||
else { /* syntax object */
|
else { /* syntax object */
|
||||||
int idx;
|
size_t idx;
|
||||||
struct pic_senv *senv = pic->lib->senv;
|
struct pic_senv *senv = pic->lib->senv;
|
||||||
|
|
||||||
idx = senv->xlen;
|
idx = senv->xlen;
|
||||||
|
@ -233,7 +233,7 @@ pic_defsyntax(pic_state *pic, const char *name, struct pic_proc *macro, struct p
|
||||||
{
|
{
|
||||||
struct pic_syntax *stx;
|
struct pic_syntax *stx;
|
||||||
struct pic_senv *global_senv = pic->lib->senv;
|
struct pic_senv *global_senv = pic->lib->senv;
|
||||||
int idx;
|
size_t idx;
|
||||||
|
|
||||||
stx = pic_syntax_new_macro(pic, pic_intern_cstr(pic, name), macro, mac_env);
|
stx = pic_syntax_new_macro(pic, pic_intern_cstr(pic, name), macro, mac_env);
|
||||||
|
|
||||||
|
|
10
src/number.c
10
src/number.c
|
@ -123,7 +123,7 @@ pic_number_nan_p(pic_state *pic)
|
||||||
{ \
|
{ \
|
||||||
size_t argc; \
|
size_t argc; \
|
||||||
pic_value *argv; \
|
pic_value *argv; \
|
||||||
int i; \
|
size_t i; \
|
||||||
double f,g; \
|
double f,g; \
|
||||||
\
|
\
|
||||||
pic_get_args(pic, "ff*", &f, &g, &argc, &argv); \
|
pic_get_args(pic, "ff*", &f, &g, &argc, &argv); \
|
||||||
|
@ -207,7 +207,7 @@ pic_number_max(pic_state *pic)
|
||||||
{
|
{
|
||||||
size_t argc;
|
size_t argc;
|
||||||
pic_value *argv;
|
pic_value *argv;
|
||||||
int i;
|
size_t i;
|
||||||
double f;
|
double f;
|
||||||
bool e = true;
|
bool e = true;
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ pic_number_min(pic_state *pic)
|
||||||
{
|
{
|
||||||
size_t argc;
|
size_t argc;
|
||||||
pic_value *argv;
|
pic_value *argv;
|
||||||
int i;
|
size_t i;
|
||||||
double f;
|
double f;
|
||||||
bool e = true;
|
bool e = true;
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ pic_number_min(pic_state *pic)
|
||||||
{ \
|
{ \
|
||||||
size_t argc; \
|
size_t argc; \
|
||||||
pic_value *argv; \
|
pic_value *argv; \
|
||||||
int i; \
|
size_t i; \
|
||||||
double f; \
|
double f; \
|
||||||
bool e = true; \
|
bool e = true; \
|
||||||
\
|
\
|
||||||
|
@ -296,7 +296,7 @@ DEFINE_ARITH_OP(*, mul, 1)
|
||||||
{ \
|
{ \
|
||||||
size_t argc; \
|
size_t argc; \
|
||||||
pic_value *argv; \
|
pic_value *argv; \
|
||||||
int i; \
|
size_t i; \
|
||||||
double f; \
|
double f; \
|
||||||
bool e; \
|
bool e; \
|
||||||
\
|
\
|
||||||
|
|
|
@ -81,7 +81,7 @@ pic_value
|
||||||
pic_list_from_array(pic_state *pic, size_t c, pic_value *vs)
|
pic_list_from_array(pic_state *pic, size_t c, pic_value *vs)
|
||||||
{
|
{
|
||||||
pic_value v;
|
pic_value v;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
v = pic_nil_value();
|
v = pic_nil_value();
|
||||||
for (i = 0; i < c; ++i) {
|
for (i = 0; i < c; ++i) {
|
||||||
|
|
|
@ -126,7 +126,7 @@ pic_open(int argc, char *argv[], char **envp)
|
||||||
void
|
void
|
||||||
pic_close(pic_state *pic)
|
pic_close(pic_state *pic)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
/* free global stacks */
|
/* free global stacks */
|
||||||
free(pic->stbase);
|
free(pic->stbase);
|
||||||
|
|
|
@ -95,7 +95,7 @@ pic_str_string_set(pic_state *pic)
|
||||||
{ \
|
{ \
|
||||||
size_t argc; \
|
size_t argc; \
|
||||||
pic_value *argv; \
|
pic_value *argv; \
|
||||||
int i; \
|
size_t i; \
|
||||||
\
|
\
|
||||||
pic_get_args(pic, "*", &argc, &argv); \
|
pic_get_args(pic, "*", &argc, &argv); \
|
||||||
\
|
\
|
||||||
|
|
17
src/vector.c
17
src/vector.c
|
@ -9,7 +9,7 @@ struct pic_vector *
|
||||||
pic_vec_new(pic_state *pic, size_t len)
|
pic_vec_new(pic_state *pic, size_t len)
|
||||||
{
|
{
|
||||||
struct pic_vector *vec;
|
struct pic_vector *vec;
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
vec = (struct pic_vector *)pic_obj_alloc(pic, sizeof(struct pic_vector), PIC_TT_VECTOR);
|
vec = (struct pic_vector *)pic_obj_alloc(pic, sizeof(struct pic_vector), PIC_TT_VECTOR);
|
||||||
vec->len = len;
|
vec->len = len;
|
||||||
|
@ -24,7 +24,7 @@ struct pic_vector *
|
||||||
pic_vec_new_from_list(pic_state *pic, pic_value data)
|
pic_vec_new_from_list(pic_state *pic, pic_value data)
|
||||||
{
|
{
|
||||||
struct pic_vector *vec;
|
struct pic_vector *vec;
|
||||||
int i, len;
|
size_t i, len;
|
||||||
|
|
||||||
len = pic_length(pic, data);
|
len = pic_length(pic, data);
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ pic_vec_new_from_list(pic_state *pic, pic_value data)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pic_vec_extend_ip(pic_state *pic, struct pic_vector *vec, int size)
|
pic_vec_extend_ip(pic_state *pic, struct pic_vector *vec, size_t size)
|
||||||
{
|
{
|
||||||
int len, i;
|
size_t len, i;
|
||||||
|
|
||||||
len = vec->len;
|
len = vec->len;
|
||||||
vec->len = size;
|
vec->len = size;
|
||||||
|
@ -63,14 +63,15 @@ static pic_value
|
||||||
pic_vec_make_vector(pic_state *pic)
|
pic_vec_make_vector(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_value v;
|
pic_value v;
|
||||||
int k, n, i;
|
int n, k;
|
||||||
|
size_t i;
|
||||||
struct pic_vector *vec;
|
struct pic_vector *vec;
|
||||||
|
|
||||||
n = pic_get_args(pic, "i|o", &k, &v);
|
n = pic_get_args(pic, "i|o", &k, &v);
|
||||||
|
|
||||||
vec = pic_vec_new(pic, k);
|
vec = pic_vec_new(pic, k);
|
||||||
if (n == 3) {
|
if (n == 3) {
|
||||||
for (i = 0; i < k; ++i) {
|
for (i = 0; i < (size_t)k; ++i) {
|
||||||
vec->data[i] = v;
|
vec->data[i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +96,7 @@ pic_vec_vector_ref(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "vi", &v, &k);
|
pic_get_args(pic, "vi", &v, &k);
|
||||||
|
|
||||||
if (k < 0 || v->len <= k) {
|
if (k < 0 || v->len <= (size_t)k) {
|
||||||
pic_error(pic, "vector-ref: index out of range");
|
pic_error(pic, "vector-ref: index out of range");
|
||||||
}
|
}
|
||||||
return v->data[k];
|
return v->data[k];
|
||||||
|
@ -110,7 +111,7 @@ pic_vec_vector_set(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "vio", &v, &k, &o);
|
pic_get_args(pic, "vio", &v, &k, &o);
|
||||||
|
|
||||||
if (k < 0 || v->len <= k) {
|
if (k < 0 || v->len <= (size_t)k) {
|
||||||
pic_error(pic, "vector-set!: index out of range");
|
pic_error(pic, "vector-set!: index out of range");
|
||||||
}
|
}
|
||||||
v->data[k] = o;
|
v->data[k] = o;
|
||||||
|
|
2
src/vm.c
2
src/vm.c
|
@ -630,7 +630,7 @@ pic_apply(pic_state *pic, struct pic_proc *proc, pic_value argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CASE(OP_TAILCALL) {
|
CASE(OP_TAILCALL) {
|
||||||
int argc;
|
int i, argc;
|
||||||
pic_value *argv;
|
pic_value *argv;
|
||||||
|
|
||||||
argc = c.u.i;
|
argc = c.u.i;
|
||||||
|
|
|
@ -30,7 +30,7 @@ write_pair(pic_state *pic, struct pic_pair *pair)
|
||||||
static void
|
static void
|
||||||
write_str(pic_state *pic, struct pic_string *str)
|
write_str(pic_state *pic, struct pic_string *str)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
const char *cstr = str->str;
|
const char *cstr = str->str;
|
||||||
|
|
||||||
for (i = 0; i < str->len; ++i) {
|
for (i = 0; i < str->len; ++i) {
|
||||||
|
@ -44,7 +44,7 @@ write_str(pic_state *pic, struct pic_string *str)
|
||||||
static void
|
static void
|
||||||
write(pic_state *pic, pic_value obj)
|
write(pic_state *pic, pic_value obj)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
switch (pic_type(obj)) {
|
switch (pic_type(obj)) {
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
|
|
Loading…
Reference in New Issue