From 7350f7e71e10b7813b88be1e6360bbad148bc028 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 27 Sep 2014 17:18:11 +0900 Subject: [PATCH] int to size_t conversion --- codegen.c | 26 +++++++++++++------------- include/picrin/irep.h | 4 ++-- string.c | 4 ++-- symbol.c | 2 +- system.c | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/codegen.c b/codegen.c index fec7ad43..c4e3121e 100644 --- a/codegen.c +++ b/codegen.c @@ -1075,20 +1075,20 @@ static int index_local(codegen_state *state, pic_sym sym) { codegen_context *cxt = state->cxt; - int i, offset; + size_t i, offset; pic_sym *var; offset = 1; - for (i = 0; i < (int)xv_size(&cxt->args); ++i) { + for (i = 0; i < xv_size(&cxt->args); ++i) { var = xv_get(&cxt->args, i); if (*var == sym) - return i + offset; + return (int)(i + offset); } offset += i; - for (i = 0; i < (int)xv_size(&cxt->locals); ++i) { + for (i = 0; i < xv_size(&cxt->locals); ++i) { var = xv_get(&cxt->locals, i); if (*var == sym) - return i + offset; + return (int)(i + offset); } return -1; } @@ -1126,7 +1126,7 @@ codegen(codegen_state *state, pic_value obj) name = pic_sym(pic_list_ref(pic, obj, 1)); if ((i = index_capture(state, name, 0)) != -1) { cxt->code[cxt->clen].insn = OP_LREF; - cxt->code[cxt->clen].u.i = i + xv_size(&cxt->args) + xv_size(&cxt->locals) + 1; + cxt->code[cxt->clen].u.i = i + (int)xv_size(&cxt->args) + (int)xv_size(&cxt->locals) + 1; cxt->clen++; return; } @@ -1172,7 +1172,7 @@ codegen(codegen_state *state, pic_value obj) name = pic_sym(pic_list_ref(pic, var, 1)); if ((i = index_capture(state, name, 0)) != -1) { cxt->code[cxt->clen].insn = OP_LSET; - cxt->code[cxt->clen].u.i = i + xv_size(&cxt->args) + xv_size(&cxt->locals) + 1; + cxt->code[cxt->clen].u.i = i + (int)xv_size(&cxt->args) + (int)xv_size(&cxt->locals) + 1; cxt->clen++; cxt->code[cxt->clen].insn = OP_PUSHNONE; cxt->clen++; @@ -1193,7 +1193,7 @@ codegen(codegen_state *state, pic_value obj) cxt->icapa *= 2; cxt->irep = pic_realloc(pic, cxt->irep, sizeof(struct pic_irep *) * cxt->icapa); } - k = cxt->ilen++; + k = (int)cxt->ilen++; cxt->code[cxt->clen].insn = OP_LAMBDA; cxt->code[cxt->clen].u.i = k; cxt->clen++; @@ -1207,18 +1207,18 @@ codegen(codegen_state *state, pic_value obj) codegen(state, pic_list_ref(pic, obj, 1)); cxt->code[cxt->clen].insn = OP_JMPIF; - s = cxt->clen++; + s = (int)cxt->clen++; /* if false branch */ codegen(state, pic_list_ref(pic, obj, 3)); cxt->code[cxt->clen].insn = OP_JMP; - t = cxt->clen++; + t = (int)cxt->clen++; - cxt->code[s].u.i = cxt->clen - s; + cxt->code[s].u.i = (int)cxt->clen - s; /* if true branch */ codegen(state, pic_list_ref(pic, obj, 2)); - cxt->code[t].u.i = cxt->clen - t; + cxt->code[t].u.i = (int)cxt->clen - t; return; } else if (sym == pic->sBEGIN) { @@ -1266,7 +1266,7 @@ codegen(codegen_state *state, pic_value obj) cxt->pcapa *= 2; cxt->pool = pic_realloc(pic, cxt->pool, sizeof(pic_value) * cxt->pcapa); } - pidx = cxt->plen++; + pidx = (int)cxt->plen++; cxt->pool[pidx] = obj; cxt->code[cxt->clen].insn = OP_PUSHCONST; cxt->code[cxt->clen].u.i = pidx; diff --git a/include/picrin/irep.h b/include/picrin/irep.h index c6e5befb..fe924bbc 100644 --- a/include/picrin/irep.h +++ b/include/picrin/irep.h @@ -52,8 +52,8 @@ struct pic_code { int i; char c; struct { - short depth; - short idx; + int depth; + int idx; } r; } u; }; diff --git a/string.c b/string.c index 3bad3daf..7f03cfae 100644 --- a/string.c +++ b/string.c @@ -240,14 +240,14 @@ pic_str_string(pic_state *pic) pic_get_args(pic, "*", &argc, &argv); - buf = pic_alloc(pic, argc); + buf = pic_alloc(pic, (size_t)argc); for (i = 0; i < argc; ++i) { pic_assert_type(pic, argv[i], char); buf[i] = pic_char(argv[i]); } - str = pic_make_str(pic, buf, argc); + str = pic_make_str(pic, buf, (size_t)argc); pic_free(pic, buf); return pic_obj_value(str); diff --git a/symbol.c b/symbol.c index d6feab13..7e9f1b52 100644 --- a/symbol.c +++ b/symbol.c @@ -80,7 +80,7 @@ pic_ungensym(pic_state *pic, pic_sym base) if ((occr = strrchr(name, '@')) == NULL) { pic_panic(pic, "logic flaw"); } - return pic_intern(pic, name, occr - name); + return pic_intern(pic, name, (size_t)(occr - name)); } bool diff --git a/system.c b/system.c index 4c54b905..e9ef1aa9 100644 --- a/system.c +++ b/system.c @@ -110,7 +110,7 @@ pic_system_getenvs(pic_state *pic) for (i = 0; (*envp)[i] != '='; ++i) ; - key = pic_make_str(pic, *envp, i); + key = pic_make_str(pic, *envp, (size_t)i); val = pic_make_str_cstr(pic, getenv(pic_str_cstr(key))); /* push */