Unverified Commit 9c5e2864 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4151 from take-cheeze/remove_op_symidx

Reduce instruction size
parents 788e4388 6a6586ca
...@@ -84,17 +84,17 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed. ...@@ -84,17 +84,17 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
|OP_RETURN_BLK' |B |return R(a) (in-block return) |OP_RETURN_BLK' |B |return R(a) (in-block return)
|OP_BREAK' |B |break R(a) |OP_BREAK' |B |break R(a)
|OP_BLKPUSH' |BS |R(a) = block (16=5:1:5:1:4) |OP_BLKPUSH' |BS |R(a) = block (16=5:1:5:1:4)
|OP_ADD" |BB |R(a) = R(a)+R(a+1) (Syms[b]=:+) |OP_ADD" |BB |R(a) = R(a)+R(a+1)
|OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c) (Syms[b]=:+) |OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c)
|OP_SUB" |BB |R(a) = R(a)-R(a+1) (Syms[b]=:-) |OP_SUB" |BB |R(a) = R(a)-R(a+1)
|OP_SUBI" |BB |R(a) = R(a)-C (Syms[b]=:-) |OP_SUBI" |BB |R(a) = R(a)-C
|OP_MUL" |BB |R(a) = R(a)*R(a+1) (Syms[b]=:*) |OP_MUL" |BB |R(a) = R(a)*R(a+1)
|OP_DIV" |BB |R(a) = R(a)/R(a+1) (Syms[b]=:/) |OP_DIV" |BB |R(a) = R(a)/R(a+1)
|OP_EQ" |BB |R(a) = R(a)==R(a+1) (Syms[b]=:==) |OP_EQ" |BB |R(a) = R(a)==R(a+1)
|OP_LT" |BB |R(a) = R(a)<R(a+1) (Syms[b]=:<) |OP_LT" |BB |R(a) = R(a)<R(a+1)
|OP_LE" |BB |R(a) = R(a)<=R(a+1) (Syms[b]=:<=) |OP_LE" |BB |R(a) = R(a)<=R(a+1)
|OP_GT" |BB |R(a) = R(a)>R(a+1) (Syms[b]=:>) |OP_GT" |BB |R(a) = R(a)>R(a+1)
|OP_GE" |BB |R(a) = R(a)>=R(a+1) (Syms[b]=:>=) |OP_GE" |BB |R(a) = R(a)>=R(a+1)
|OP_ARRAY' |BB |R(a) = ary_new(R(a),R(a+1)..R(a+b)) |OP_ARRAY' |BB |R(a) = ary_new(R(a),R(a+1)..R(a+b))
|OP_ARRAY2" |BB |R(a) = ary_new(R(b),R(b+1)..R(b+c)) |OP_ARRAY2" |BB |R(a) = ary_new(R(b),R(b+1)..R(b+c))
|OP_ARYCAT' |B |ary_cat(R(a),R(a+1)) |OP_ARYCAT' |B |ary_cat(R(a),R(a+1))
......
...@@ -70,17 +70,17 @@ OPCODE(RETURN, B) /* return R(a) (normal) */ ...@@ -70,17 +70,17 @@ OPCODE(RETURN, B) /* return R(a) (normal) */
OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */ OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */
OPCODE(BREAK, B) /* break R(a) */ OPCODE(BREAK, B) /* break R(a) */
OPCODE(BLKPUSH, BS) /* R(a) = block (16=m5:r1:m5:d1:lv4) */ OPCODE(BLKPUSH, BS) /* R(a) = block (16=m5:r1:m5:d1:lv4) */
OPCODE(ADD, BB) /* R(a) = R(a)+R(a+1) (Syms[b]=:+) */ OPCODE(ADD, B) /* R(a) = R(a)+R(a+1) */
OPCODE(ADDI, BBB) /* R(a) = R(a)+mrb_int(c) (Syms[b]=:+) */ OPCODE(ADDI, BB) /* R(a) = R(a)+mrb_int(c) */
OPCODE(SUB, BB) /* R(a) = R(a)-R(a+1) (Syms[b]=:-) */ OPCODE(SUB, B) /* R(a) = R(a)-R(a+1) */
OPCODE(SUBI, BBB) /* R(a) = R(a)-C (Syms[b]=:-) */ OPCODE(SUBI, BB) /* R(a) = R(a)-C */
OPCODE(MUL, BB) /* R(a) = R(a)*R(a+1) (Syms[b]=:*) */ OPCODE(MUL, B) /* R(a) = R(a)*R(a+1) */
OPCODE(DIV, BB) /* R(a) = R(a)/R(a+1) (Syms[b]=:/) */ OPCODE(DIV, B) /* R(a) = R(a)/R(a+1) */
OPCODE(EQ, BB) /* R(a) = R(a)==R(a+1) (Syms[b]=:==) */ OPCODE(EQ, B) /* R(a) = R(a)==R(a+1) */
OPCODE(LT, BB) /* R(a) = R(a)<R(a+1) (Syms[b]=:<) */ OPCODE(LT, B) /* R(a) = R(a)<R(a+1) */
OPCODE(LE, BB) /* R(a) = R(a)<=R(a+1) (Syms[b]=:<=) */ OPCODE(LE, B) /* R(a) = R(a)<=R(a+1) */
OPCODE(GT, BB) /* R(a) = R(a)>R(a+1) (Syms[b]=:>) */ OPCODE(GT, B) /* R(a) = R(a)>R(a+1) */
OPCODE(GE, BB) /* R(a) = R(a)>=R(a+1) (Syms[b]=:>=) */ OPCODE(GE, B) /* R(a) = R(a)>=R(a+1) */
OPCODE(ARRAY, BB) /* R(a) = ary_new(R(a),R(a+1)..R(a+b)) */ OPCODE(ARRAY, BB) /* R(a) = ary_new(R(a),R(a+1)..R(a+b)) */
OPCODE(ARRAY2, BBB) /* R(a) = ary_new(R(b),R(b+1)..R(b+c)) */ OPCODE(ARRAY2, BBB) /* R(a) = ary_new(R(b),R(b+1)..R(b+c)) */
OPCODE(ARYCAT, B) /* ary_cat(R(a),R(a+1)) */ OPCODE(ARYCAT, B) /* ary_cat(R(a),R(a+1)) */
......
/*
** mruby/symbol.h - symbol utilities
**
** See Copyright Notice in mruby.h
*/
#ifndef MRUBY_SYMBOL_H
#define MRUBY_SYMBOL_H
#include "common.h"
/**
* Symbol utilities
*/
MRB_BEGIN_DECL
typedef enum mrb_reserved_symbol {
mrb_sym_null = 0, // NULL symbol
mrb_sym_add = 1, // +
mrb_sym_sub = 2, // -
mrb_sym_mul = 3, // *
mrb_sym_div = 4, // /
mrb_sym_eq = 5, // ==
mrb_sym_lt = 6, // <
mrb_sym_le = 7, // <=
mrb_sym_gt = 8, // >
mrb_sym_ge = 9, // >=
mrb_sym_method_missing = 10, // method_missing
} mrb_reserved_symbol;
static inline mrb_bool
mrb_symbol_constsym_send_p(mrb_sym sym) {
return mrb_sym_add <= sym && sym <= mrb_sym_ge;
}
MRB_END_DECL
#endif /* MRUBY_SYMBOL_H */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <mruby/opcode.h> #include <mruby/opcode.h>
#include <mruby/re.h> #include <mruby/re.h>
#include <mruby/throw.h> #include <mruby/throw.h>
#include <mruby/symbol.h>
#ifndef MRB_CODEGEN_LEVEL_MAX #ifndef MRB_CODEGEN_LEVEL_MAX
#define MRB_CODEGEN_LEVEL_MAX 1024 #define MRB_CODEGEN_LEVEL_MAX 1024
...@@ -468,11 +469,11 @@ gen_return(codegen_scope *s, uint8_t op, uint16_t src) ...@@ -468,11 +469,11 @@ gen_return(codegen_scope *s, uint8_t op, uint16_t src)
} }
static void static void
gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst, uint16_t idx) gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
{ {
if (no_peephole(s)) { if (no_peephole(s)) {
normal: normal:
genop_2(s, op, dst, idx); genop_1(s, op, dst);
return; return;
} }
else { else {
...@@ -493,10 +494,10 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst, uint16_t idx) ...@@ -493,10 +494,10 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst, uint16_t idx)
if (data.b >= 128) goto normal; if (data.b >= 128) goto normal;
s->pc = s->lastpc; s->pc = s->lastpc;
if (op == OP_ADD) { if (op == OP_ADD) {
genop_3(s, OP_ADDI, dst, idx, (uint8_t)data.b); genop_2(s, OP_ADDI, dst, (uint8_t)data.b);
} }
else { else {
genop_3(s, OP_SUBI, dst, idx, (uint8_t)data.b); genop_2(s, OP_SUBI, dst, (uint8_t)data.b);
} }
break; break;
default: default:
...@@ -982,7 +983,9 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe) ...@@ -982,7 +983,9 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
gen_move(s, cursp(), recv, 1); gen_move(s, cursp(), recv, 1);
skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val); skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
} }
idx = new_sym(s, sym); if (!mrb_symbol_constsym_send_p(sym)) {
idx = new_sym(s, sym);
}
tree = tree->cdr->cdr->car; tree = tree->cdr->cdr->car;
if (tree) { if (tree) {
n = gen_values(s, tree->car, VAL, sp?1:0); n = gen_values(s, tree->car, VAL, sp?1:0);
...@@ -1017,31 +1020,31 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe) ...@@ -1017,31 +1020,31 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
const char *symname = mrb_sym2name_len(s->mrb, sym, &symlen); const char *symname = mrb_sym2name_len(s->mrb, sym, &symlen);
if (!noop && symlen == 1 && symname[0] == '+' && n == 1) { if (!noop && symlen == 1 && symname[0] == '+' && n == 1) {
gen_addsub(s, OP_ADD, cursp(), idx); gen_addsub(s, OP_ADD, cursp());
} }
else if (!noop && symlen == 1 && symname[0] == '-' && n == 1) { else if (!noop && symlen == 1 && symname[0] == '-' && n == 1) {
gen_addsub(s, OP_SUB, cursp(), idx); gen_addsub(s, OP_SUB, cursp());
} }
else if (!noop && symlen == 1 && symname[0] == '*' && n == 1) { else if (!noop && symlen == 1 && symname[0] == '*' && n == 1) {
genop_2(s, OP_MUL, cursp(), idx); genop_1(s, OP_MUL, cursp());
} }
else if (!noop && symlen == 1 && symname[0] == '/' && n == 1) { else if (!noop && symlen == 1 && symname[0] == '/' && n == 1) {
genop_2(s, OP_DIV, cursp(), idx); genop_1(s, OP_DIV, cursp());
} }
else if (!noop && symlen == 1 && symname[0] == '<' && n == 1) { else if (!noop && symlen == 1 && symname[0] == '<' && n == 1) {
genop_2(s, OP_LT, cursp(), idx); genop_1(s, OP_LT, cursp());
} }
else if (!noop && symlen == 2 && symname[0] == '<' && symname[1] == '=' && n == 1) { else if (!noop && symlen == 2 && symname[0] == '<' && symname[1] == '=' && n == 1) {
genop_2(s, OP_LE, cursp(), idx); genop_1(s, OP_LE, cursp());
} }
else if (!noop && symlen == 1 && symname[0] == '>' && n == 1) { else if (!noop && symlen == 1 && symname[0] == '>' && n == 1) {
genop_2(s, OP_GT, cursp(), idx); genop_1(s, OP_GT, cursp());
} }
else if (!noop && symlen == 2 && symname[0] == '>' && symname[1] == '=' && n == 1) { else if (!noop && symlen == 2 && symname[0] == '>' && symname[1] == '=' && n == 1) {
genop_2(s, OP_GE, cursp(), idx); genop_1(s, OP_GE, cursp());
} }
else if (!noop && symlen == 2 && symname[0] == '=' && symname[1] == '=' && n == 1) { else if (!noop && symlen == 2 && symname[0] == '=' && symname[1] == '=' && n == 1) {
genop_2(s, OP_EQ, cursp(), idx); genop_1(s, OP_EQ, cursp());
} }
else { else {
if (sendv) { if (sendv) {
...@@ -2023,30 +2026,32 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -2023,30 +2026,32 @@ codegen(codegen_scope *s, node *tree, int val)
push(); pop(); push(); pop();
pop(); pop(); pop(); pop();
idx = new_sym(s, sym); if (!mrb_symbol_constsym_send_p(sym)) {
idx = new_sym(s, sym);
}
if (len == 1 && name[0] == '+') { if (len == 1 && name[0] == '+') {
gen_addsub(s, OP_ADD, cursp(), idx); gen_addsub(s, OP_ADD, cursp());
} }
else if (len == 1 && name[0] == '-') { else if (len == 1 && name[0] == '-') {
gen_addsub(s, OP_SUB, cursp(), idx); gen_addsub(s, OP_SUB, cursp());
} }
else if (len == 1 && name[0] == '*') { else if (len == 1 && name[0] == '*') {
genop_2(s, OP_MUL, cursp(), idx); genop_1(s, OP_MUL, cursp());
} }
else if (len == 1 && name[0] == '/') { else if (len == 1 && name[0] == '/') {
genop_2(s, OP_DIV, cursp(), idx); genop_1(s, OP_DIV, cursp());
} }
else if (len == 1 && name[0] == '<') { else if (len == 1 && name[0] == '<') {
genop_2(s, OP_LT, cursp(), idx); genop_1(s, OP_LT, cursp());
} }
else if (len == 2 && name[0] == '<' && name[1] == '=') { else if (len == 2 && name[0] == '<' && name[1] == '=') {
genop_2(s, OP_LE, cursp(), idx); genop_1(s, OP_LE, cursp());
} }
else if (len == 1 && name[0] == '>') { else if (len == 1 && name[0] == '>') {
genop_2(s, OP_GT, cursp(), idx); genop_1(s, OP_GT, cursp());
} }
else if (len == 2 && name[0] == '>' && name[1] == '=') { else if (len == 2 && name[0] == '>' && name[1] == '=') {
genop_2(s, OP_GE, cursp(), idx); genop_1(s, OP_GE, cursp());
} }
else { else {
genop_3(s, OP_SEND, cursp(), idx, 1); genop_3(s, OP_SEND, cursp(), idx, 1);
......
...@@ -328,38 +328,38 @@ codedump(mrb_state *mrb, mrb_irep *irep) ...@@ -328,38 +328,38 @@ codedump(mrb_state *mrb, mrb_irep *irep)
CASE(OP_ALIAS, BB): CASE(OP_ALIAS, BB):
printf("OP_ALIAS\t:%s\t%s\n", mrb_sym2name(mrb, irep->syms[a]), mrb_sym2name(mrb, irep->syms[b])); printf("OP_ALIAS\t:%s\t%s\n", mrb_sym2name(mrb, irep->syms[a]), mrb_sym2name(mrb, irep->syms[b]));
break; break;
CASE(OP_ADD, BB): CASE(OP_ADD, B):
printf("OP_ADD\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_ADD\tR%d\t\n", a);
break; break;
CASE(OP_ADDI, BBB): CASE(OP_ADDI, BB):
printf("OP_ADDI\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c); printf("OP_ADDI\tR%d\t%d\n", a, b);
break; break;
CASE(OP_SUB, BB): CASE(OP_SUB, B):
printf("OP_SUB\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_SUB\tR%d\t\n", a);
break; break;
CASE(OP_SUBI, BBB): CASE(OP_SUBI, BB):
printf("OP_SUBI\tR%d\t:%s\t%d\n", a, mrb_sym2name(mrb, irep->syms[b]), c); printf("OP_SUBI\tR%d\t%d\n", a, b);
break; break;
CASE(OP_MUL, BB): CASE(OP_MUL, B):
printf("OP_MUL\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_MUL\tR%d\t\n", a);
break; break;
CASE(OP_DIV, BB): CASE(OP_DIV, B):
printf("OP_DIV\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_DIV\tR%d\t\n", a);
break; break;
CASE(OP_LT, BB): CASE(OP_LT, B):
printf("OP_LT\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_LT\t\tR%d\t\n", a);
break; break;
CASE(OP_LE, BB): CASE(OP_LE, B):
printf("OP_LE\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_LE\t\tR%d\t\n", a);
break; break;
CASE(OP_GT, BB): CASE(OP_GT, B):
printf("OP_GT\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_GT\t\tR%d\t\n", a);
break; break;
CASE(OP_GE, BB): CASE(OP_GE, B):
printf("OP_GE\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_GE\t\tR%d\t\n", a);
break; break;
CASE(OP_EQ, BB): CASE(OP_EQ, B):
printf("OP_EQ\t\tR%d\t:%s\t\n", a, mrb_sym2name(mrb, irep->syms[b])); printf("OP_EQ\t\tR%d\t\n", a);
break; break;
CASE(OP_ARRAY, BB): CASE(OP_ARRAY, BB):
printf("OP_ARRAY\tR%d\t%d\t", a, b); printf("OP_ARRAY\tR%d\t%d\t", a, b);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <mruby/string.h> #include <mruby/string.h>
#include <mruby/dump.h> #include <mruby/dump.h>
#include <mruby/class.h> #include <mruby/class.h>
#include <mruby/symbol.h>
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
typedef struct symbol_name { typedef struct symbol_name {
...@@ -170,10 +171,35 @@ mrb_free_symtbl(mrb_state *mrb) ...@@ -170,10 +171,35 @@ mrb_free_symtbl(mrb_state *mrb)
kh_destroy(n2s, mrb, mrb->name2sym); kh_destroy(n2s, mrb, mrb->name2sym);
} }
struct reserved_symbol_t {
mrb_reserved_symbol sym;
char const *str;
};
static struct reserved_symbol_t reserved_symbols[] = {
{ mrb_sym_add, "+" },
{ mrb_sym_sub, "-" },
{ mrb_sym_mul, "*" },
{ mrb_sym_div, "/" },
{ mrb_sym_eq, "==" },
{ mrb_sym_lt, "<" },
{ mrb_sym_le, "<=" },
{ mrb_sym_gt, ">" },
{ mrb_sym_ge, ">=" },
{ mrb_sym_method_missing, "method_missing" },
{ mrb_sym_null, NULL },
};
void void
mrb_init_symtbl(mrb_state *mrb) mrb_init_symtbl(mrb_state *mrb)
{ {
int i;
mrb->name2sym = kh_init(n2s, mrb); mrb->name2sym = kh_init(n2s, mrb);
for (i = 0; reserved_symbols[i].sym != mrb_sym_null; ++i) {
mrb_sym s = mrb_intern_static(mrb, reserved_symbols[i].str, strlen(reserved_symbols[i].str));
mrb_assert(s == reserved_symbols[i].sym);
}
} }
/********************************************************************** /**********************************************************************
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <mruby/opcode.h> #include <mruby/opcode.h>
#include "value_array.h" #include "value_array.h"
#include <mruby/throw.h> #include <mruby/throw.h>
#include <mruby/symbol.h>
#ifdef MRB_DISABLE_STDIO #ifdef MRB_DISABLE_STDIO
#if defined(__cplusplus) #if defined(__cplusplus)
...@@ -1009,6 +1010,7 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc) ...@@ -1009,6 +1010,7 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
uint32_t a; uint32_t a;
uint16_t b; uint16_t b;
uint8_t c; uint8_t c;
mrb_sym mid;
#ifdef DIRECT_THREADED #ifdef DIRECT_THREADED
static void *optable[] = { static void *optable[] = {
...@@ -1386,9 +1388,18 @@ RETRY_TRY_BLOCK: ...@@ -1386,9 +1388,18 @@ RETRY_TRY_BLOCK:
SET_NIL_VALUE(regs[bidx]); SET_NIL_VALUE(regs[bidx]);
goto L_SENDB; goto L_SENDB;
}; };
L_SEND_CONSTSYM:
{
/* push nil after arguments */
int bidx = (c == CALL_MAXARGS) ? a+2 : a+c+1;
SET_NIL_VALUE(regs[bidx]);
goto L_SENDB_CONSTSYM;
};
CASE(OP_SENDB, BBB) CASE(OP_SENDB, BBB)
L_SENDB: L_SENDB:
mid = syms[b];
L_SENDB_CONSTSYM:
{ {
int argc = (c == CALL_MAXARGS) ? -1 : c; int argc = (c == CALL_MAXARGS) ? -1 : c;
int bidx = (argc < 0) ? a+2 : a+c+1; int bidx = (argc < 0) ? a+2 : a+c+1;
...@@ -1396,7 +1407,6 @@ RETRY_TRY_BLOCK: ...@@ -1396,7 +1407,6 @@ RETRY_TRY_BLOCK:
struct RClass *cls; struct RClass *cls;
mrb_callinfo *ci = mrb->c->ci; mrb_callinfo *ci = mrb->c->ci;
mrb_value recv, blk; mrb_value recv, blk;
mrb_sym mid = syms[b];
mrb_assert(bidx < irep->nregs); mrb_assert(bidx < irep->nregs);
...@@ -2204,7 +2214,7 @@ RETRY_TRY_BLOCK: ...@@ -2204,7 +2214,7 @@ RETRY_TRY_BLOCK:
v1(regs[a]) = v1(regs[a]) op v2(regs[a+1]);\ v1(regs[a]) = v1(regs[a]) op v2(regs[a+1]);\
} while(0) } while(0)
CASE(OP_ADD, BB) { CASE(OP_ADD, B) {
/* need to check if op is overridden */ /* need to check if op is overridden */
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
...@@ -2259,13 +2269,14 @@ RETRY_TRY_BLOCK: ...@@ -2259,13 +2269,14 @@ RETRY_TRY_BLOCK:
break; break;
default: default:
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_add;
goto L_SEND_CONSTSYM;
} }
mrb_gc_arena_restore(mrb, ai); mrb_gc_arena_restore(mrb, ai);
NEXT; NEXT;
} }
CASE(OP_SUB, BB) { CASE(OP_SUB, B) {
/* need to check if op is overridden */ /* need to check if op is overridden */
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
...@@ -2316,12 +2327,13 @@ RETRY_TRY_BLOCK: ...@@ -2316,12 +2327,13 @@ RETRY_TRY_BLOCK:
#endif #endif
default: default:
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_sub;
goto L_SEND_CONSTSYM;
} }
NEXT; NEXT;
} }
CASE(OP_MUL, BB) { CASE(OP_MUL, B) {
/* need to check if op is overridden */ /* need to check if op is overridden */
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
...@@ -2372,12 +2384,13 @@ RETRY_TRY_BLOCK: ...@@ -2372,12 +2384,13 @@ RETRY_TRY_BLOCK:
#endif #endif
default: default:
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_mul;
goto L_SEND_CONSTSYM;
} }
NEXT; NEXT;
} }
CASE(OP_DIV, BB) { CASE(OP_DIV, B) {
#ifndef MRB_WITHOUT_FLOAT #ifndef MRB_WITHOUT_FLOAT
double x, y, f; double x, y, f;
#endif #endif
...@@ -2411,7 +2424,8 @@ RETRY_TRY_BLOCK: ...@@ -2411,7 +2424,8 @@ RETRY_TRY_BLOCK:
#endif #endif
default: default:
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_div;
goto L_SEND_CONSTSYM;
} }
#ifndef MRB_WITHOUT_FLOAT #ifndef MRB_WITHOUT_FLOAT
...@@ -2428,13 +2442,13 @@ RETRY_TRY_BLOCK: ...@@ -2428,13 +2442,13 @@ RETRY_TRY_BLOCK:
NEXT; NEXT;
} }
CASE(OP_ADDI, BBB) { CASE(OP_ADDI, BB) {
/* need to check if + is overridden */ /* need to check if + is overridden */
switch (mrb_type(regs[a])) { switch (mrb_type(regs[a])) {
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
{ {
mrb_int x = mrb_fixnum(regs[a]); mrb_int x = mrb_fixnum(regs[a]);
mrb_int y = (mrb_int)c; mrb_int y = (mrb_int)b;
mrb_int z; mrb_int z;
if (mrb_int_add_overflow(x, y, &z)) { if (mrb_int_add_overflow(x, y, &z)) {
...@@ -2451,22 +2465,23 @@ RETRY_TRY_BLOCK: ...@@ -2451,22 +2465,23 @@ RETRY_TRY_BLOCK:
#ifdef MRB_WORD_BOXING #ifdef MRB_WORD_BOXING
{ {
mrb_float x = mrb_float(regs[a]); mrb_float x = mrb_float(regs[a]);
SET_FLOAT_VALUE(mrb, regs[a], x + c); SET_FLOAT_VALUE(mrb, regs[a], x + b);
} }
#else #else
mrb_float(regs[a]) += c; mrb_float(regs[a]) += b;
#endif #endif
break; break;
#endif #endif
default: default:
SET_INT_VALUE(regs[a+1], c); SET_INT_VALUE(regs[a+1], b);
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_add;
goto L_SEND_CONSTSYM;
} }
NEXT; NEXT;
} }
CASE(OP_SUBI, BBB) { CASE(OP_SUBI, BB) {
mrb_value *regs_a = regs + a; mrb_value *regs_a = regs + a;
/* need to check if + is overridden */ /* need to check if + is overridden */
...@@ -2474,7 +2489,7 @@ RETRY_TRY_BLOCK: ...@@ -2474,7 +2489,7 @@ RETRY_TRY_BLOCK:
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
{ {
mrb_int x = mrb_fixnum(regs_a[0]); mrb_int x = mrb_fixnum(regs_a[0]);
mrb_int y = (mrb_int)c; mrb_int y = (mrb_int)b;
mrb_int z; mrb_int z;
if (mrb_int_sub_overflow(x, y, &z)) { if (mrb_int_sub_overflow(x, y, &z)) {
...@@ -2491,17 +2506,18 @@ RETRY_TRY_BLOCK: ...@@ -2491,17 +2506,18 @@ RETRY_TRY_BLOCK:
#ifdef MRB_WORD_BOXING #ifdef MRB_WORD_BOXING
{ {
mrb_float x = mrb_float(regs[a]); mrb_float x = mrb_float(regs[a]);
SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x - (mrb_float)c); SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x - (mrb_float)b);
} }
#else #else
mrb_float(regs_a[0]) -= c; mrb_float(regs_a[0]) -= b;
#endif #endif
break; break;
#endif #endif
default: default:
SET_INT_VALUE(regs_a[1], c); SET_INT_VALUE(regs_a[1], b);
c = 1; c = 1;
goto L_SEND; mid = mrb_sym_sub;
goto L_SEND_CONSTSYM;
} }
NEXT; NEXT;
} }
...@@ -2509,7 +2525,7 @@ RETRY_TRY_BLOCK: ...@@ -2509,7 +2525,7 @@ RETRY_TRY_BLOCK:
#define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1])) #define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1]))
#ifdef MRB_WITHOUT_FLOAT #ifdef MRB_WITHOUT_FLOAT
#define OP_CMP(op) do {\ #define OP_CMP(op, sym) do {\
int result;\ int result;\
/* need to check if - is overridden */\ /* need to check if - is overridden */\
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
...@@ -2518,7 +2534,8 @@ RETRY_TRY_BLOCK: ...@@ -2518,7 +2534,8 @@ RETRY_TRY_BLOCK:
break;\ break;\
default:\ default:\
c = 1;\ c = 1;\
goto L_SEND;\ mid = mrb_sym_ ## sym;\
goto L_SEND_CONSTSYM;\
}\ }\
if (result) {\ if (result) {\
SET_TRUE_VALUE(regs[a]);\ SET_TRUE_VALUE(regs[a]);\
...@@ -2528,7 +2545,7 @@ RETRY_TRY_BLOCK: ...@@ -2528,7 +2545,7 @@ RETRY_TRY_BLOCK:
}\ }\
} while(0) } while(0)
#else #else
#define OP_CMP(op) do {\ #define OP_CMP(op, sym) do {\
int result;\ int result;\
/* need to check if - is overridden */\ /* need to check if - is overridden */\
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\
...@@ -2546,7 +2563,8 @@ RETRY_TRY_BLOCK: ...@@ -2546,7 +2563,8 @@ RETRY_TRY_BLOCK:
break;\ break;\
default:\ default:\
c = 1;\ c = 1;\
goto L_SEND;\ mid = mrb_sym_ ## sym;\
goto L_SEND_CONSTSYM;\
}\ }\
if (result) {\ if (result) {\
SET_TRUE_VALUE(regs[a]);\ SET_TRUE_VALUE(regs[a]);\
...@@ -2557,33 +2575,33 @@ RETRY_TRY_BLOCK: ...@@ -2557,33 +2575,33 @@ RETRY_TRY_BLOCK:
} while(0) } while(0)
#endif #endif
CASE(OP_EQ, BB) { CASE(OP_EQ, B) {
if (mrb_obj_eq(mrb, regs[a], regs[a+1])) { if (mrb_obj_eq(mrb, regs[a], regs[a+1])) {
SET_TRUE_VALUE(regs[a]); SET_TRUE_VALUE(regs[a]);
} }
else { else {
OP_CMP(==); OP_CMP(==, eq);
} }
NEXT; NEXT;
} }
CASE(OP_LT, BB) { CASE(OP_LT, B) {
OP_CMP(<); OP_CMP(<, lt);
NEXT; NEXT;
} }
CASE(OP_LE, BB) { CASE(OP_LE, B) {
OP_CMP(<=); OP_CMP(<=, le);
NEXT; NEXT;
} }
CASE(OP_GT, BB) { CASE(OP_GT, B) {
OP_CMP(>); OP_CMP(>, gt);
NEXT; NEXT;
} }
CASE(OP_GE, BB) { CASE(OP_GE, B) {
OP_CMP(>=); OP_CMP(>=, ge);
NEXT; NEXT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment