diff options
| -rw-r--r-- | src/codegen.c | 8 | ||||
| -rw-r--r-- | src/dump.c | 18 | ||||
| -rw-r--r-- | src/vm.c | 23 | ||||
| -rw-r--r-- | test/t/exception.rb | 23 | ||||
| -rw-r--r-- | tools/mirb/mirb.c | 2 | ||||
| -rw-r--r-- | tools/mrbc/mrbc.c | 4 |
6 files changed, 45 insertions, 33 deletions
diff --git a/src/codegen.c b/src/codegen.c index 83d0136ef..d9fc10657 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -317,6 +317,14 @@ genop_peep(codegen_scope *s, mrb_code i, int val) s->iseq[s->pc-1] = MKOP_A(c0, 0); genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL)); return; +#if 0 + case OP_SEND: + if (GETARG_B(i) == OP_R_NORMAL && GETARG_A(i) == GETARG_A(i0)) { + s->iseq[s->pc-1] = MKOP_ABC(OP_TAILCALL, GETARG_A(i0), GETARG_B(i0), GETARG_C(i0)); + return; + } + break; +#endif default: break; } diff --git a/src/dump.c b/src/dump.c index 9579dabd4..1d59e667b 100644 --- a/src/dump.c +++ b/src/dump.c @@ -499,6 +499,22 @@ mrb_dump_irep_binary(mrb_state *mrb, size_t start_index, int debug_info, FILE* f return result; } +static int +is_valid_c_symbol_name(const char *name) +{ + const char *c = NULL; + + if (name == NULL || name[0] == '\0') return 0; + if (!ISALPHA(name[0]) && name[0] != '_') return 0; + + c = &name[1]; + for (; *c != '\0'; ++c) { + if (!ISALNUM(*c) && *c != '_') return 0; + } + + return 1; +} + int mrb_dump_irep_cfunc(mrb_state *mrb, size_t start_index, int debug_info, FILE *fp, const char *initname) { @@ -506,7 +522,7 @@ mrb_dump_irep_cfunc(mrb_state *mrb, size_t start_index, int debug_info, FILE *fp size_t bin_size = 0, bin_idx = 0; int result; - if (fp == NULL || initname == NULL) { + if (fp == NULL || initname == NULL || !is_valid_c_symbol_name(initname)) { return MRB_DUMP_INVALID_ARGUMENT; } @@ -403,7 +403,7 @@ mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv, mrb_v ci->nregs = argc + 2; } else { - ci->nregs = p->body.irep->nregs + 2; + ci->nregs = p->body.irep->nregs + 1; } ci->acc = -1; mrb->stack = mrb->stack + n; @@ -568,7 +568,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } stack_extend(mrb, irep->nregs, irep->nregs); mrb->ci->proc = proc; - mrb->ci->nregs = irep->nregs + 2; + mrb->ci->nregs = irep->nregs + 1; regs = mrb->stack; regs[0] = self; @@ -873,7 +873,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) else { ci->argc = n; } - ci->target_class = c; + if (c->tt == MRB_TT_ICLASS) { + ci->target_class = c->c; + } + else { + ci->target_class = c; + } + ci->pc = pc + 1; ci->acc = a; @@ -1189,9 +1195,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) NEXT; } + L_RETURN: + i = MKOP_AB(OP_RETURN, GETARG_A(i), OP_R_NORMAL); + /* fall through */ CASE(OP_RETURN) { /* A return R(A) */ - L_RETURN: if (mrb->exc) { mrb_callinfo *ci; int eidx; @@ -1327,7 +1335,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } } - /* replace callinfo */ ci = mrb->ci; ci->mid = mid; @@ -1652,7 +1659,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } while (0) CASE(OP_EQ) { - /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/ + /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:==,C=1)*/ int a = GETARG_A(i); if (mrb_obj_eq(mrb, regs[a], regs[a+1])) { SET_TRUE_VALUE(regs[a]); @@ -1670,7 +1677,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } CASE(OP_LE) { - /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/ + /* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1)*/ OP_CMP(<=); NEXT; } @@ -1682,7 +1689,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) } CASE(OP_GE) { - /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/ + /* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1)*/ OP_CMP(>=); NEXT; } diff --git a/test/t/exception.rb b/test/t/exception.rb index 7ecc51fa8..d43ce8833 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -318,26 +318,3 @@ end assert('Exception#inspect without message') do Exception.new.inspect end - -# very deeply recursive function that stil returns albeit very deeply so -$test_infinite_recursion = 0 -TEST_INFINITE_RECURSION_MAX = 1000000 -def test_infinite_recursion - $test_infinite_recursion += 1 - if $test_infinite_recursion > TEST_INFINITE_RECURSION_MAX - return $test_infinite_recursion - end - test_infinite_recursion -end - -assert('Infinite recursion should result in an exception being raised') do - a = begin - test_infinite_recursion - rescue - :ok - end - # OK if an exception was caught, otherwise a number will be stored in a - a == :ok -end - - diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 008829cfb..cde0b0d4b 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -273,7 +273,7 @@ main(int argc, char **argv) printf("\n"); break; } - strncat(last_code_line, line, sizeof(last_code_line)-1); + strncpy(last_code_line, line, sizeof(last_code_line)-1); add_history(line); free(line); #endif diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 9eb7e9614..cb4de6d2a 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -215,6 +215,10 @@ main(int argc, char **argv) } if (args.initname) { n = mrb_dump_irep_cfunc(mrb, n, args.debug_info, args.wfp, args.initname); + if (n == MRB_DUMP_INVALID_ARGUMENT) { + printf("%s: Invalid C language symbol name\n", args.initname); + return EXIT_FAILURE; + } } else { n = mrb_dump_irep_binary(mrb, n, args.debug_info, args.wfp); |
