summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cdump.c19
-rw-r--r--src/numeric.c3
-rw-r--r--src/proc.c7
-rw-r--r--src/state.c3
4 files changed, 21 insertions, 11 deletions
diff --git a/src/cdump.c b/src/cdump.c
index ba05a1899..c7597e12f 100644
--- a/src/cdump.c
+++ b/src/cdump.c
@@ -113,6 +113,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
SOURCE_CODE0 (" ai = mrb->arena_idx;");
SOURCE_CODE0 (" irep = mrb->irep[idx] = mrb_malloc(mrb, sizeof(mrb_irep));");
+ SOURCE_CODE0 (" irep->flags = MRB_ISEQ_NO_FREE;");
SOURCE_CODE0 (" irep->idx = idx++;");
SOURCE_CODE (" irep->nlocals = %d;", irep->nlocals);
SOURCE_CODE (" irep->nregs = %d;", irep->nregs);
@@ -124,13 +125,19 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
SOURCE_CODE (" irep->syms = mrb_malloc(mrb, sizeof(mrb_sym)*%d);", irep->slen);
for (n=0; n<irep->slen; n++)
if (irep->syms[n]) {
- SOURCE_CODE (" irep->syms[%d] = mrb_intern(mrb, \"%s\");", n, mrb_sym2name(mrb, irep->syms[n]));
+ const char *name;
+ int len;
+
+ name = mrb_sym2name_len(mrb, irep->syms[n], &len);
+ SOURCE_CODE (" irep->syms[%d] = mrb_intern2(mrb, \"%s\", %d);", n, name, len);
}
}
else
SOURCE_CODE0 (" irep->syms = NULL;");
- SOURCE_CODE (" irep->plen = %d;", irep->plen);
+ SOURCE_CODE0 (" irep->pool = NULL;");
+ SOURCE_CODE0 (" mrb->irep_len = idx;");
+ SOURCE_CODE0 (" irep->plen = 0;");
if(irep->plen > 0) {
SOURCE_CODE (" irep->pool = mrb_malloc(mrb, sizeof(mrb_value)*%d);", irep->plen);
for (n=0; n<irep->plen; n++) {
@@ -148,16 +155,16 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
}
}
memset(buf, 0, buf_len);
- SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break;
+ SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n]));
+ SOURCE_CODE0 (" mrb->arena_idx = ai;");
+ break;
/* TODO MRB_TT_REGEX */
default: break;
}
+ SOURCE_CODE0(" irep->plen++;");
}
}
else
- SOURCE_CODE0 (" irep->pool = NULL;");
- SOURCE_CODE0 (" mrb->irep_len = idx;");
- SOURCE_CODE0 (" mrb->arena_idx = ai;");
SOURCE_CODE0("");
return MRB_CDUMP_OK;
}
diff --git a/src/numeric.c b/src/numeric.c
index 6970869df..284d0a82e 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -949,8 +949,7 @@ fix_xor(mrb_state *mrb, mrb_value x)
static mrb_value
lshift(mrb_state *mrb, mrb_int val, unsigned long width)
{
- if (width > (sizeof(mrb_int)*CHAR_BIT-1)
- || ((unsigned long)abs(val))>>(sizeof(mrb_int)*CHAR_BIT-1-width) > 0) {
+ if (width > (sizeof(mrb_int)*CHAR_BIT-1)) {
mrb_raise(mrb, E_RANGE_ERROR, "width(%d) > (%d:sizeof(mrb_int)*CHAR_BIT-1)", width,
sizeof(mrb_int)*CHAR_BIT-1);
}
diff --git a/src/proc.c b/src/proc.c
index 0efc8d286..3321c2a91 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -9,6 +9,10 @@
#include "mruby/class.h"
#include "opcode.h"
+static mrb_code call_iseq[] = {
+ MKOP_A(OP_CALL, 0),
+};
+
struct RProc *
mrb_proc_new(mrb_state *mrb, mrb_irep *irep)
{
@@ -144,14 +148,13 @@ void
mrb_init_proc(mrb_state *mrb)
{
struct RProc *m;
- mrb_code *call_iseq = (mrb_code *)mrb_alloca(mrb, sizeof(mrb_code));
mrb_irep *call_irep = (mrb_irep *)mrb_alloca(mrb, sizeof(mrb_irep));
if ( call_iseq == NULL || call_irep == NULL )
return;
memset(call_irep, 0, sizeof(mrb_irep));
- *call_iseq = MKOP_A(OP_CALL, 0);
+ call_irep->flags = MRB_ISEQ_NO_FREE;
call_irep->idx = -1;
call_irep->iseq = call_iseq;
call_irep->ilen = 1;
diff --git a/src/state.c b/src/state.c
index 40d9bfc45..991be310e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -92,7 +92,8 @@ mrb_close(mrb_state *mrb)
mrb_free(mrb, mrb->stbase);
mrb_free(mrb, mrb->cibase);
for (i=0; i<mrb->irep_len; i++) {
- mrb_free(mrb, mrb->irep[i]->iseq);
+ if (!(mrb->irep[i]->flags & MRB_ISEQ_NO_FREE))
+ mrb_free(mrb, mrb->irep[i]->iseq);
mrb_free(mrb, mrb->irep[i]->pool);
mrb_free(mrb, mrb->irep[i]->syms);
mrb_free(mrb, mrb->irep[i]->lines);