summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mruby/cdump.h3
-rw-r--r--mrblib/array.rb10
-rw-r--r--src/cdump.c21
-rw-r--r--src/codegen.c4
-rw-r--r--src/dump.c5
-rw-r--r--src/error.c2
-rw-r--r--src/gc.c2
-rw-r--r--tools/mirb/mirb.c3
8 files changed, 32 insertions, 18 deletions
diff --git a/include/mruby/cdump.h b/include/mruby/cdump.h
index 6afbb985e..ccb5fc06b 100644
--- a/include/mruby/cdump.h
+++ b/include/mruby/cdump.h
@@ -23,6 +23,9 @@ int mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
/* error code */
#define MRB_CDUMP_OK 0
#define MRB_CDUMP_GENERAL_FAILURE -1
+#define MRB_CDUMP_WRITE_FAULT -2
+#define MRB_CDUMP_INVALID_IREP -6
+#define MRB_CDUMP_INVALID_ARGUMENT -7
#if defined(__cplusplus)
} /* extern "C" { */
diff --git a/mrblib/array.rb b/mrblib/array.rb
index 3c4e2dd76..56bf5ceb2 100644
--- a/mrblib/array.rb
+++ b/mrblib/array.rb
@@ -11,8 +11,14 @@ class Array
# ISO 15.2.12.5.10
def each(&block)
idx, length = -1, self.length-1
- while(idx < length)
- block.call(self[idx += 1])
+ while idx < length and length < self.length and length = self.length-1
+ elm = self[idx += 1]
+ unless elm
+ if elm == nil and length >= self.length
+ break
+ end
+ end
+ block.call(elm)
end
self
end
diff --git a/src/cdump.c b/src/cdump.c
index 7cb159046..247511f5a 100644
--- a/src/cdump.c
+++ b/src/cdump.c
@@ -23,7 +23,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f)
mrb_irep *irep = mrb->irep[irep_no];
if (irep == NULL)
- return -1;
+ return MRB_CDUMP_INVALID_IREP;
/* dump isec struct*/
if (irep->ilen > 0) {
@@ -34,7 +34,7 @@ make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f)
SOURCE_CODE0 ("");
}
- return 0;
+ return MRB_CDUMP_OK;
}
static size_t
@@ -104,7 +104,7 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
size_t buf_len, str_len;
if (irep == NULL)
- return -1;
+ return MRB_CDUMP_INVALID_IREP;
buf_len = MRB_CDUMP_LINE_LEN;
if ((buf = (char *)mrb_malloc(mrb, buf_len)) == NULL) {
@@ -176,9 +176,10 @@ int
mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
{
int irep_no;
+ int error;
if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL)
- return -1;
+ return MRB_CDUMP_INVALID_ARGUMENT;
SOURCE_CODE0("#include \"mruby.h\"");
SOURCE_CODE0("#include \"mruby/irep.h\"");
@@ -187,8 +188,9 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
SOURCE_CODE0("");
for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
- if (make_cdump_isec(mrb, irep_no, f) != 0)
- return -1;
+ error = make_cdump_isec(mrb, irep_no, f);
+ if (error != MRB_CDUMP_OK)
+ return error;
}
SOURCE_CODE0("void");
@@ -200,12 +202,13 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
SOURCE_CODE0(" mrb_irep *irep;");
SOURCE_CODE0("");
for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
- if (make_cdump_irep(mrb, irep_no, f) != 0)
- return -1;
+ error = make_cdump_irep(mrb, irep_no, f);
+ if (error != MRB_CDUMP_OK)
+ return error;
}
SOURCE_CODE0(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));");
SOURCE_CODE0("}");
- return 0;
+ return MRB_CDUMP_OK;
}
diff --git a/src/codegen.c b/src/codegen.c
index 6168c7c0e..e728da4ca 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -429,12 +429,12 @@ new_msym(codegen_scope *s, mrb_sym sym)
int i, len;
len = s->irep->slen;
- if (len > 255) len = 255;
+ if (len > 256) len = 256;
for (i=0; i<len; i++) {
if (s->irep->syms[i] == sym) return i;
if (s->irep->syms[i] == 0) break;
}
- if (i > 255) {
+ if (i == 256) {
codegen_error(s, "too many symbols (max 256)");
}
s->irep->syms[i] = sym;
diff --git a/src/dump.c b/src/dump.c
index 2885c225a..884a9141f 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -507,6 +507,7 @@ calc_crc_section(mrb_state *mrb, mrb_irep *irep, uint16_t *crc, int section)
result = write_syms_block(mrb, irep, buf, type);
break;
default:
+ result = MRB_DUMP_GENERAL_FAILURE;
break; /* Already checked above. */
}
if (result < 0) {
@@ -689,7 +690,7 @@ mrb_write_irep(mrb_state *mrb, int top, char *bin)
for (irep_no=top; irep_no<mrb->irep_len; irep_no++) {
rc = write_irep_record(mrb, irep_no, bin, &rlen, DUMP_TYPE_BIN);
- if (rc != 0)
+ if (rc != MRB_DUMP_OK)
return rc;
bin += (rlen + DUMP_SIZE(MRB_DUMP_SIZE_OF_LONG, DUMP_TYPE_BIN));
@@ -718,7 +719,7 @@ mrb_dump_irep(mrb_state *mrb, int top, FILE* fp)
for (irep_no=top; irep_no<mrb->irep_len; irep_no++) {
rc = dump_irep_record(mrb, irep_no, fp, &rlen);
- if (rc != 0)
+ if (rc != MRB_DUMP_OK)
return rc;
rbds += rlen;
diff --git a/src/error.c b/src/error.c
index 430728db0..b9e5690a8 100644
--- a/src/error.c
+++ b/src/error.c
@@ -419,8 +419,6 @@ mrb_init_exception(mrb_state *mrb)
mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */
mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */
-
- mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */
e = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */
mrb_define_class(mrb, "SyntaxError", e); /* 15.2.38 */
}
diff --git a/src/gc.c b/src/gc.c
index 2505fce28..69e36640d 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -983,7 +983,7 @@ mrb_field_write_barrier(mrb_state *mrb, struct RBasic *obj, struct RBasic *value
gc_assert(!is_dead(mrb, value) && !is_dead(mrb, obj));
gc_assert(is_generational(mrb) || mrb->gc_state != GC_STATE_NONE);
- if (is_minor_gc(mrb) || mrb->gc_state == GC_STATE_MARK) {
+ if (is_generational(mrb) || mrb->gc_state == GC_STATE_MARK) {
add_gray_list(mrb, value);
}
else {
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index b89c63cff..85c3249d2 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -159,6 +159,7 @@ main(void)
mrb_value result;
int n;
int code_block_open = FALSE;
+ int ai;
print_hint();
@@ -172,6 +173,7 @@ main(void)
cxt = mrbc_context_new(mrb);
cxt->capture_errors = 1;
+ ai = mrb_gc_arena_save(mrb);
while (TRUE) {
#ifndef ENABLE_READLINE
print_cmdline(code_block_open);
@@ -253,6 +255,7 @@ main(void)
ruby_code[0] = '\0';
last_code_line[0] = '\0';
mrb_parser_free(parser);
+ mrb_gc_arena_restore(mrb, ai);
}
}
mrbc_context_free(mrb, cxt);