diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-03-22 19:11:51 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-03-22 19:11:51 -0700 |
| commit | acab35a2a54e00e197b7372e940b83235480179d (patch) | |
| tree | b8ec207c86e6f9e270c04799c5cb7d59354acac6 | |
| parent | 04d9c5ea6bfbdaf425526cf3556704f6b9fd0971 (diff) | |
| parent | f4b943771881b01b40b34ca38ccdd62bb5eaaa66 (diff) | |
| download | mruby-acab35a2a54e00e197b7372e940b83235480179d.tar.gz mruby-acab35a2a54e00e197b7372e940b83235480179d.zip | |
Merge pull request #1039 from crimsonwoods/fix_the_type_of_opcode
Fix the type of value that is returned by bit shift expression.
| -rw-r--r-- | src/codegen.c | 7 | ||||
| -rw-r--r-- | src/hash.c | 2 | ||||
| -rw-r--r-- | src/opcode.h | 17 | ||||
| -rw-r--r-- | src/vm.c | 2 |
4 files changed, 16 insertions, 12 deletions
diff --git a/src/codegen.c b/src/codegen.c index 909bd5f7d..30efa248e 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -580,7 +580,8 @@ lambda_body(codegen_scope *s, node *tree, int blk) } tree = tree->cdr; if (tree->car) { - int ma, oa, ra, pa, ka, kd, ba, a; + int32_t a; + int ma, oa, ra, pa, ka, kd, ba; int pos, i; node *n, *opt; @@ -595,8 +596,8 @@ lambda_body(codegen_scope *s, node *tree, int blk) ka = kd = 0; ba = tree->car->cdr->cdr->cdr->cdr ? 1 : 0; - a = ((ma & 0x1f) << 18) - | ((oa & 0x1f) << 13) + a = ((int32_t)(ma & 0x1f) << 18) + | ((int32_t)(oa & 0x1f) << 13) | ((ra & 1) << 12) | ((pa & 0x1f) << 7) | ((ka & 0x1f) << 2) diff --git a/src/hash.c b/src/hash.c index 74474df95..6976530e1 100644 --- a/src/hash.c +++ b/src/hash.c @@ -15,7 +15,7 @@ static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) { - khint_t h = mrb_type(key) << 24; + khint_t h = (khint_t)mrb_type(key) << 24; mrb_value h2; h2 = mrb_funcall(mrb, key, "hash", 0, 0); diff --git a/src/opcode.h b/src/opcode.h index 7c2ec204d..8678ef73d 100644 --- a/src/opcode.h +++ b/src/opcode.h @@ -10,9 +10,12 @@ #define MAXARG_Bx (0xffff) #define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ -/* instructions OP:A:B:C = 7:9:9:7 (32 bits) */ -/* OP:A:Bx = 7:9:16 */ -/* OP:Ax = 7:25 */ +/* instructions: packed 32 bit */ +/* ------------------------------- */ +/* A:B:C:OP = 9: 9: 7: 7 */ +/* A:Bx:OP = 9:16: 7 */ +/* Ax:OP = 25: 7 */ +/* A:Bz:Cz:OP = 9:14: 2: 7 */ #define GET_OPCODE(i) ((int)(((mrb_code)(i)) & 0x7f)) #define GETARG_A(i) ((int)((((mrb_code)(i)) >> 23) & 0x1ff)) @@ -20,17 +23,17 @@ #define GETARG_C(i) ((int)((((mrb_code)(i)) >> 7) & 0x7f)) #define GETARG_Bx(i) ((int)((((mrb_code)(i)) >> 7) & 0xffff)) #define GETARG_sBx(i) ((int)(GETARG_Bx(i)-MAXARG_sBx)) -#define GETARG_Ax(i) ((int)((((mrb_code)(i)) >> 7) & 0x1ffffff)) +#define GETARG_Ax(i) ((int32_t)((((mrb_code)(i)) >> 7) & 0x1ffffff)) #define GETARG_UNPACK_b(i,n1,n2) ((int)((((mrb_code)(i)) >> (7+n2)) & (((1<<n1)-1)))) #define GETARG_UNPACK_c(i,n1,n2) ((int)((((mrb_code)(i)) >> 7) & (((1<<n2)-1)))) #define GETARG_b(i) GETARG_UNPACK_b(i,14,2) #define GETARG_c(i) GETARG_UNPACK_c(i,14,2) #define MKOPCODE(op) ((op) & 0x7f) -#define MKARG_A(c) (((c) & 0x1ff) << 23) -#define MKARG_B(c) (((c) & 0x1ff) << 14) +#define MKARG_A(c) ((mrb_code)((c) & 0x1ff) << 23) +#define MKARG_B(c) ((mrb_code)((c) & 0x1ff) << 14) #define MKARG_C(c) (((c) & 0x7f) << 7) -#define MKARG_Bx(v) (((v) & 0xffff) << 7) +#define MKARG_Bx(v) ((mrb_code)((v) & 0xffff) << 7) #define MKARG_sBx(v) MKARG_Bx((v)+MAXARG_sBx) #define MKARG_Ax(v) (((v) & 0x1ffffff) << 7) #define MKARG_PACK(b,n1,c,n2) ((((b) & ((1<<n1)-1)) << (7+n2))|(((c) & ((1<<n2)-1)) << 7)) @@ -1126,7 +1126,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_ENTER) { /* Ax arg setup according to flags (24=5:5:1:5:5:1:1) */ /* number of optional arguments times OP_JMP should follow */ - int ax = GETARG_Ax(i); + int32_t ax = GETARG_Ax(i); int m1 = (ax>>18)&0x1f; int o = (ax>>13)&0x1f; int r = (ax>>12)&0x1; |
