summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--INSTALL4
-rw-r--r--Makefile2
-rw-r--r--include/mrbconf.h16
-rw-r--r--include/mruby.h2
-rw-r--r--include/mruby/array.h6
-rw-r--r--include/mruby/cdump.h (renamed from src/cdump.h)6
-rw-r--r--include/mruby/class.h6
-rw-r--r--include/mruby/data.h13
-rw-r--r--include/mruby/dump.h (renamed from src/dump.h)8
-rw-r--r--include/mruby/hash.h6
-rw-r--r--include/mruby/irep.h (renamed from src/irep.h)6
-rw-r--r--include/mruby/khash.h (renamed from src/ritehash.h)12
-rw-r--r--include/mruby/numeric.h8
-rw-r--r--include/mruby/object.h6
-rw-r--r--include/mruby/proc.h6
-rw-r--r--include/mruby/range.h6
-rw-r--r--include/mruby/string.h15
-rw-r--r--include/mruby/struct.h6
-rw-r--r--include/mruby/variable.h (renamed from src/variable.h)6
-rw-r--r--mrblib/Makefile2
-rw-r--r--mrblib/init_mrblib.c4
-rw-r--r--src/Makefile1
-rw-r--r--src/array.c27
-rw-r--r--src/cdump.c14
-rw-r--r--src/class.c46
-rw-r--r--src/codegen.c8
-rw-r--r--src/compar.c6
-rw-r--r--src/compile.h18
-rw-r--r--src/crc.c6
-rw-r--r--src/dump.c10
-rw-r--r--src/encoding.c17
-rw-r--r--src/encoding.h15
-rw-r--r--src/enum.c16
-rw-r--r--src/error.c12
-rw-r--r--src/error.h6
-rw-r--r--src/etc.c8
-rw-r--r--src/eval_intern.h6
-rw-r--r--src/gc.c65
-rw-r--r--src/gc.h6
-rw-r--r--src/hash.c28
-rw-r--r--src/init.c6
-rw-r--r--src/init_ext.c6
-rw-r--r--src/kernel.c50
-rw-r--r--src/load.c16
-rw-r--r--src/method.h14
-rw-r--r--src/minimain.c6
-rw-r--r--src/node.h6
-rw-r--r--src/numeric.c151
-rw-r--r--src/object.c9
-rw-r--r--src/opcode.h6
-rw-r--r--src/parse.y104
-rw-r--r--src/pool.c6
-rw-r--r--src/pool.h6
-rw-r--r--src/print.c10
-rw-r--r--src/proc.c8
-rw-r--r--src/range.c10
-rw-r--r--src/re.c40
-rw-r--r--src/re.h10
-rw-r--r--src/regex.h14
-rw-r--r--src/sprintf.c26
-rw-r--r--src/state.c8
-rw-r--r--src/string.c94
-rw-r--r--src/struct.c18
-rw-r--r--src/symbol.c15
-rw-r--r--src/transcode.c2
-rw-r--r--src/variable.c28
-rw-r--r--src/version.c18
-rw-r--r--src/version.h6
-rw-r--r--src/vm.c13
-rw-r--r--src/vm_core.h15
-rw-r--r--tools/mrbc/Makefile1
-rw-r--r--tools/mrbc/mrbc.c10
-rw-r--r--tools/mruby/Makefile1
-rw-r--r--tools/mruby/mruby.c136
75 files changed, 792 insertions, 545 deletions
diff --git a/.gitignore b/.gitignore
index 76fdc3066..94a9f5d79 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@
*.dylib
*.inc
*.o
+*.a
*.orig
*.rej
*.sav
@@ -14,5 +15,7 @@
.svn
/.git
cscope.out
-mruby.exe
-y.tab.c
+/src/y.tab.c
+/bin
+/mrblib/mrblib.c
+/mrblib/*.*tmp
diff --git a/INSTALL b/INSTALL
index e6c84b501..92851c86d 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,3 +1,7 @@
+* Prerequisites
+
+ 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system.
+
* Compilation and Installation
1. Run make in the top directory.
diff --git a/Makefile b/Makefile
index 76f4ef594..55988683b 100644
--- a/Makefile
+++ b/Makefile
@@ -113,8 +113,10 @@ $(OBJM) : $(MSRC)
.PHONY : clean
clean :
$(MAKE) clean -C src $(MAKE_FLAGS)
+ $(MAKE) clean -C tools/mrbc $(MAKE_FLAGS)
$(MAKE) clean -C tools/mruby $(MAKE_FLAGS)
-rm -f $(EXE) $(OBJM)
-rm -f $(OBJM:.o=.d)
+ -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
-rm -f $(IOSLIB) $(IOSSIMLIB) $(IOSDEVLIB)
@echo "make: removing targets, objects and depend files of `pwd`"
diff --git a/include/mrbconf.h b/include/mrbconf.h
index 923558fd9..4963634e3 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -1,13 +1,25 @@
+/*
+** mrbconf.h - mruby core configuration
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBYCONF_H
#define MRUBYCONF_H
#include <stdint.h>
+#undef MRB_USE_FLOAT
+
+#ifdef MRB_USE_FLOAT
+typedef float mrb_float;
+#else
typedef double mrb_float;
+#endif
+#define readfloat(p) (mrb_float)strtod((p),NULL)
+
typedef int32_t mrb_int;
typedef intptr_t mrb_sym;
-
#define readint(p,base) strtol((p),NULL,(base))
-#define readfloat(p) strtod((p),NULL)
#undef INCLUDE_ENCODING /* not use encoding classes (ascii only) */
#define INCLUDE_ENCODING /* use UTF-8 encoding classes */
diff --git a/include/mruby.h b/include/mruby.h
index d0f8af90f..ace3b67ec 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -24,6 +24,7 @@
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/
+
#ifndef MRUBY_H
#define MRUBY_H
@@ -348,6 +349,7 @@ mrb_state* mrb_open_allocf(mrb_allocf);
void mrb_close(mrb_state*);
int mrb_checkstack(mrb_state*,int);
+mrb_value mrb_top_self(mrb_state *);
mrb_value mrb_run(mrb_state*, struct RProc*, mrb_value);
mrb_value mrb_p(mrb_state*, mrb_value);
diff --git a/include/mruby/array.h b/include/mruby/array.h
index 6f382ef6a..4d43f4c07 100644
--- a/include/mruby/array.h
+++ b/include/mruby/array.h
@@ -1,3 +1,9 @@
+/*
+** array.h - Array class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_ARRAY_H
#define MRUBY_ARRAY_H
diff --git a/src/cdump.h b/include/mruby/cdump.h
index 82fc442a6..f74d7a046 100644
--- a/src/cdump.h
+++ b/include/mruby/cdump.h
@@ -1,3 +1,9 @@
+/*
+** cdump.h - mruby binary dumper (C source format)
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdio.h>
diff --git a/include/mruby/class.h b/include/mruby/class.h
index 470f517c3..5f4e8e0d2 100644
--- a/include/mruby/class.h
+++ b/include/mruby/class.h
@@ -1,3 +1,9 @@
+/*
+** class.h - Class class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_CLASS_H
#define MRUBY_CLASS_H
diff --git a/include/mruby/data.h b/include/mruby/data.h
index 07e0f72cd..02d81155a 100644
--- a/include/mruby/data.h
+++ b/include/mruby/data.h
@@ -1,11 +1,8 @@
-/**********************************************************************
-
- data.h -
-
-
- Copyright (C) 2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** data.h - Data class
+**
+** See Copyright Notice in mruby.h
+*/
#ifndef RUBY_DATA_H
#define RUBY_DATA_H 1
diff --git a/src/dump.h b/include/mruby/dump.h
index 410dfcd71..1bdd9b91e 100644
--- a/src/dump.h
+++ b/include/mruby/dump.h
@@ -1,3 +1,9 @@
+/*
+** dump.h - mruby binary dumper (Rite binary format)
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdio.h>
#include <stdint.h>
@@ -5,7 +11,7 @@
int mrb_dump_irep(mrb_state*,int,FILE*);
int mrb_load_irep(mrb_state*,FILE*);
int mrb_load_irep_offset(mrb_state*,FILE*,long);
-int mrb_read_irep(mrb_state*,char*);
+int mrb_read_irep(mrb_state*,const char*);
int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
diff --git a/include/mruby/hash.h b/include/mruby/hash.h
index b2c3d69c8..4bbb8f764 100644
--- a/include/mruby/hash.h
+++ b/include/mruby/hash.h
@@ -1,3 +1,9 @@
+/*
+** hash.h - Hash class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_HASH_H
#define MRUBY_HASH_H
diff --git a/src/irep.h b/include/mruby/irep.h
index d73931a90..b3f9e8d87 100644
--- a/src/irep.h
+++ b/include/mruby/irep.h
@@ -1,3 +1,9 @@
+/*
+** irep.h - mrb_irep structure
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_IREP_H
#define MRUBY_IREP_H
diff --git a/src/ritehash.h b/include/mruby/khash.h
index 48feb9656..6f369a455 100644
--- a/src/ritehash.h
+++ b/include/mruby/khash.h
@@ -1,8 +1,9 @@
/*
- * Rite Hash
- *
- *
- */
+** ritehash.c - Rite Hash for mruby
+**
+** See Copyright Notice in mruby.h
+*/
+
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -107,7 +108,6 @@ static uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
while( new_n_buckets < limit ) new_n_buckets *= 2; \
} \
uint8_t *old_e_flags = h->e_flags; \
- uint8_t *old_d_flags = h->d_flags; \
khkey_t *old_keys = h->keys; \
khval_t *old_vals = h->vals; \
khint_t old_n_buckets = h->n_buckets; \
@@ -167,7 +167,7 @@ static uint8_t __m[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
#define kh_destroy(name, h) kh_destroy_##name(h)
#define kh_clear(name, h) kh_clear_##name(h)
#define kh_resize(name, h, s) kh_resize_##name(h, s)
-#define kh_put(name, h, k, r) kh_put_##name(h, k)
+#define kh_put(name, h, k) kh_put_##name(h, k)
#define kh_get(name, h, k) kh_get_##name(h, k)
#define kh_del(name, h, k) kh_del_##name(h, k)
#define kh_debug(name, h) kh_debug_##name(h)
diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h
index ee559fa1d..af1b671e2 100644
--- a/include/mruby/numeric.h
+++ b/include/mruby/numeric.h
@@ -1,3 +1,9 @@
+/*
+** numeric.h - Numeric, Integer, Float, Fixnum class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_NUMERIC_H
#define MRUBY_NUMERIC_H
@@ -10,7 +16,7 @@
#define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
-mrb_value mrb_dbl2big(mrb_state *mrb, float d);
+mrb_value mrb_flt2big(mrb_state *mrb, float d);
void mrb_num_zerodiv(mrb_state *mrb);
mrb_value mrb_fix2str(mrb_state *mrb, mrb_value x, int base);
diff --git a/include/mruby/object.h b/include/mruby/object.h
index e73ebe79a..e509baf79 100644
--- a/include/mruby/object.h
+++ b/include/mruby/object.h
@@ -1,3 +1,9 @@
+/*
+** object.h - Object, NilClass, TrueClass, FalseClass class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_OBJECT_H
#define MRUBY_OBJECT_H
diff --git a/include/mruby/proc.h b/include/mruby/proc.h
index eafe54cf9..a06896a3f 100644
--- a/include/mruby/proc.h
+++ b/include/mruby/proc.h
@@ -1,3 +1,9 @@
+/*
+** proc.h - Proc class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_PROC_H
#define MRUBY_PROC_H
diff --git a/include/mruby/range.h b/include/mruby/range.h
index d25690ab3..9ffddbcae 100644
--- a/include/mruby/range.h
+++ b/include/mruby/range.h
@@ -1,3 +1,9 @@
+/*
+** range.h - Range class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_RANGE_H
#define MRUBY_RANGE_H
diff --git a/include/mruby/string.h b/include/mruby/string.h
index e889d8447..d35a5fe53 100644
--- a/include/mruby/string.h
+++ b/include/mruby/string.h
@@ -1,3 +1,9 @@
+/*
+** string.h - String class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_STRING_H
#define MRUBY_STRING_H
@@ -20,10 +26,10 @@ extern const char ruby_digitmap[];
struct RString {
MRUBY_OBJECT_HEADER;
- size_t len;
+ long len;
union {
size_t capa;
- mrb_value shared;
+ struct RString *shared;
} aux;
char *buf;
};
@@ -43,11 +49,6 @@ struct RVarmap {
};
extern struct RVarmap *ruby_dyna_vars;
-//struct st_hash_type {
-// int (*compare)();
-// int (*hash)();
-//};
-
#define mrb_str_ptr(s) ((struct RString*)((s).value.p))
#define RSTRING(s) ((struct RString*)((s).value.p))
#define RSTRING_PTR(s) (RSTRING(s)->buf)
diff --git a/include/mruby/struct.h b/include/mruby/struct.h
index b8244045d..32fa48030 100644
--- a/include/mruby/struct.h
+++ b/include/mruby/struct.h
@@ -1,3 +1,9 @@
+/*
+** struct.h - Struct class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MSTRUCT_H
#define MSTRUCT_H
diff --git a/src/variable.h b/include/mruby/variable.h
index 4f2f6a598..9076fcf7c 100644
--- a/src/variable.h
+++ b/include/mruby/variable.h
@@ -1,3 +1,9 @@
+/*
+** variable.h - mruby variables
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_VARIABLE_H
#define MRUBY_VARIABLE_H
diff --git a/mrblib/Makefile b/mrblib/Makefile
index 0192ec941..ef60654fd 100644
--- a/mrblib/Makefile
+++ b/mrblib/Makefile
@@ -59,5 +59,7 @@ $(RLIB) : $(MRBS)
.PHONY : clean
clean :
-rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB)
+ -rm -f $(patsubst %.c,%.d,$(CLIB))
+ -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
@echo "make: removing targets, objects and depend files of `pwd`"
diff --git a/mrblib/init_mrblib.c b/mrblib/init_mrblib.c
index c44d28f94..a845489f5 100644
--- a/mrblib/init_mrblib.c
+++ b/mrblib/init_mrblib.c
@@ -1,6 +1,6 @@
#include "mruby.h"
-#include "irep.h"
-#include "dump.h"
+#include "mruby/irep.h"
+#include "mruby/dump.h"
#include "mruby/string.h"
#include "mruby/proc.h"
diff --git a/src/Makefile b/src/Makefile
index abb6f4c4b..fb5483a72 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -86,5 +86,6 @@ clean :
$(MAKE) clean -C ../mrblib $(MAKE_FLAGS)
-rm -f $(LIB) $(OBJS) $(OBJY) $(YC)
-rm -f $(OBJS:.o=.d) $(OBJY:.o=.d)
+ -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
@echo "make: removing targets, objects and depend files of `pwd`"
diff --git a/src/array.c b/src/array.c
index 75b2cd0c1..5ffa03821 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1,3 +1,9 @@
+/*
+** array.c - Array class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/array.h"
#include <string.h>
@@ -900,6 +906,7 @@ mrb_ary_sort_bang(mrb_value ary)
}
#endif
+#if 0
mrb_value
mrb_ary_dup(mrb_state *mrb, mrb_value self)
{
@@ -922,7 +929,6 @@ mrb_ary_dup(mrb_state *mrb, mrb_value self)
return ary;
}
-#if 0
/*
* call-seq:
* ary.sort -> new_ary
@@ -995,24 +1001,19 @@ inspect_ary(mrb_state *mrb, mrb_value ary, mrb_value list)
static mrb_value
inspect_ary_r(mrb_state *mrb, mrb_value ary, mrb_value dummy, int recur)
{
- //int tainted = OBJ_TAINTED(ary);
- //int untrust = OBJ_UNTRUSTED(ary);
long i;
mrb_value s, arystr;
- //if (recur) return mrb_tainted_str_new2("[...]");
+
arystr = mrb_str_buf_new(mrb, 128);
mrb_str_buf_cat(mrb, arystr, "[", strlen("[")); /* for capa */
//arystr = mrb_str_new_cstr(mrb, "[");//mrb_str_buf_new2("[");
for (i=0; i<RARRAY_LEN(ary); i++) {
s = mrb_inspect(mrb, RARRAY_PTR(ary)[i]);//mrb_inspect(RARRAY_PTR(ary)[i]);
- //if (OBJ_TAINTED(s)) tainted = TRUE;
- //if (OBJ_UNTRUSTED(s)) untrust = TRUE;
if (i > 0) mrb_str_buf_cat(mrb, arystr, ", ", strlen(", "));//mrb_str_buf_cat2(str, ", ");
mrb_str_buf_append(mrb, arystr, s);
}
mrb_str_buf_cat(mrb, arystr, "]", strlen("]"));// mrb_str_buf_cat2(str, "]");
- //if (tainted) OBJ_TAINT(str);
- //if (untrust) OBJ_UNTRUST(str);
+
return arystr;
}
#endif
@@ -1132,8 +1133,6 @@ ary_join_0(mrb_state *mrb, mrb_value ary, mrb_value sep, long max, mrb_value res
if (i > 0 && !mrb_nil_p(sep))
mrb_str_buf_append(mrb, result, sep);
mrb_str_buf_append(mrb, result, val);
- //if (OBJ_TAINTED(val)) OBJ_TAINT(result);
- //if (OBJ_UNTRUSTED(val)) OBJ_TAINT(result);
}
}
@@ -1199,13 +1198,9 @@ mrb_value
mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
{
long len = 1, i;
- //int taint = FALSE;
- //int untrust = FALSE;
mrb_value val, tmp, result;
if (RARRAY_LEN(ary) == 0) return mrb_str_new2(mrb, "");
- //if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) taint = TRUE;
- //if (OBJ_UNTRUSTED(ary) || OBJ_UNTRUSTED(sep)) untrust = TRUE;
if (!mrb_nil_p(sep)) {
//StringValue(sep);
@@ -1221,8 +1216,6 @@ mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
mrb_value first;
result = mrb_str_buf_new(mrb, len + (RARRAY_LEN(ary)-i)*10);
- //if (taint) OBJ_TAINT(result);
- //if (untrust) OBJ_UNTRUST(result);
first = (i == 0)? mrb_true_value(): mrb_false_value();
mrb_realloc(mrb, RSTRING(result)->buf, ++(RSTRING(result)->capa));
ary_join_0(mrb, ary, sep, i, result);
@@ -1236,8 +1229,6 @@ mrb_realloc(mrb, RSTRING(result)->buf, ++(RSTRING(result)->capa));
}
result = mrb_str_buf_new(mrb, len);
- //if (taint) OBJ_TAINT(result);
- //if (untrust) OBJ_UNTRUST(result);
ary_join_0(mrb, ary, sep, RARRAY_LEN(ary), result);
return result;
diff --git a/src/cdump.c b/src/cdump.c
index 424b4f69b..47c89300c 100644
--- a/src/cdump.c
+++ b/src/cdump.c
@@ -1,8 +1,14 @@
-#include "cdump.h"
+/*
+** cdump.c - mruby binary dumper (C source format)
+**
+** See Copyright Notice in mruby.h
+*/
+
+#include "mruby/cdump.h"
#include <string.h>
-#include "irep.h"
+#include "mruby/irep.h"
#include "mruby/string.h"
#include "re.h"
@@ -140,7 +146,7 @@ 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\", %zd);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break;
+ SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %ld);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n])); break;
/* TODO MRB_TT_REGEX */
default: break;
}
@@ -163,7 +169,7 @@ mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
irep_num = mrb->irep_len - n;
SOURCE_CODE0("#include \"mruby.h\"");
- SOURCE_CODE0("#include \"irep.h\"");
+ SOURCE_CODE0("#include \"mruby/irep.h\"");
SOURCE_CODE0("#include \"mruby/string.h\"");
SOURCE_CODE0("#include \"mruby/proc.h\"");
SOURCE_CODE0("");
diff --git a/src/class.c b/src/class.c
index 9abd90c31..879502364 100644
--- a/src/class.c
+++ b/src/class.c
@@ -1,3 +1,9 @@
+/*
+** class.c - Class class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdarg.h>
#include <stdio.h>
@@ -5,11 +11,11 @@
#include "mruby/proc.h"
#include "mruby/string.h"
#include "mruby/numeric.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "mruby/array.h"
#include "error.h"
-#include "ritehash.h"
+#include "mruby/khash.h"
#ifdef INCLUDE_REGEXP
#define mrb_usascii_str_new2 mrb_usascii_str_new_cstr
@@ -105,7 +111,12 @@ make_metaclass(mrb_state *mrb, struct RClass *c)
}
sc = mrb_obj_alloc(mrb, MRB_TT_SCLASS, mrb->class_class);
sc->mt = 0;
- sc->super = c->c;
+ if (!c->super) {
+ sc->super = mrb->class_class;
+ }
+ else {
+ sc->super = c->super->c;
+ }
c->c = sc;
mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)sc);
mrb_field_write_barrier(mrb, (struct RBasic*)sc, (struct RBasic*)sc->super);
@@ -202,7 +213,10 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
if (!c) {
struct RClass *s = 0;
- if (!mrb_nil_p(super)) s = mrb_class_ptr(super);
+ if (!mrb_nil_p(super)) {
+ mrb_check_type(mrb, super, MRB_TT_CLASS);
+ s = mrb_class_ptr(super);
+ }
c = mrb_class_new(mrb, s);
setup_class(mrb, outer, c, id);
}
@@ -278,10 +292,9 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, struct RPro
{
khash_t(mt) *h = c->mt;
khiter_t k;
- int ret;
if (!h) h = c->mt = kh_init(mt, mrb);
- k = kh_put(mt, h, mid, &ret);
+ k = kh_put(mt, h, mid);
kh_value(h, k) = p;
}
@@ -306,10 +319,9 @@ mrb_define_method_vm(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_value b
{
khash_t(mt) *h = c->mt;
khiter_t k;
- int ret;
if (!h) h = c->mt = kh_init(mt, mrb);
- k = kh_put(mt, h, name, &ret);
+ k = kh_put(mt, h, name);
kh_value(h, k) = mrb_proc_ptr(body);
}
@@ -829,7 +841,6 @@ mrb_class_new(mrb_state *mrb, struct RClass *super)
struct RClass *c;
if (super) {
-// mrb_check_type(mrb, super, MRB_TT_CLASS);
mrb_check_inheritable(mrb, super);
}
c = boot_defclass(mrb, super);
@@ -845,7 +856,6 @@ struct RClass *
mrb_module_new(mrb_state *mrb)
{
struct RClass *m = mrb_obj_alloc(mrb, MRB_TT_MODULE, mrb->module_class);
- make_metaclass(mrb, m);
return m;
}
@@ -930,12 +940,16 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
switch (mrb_type(klass)) {
- case MRB_TT_CLASS:
- snprintf(buf, 256, "#<Class:%p>", c);
- break;
- case MRB_TT_MODULE:
- snprintf(buf, 256, "#<Module:%p>", c);
- break;
+ case MRB_TT_CLASS:
+ snprintf(buf, 256, "#<Class:%p>", c);
+ break;
+
+ case MRB_TT_MODULE:
+ snprintf(buf, 256, "#<Module:%p>", c);
+ break;
+
+ default:
+ break;
}
return mrb_str_dup(mrb, mrb_str_new_cstr(mrb, buf));
}
diff --git a/src/codegen.c b/src/codegen.c
index c44e619e9..5eca94ad0 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1,8 +1,14 @@
+/*
+** codegen.c - mruby code generator
+**
+** See Copyright Notice in mruby.h
+*/
+
#undef CODEGEN_TEST
#define CODEGEN_DUMP
#include "mruby.h"
-#include "irep.h"
+#include "mruby/irep.h"
#include "compile.h"
#include "mruby/proc.h"
#include "opcode.h"
diff --git a/src/compar.c b/src/compar.c
index d66525c15..5fef89329 100644
--- a/src/compar.c
+++ b/src/compar.c
@@ -1,3 +1,9 @@
+/*
+** compar.c - Comparable module
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/string.h"
#include "mruby/numeric.h"
diff --git a/src/compile.h b/src/compile.h
index f0e6b1874..6e6975cbf 100644
--- a/src/compile.h
+++ b/src/compile.h
@@ -1,3 +1,9 @@
+/*
+** compile.h - mruby parser
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdio.h>
#include <setjmp.h>
@@ -25,6 +31,12 @@ enum mrb_lex_state_enum {
EXPR_MAX_STATE
};
+struct mrb_parser_message {
+ int lineno;
+ int column;
+ char* message;
+};
+
struct mrb_parser_state {
mrb_state *mrb;
struct mrb_pool *pool;
@@ -55,14 +67,20 @@ struct mrb_parser_state {
void *ylval;
int nerr;
+ int nwarn;
mrb_ast_node *tree, *begin_tree;
+ int capture_errors;
+ struct mrb_parser_message error_buffer[10];
+ struct mrb_parser_message warn_buffer[10];
+
jmp_buf jmp;
};
struct mrb_parser_state* mrb_parse_file(mrb_state*,FILE*);
struct mrb_parser_state* mrb_parse_string(mrb_state*,char*);
struct mrb_parser_state* mrb_parse_nstring(mrb_state*,char*,size_t);
+struct mrb_parser_state* mrb_parse_nstring_ext(mrb_state*,char*,size_t);
int mrb_generate_code(mrb_state*, mrb_ast_node*);
int mrb_compile_file(mrb_state*,FILE*);
diff --git a/src/crc.c b/src/crc.c
index 513622a09..412252347 100644
--- a/src/crc.c
+++ b/src/crc.c
@@ -1,3 +1,9 @@
+/*
+** crc.c - calculate CRC
+**
+** See Copyright Notice in mruby.h
+*/
+
#include <limits.h>
#include <stdint.h>
// Calculate CRC (CRC-16-CCITT)
diff --git a/src/dump.c b/src/dump.c
index ba2a9ab7a..61297eb10 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -1,11 +1,17 @@
+/*
+** dump.c - mruby binary dumper (Rite binary format)
+**
+** See Copyright Notice in mruby.h
+*/
+
#include <string.h>
-#include "dump.h"
+#include "mruby/dump.h"
#include "mruby/string.h"
#ifdef INCLUDE_REGEXP
#include "re.h"
#endif
-#include "irep.h"
+#include "mruby/irep.h"
static const unsigned char def_rite_binary_header[] =
RITE_FILE_IDENFIFIER
diff --git a/src/encoding.c b/src/encoding.c
index 9c50686c6..2f698865b 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- encoding.c -
-
- $Author: naruse $
- created at: Thu May 24 17:23:27 JST 2007
-
- Copyright (C) 2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** encoding.c - Encoding class
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#ifdef INCLUDE_ENCODING
@@ -33,7 +28,7 @@
#include "mruby/numeric.h"
#include "mruby/string.h"
#include "mruby/array.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "mruby/hash.h"
#define pprintf printf
diff --git a/src/encoding.h b/src/encoding.h
index 92e16e5f2..bc4a7ccc2 100644
--- a/src/encoding.h
+++ b/src/encoding.h
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- encoding.h -
-
- $Author: matz $
- created at: Thu May 24 11:49:41 JST 2007
-
- Copyright (C) 2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** encoding.h - Encoding class
+**
+** See Copyright Notice in mruby.h
+*/
#ifndef RUBY_ENCODING_H
#define RUBY_ENCODING_H 1
diff --git a/src/enum.c b/src/enum.c
index c9bb43139..0b8e6dcdb 100644
--- a/src/enum.c
+++ b/src/enum.c
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- enum.c -
-
- $Author: yugui $
- created at: Fri Oct 1 15:15:19 JST 1993
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** enum.c - Enumerable module
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
@@ -418,7 +413,6 @@ enum_to_a(mrb_state *mrb, int argc, mrb_value *argv, mrb_value obj)
mrb_value ary = mrb_ary_new(mrb);
mrb_block_call(mrb, obj, id_each, argc, argv, collect_all, &ary);
- //OBJ_INFECT(ary, obj);
return ary;
}
diff --git a/src/error.c b/src/error.c
index a671c6bbd..2dbfe0ac2 100644
--- a/src/error.c
+++ b/src/error.c
@@ -1,3 +1,9 @@
+/*
+** error.c - Exception class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdarg.h>
#include <string.h>
@@ -5,10 +11,10 @@
#include <setjmp.h>
#include "error.h"
#include "opcode.h"
-#include "irep.h"
+#include "mruby/irep.h"
#include "mruby/proc.h"
#include "mruby/numeric.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "mruby/string.h"
#include "eval_intern.h"
#include "mruby/class.h"
@@ -419,7 +425,7 @@ mrb_exc_exception(mrb_state *mrb, mrb_value exc)
mrb_get_args(mrb, "*", &argv, &argc);
if (argc == 0) return exc;
exclass = mrb_obj_value(mrb_class(mrb, exc));
- return mrb_funcall(mrb, exclass, mrb_intern(mrb, "exception"), argc, argv);
+ return mrb_funcall(mrb, exclass, "exception", argc, argv);
}
void
diff --git a/src/error.h b/src/error.h
index 5b1873b1d..42fb635c5 100644
--- a/src/error.h
+++ b/src/error.h
@@ -1,3 +1,9 @@
+/*
+** error.h - Exception class
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_ERROR_H
#define MRUBY_ERROR_H
diff --git a/src/etc.c b/src/etc.c
index 865992566..e82657a97 100644
--- a/src/etc.c
+++ b/src/etc.c
@@ -1,3 +1,9 @@
+/*
+** etc.c -
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/string.h"
#include "error.h"
@@ -25,7 +31,7 @@ mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const str
data = mrb_obj_alloc(mrb, MRB_TT_DATA, klass);
data->data = ptr;
- data->type = type;
+ data->type = (struct mrb_data_type *) type;
return data;
}
diff --git a/src/eval_intern.h b/src/eval_intern.h
index c3e8cdf50..3179f50b2 100644
--- a/src/eval_intern.h
+++ b/src/eval_intern.h
@@ -1,3 +1,9 @@
+/*
+** eval_intern.h -
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef RUBY_EVAL_INTERN_H
#define RUBY_EVAL_INTERN_H
diff --git a/src/gc.c b/src/gc.c
index ad5bcc7a8..e90c8a293 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -1,3 +1,9 @@
+/*
+** gc.c - garbage collector for RiteVM
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/object.h"
#include "mruby/class.h"
@@ -5,7 +11,7 @@
#include "mruby/string.h"
#include "mruby/hash.h"
#include "mruby/range.h"
-#include "ritehash.h"
+#include "mruby/khash.h"
#include <string.h>
#include <stdio.h>
#include "mruby/struct.h"
@@ -317,12 +323,12 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
struct REnv *e = (struct REnv *)obj;
if (e->cioff < 0) {
- int i, len;
+ int i, len;
- len = (int)e->flags;
- for (i=0; i<len; i++) {
- mrb_gc_mark_value(mrb, e->stack[i]);
- }
+ len = (int)e->flags;
+ for (i=0; i<len; i++) {
+ mrb_gc_mark_value(mrb, e->stack[i]);
+ }
}
}
break;
@@ -333,7 +339,7 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
size_t i, e;
for (i=0,e=a->len; i<e; i++) {
- mrb_gc_mark_value(mrb, a->buf[i]);
+ mrb_gc_mark_value(mrb, a->buf[i]);
}
}
break;
@@ -341,15 +347,18 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_HASH:
mrb_gc_mark_ht(mrb, (struct RClass*)obj);
break;
+
case MRB_TT_STRING:
{
struct RString *s = (struct RString*)obj;
- if (s->flags & MRB_STR_SHARED) {
- mrb_gc_mark_value(mrb, s->aux.shared)
+ while (s->flags & MRB_STR_SHARED) {
+ s = s->aux.shared;
+ if (!s) break;
}
}
break;
+
case MRB_TT_RANGE:
{
struct RRange *r = (struct RRange*)obj;
@@ -358,9 +367,8 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
mrb_gc_mark_value(mrb, r->edges->end);
}
break;
- case MRB_TT_REGEX:
- case MRB_TT_STRUCT:
- case MRB_TT_EXCEPTION:
+
+ default:
break;
}
}
@@ -390,41 +398,52 @@ obj_free(mrb_state *mrb, struct RBasic *obj)
case MRB_TT_OBJECT:
mrb_gc_free_iv(mrb, (struct RObject*)obj);
break;
+
case MRB_TT_CLASS:
case MRB_TT_MODULE:
case MRB_TT_SCLASS:
mrb_gc_free_mt(mrb, (struct RClass*)obj);
mrb_gc_free_iv(mrb, (struct RObject*)obj);
break;
+
case MRB_TT_ENV:
{
struct REnv *e = (struct REnv *)obj;
if (e->cioff < 0) {
- mrb_free(mrb, e->stack);
- e->stack = 0;
+ mrb_free(mrb, e->stack);
+ e->stack = 0;
}
}
break;
- case MRB_TT_PROC:
- case MRB_TT_ICLASS:
- break;
+
case MRB_TT_ARRAY:
mrb_free(mrb, ((struct RArray*)obj)->buf);
break;
+
case MRB_TT_HASH:
mrb_gc_free_ht(mrb, (struct RClass*)obj);
break;
+
case MRB_TT_STRING:
if (!(obj->flags & MRB_STR_SHARED))
mrb_free(mrb, ((struct RString*)obj)->buf);
break;
+
case MRB_TT_RANGE:
mrb_free(mrb, ((struct RRange*)obj)->edges);
break;
- case MRB_TT_REGEX:
- case MRB_TT_STRUCT:
- case MRB_TT_EXCEPTION:
+
+ case MRB_TT_DATA:
+ {
+ struct RData *d = (struct RData *)obj;
+ if (d->type->dfree) {
+ d->type->dfree(mrb, d->data);
+ }
+ }
+ break;
+
+ default:
break;
}
obj->tt = MRB_TT_FREE;
@@ -514,16 +533,12 @@ gc_gray_mark(mrb_state *mrb, struct RBasic *obj)
children += mrb_gc_mark_ht_size(mrb, (struct RClass*)obj);
break;
- case MRB_TT_STRING:
- break;
case MRB_TT_PROC:
case MRB_TT_RANGE:
children+=2;
break;
- case MRB_TT_REGEX:
- case MRB_TT_STRUCT:
- case MRB_TT_EXCEPTION:
+ default:
break;
}
return children;
diff --git a/src/gc.h b/src/gc.h
index 139580533..38637d507 100644
--- a/src/gc.h
+++ b/src/gc.h
@@ -1,3 +1,9 @@
+/*
+** gc.h - garbage collector for RiteVM
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef MRUBY_GC_H
#define MRUBY_GC_H
diff --git a/src/hash.c b/src/hash.c
index 3f336f425..b1df78a3e 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -1,19 +1,12 @@
-/**********************************************************************
-
- hash.c -
-
- $Author: yugui $
- created at: Mon Nov 22 18:51:18 JST 1993
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
- Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
- Copyright (C) 2000 Information-technology Promotion Agency, Japan
-
-**********************************************************************/
+/*
+** hash.c - Hash class
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#include "mruby/hash.h"
-#include "ritehash.h"
+#include "mruby/khash.h"
#include "mruby/class.h"
#include "mruby/array.h"
#include "error.h"
@@ -171,7 +164,6 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val) /* mr
{
khash_t(ht) *h;
khiter_t k;
- int r;
mrb_hash_modify(mrb, hash);
h = RHASH_H_TBL(hash);
@@ -179,7 +171,7 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val) /* mr
k = kh_get(ht, h, key);
if (k == kh_end(h)) {
/* expand */
- k = kh_put(ht, h, KEY(key), &r);
+ k = kh_put(ht, h, KEY(key));
}
kh_value(h, k) = val;
@@ -227,7 +219,6 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
struct RHash* ret;
khash_t(ht) *h, *ret_h;
khiter_t k, ret_k;
- int r;
ret = mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class);
ret->ht = kh_init(ht, mrb);
@@ -238,7 +229,7 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
for (k = kh_begin(h); k != kh_end(h); k++) {
if (kh_exist(h,k)) {
- ret_k = kh_put(ht, ret_h, KEY(kh_key(h,k)), &r);
+ ret_k = kh_put(ht, ret_h, KEY(kh_key(h,k)));
kh_val(ret_h, ret_k) = kh_val(h,k);
}
}
@@ -623,7 +614,6 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
khiter_t k;
mrb_value delKey, delVal;
mrb_value result;
- int r;
mrb_hash_modify(mrb, hash);
if (h) {
@@ -635,7 +625,7 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
delVal = mrb_hash_delete_key(mrb, hash, delKey);
result = mrb_hash_new(mrb, 1);
- k = kh_put(ht, RHASH_H_TBL(result), KEY(delKey), &r);
+ k = kh_put(ht, RHASH_H_TBL(result), KEY(delKey));
kh_value(RHASH_H_TBL(result), k) = delVal;
return result;
}
diff --git a/src/init.c b/src/init.c
index ce039ce30..869201eea 100644
--- a/src/init.c
+++ b/src/init.c
@@ -1,3 +1,9 @@
+/*
+** init.c - initialize mruby core
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
void mrb_init_class(mrb_state*);
diff --git a/src/init_ext.c b/src/init_ext.c
index cb094f171..0643bd4fd 100644
--- a/src/init_ext.c
+++ b/src/init_ext.c
@@ -1,3 +1,9 @@
+/*
+** init_ext.c - initialize extend libraries
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
void
diff --git a/src/kernel.c b/src/kernel.c
index 80b64c26a..eeaa0fe27 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1,3 +1,9 @@
+/*
+** kernel.c - Kernel module
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/string.h"
#include <string.h>
@@ -10,8 +16,8 @@
#include "mruby/hash.h"
#include "mruby/class.h"
#include "mruby/struct.h"
-#include "variable.h"
-#include "ritehash.h"
+#include "mruby/variable.h"
+#include "mruby/khash.h"
#include "error.h"
#include "method.h"
@@ -391,6 +397,10 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
if (ROBJECT(obj)->iv) {
ROBJECT(dest)->iv = ROBJECT(obj)->iv;
}
+ break;
+
+ default:
+ break;
}
mrb_funcall(mrb, dest, "initialize_copy", 1, obj);
}
@@ -402,7 +412,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
*
* Produces a shallow copy of <i>obj</i>---the instance variables of
* <i>obj</i> are copied, but not the objects they reference. Copies
- * the frozen and tainted state of <i>obj</i>. See also the discussion
+ * the frozen state of <i>obj</i>. See also the discussion
* under <code>Object#dup</code>.
*
* class Klass
@@ -431,7 +441,6 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
}
clone = mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self));
clone->c = mrb_singleton_class_clone(mrb, self);
- //RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT) | FL_TEST(clone, FL_UNTRUSTED)) & ~(FL_FREEZE|FL_FINALIZE);
init_copy(mrb, mrb_obj_value(clone), self);
//1-9-2 no bug mrb_funcall(mrb, clone, "initialize_clone", 1, self);
//RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
@@ -446,7 +455,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
*
* Produces a shallow copy of <i>obj</i>---the instance variables of
* <i>obj</i> are copied, but not the objects they reference.
- * <code>dup</code> copies the tainted state of <i>obj</i>. See also
+ * <code>dup</code> copies the frozen state of <i>obj</i>. See also
* the discussion under <code>Object#clone</code>. In general,
* <code>clone</code> and <code>dup</code> may have different semantics
* in descendant classes. While <code>clone</code> is used to duplicate
@@ -623,9 +632,7 @@ mrb_obj_init_copy(mrb_state *mrb, mrb_value self)
mrb_value
mrb_obj_instance_eval(mrb_state *mrb, mrb_value self)
{
- mrb_value *argv;
- int argc;
- mrb_value b, klass;
+ mrb_value b;
mrb_get_args(mrb, "&", &b);
return mrb_yield_with_self(mrb, b, 0, 0, self);
@@ -681,17 +688,13 @@ mrb_obj_ivar_defined(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "o", &arg);
mrb_sym mid = mrb_to_id(mrb, arg);
- //if (!mrb_is_instance_id(id)) {
- // mrb_name_error(id, "`%s' is not allowed as an instance variable name", mrb_sym2name(mrb, id));
- //}
- //return mrb_ivar_defined(self, id);
- k = kh_get(iv, h, mid);
- if (k != kh_end(h)) {
- return mrb_true_value();
- }
- else {
- return mrb_false_value();
+ if (h) {
+ k = kh_get(iv, h, mid);
+ if (k != kh_end(h)) {
+ return mrb_true_value();
+ }
}
+ return mrb_false_value();
}
/* 15.3.1.3.21 */
@@ -790,16 +793,15 @@ mrb_obj_instance_variables(mrb_state *mrb, mrb_value self)
const char* p;
ary = mrb_ary_new(mrb);
- //if (mrb_is_instance_id(key)) {
- // mrb_ary_push(mrb, ary, mrb_sym2name(mrb, key));
- //}
- for (i=0;i<kh_end(h);i++) {
- if (kh_exist(h, i)) {
+ if (h) {
+ for (i=0;i<kh_end(h);i++) {
+ if (kh_exist(h, i)) {
p = mrb_sym2name(mrb, kh_key(h,i));
if (*p == '@') {
if (mrb_type(kh_value(h, i)) != MRB_TT_UNDEF)
mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, p));
}
+ }
}
}
return ary;
@@ -917,6 +919,7 @@ method_entry_loop(mrb_state *mrb, struct RClass* klass, mrb_value ary)
int i;
khash_t(mt) *h = klass->mt;
+ if (!h) return;
for (i=0;i<kh_end(h);i++) {
if (kh_exist(h, i)) {
mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(h,i)));
@@ -1239,6 +1242,7 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self)
case MRB_TT_MODULE:
if (!mrb_obj_ptr(self)->iv) break;
h = mrb_obj_ptr(self)->iv;
+ if (!h) break;
k = kh_get(iv, h, sym);
if (k != kh_end(h)) {
val = kh_value(h, k);
diff --git a/src/load.c b/src/load.c
index 3f5dc2c57..3b62a0e7a 100644
--- a/src/load.c
+++ b/src/load.c
@@ -1,11 +1,17 @@
+/*
+** load.c - mruby binary loader
+**
+** See Copyright Notice in mruby.h
+*/
+
#include <string.h>
-#include "dump.h"
+#include "mruby/dump.h"
#include "mruby/string.h"
#ifdef INCLUDE_REGEXP
#include "re.h"
#endif
-#include "irep.h"
+#include "mruby/irep.h"
#ifndef FALSE
#define FALSE 0
@@ -406,12 +412,12 @@ read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32
switch (tt) { //pool data
case MRB_TT_FIXNUM:
- sscanf(buf, "%d", &fix_num);
+ fix_num = readint(buf, 10);
irep->pool[i] = mrb_fixnum_value(fix_num);
break;
case MRB_TT_FLOAT:
- sscanf(buf, "%le", &f);
+ f = readfloat(buf);
irep->pool[i] = mrb_float_value(f);
break;
@@ -489,7 +495,7 @@ error_exit:
}
int
-mrb_read_irep(mrb_state *mrb, char *bin)
+mrb_read_irep(mrb_state *mrb, const char *bin)
{
int ret = MRB_DUMP_OK, i, n, nirep, sirep;
uint32_t len;
diff --git a/src/method.h b/src/method.h
index 3591917a2..0856ffa8b 100644
--- a/src/method.h
+++ b/src/method.h
@@ -1,13 +1,9 @@
-/**********************************************************************
+/*
+** method.h - method structures and functions
+**
+** See Copyright Notice in mruby.h
+*/
- method.h -
-
- $Author: ko1 $
- created at: Wed Jul 15 20:02:33 2009
-
- Copyright (C) 2009 Koichi Sasada
-
-**********************************************************************/
#ifndef METHOD_H
#define METHOD_H
diff --git a/src/minimain.c b/src/minimain.c
index b1b70c2af..3ba5bb0b3 100644
--- a/src/minimain.c
+++ b/src/minimain.c
@@ -1,3 +1,9 @@
+/*
+** minimain.c -
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/proc.h"
diff --git a/src/node.h b/src/node.h
index a6e3d58fe..74af5f1e9 100644
--- a/src/node.h
+++ b/src/node.h
@@ -1,3 +1,9 @@
+/*
+** node.h - nodes of abstract syntax tree
+**
+** See Copyright Notice in mruby.h
+*/
+
enum node_type {
NODE_METHOD,
NODE_FBODY,
diff --git a/src/numeric.c b/src/numeric.c
index 135691644..23da9089c 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- numeric.c -
-
- $Author: yugui $
- created at: Fri Aug 13 18:33:09 JST 1993
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** numeric.c - Numeric, Integer, Float, Fixnum class
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#include "mruby/numeric.h"
@@ -15,7 +10,7 @@
#include "mruby/array.h"
#include <string.h>
#include "mruby/class.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include <ctype.h>
#include <math.h>
@@ -106,29 +101,14 @@ const unsigned char mrb_nan[] = "\x00\x00\xc0\x7f";
const unsigned char mrb_nan[] = "\x7f\xc0\x00\x00";
#endif
-extern double round(double);
-
-#ifndef HAVE_ROUND
-double
-round(double x)
-{
- double f;
-
- if (x > 0.0) {
- f = floor(x);
- x = f + (x - f >= 0.5);
- }
- else if (x < 0.0) {
- f = ceil(x);
- x = f - (f - x >= 0.5);
- }
- return x;
-}
+#ifdef MRB_USE_FLOAT
+#define round(f) roundf(f)
+#define floor(f) floorf(f)
+#define ceil(f) ceilf(f)
+#define floor(f) floorf(f)
+#define fmod(x,y) fmodf(x,y)
#endif
-
-
-
void mrb_cmperr(mrb_state *mrb, mrb_value x, mrb_value y);
void
@@ -279,7 +259,7 @@ num_quo(mrb_state *mrb, mrb_value x)
mrb_value y;
mrb_get_args(mrb, "o", &y);
- return mrb_funcall(mrb, mrb_float_value((double)mrb_fixnum(x)), "/", 1, y);
+ return mrb_funcall(mrb, mrb_float_value((mrb_float)mrb_fixnum(x)), "/", 1, y);
}
/*
@@ -313,7 +293,7 @@ num_abs(mrb_state *mrb, mrb_value num)
*/
mrb_value
-mrb_float_new(double d)
+mrb_float_new(mrb_float d)
{
//NEWOBJ(flt, struct RFloat);
//OBJSETUP(flt, mrb_cFloat, MRB_TT_FLOAT);
@@ -338,7 +318,7 @@ static mrb_value
flo_to_s(mrb_state *mrb, mrb_value flt)
{
char buf[32];
- double value = mrb_float(flt);
+ mrb_float value = mrb_float(flt);
char *p, *e;
if (isinf(value))
@@ -381,7 +361,7 @@ flo_minus(mrb_state *mrb, mrb_value x)
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
- return mrb_float_value(mrb_float(x) - (double)mrb_fixnum(y));
+ return mrb_float_value(mrb_float(x) - (mrb_float)mrb_fixnum(y));
case MRB_TT_FLOAT:
return mrb_float_value(mrb_float(x) - mrb_float(y));
default:
@@ -407,7 +387,7 @@ flo_mul(mrb_state *mrb, mrb_value x)
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
- return mrb_float_value(mrb_float(x) * (double)mrb_fixnum(y));
+ return mrb_float_value(mrb_float(x) * (mrb_float)mrb_fixnum(y));
case MRB_TT_FLOAT:
return mrb_float_value(mrb_float(x) * mrb_float(y));
default:
@@ -429,14 +409,13 @@ flo_div(mrb_state *mrb, mrb_value x)
{
mrb_value y;
long f_y;
- //double d;
mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
f_y = mrb_fixnum(y);
- return mrb_float_value(mrb_float(x) / (double)f_y);
+ return mrb_float_value(mrb_float(x) / (mrb_float)f_y);
case MRB_TT_FLOAT:
return mrb_float_value(mrb_float(x) / mrb_float(y));
default:
@@ -460,21 +439,12 @@ flo_quo(mrb_state *mrb, mrb_value x)
}
static void
-flodivmod(mrb_state *mrb, double x, double y, double *divp, double *modp)
+flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *modp)
{
- double div, mod;
+ mrb_float div, mod;
if (y == 0.0) mrb_num_zerodiv(mrb);
-#ifdef HAVE_FMOD
mod = fmod(x, y);
-#else
- {
- double z;
-
- modf(x/y, &z);
- mod = x - z * y;
- }
-#endif
if (isinf(x) && !isinf(y) && !isnan(y))
div = x;
else
@@ -503,12 +473,12 @@ static mrb_value
flo_mod(mrb_state *mrb, mrb_value x)
{
mrb_value y;
- double fy, mod;
+ mrb_float fy, mod;
mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
- fy = (double)mrb_fixnum(y);
+ fy = (mrb_float)mrb_fixnum(y);
break;
case MRB_TT_FLOAT:
fy = mrb_float(y);
@@ -521,13 +491,13 @@ flo_mod(mrb_state *mrb, mrb_value x)
}
static mrb_value
-dbl2ival(double d)
+flt2ival(mrb_float d)
{
if (FIXABLE(d)) {
d = round(d);
return mrb_fixnum_value((long)d);
}
- return mrb_nil_value(); /* range over */ //mrb_dbl2big(d);
+ return mrb_nil_value();
}
@@ -581,12 +551,12 @@ static mrb_value
flo_eq(mrb_state *mrb, mrb_value x)
{
mrb_value y;
- volatile double a, b;
+ volatile mrb_float a, b;
mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_FIXNUM:
- b = (double)mrb_fixnum(y);
+ b = (mrb_float)mrb_fixnum(y);
break;
case MRB_TT_FLOAT:
b = mrb_float(y);
@@ -614,14 +584,14 @@ flo_eq(mrb_state *mrb, mrb_value x)
static mrb_value
flo_hash(mrb_state *mrb, mrb_value num)
{
- double d;
+ mrb_float d;
char *c;
int i, hash;
- d = (double)mrb_fixnum(num);
+ d = (mrb_float)mrb_fixnum(num);
if (d == 0) d = fabs(d);
c = (char*)&d;
- for (hash=0, i=0; i<sizeof(double);i++) {
+ for (hash=0, i=0; i<sizeof(mrb_float);i++) {
hash = (hash * 971) ^ (unsigned char)c[i];
}
if (hash < 0) hash = -hash;
@@ -629,7 +599,7 @@ flo_hash(mrb_state *mrb, mrb_value num)
}
mrb_value
-mrb_dbl_cmp(double a, double b)
+mrb_flt_cmp(double a, double b)
{
if (isnan(a) || isnan(b)) return mrb_nil_value();
if (a == b) return mrb_fixnum_value(0);
@@ -668,7 +638,7 @@ flo_to_f(mrb_state *mrb, mrb_value num)
static mrb_value
flo_is_infinite_p(mrb_state *mrb, mrb_value num)
{
- double value = mrb_float(num);
+ mrb_float value = mrb_float(num);
if (isinf(value)) {
return mrb_fixnum_value( value < 0 ? -1 : 1 );
@@ -691,7 +661,7 @@ flo_is_infinite_p(mrb_state *mrb, mrb_value num)
static mrb_value
flo_is_finite_p(mrb_state *mrb, mrb_value num)
{
- double value = mrb_float(num);
+ mrb_float value = mrb_float(num);
#if HAVE_FINITE
if (!finite(value))
@@ -720,11 +690,11 @@ flo_is_finite_p(mrb_state *mrb, mrb_value num)
static mrb_value
flo_floor(mrb_state *mrb, mrb_value num)
{
- double f = floor(mrb_float(num));
+ mrb_float f = floor(mrb_float(num));
long val;
if (!FIXABLE(f)) {
- return mrb_dbl2big(mrb, f);
+ return mrb_flt2big(mrb, f);
}
val = (long)f;
return mrb_fixnum_value(val);
@@ -747,11 +717,11 @@ flo_floor(mrb_state *mrb, mrb_value num)
static mrb_value
flo_ceil(mrb_state *mrb, mrb_value num)
{
- double f = ceil(mrb_float(num));
+ mrb_float f = ceil(mrb_float(num));
long val;
if (!FIXABLE(f)) {
- return mrb_dbl2big(mrb, f);
+ return mrb_flt2big(mrb, f);
}
val = (long)f;
return mrb_fixnum_value(val);
@@ -792,7 +762,7 @@ static mrb_value
flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num)
{
mrb_value nd;
- double number, f;
+ mrb_float number, f;
int ndigits = 0, i;
long val;
mrb_value *argv;
@@ -824,7 +794,7 @@ flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num)
if (ndigits > 0) return mrb_float_value(number);
if (!FIXABLE(number)) {
- return mrb_dbl2big(mrb, number);
+ return mrb_flt2big(mrb, number);
}
val = (long)number;
return mrb_fixnum_value(val);
@@ -844,14 +814,14 @@ flo_round(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value num)
static mrb_value
flo_truncate(mrb_state *mrb, mrb_value num)
{
- double f = mrb_float(num);
+ mrb_float f = mrb_float(num);
long val;
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
if (!FIXABLE(f)) {
- return mrb_dbl2big(mrb, f);
+ return mrb_flt2big(mrb, f);
}
val = (long)f;
return mrb_fixnum_value(val);
@@ -905,8 +875,8 @@ mrb_num2long(mrb_state *mrb, mrb_value val)
switch (mrb_type(val)) {
case MRB_TT_FLOAT:
- if (mrb_float(val) <= (double)LONG_MAX
- && mrb_float(val) >= (double)LONG_MIN) {
+ if (mrb_float(val) <= (mrb_float)LONG_MAX
+ && mrb_float(val) >= (mrb_float)LONG_MIN) {
return (SIGNED_VALUE)(mrb_float(val));
}
else {
@@ -936,8 +906,8 @@ mrb_num2ulong(mrb_state *mrb, mrb_value val)
switch (mrb_type(val)) {
case MRB_TT_FLOAT:
- if (mrb_float(val) <= (double)LONG_MAX
- && mrb_float(val) >= (double)LONG_MIN) {
+ if (mrb_float(val) <= (mrb_float)LONG_MAX
+ && mrb_float(val) >= (mrb_float)LONG_MIN) {
return mrb_fixnum_value(mrb_float(val));
}
else {
@@ -1126,7 +1096,7 @@ fix_mul(mrb_state *mrb, mrb_value x)
}
switch (mrb_type(y)) {
case MRB_TT_FLOAT:
- return mrb_float_value((double)mrb_fixnum(x) * mrb_float(y));
+ return mrb_float_value((mrb_float)mrb_fixnum(x) * mrb_float(y));
default:
return mrb_num_coerce_bin(mrb, x, y, "*");
}
@@ -1175,16 +1145,16 @@ fix_divide(mrb_state *mrb, mrb_value x, mrb_value y, char* op)
switch (mrb_type(y)) {
case MRB_TT_FLOAT:
{
- double div;
+ mrb_float div;
if (*op == '/') {
- div = (double)mrb_fixnum(x) / mrb_float(y);
+ div = (mrb_float)mrb_fixnum(x) / mrb_float(y);
return mrb_float_value(div);
}
else {
if (mrb_float(y) == 0) mrb_num_zerodiv(mrb);
- div = (double)mrb_fixnum(x) / mrb_float(y);
- return mrb_dbl2big(mrb, floor(div));
+ div = (mrb_float)mrb_fixnum(x) / mrb_float(y);
+ return mrb_flt2big(mrb, floor(div));
}
}
//case MRB_TT_RATIONAL:
@@ -1240,9 +1210,9 @@ fix_mod(mrb_state *mrb, mrb_value x)
switch (mrb_type(y)) {
case MRB_TT_FLOAT:
{
- double mod;
+ mrb_float mod;
- flodivmod(mrb, (double)mrb_fixnum(x), mrb_float(y), 0, &mod);
+ flodivmod(mrb, (mrb_float)mrb_fixnum(x), mrb_float(y), 0, &mod);
return mrb_float_value(mod);
}
default:
@@ -1272,11 +1242,11 @@ fix_divmod(mrb_state *mrb, mrb_value x)
switch (mrb_type(y)) {
case MRB_TT_FLOAT:
{
- double div, mod;
+ mrb_float div, mod;
volatile mrb_value a, b;
- flodivmod(mrb, (double)mrb_fixnum(x), mrb_float(y), &div, &mod);
- a = dbl2ival(div);
+ flodivmod(mrb, (mrb_float)mrb_fixnum(x), mrb_float(y), &div, &mod);
+ a = flt2ival(div);
b = mrb_float_value(mod);
return mrb_assoc_new(mrb, a, b);
}
@@ -1307,7 +1277,7 @@ fix_equal(mrb_state *mrb, mrb_value x)
if (FIXNUM_P(y)) return mrb_false_value();
switch (mrb_type(y)) {
case MRB_TT_FLOAT:
- return (double)mrb_fixnum(x) == mrb_float(y) ? mrb_true_value() : mrb_false_value();
+ return (mrb_float)mrb_fixnum(x) == mrb_float(y) ? mrb_true_value() : mrb_false_value();
default:
return num_equal(mrb, x, y);
}
@@ -1512,9 +1482,9 @@ fix_rshift(long val, unsigned long i)
static mrb_value
fix_to_f(mrb_state *mrb, mrb_value num)
{
- double val;
+ mrb_float val;
- val = (double)mrb_fixnum(num);
+ val = (mrb_float)mrb_fixnum(num);
return mrb_float_value(val);
}
@@ -1552,13 +1522,12 @@ fix_to_f(mrb_state *mrb, mrb_value num)
*/
/* ------------------------------------------------------------------------*/
static mrb_int
-dbl2big(mrb_state *mrb, float d)
+flt2big(mrb_state *mrb, float d)
{
//long i = 0;
//BDIGIT c;
//BDIGIT *digits;
mrb_int z;
- //double u = (d < 0)?-d:d;
if (isinf(d)) {
mrb_raise(mrb, E_FLOATDOMAIN_ERROR, d < 0 ? "-Infinity" : "Infinity");
@@ -1571,9 +1540,9 @@ dbl2big(mrb_state *mrb, float d)
}
mrb_value
-mrb_dbl2big(mrb_state *mrb, float d)
+mrb_flt2big(mrb_state *mrb, float d)
{
- return mrb_fixnum_value(dbl2big(mrb, d));//bignorm(dbl2big(d));
+ return mrb_fixnum_value(flt2big(mrb, d));
}
/* 15.2.8.3.1 */
diff --git a/src/object.c b/src/object.c
index 0a31fa108..7f2cfcb0f 100644
--- a/src/object.c
+++ b/src/object.c
@@ -1,3 +1,9 @@
+/*
+** object.c - Object, NilClass, TrueClass, FalseClass class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <string.h>
#include "mruby/string.h"
@@ -472,7 +478,6 @@ mrb_any_to_s(mrb_state *mrb, mrb_value obj)
// snprintf(RSTRING(str)->ptr, len+1, "#<%s:0x%lx>", cname, obj);
sprintf(s->buf, "#<%s:0x%lx>", cname, (unsigned long)(obj.value.p));
s->len = strlen(s->buf);
- /*if (OBJ_TAINTED(obj)) OBJ_TAINT(str);*/
return str;
}
@@ -564,7 +569,7 @@ mrb_convert_to_integer(mrb_state *mrb, mrb_value val, int base)
&& mrb_float(val) >= (double)FIXNUM_MIN) {
break;
}
- return mrb_dbl2big(mrb, mrb_float(val));
+ return mrb_flt2big(mrb, mrb_float(val));
case MRB_TT_FIXNUM:
if (base != 0) goto arg_error;
diff --git a/src/opcode.h b/src/opcode.h
index e6ea74f79..9cf261ce8 100644
--- a/src/opcode.h
+++ b/src/opcode.h
@@ -1,3 +1,9 @@
+/*
+** opcode.h - RiteVM operation codes
+**
+** See Copyright Notice in mruby.h
+*/
+
#ifndef OPCODE_H
#define OPCODE_H
diff --git a/src/parse.y b/src/parse.y
index 2bc78f577..04e0a9d01 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -1,3 +1,9 @@
+/*
+** parse.y - mruby parser
+**
+** See Copyright Notice in mruby.h
+*/
+
%{
#undef PARSER_TEST
#undef PARSER_DEBUG
@@ -2575,6 +2581,7 @@ superclass : term
| '<'
{
p->lstate = EXPR_BEG;
+ p->cmd_start = TRUE;
}
expr_value term
{
@@ -2898,8 +2905,21 @@ none : /* none */
static void
yyerror(parser_state *p, const char *s)
{
- fputs(s, stderr);
- fputs("\n", stderr);
+ char* c;
+ size_t n;
+
+ if (! p->capture_errors) {
+ fputs(s, stderr);
+ fputs("\n", stderr);
+ }
+ else if (p->nerr < sizeof(p->error_buffer) / sizeof(p->error_buffer[0])) {
+ n = strlen(s);
+ c = parser_palloc(p, n + 1);
+ memcpy(c, s, n + 1);
+ p->error_buffer[p->nerr].message = c;
+ p->error_buffer[p->nerr].lineno = p->lineno;
+ p->error_buffer[p->nerr].column = p->column;
+ }
p->nerr++;
}
@@ -2915,8 +2935,22 @@ yyerror_i(parser_state *p, const char *fmt, int i)
static void
yywarn(parser_state *p, const char *s)
{
- fputs(s, stderr);
- fputs("\n", stderr);
+ char* c;
+ size_t n;
+
+ if (! p->capture_errors) {
+ fputs(s, stderr);
+ fputs("\n", stderr);
+ }
+ else if (p->nerr < sizeof(p->warn_buffer) / sizeof(p->warn_buffer[0])) {
+ n = strlen(s);
+ c = parser_palloc(p, n + 1);
+ memcpy(c, s, n + 1);
+ p->error_buffer[p->nwarn].message = c;
+ p->error_buffer[p->nwarn].lineno = p->lineno;
+ p->error_buffer[p->nwarn].column = p->column;
+ }
+ p->nwarn++;
}
static void
@@ -2976,8 +3010,13 @@ nextc(parser_state *p)
c = *p->s++;
}
if (c == '\n') {
- p->lineno++;
- p->column = 0;
+ if (p->column < 0) {
+ p->column++; // pushback caused an underflow
+ }
+ else {
+ p->lineno++;
+ p->column = 0;
+ }
// must understand heredoc
}
else {
@@ -2999,8 +3038,11 @@ skip(parser_state *p, char term)
{
int c;
- while ((c = nextc(p)) != term)
- ;
+ for (;;) {
+ c = nextc(p);
+ if (c < 0) break;
+ if (c == term) break;
+ }
}
static int
@@ -3087,10 +3129,11 @@ enum string_type {
str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND)
};
-static void
+static int
newtok(parser_state *p)
{
p->bidx = 0;
+ return p->column - 1;
}
static void
@@ -3307,8 +3350,9 @@ parse_string(parser_state *p, int term)
c = nextc(p);
if (c == '{') {
tokfix(p);
- p->lstate = EXPR_END;
+ p->lstate = EXPR_BEG;
p->sterm = term;
+ p->cmd_start = TRUE;
yylval.node = new_str(p, tok(p), toklen(p));
return tSTRING_PART;
}
@@ -3382,6 +3426,7 @@ parser_yylex(parser_state *p)
int space_seen = 0;
int cmd_state;
enum mrb_lex_state_enum last_state;
+ int token_column;
if (p->sterm) {
return parse_string(p, p->sterm);
@@ -3437,6 +3482,7 @@ parser_yylex(parser_state *p)
}
}
normal_newline:
+ p->cmd_start = TRUE;
p->lstate = EXPR_BEG;
return '\n';
@@ -3542,6 +3588,8 @@ parser_yylex(parser_state *p)
switch (p->lstate) {
case EXPR_FNAME: case EXPR_DOT:
p->lstate = EXPR_ARG; break;
+ case EXPR_CLASS:
+ p->cmd_start = TRUE;
default:
p->lstate = EXPR_BEG; break;
}
@@ -3637,7 +3685,7 @@ parser_yylex(parser_state *p)
p->lstate = EXPR_VALUE;
return '?';
}
- newtok(p);
+ token_column = newtok(p);
// need support UTF-8 if configured
if ((isalnum(c) || c == '_')) {
int c2 = nextc(p);
@@ -3810,7 +3858,7 @@ parser_yylex(parser_state *p)
is_float = seen_point = seen_e = nondigit = 0;
p->lstate = EXPR_END;
- newtok(p);
+ token_column = newtok(p);
if (c == '-' || c == '+') {
tokadd(p, c);
c = nextc(p);
@@ -4299,7 +4347,7 @@ parser_yylex(parser_state *p)
case '$':
p->lstate = EXPR_END;
- newtok(p);
+ token_column = newtok(p);
c = nextc(p);
switch (c) {
case '_': /* $_: last read line string */
@@ -4377,7 +4425,7 @@ parser_yylex(parser_state *p)
case '@':
c = nextc(p);
- newtok(p);
+ token_column = newtok(p);
tokadd(p, '@');
if (c == '@') {
tokadd(p, '@');
@@ -4399,7 +4447,7 @@ parser_yylex(parser_state *p)
break;
case '_':
- newtok(p);
+ token_column = newtok(p);
break;
default:
@@ -4408,7 +4456,7 @@ parser_yylex(parser_state *p)
goto retry;
}
- newtok(p);
+ token_column = newtok(p);
break;
}
@@ -4417,6 +4465,9 @@ parser_yylex(parser_state *p)
c = nextc(p);
if (c < 0) break;
} while (identchar(c));
+ if (token_column == 0 && toklen(p) == 7 && (c < 0 || c == '\n') &&
+ strncmp(tok(p), "__END__", toklen(p)) == 0)
+ return -1;
switch (tok(p)[0]) {
case '@': case '$':
@@ -4493,6 +4544,9 @@ parser_yylex(parser_state *p)
yylval.id = intern(kw->name);
return kw->id[0];
}
+ if (p->lstate == EXPR_BEG) {
+ p->cmd_start = TRUE;
+ }
if (kw->id[0] == keyword_do) {
if (p->lpar_beg && p->lpar_beg == p->paren_nest) {
p->lpar_beg = 0;
@@ -4604,6 +4658,8 @@ parser_new(mrb_state *mrb)
p->cmd_start = TRUE;
p->in_def = p->in_single = FALSE;
+ p->capture_errors = 0;
+
p->lineno = 1;
#if defined(PARSER_TEST) || defined(PARSER_DEBUG)
yydebug = 1;
@@ -4642,6 +4698,22 @@ mrb_parse_nstring(mrb_state *mrb, char *s, size_t len)
}
parser_state*
+mrb_parse_nstring_ext(mrb_state *mrb, char *s, size_t len)
+{
+ parser_state *p;
+
+ p = parser_new(mrb);
+ if (!p) return 0;
+ p->s = s;
+ p->send = s + len;
+ p->f = NULL;
+ p->capture_errors = 1;
+
+ start_parser(p);
+ return p;
+}
+
+parser_state*
mrb_parse_string(mrb_state *mrb, char *s)
{
return mrb_parse_nstring(mrb, s, strlen(s));
diff --git a/src/pool.c b/src/pool.c
index 1a2bec642..9461ecf60 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -1,3 +1,9 @@
+/*
+** pool.c - memory pool
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "pool.h"
#include <string.h>
diff --git a/src/pool.h b/src/pool.h
index 4f0b906a5..7b0ae78cb 100644
--- a/src/pool.h
+++ b/src/pool.h
@@ -1,3 +1,9 @@
+/*
+** pool.h - memory pool
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stddef.h>
diff --git a/src/print.c b/src/print.c
index a3e05b6f0..e13e1ef5c 100644
--- a/src/print.c
+++ b/src/print.c
@@ -1,3 +1,9 @@
+/*
+** print.c - Kernel.#p
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/string.h"
#include <stdio.h>
@@ -36,14 +42,14 @@ static mrb_value
p_m(mrb_state *mrb, mrb_value self)
{
int argc, i;
- mrb_value *argv;
+ mrb_value *argv = NULL;
mrb_get_args(mrb, "*", &argv, &argc);
for (i=0; i<argc; i++) {
mrb_p(mrb, argv[i]);
}
- return argv[0];
+ return argv ? argv[0] : mrb_nil_value();
}
mrb_value
diff --git a/src/proc.c b/src/proc.c
index 5e74a1af8..ab5e3ac53 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -1,3 +1,9 @@
+/*
+** proc.c - Proc class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/array.h"
@@ -24,7 +30,7 @@ mrb_closure_new(mrb_state *mrb, mrb_irep *irep)
struct REnv *e;
if (!mrb->ci->env) {
- e = mrb_obj_alloc(mrb, MRB_TT_ENV, mrb->ci->proc->env);
+ e = mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass *) mrb->ci->proc->env);
e->flags= (unsigned int)irep->nlocals;
e->mid = mrb->ci->mid;
e->cioff = mrb->ci - mrb->cibase;
diff --git a/src/range.c b/src/range.c
index bc85f1f62..a12e7bae6 100644
--- a/src/range.c
+++ b/src/range.c
@@ -1,7 +1,13 @@
+/*
+** range.c - Range class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "mruby/class.h"
#include "mruby/range.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "error.h"
#include "mruby/numeric.h"
#include "mruby/string.h"
@@ -371,7 +377,6 @@ range_to_s(mrb_state *mrb, mrb_value range)
str = mrb_str_dup(mrb, str);
mrb_str_cat(mrb, str, "...", r->excl ? 3 : 2);
mrb_str_append(mrb, str, str2);
- //OBJ_INFECT(str, str2);
return str;
}
@@ -390,7 +395,6 @@ inspect_range(mrb_state *mrb, mrb_value range, mrb_value dummy, int recur)
str = mrb_str_dup(mrb, str);
mrb_str_cat(mrb, str, "...", r->excl ? 3 : 2);
mrb_str_append(mrb, str, str2);
- // OBJ_INFECT(str, str2);
return str;
}
diff --git a/src/re.c b/src/re.c
index 0cdf58e7a..c72f22146 100644
--- a/src/re.c
+++ b/src/re.c
@@ -1,8 +1,13 @@
-/* re.c for RegExp Class */
+/*
+** re.c - Regexp class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <string.h>
#include "mruby/string.h"
-#include "ritehash.h"
+#include "mruby/khash.h"
#include "encoding.h"
#include "re.h"
#include "mruby/numeric.h"
@@ -11,7 +16,7 @@
#include "regint.h"
#include "mruby/class.h"
#include "mruby/hash.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "error.h"
#ifdef INCLUDE_REGEXP
@@ -184,7 +189,7 @@ meta_found:
t += mrb_enc_mbcput(c, t, enc);
}
mrb_str_resize(mrb, tmp, t - RSTRING_PTR(tmp));
- /*OBJ_INFECT(tmp, str);*/
+
return tmp;
}
@@ -258,7 +263,7 @@ mrb_reg_nth_match(mrb_state *mrb, mrb_int nth, mrb_value match)
end = m->rmatch->regs.end[nth];
len = end - start;
str = mrb_str_substr(mrb, m->str, start, len);
- /*OBJ_INFECT(str, match);*/
+
return str;
}
@@ -453,7 +458,7 @@ mrb_reg_desc(mrb_state *mrb, const char *s, long len, mrb_value re)
if (RBASIC(re)->flags & REG_ENCODING_NONE)
mrb_str_buf_cat(mrb, str, "n", strlen("n"));//mrb_str_buf_cat2(str, "n");
}
- /*OBJ_INFECT(str, re);*/
+
return str;
}
static void
@@ -575,21 +580,12 @@ mrb_reg_search(mrb_state *mrb, mrb_value re, mrb_value str, mrb_int pos, mrb_int
onig_region_copy(RMATCH_REGS(match), regs);
onig_region_free(regs, 0);
}
- /*else {
- if (mrb_safe_level() >= 3)
- OBJ_TAINT(match);
- else
- FL_UNSET(match, FL_TAINT);
- }*/
RMATCH(match)->str = str_new4(mrb, str.tt, str);
RMATCH(match)->regexp = re;
RMATCH(match)->rmatch->char_offset_updated = 0;
mrb_backref_set(mrb, match);
- //OBJ_INFECT(match, re);
- //OBJ_INFECT(match, str);
-
return result;
}
@@ -1243,8 +1239,7 @@ mrb_reg_initialize_str(mrb_state *mrb, mrb_value obj, mrb_value str, int options
ret = mrb_reg_initialize(mrb, obj, RSTRING_PTR(str), RSTRING_LEN(str), enc,
options, err, sourcefile, sourceline);
- /*OBJ_INFECT(obj, str);
- RB_GC_GUARD(str);*/
+
return ret;
}
@@ -1637,7 +1632,6 @@ mrb_reg_source(mrb_state *mrb, mrb_value re)
mrb_reg_check(mrb, re);
str = mrb_enc_str_new(mrb, RREGEXP_SRC_PTR(re),RREGEXP_SRC_LEN(re), mrb_enc_get(mrb, re));
- /*if (OBJ_TAINTED(re)) OBJ_TAINT(str);*/
return str;
}
@@ -1897,7 +1891,6 @@ match_array(mrb_state *mrb, mrb_value match, int start)
mrb_value ary;
mrb_value target;
int i;
- /*int taint = OBJ_TAINTED(match);*/
match_check(mrb, match);
regs = RMATCH_REGS(match);
@@ -1910,7 +1903,6 @@ match_array(mrb_state *mrb, mrb_value match, int start)
}
else {
mrb_value str = mrb_str_subseq(mrb, target, regs->beg[i], regs->end[i]-regs->beg[i]);
- /*if (taint) OBJ_TAINT(str);*/
mrb_ary_push(mrb, ary, str);
}
}
@@ -2106,7 +2098,7 @@ mrb_reg_match_post(mrb_state *mrb, mrb_value match)
str = RMATCH(match)->str;
pos = END(0);
str = mrb_str_subseq(mrb, str, pos, RSTRING_LEN(str) - pos);
- /*if (OBJ_TAINTED(match)) OBJ_TAINT(str);*/
+
return str;
}
@@ -2133,7 +2125,7 @@ mrb_reg_match_pre(mrb_state *mrb, mrb_value match)
regs = RMATCH_REGS(match);
if (BEG(0) == -1) return mrb_nil_value();
str = mrb_str_subseq(mrb, RMATCH(match)->str, 0, BEG(0));
- /*if (OBJ_TAINTED(match)) OBJ_TAINT(str);*/
+
return str;
}
@@ -2202,8 +2194,7 @@ mrb_match_to_s(mrb_state *mrb, mrb_value match)
match_check(mrb, match);
if (mrb_nil_p(str)) str = mrb_str_new(mrb, 0, 0);//mrb_str_new(0,0);
- /*if (OBJ_TAINTED(match)) OBJ_TAINT(str); */
- /*if (OBJ_TAINTED(RMATCH(match)->str)) OBJ_TAINT(str); */
+
return str;
}
@@ -2431,7 +2422,6 @@ again:
mrb_str_buf_cat(mrb, str, ")", strlen(")"));
mrb_enc_copy(mrb, str, re);
- /*OBJ_INFECT(str, re);*/
return str;
}
diff --git a/src/re.h b/src/re.h
index e388f602c..e53927e60 100644
--- a/src/re.h
+++ b/src/re.h
@@ -1,8 +1,8 @@
-/**********************************************************************
-
- re.h -
-
-**********************************************************************/
+/*
+** re.h - Regexp class
+**
+** See Copyright Notice in mruby.h
+*/
#ifndef RE_H
#define RE_H
diff --git a/src/regex.h b/src/regex.h
index b5472122a..0669e6f70 100644
--- a/src/regex.h
+++ b/src/regex.h
@@ -1,12 +1,8 @@
-/**********************************************************************
-
- regex.h -
-
- $Author: akr $
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** regex.h - Regexp class
+**
+** See Copyright Notice in mruby.h
+*/
#ifndef ONIGURUMA_REGEX_H
#define ONIGURUMA_REGEX_H 1
diff --git a/src/sprintf.c b/src/sprintf.c
index 06e6b33d7..9a960e2cf 100644
--- a/src/sprintf.c
+++ b/src/sprintf.c
@@ -1,15 +1,8 @@
-/**********************************************************************
-
- sprintf.c -
-
- $Author: yugui $
- created at: Fri Oct 15 10:39:26 JST 1993
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
- Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
- Copyright (C) 2000 Information-technology Promotion Agency, Japan
-
-**********************************************************************/
+/*
+** sprintf.c - Kernel.#sprintf
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#include <stdio.h>
@@ -26,10 +19,6 @@
#include <ieeefp.h>
#endif
-#ifndef MRB_TAINT_P
- #define MRB_TAINTED_P(p) FALSE
-#endif
-
#define BIT_DIGITS(N) (((N)*146)/485 + 1) /* log2(10) =~ 146/485 */
#define BITSPERDIG (sizeof(mrb_int)*CHAR_BIT)
#define EXTENDSIGN(n, l) (((~0 << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0 << (n)))
@@ -506,7 +495,6 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
int width, prec, flags = FNONE;
int nextarg = 1;
int posarg = 0;
- int tainted = 0;
mrb_value nextvalue;
mrb_value tmp;
mrb_value str;
@@ -529,7 +517,6 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
++argc;
--argv;
- if (MRB_TAINTED_P(fmt)) tainted = 1;
mrb_string_value(mrb, &fmt);
fmt = mrb_str_new4(mrb, fmt);
p = RSTRING_PTR(fmt);
@@ -733,7 +720,6 @@ format_s:
if (*p == 'p') arg = mrb_inspect(mrb, arg);
str = mrb_obj_as_string(mrb, arg);
- if (MRB_TAINTED_P(str)) tainted = 1;
len = RSTRING_LEN(str);
mrb_str_set_len(mrb, result, blen);
if (flags&(FPREC|FWIDTH)) {
@@ -825,7 +811,7 @@ bin_retry:
val = mrb_fixnum_value((mrb_int)mrb_float(val));
goto bin_retry;
}
- val = mrb_dbl2big(mrb, mrb_float(val));
+ val = mrb_flt2big(mrb, mrb_float(val));
if (FIXNUM_P(val)) goto bin_retry;
break;
case MRB_TT_STRING:
diff --git a/src/state.c b/src/state.c
index 14efed986..f705060e8 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1,5 +1,11 @@
+/*
+** state.c - RiteVM open/close functions
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
-#include "irep.h"
+#include "mruby/irep.h"
#include <string.h>
void mrb_init_heap(mrb_state*);
diff --git a/src/string.c b/src/string.c
index 6b8861ace..e92d76b18 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1,3 +1,9 @@
+/*
+** string.c - String class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include <stdarg.h>
@@ -8,10 +14,9 @@
#include <ctype.h>
#include "mruby/array.h"
#include "mruby/class.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "mruby/hash.h"
#include <stdio.h>
-#include "variable.h"
#include "re.h"
#ifdef INCLUDE_REGEXP
#include "regex.h"
@@ -75,14 +80,6 @@ mrb_str_set_len(mrb_state *mrb, mrb_value str, long len)
static mrb_value mrb_enc_cr_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, long len,
int ptr_encindex, int ptr_cr, int *ptr_cr_ret);
#endif //INCLUDE_ENCODING
-mrb_value
-mrb_tainted_str_new(mrb_state *mrb, const char *ptr, long len)
-{
- mrb_value str = mrb_str_new(mrb, ptr, len);
-
- //OBJ_TAINT(str);
- return str;
-}
#ifdef INCLUDE_ENCODING
mrb_value
@@ -98,7 +95,7 @@ mrb_external_str_new_with_enc(mrb_state *mrb, const char *ptr, long len, mrb_enc
{
mrb_value str;
- str = mrb_tainted_str_new(mrb, ptr, len);
+ str = mrb_str_new(mrb, ptr, len);
if (eenc == mrb_usascii_encoding(mrb) &&
mrb_enc_str_coderange(mrb, str) != ENC_CODERANGE_7BIT) {
mrb_enc_associate(mrb, str, mrb_ascii8bit_encoding(mrb));
@@ -151,10 +148,6 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, size_t len)
{
size_t slen;
- if (len < 0) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "negative string size (or size too big)");
- }
-
mrb_str_modify(mrb, str);
slen = RSTRING_LEN(str);
if (len != slen) {
@@ -495,13 +488,13 @@ str_new4(mrb_state *mrb, enum mrb_vtype ttype, mrb_value str)
RSTRING(str2)->buf = RSTRING_PTR(str);
if (MRB_STR_SHARED_P(str)) {
- mrb_value shared = RSTRING_SHARED(str);
+ struct RString *shared = RSTRING_SHARED(str);
FL_SET(str2, MRB_STR_SHARED);
RSTRING_SHARED(str2) = shared;
}
else {
FL_SET(str, MRB_STR_SHARED);
- RSTRING_SHARED(str) = str2;
+ RSTRING_SHARED(str) = mrb_str_ptr(str2);
}
mrb_enc_cr_str_exact_copy(mrb, str2, str);
return str2;
@@ -512,10 +505,6 @@ str_new(mrb_state *mrb, enum mrb_vtype ttype, const char *p, size_t len)
{
mrb_value str;
- if (len < 0) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "negative string size (or size too big)");
- }
-
//str = str_alloc(mrb);
str = mrb_str_buf_new(mrb, len);
#ifdef INCLUDE_ENCODING
@@ -603,9 +592,6 @@ mrb_value
mrb_str_buf_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
{
if (len == 0) return str;
- if (len < 0) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "negative string size (or size too big)");
- }
return str_buf_cat(mrb, str, ptr, len);
}
@@ -791,8 +777,6 @@ mrb_str_plus_m(mrb_state *mrb, mrb_value self)
RSTRING_PTR(str2), RSTRING_LEN(str2));
RSTRING_PTR(str3)[RSTRING_LEN(str3)] = '\0';
#ifdef INCLUDE_ENCODING
- //if (OBJ_TAINTED(str1) || OBJ_TAINTED(str2))
- // OBJ_TAINT(str3);
ENCODING_CODERANGE_SET(mrb, str3, mrb_enc_to_index(enc),
ENC_CODERANGE_AND(ENC_CODERANGE(self), ENC_CODERANGE(str2)));
#endif //INCLUDE_ENCODING
@@ -883,7 +867,6 @@ mrb_str_times(mrb_state *mrb, mrb_value self)
}
ptr2[RSTRING_LEN(str2)] = '\0';
- //OBJ_INFECT(str2, str);
mrb_enc_cr_str_copy_for_substr(mrb, str2, self);
return str2;
@@ -1498,7 +1481,6 @@ num_index:
return mrb_nil_value();
default:
tmp = mrb_str_substr(mrb, str, beg, len);
- /*OBJ_INFECT(tmp, indx);*/
return tmp;
}
}
@@ -2100,7 +2082,6 @@ mrb_str_each_line(mrb_state *mrb, mrb_value str)
(rslen <= 1 ||
memcmp(prs->buf, p-rslen, rslen) == 0)) {
line = mrb_str_new5(mrb, str, s, p - s);
- /*OBJ_INFECT(line, str);*/
mrb_yield(mrb, b, line);
str_mod_check(mrb, str, ptr, len);
s = p;
@@ -2110,7 +2091,6 @@ mrb_str_each_line(mrb_state *mrb, mrb_value str)
if (s != pend) {
if (p > pend) p = pend;
line = mrb_str_new5(mrb, str, s, p - s);
- /*OBJ_INFECT(line, str);*/
mrb_yield(mrb, b, line);
}
@@ -2194,7 +2174,7 @@ str_replace_shared(mrb_state *mrb, mrb_value str2, mrb_value str)
str = mrb_str_new_frozen(mrb, str);
RSTRING(str2)->len = RSTRING_LEN(str);
RSTRING(str2)->buf = RSTRING_PTR(str);
- RSTRING_SHARED(str2) = str;
+ RSTRING_SHARED(str2) = mrb_str_ptr(str);
FL_SET(str2, MRB_STR_SHARED);
mrb_enc_cr_str_exact_copy(mrb, str2, str);
@@ -2218,7 +2198,6 @@ mrb_str_new_shared(mrb_state *mrb, mrb_value str)
{
mrb_value str2 = str_new3(mrb, mrb_obj_class(mrb, str), str);
- //OBJ_INFECT(str2, str);
return str2;
}
@@ -2230,9 +2209,9 @@ mrb_str_new_frozen(mrb_state *mrb, mrb_value orig)
klass = mrb_obj_class(mrb, orig);
- if (MRB_STR_SHARED_P(orig) && !mrb_nil_p(RSTRING_SHARED(orig))) {
+ if (MRB_STR_SHARED_P(orig) && RSTRING_SHARED(orig)) {
long ofs;
- ofs = RSTRING_LEN(str) - RSTRING_LEN(orig);
+ ofs = RSTRING_LEN(str) - RSTRING_SHARED(orig)->len;
#ifdef INCLUDE_ENCODING
if ((ofs > 0) || (klass != RBASIC(str)->c) ||
ENCODING_GET(mrb, str) != ENCODING_GET(mrb, orig)) {
@@ -2405,7 +2384,6 @@ mrb_str_buf_append(mrb_state *mrb, mrb_value str, mrb_value str2)
mrb_enc_cr_str_buf_cat(mrb, str, RSTRING_PTR(str2), RSTRING_LEN(str2),
ENCODING_GET(mrb, str2), str2_cr, &str2_cr);
- //OBJ_INFECT(str, str2);
ENC_CODERANGE_SET(str2, str2_cr);
return str;
@@ -2468,7 +2446,6 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang)
mrb_int offset, blen, slen, len, last;
int iter = 0;
char *sp, *cp;
- //int tainted = 0;
mrb_encoding *str_enc;
mrb_get_args(mrb, "*", &argv, &argc);
@@ -2480,7 +2457,6 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang)
case 2:
repl = argv[1];
mrb_string_value(mrb, &repl);
- /*if (OBJ_TAINTED(repl)) tainted = 1;*/
break;
default:
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%d for 2)", argc);
@@ -2572,9 +2548,6 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang)
* <code>$&</code>, and <code>$'</code> will be set appropriately. The value
* returned by the block will be substituted for the match on each call.
*
- * The result inherits any tainting in the original string or any supplied
- * replacement string.
- *
* When neither a block nor a second argument is supplied, an
* <code>Enumerator</code> is returned.
*
@@ -2792,9 +2765,9 @@ str_replace(mrb_state *mrb, mrb_value str, mrb_value str2)
len = RSTRING_LEN(str2);
if (MRB_STR_SHARED_P(str2)) {
- mrb_value shared = RSTRING_SHARED(str2);
+ struct RString *shared = RSTRING_SHARED(str2);
RSTRING_LEN(str) = len;
- RSTRING_PTR(str) = RSTRING_PTR(str2);
+ RSTRING_PTR(str) = shared->buf;
FL_SET(str, MRB_STR_SHARED);
RSTRING_SHARED(str) = shared;
}
@@ -2812,9 +2785,6 @@ str_replace(mrb_state *mrb, mrb_value str, mrb_value str2)
* call-seq:
* str.replace(other_str) => str
*
- * Replaces the contents and taintedness of <i>str</i> with the corresponding
- * values in <i>other_str</i>.
- *
* s = "hello" #=> "hello"
* s.replace "world" #=> "world"
*/
@@ -3769,8 +3739,6 @@ mrb_str_sub_bang(mrb_state *mrb, mrb_value str)
}
mrb_str_modify(mrb, str);
mrb_enc_associate(mrb, str, enc);
- //if (OBJ_TAINTED(repl)) tainted = 1;
- //if (OBJ_UNTRUSTED(repl)) untrusted = 1;
if (ENC_CODERANGE_UNKNOWN < cr && cr < ENC_CODERANGE_BROKEN) {
int cr2 = ENC_CODERANGE(repl);
if (cr2 == ENC_CODERANGE_BROKEN ||
@@ -3832,9 +3800,6 @@ mrb_str_sub_bang(mrb_state *mrb, mrb_value str)
* <code>$&</code>, and <code>$'</code> will be set appropriately. The value
* returned by the block will be substituted for the match on each call.
*
- * The result inherits any tainting in the original string or any supplied
- * replacement string.
- *
* "hello".sub(/[aeiou]/, '*') #=> "h*llo"
* "hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo"
* "hello".sub(/./) {|s| s.ord.to_s + ' ' } #=> "104 ello"
@@ -4697,7 +4662,6 @@ mrb_str_dump(mrb_state *mrb, mrb_value str)
snprintf(q, qend-q, ".force_encoding(\"%s\")", enc->name);
enc = mrb_ascii8bit_encoding(mrb);
}
- //OBJ_INFECT(result, str);
/* result from dump is ASCII */
mrb_enc_associate(mrb, result, enc);
ENC_CODERANGE_SET(result, ENC_CODERANGE_7BIT);
@@ -4765,35 +4729,8 @@ mrb_lastline_set(mrb_value val)
mrb_value
mrb_str_append(mrb_state *mrb, mrb_value str, mrb_value str2)
{
-#ifdef INCLUDE_ENCODING
- mrb_encoding *enc;
- int cr, cr2;
-#endif //INCLUDE_ENCODING
-
- //StringValue(str2);
mrb_string_value(mrb, &str2);
- if (RSTRING_LEN(str2) > 0 /*&& STR_ASSOC_P(str)*/) {
- long len = RSTRING_LEN(str)+RSTRING_LEN(str2);
-#ifdef INCLUDE_ENCODING
- enc = mrb_enc_check(mrb, str, str2);
- cr = ENC_CODERANGE(str);
- if ((cr2 = ENC_CODERANGE(str2)) > cr) cr = cr2;
-#endif //INCLUDE_ENCODING
- mrb_str_modify(mrb, str);
- REALLOC_N(mrb, RSTRING(str)->buf, char, len+1);
- memcpy(RSTRING(str)->buf + RSTRING(str)->len,
- RSTRING_PTR(str2), RSTRING_LEN(str2)+1);
- RSTRING(str)->len = len;
- mrb_enc_associate(mrb, str, enc);
- ENC_CODERANGE_SET(str, cr);
- //OBJ_INFECT(str, str2);
- return str;
- }
-#ifdef INCLUDE_ENCODING
return mrb_str_buf_append(mrb, str, str2);
-#else
- return str;
-#endif //INCLUDE_ENCODING
}
void
@@ -4983,7 +4920,6 @@ mrb_str_inspect(mrb_state *mrb, mrb_value str)
if (p > prev) mrb_str_buf_cat(mrb, result, prev, p - prev);
mrb_str_buf_cat(mrb, result, "\"", strlen("\"")); //str_buf_cat2(result, "\"");
- //OBJ_INFECT(result, str);
return result;
}
diff --git a/src/struct.c b/src/struct.c
index 9af6e2ee4..c7e09d4ed 100644
--- a/src/struct.c
+++ b/src/struct.c
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- struct.c -
-
- $Author: marcandre $
- created at: Tue Mar 22 18:44:30 JST 1995
-
- Copyright (C) 1993-2007 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** struct.c - Struct class
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#include <string.h>
@@ -29,7 +24,7 @@ mrb_value mrb_exec_recursive_paired(mrb_state *mrb, mrb_value (*func) (mrb_state
#include "mruby/hash.h"
#include "mruby/string.h"
#include "mruby/class.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include "mruby/range.h"
#include "error.h"
//#include "defines.h"
@@ -517,7 +512,6 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_value dummy, int recur)
mrb_str_append(mrb, str, mrb_inspect(mrb, ptr[i]));
}
mrb_str_cat2(mrb, str, ">");
- //OBJ_INFECT(str, s);
return str;
}
diff --git a/src/symbol.c b/src/symbol.c
index ad3400834..bbc5246fe 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -1,5 +1,11 @@
+/*
+** symbol.c - Symbol class
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
-#include "ritehash.h"
+#include "mruby/khash.h"
#include <string.h>
#include <stdarg.h>
@@ -7,7 +13,7 @@
#include "mruby/string.h"
#include <ctype.h>
#include "mruby/class.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include <stdio.h>
#ifdef INCLUDE_REGEXP
@@ -26,7 +32,6 @@ mrb_intern(mrb_state *mrb, const char *name)
khash_t(n2s) *h = mrb->name2sym;
khash_t(s2n) *rh = mrb->sym2name;
khiter_t k;
- int r;
size_t len;
char *p;
mrb_sym sym;
@@ -40,10 +45,10 @@ mrb_intern(mrb_state *mrb, const char *name)
p = mrb_malloc(mrb, len+1);
memcpy(p, name, len);
p[len] = 0;
- k = kh_put(n2s, h, p, &r);
+ k = kh_put(n2s, h, p);
kh_value(h, k) = sym;
- k = kh_put(s2n, rh, sym, &r);
+ k = kh_put(s2n, rh, sym);
kh_value(rh, k) = p;
return sym;
diff --git a/src/transcode.c b/src/transcode.c
index 66a4d4e42..3aab69581 100644
--- a/src/transcode.c
+++ b/src/transcode.c
@@ -16,7 +16,7 @@
#include "transcode_data.h"
#include <ctype.h>
#include "st.h"
-#include "variable.h"
+#include "mruby/variable.h"
#include <string.h>
#include "mruby/string.h"
#include "mruby/array.h"
diff --git a/src/variable.c b/src/variable.c
index 0bc1f0de1..5aba846b1 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -1,7 +1,14 @@
+/*
+** variable.c - mruby variables
+**
+** See Copyright Notice in mruby.h
+*/
+
+#include <stdio.h>
#include "mruby.h"
#include "mruby/class.h"
-#include "ritehash.h"
-#include "variable.h"
+#include "mruby/khash.h"
+#include "mruby/variable.h"
#include "mruby/string.h"
#include "mruby/range.h"
#include "error.h"
@@ -54,7 +61,6 @@ mrb_gc_mark_iv(mrb_state *mrb, struct RObject *obj)
size_t
mrb_gc_mark_iv_size(mrb_state *mrb, struct RObject *obj)
{
- khiter_t k;
struct kh_iv *h = obj->iv;
if (!h) return 0;
@@ -108,9 +114,8 @@ static void
ivset(mrb_state *mrb, struct kh_iv *h, mrb_sym sym, mrb_value v)
{
khiter_t k;
- int r;
- k = kh_put(iv, h, sym, &r);
+ k = kh_put(iv, h, sym);
kh_value(h, k) = v;
}
@@ -173,14 +178,13 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v)
struct RClass *c = mrb->ci->target_class;
khash_t(iv) *h;
khiter_t k;
- int r;
while (c) {
if (c->iv) {
h = c->iv;
k = kh_get(iv, h, sym);
if (k != kh_end(h)) {
- k = kh_put(iv, h, sym, &r);
+ k = kh_put(iv, h, sym);
kh_value(h, k) = v;
}
}
@@ -188,7 +192,7 @@ mrb_vm_cv_set(mrb_state *mrb, mrb_sym sym, mrb_value v)
}
c = mrb->ci->target_class;
h = c->iv = kh_init(iv, mrb);
- k = kh_put(iv, h, sym, &r);
+ k = kh_put(iv, h, sym);
kh_value(h, k) = v;
}
@@ -340,9 +344,11 @@ mrb_f_global_variables(mrb_state *mrb, mrb_value self)
struct kh_iv *h = mrb->globals;
mrb_value ary = mrb_ary_new(mrb);
- for (i=0;i< kh_end(h);i++) {
- if (kh_exist(h, i)) {
- mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(h,i)));
+ if (h) {
+ for (i=0;i < kh_end(h);i++) {
+ if (kh_exist(h, i)) {
+ mrb_ary_push(mrb, ary, mrb_symbol_value(kh_key(h,i)));
+ }
}
}
buf[0] = '$';
diff --git a/src/version.c b/src/version.c
index d69c6941c..9be292a35 100644
--- a/src/version.c
+++ b/src/version.c
@@ -1,20 +1,14 @@
-/**********************************************************************
-
- version.c -
-
- $Author: knu $
- $Date: 2008-05-31 22:37:06 +0900 (Sat, 31 May 2008) $
- created at: Thu Sep 30 20:08:01 JST 1993
-
- Copyright (C) 1993-2003 Yukihiro Matsumoto
-
-**********************************************************************/
+/*
+** version.c - version information
+**
+** See Copyright Notice in mruby.h
+*/
#include "mruby.h"
#include "version.h"
#include <stdio.h>
#include "mruby/string.h"
-#include "variable.h"
+#include "mruby/variable.h"
#define PRINT(type) puts(ruby_##type)
//#define MKSTR(type) mrb_obj_freeze(mrb_str_new(ruby_##type, sizeof(ruby_##type)-1))
diff --git a/src/version.h b/src/version.h
index e132efdf4..0188acf19 100644
--- a/src/version.h
+++ b/src/version.h
@@ -1,3 +1,9 @@
+/*
+** version.h - version information
+**
+** See Copyright Notice in mruby.h
+*/
+
#define RUBY_VERSION "1.8.7"
#define RUBY_RELEASE_DATE "2010-08-16"
#define RUBY_VERSION_CODE 187
diff --git a/src/vm.c b/src/vm.c
index 6983fd86f..f74aac1b8 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -1,7 +1,13 @@
+/*
+** vm.c - virtual machine for mruby (RiteVM)
+**
+** See Copyright Notice in mruby.h
+*/
+
#include "mruby.h"
#include "opcode.h"
-#include "irep.h"
-#include "variable.h"
+#include "mruby/irep.h"
+#include "mruby/variable.h"
#include "mruby/proc.h"
#include "mruby/array.h"
#include "mruby/string.h"
@@ -871,9 +877,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
int o = (ax>>13)&0x1f;
int r = (ax>>12)&0x1;
int m2 = (ax>>7)&0x1f;
+ /* unused
int k = (ax>>2)&0x1f;
int kd = (ax>>1)&0x1;
int b = (ax>>0)& 0x1;
+ */
int argc = mrb->ci->argc;
mrb_value *argv = regs+1;
int len = m1 + o + r + m2;
@@ -947,7 +955,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
if (mrb->exc) {
mrb_callinfo *ci;
- int ridx;
L_RAISE:
ci = mrb->ci;
diff --git a/src/vm_core.h b/src/vm_core.h
index 98da043a2..1fadffaee 100644
--- a/src/vm_core.h
+++ b/src/vm_core.h
@@ -1,13 +1,8 @@
-/**********************************************************************
-
- vm_core.h -
-
- $Author: yugui $
- created at: 04/01/01 19:41:38 JST
-
- Copyright (C) 2004-2007 Koichi Sasada
-
-**********************************************************************/
+/*
+** vm_core.h - RiteVM core
+**
+** See Copyright Notice in mruby.h
+*/
#ifndef RUBY_VM_CORE_H
#define RUBY_VM_CORE_H
diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile
index ba7764b78..7271a2fed 100644
--- a/tools/mrbc/Makefile
+++ b/tools/mrbc/Makefile
@@ -69,5 +69,6 @@ $(YC) : $(YSRC)
clean :
-rm -f $(EXE) $(OBJS) $(OBJY) $(YC)
-rm -f $(OBJS:.o=.d) $(OBJY:.o=.d)
+ -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
@echo "make: removing targets, objects and depend files of `pwd`"
diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c
index 1e54edbdf..cf73ef1d5 100644
--- a/tools/mrbc/mrbc.c
+++ b/tools/mrbc/mrbc.c
@@ -1,11 +1,11 @@
#include "mruby.h"
#include "mruby/proc.h"
+#include "mruby/dump.h"
+#include "mruby/cdump.h"
#include "compile.h"
-#include "dump.h"
-#include "cdump.h"
-#include "stdio.h"
-#include "memory.h"
-#include "stdlib.h"
+#include <stdio.h>
+#include <memory.h>
+#include <stdlib.h>
#define RITEBIN_EXT ".mrb"
#define C_EXT ".c"
diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile
index dfb8b7f7c..62d7cdd3f 100644
--- a/tools/mruby/Makefile
+++ b/tools/mruby/Makefile
@@ -86,4 +86,5 @@ clean :
$(MAKE) clean -C ../../mrblib $(MAKE_FLAGS)
-rm -f $(EXE) $(OBJS) $(OBJY) $(YC) $(EXTS)
-rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) $(EXTS:.o=.d)
+ -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1))
@echo "make: removing targets, objects and depend files of `pwd`"
diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c
index 769746530..ef513312b 100644
--- a/tools/mruby/mruby.c
+++ b/tools/mruby/mruby.c
@@ -1,9 +1,11 @@
#include "mruby.h"
#include "mruby/proc.h"
+#include "mruby/array.h"
+#include "mruby/string.h"
#include "compile.h"
-#include "dump.h"
-#include "stdio.h"
-#include "string.h"
+#include "mruby/dump.h"
+#include <stdio.h>
+#include <string.h>
void ruby_show_version(mrb_state *);
void ruby_show_copyright(mrb_state *);
@@ -12,9 +14,12 @@ void codedump_all(mrb_state*, int);
struct _args {
FILE *rfp;
+ char* cmdline;
int mrbfile : 1;
int check_syntax : 1;
int verbose : 1;
+ int argc;
+ char** argv;
};
static void
@@ -24,6 +29,7 @@ usage(const char *name)
"switches:",
"-b load and execute RiteBinary (mrb) file",
"-c check syntax only",
+ "-e 'command' one line of script",
"-v print version number, then run in verbose mode",
"--verbose run in verbose mode",
"--version print the version",
@@ -45,52 +51,80 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
memset(args, 0, sizeof(*args));
for (argc--,argv++; argc > 0; argc--,argv++) {
- if (**argv == '-') {
- if (strlen(*argv) <= 1)
- return -1;
-
- switch ((*argv)[1]) {
- case 'b':
- args->mrbfile = 1;
- break;
- case 'c':
- args->check_syntax = 1;
- break;
- case 'v':
- ruby_show_version(mrb);
- args->verbose = 1;
- break;
- case '-':
- if (strcmp((*argv) + 2, "version") == 0) {
- ruby_show_version(mrb);
- }
- else if (strcmp((*argv) + 2, "verbose") == 0) {
- args->verbose = 1;
- break;
- }
- else if (strcmp((*argv) + 2, "copyright") == 0) {
- ruby_show_copyright(mrb);
- }
- else return -3;
- return 0;
+ if (argv[0][0] != '-') break;
+
+ if (strlen(*argv) <= 1)
+ return -1;
+
+ switch ((*argv)[1]) {
+ case 'b':
+ args->mrbfile = 1;
+ break;
+ case 'c':
+ args->check_syntax = 1;
+ break;
+ case 'e':
+ if (argc > 1) {
+ argc--; argv++;
+ if (!args->cmdline) {
+ char *buf;
+
+ buf = mrb_malloc(mrb, strlen(argv[0])+1);
+ strcpy(buf, argv[0]);
+ args->cmdline = buf;
+ }
+ else {
+ args->cmdline = mrb_realloc(mrb, args->cmdline, strlen(args->cmdline)+strlen(argv[0])+2);
+ strcat(args->cmdline, "\n");
+ strcat(args->cmdline, argv[0]);
+ }
}
- }
- else if (args->rfp == NULL) {
- if ((args->rfp = fopen(*argv, args->mrbfile ? "rb" : "r")) == NULL) {
- printf("%s: Cannot open program file. (%s)\n", *origargv, *argv);
- return 0;
+ else {
+ printf("%s: No code specified for -e\n", *origargv);
+ return 0;
+ }
+ break;
+ case 'v':
+ ruby_show_version(mrb);
+ args->verbose = 1;
+ break;
+ case '-':
+ if (strcmp((*argv) + 2, "version") == 0) {
+ ruby_show_version(mrb);
+ }
+ else if (strcmp((*argv) + 2, "verbose") == 0) {
+ args->verbose = 1;
+ break;
+ }
+ else if (strcmp((*argv) + 2, "copyright") == 0) {
+ ruby_show_copyright(mrb);
}
+ else return -3;
+ return 0;
}
}
+
+ if (args->rfp == NULL && args->cmdline == NULL && (args->rfp = fopen(*argv, args->mrbfile ? "rb" : "r")) == NULL) {
+ printf("%s: Cannot open program file. (%s)\n", *origargv, *argv);
+ return 0;
+ }
+ args->argv = mrb_realloc(mrb, args->argv, sizeof(char*) * (argc + 1));
+ memcpy(args->argv, argv, (argc+1) * sizeof(char*));
+ args->argc = argc;
+
return 0;
}
static void
-cleanup(struct _args *args)
+cleanup(mrb_state *mrb, struct _args *args)
{
if (args->rfp)
fclose(args->rfp);
+ if (args->cmdline)
+ mrb_free(mrb, args->cmdline);
+ if (args->argv)
+ mrb_free(mrb, args->argv);
}
int
@@ -98,12 +132,13 @@ main(int argc, char **argv)
{
mrb_state *mrb = mrb_open();
int n = -1;
+ int i;
struct _args args;
struct mrb_parser_state *p;
n = parse_args(mrb, argc, argv, &args);
- if (n < 0 || args.rfp == NULL) {
- cleanup(&args);
+ if (n < 0 || (args.cmdline == NULL && args.rfp == NULL)) {
+ cleanup(mrb, &args);
usage(argv[0]);
return n;
}
@@ -112,9 +147,14 @@ main(int argc, char **argv)
n = mrb_load_irep(mrb, args.rfp);
}
else {
- p = mrb_parse_file(mrb, args.rfp);
+ if (args.cmdline) {
+ p = mrb_parse_string(mrb, (char*)args.cmdline);
+ }
+ else {
+ p = mrb_parse_file(mrb, args.rfp);
+ }
if (!p || !p->tree || p->nerr) {
- cleanup(&args);
+ cleanup(mrb, &args);
return -1;
}
@@ -126,18 +166,24 @@ main(int argc, char **argv)
}
if (n >= 0) {
+ mrb_value ARGV = mrb_ary_new(mrb);
+ for (i = 0; i < args.argc; i++) {
+ mrb_ary_push(mrb, ARGV, mrb_str_new(mrb, args.argv[i], strlen(args.argv[i])));
+ }
+ mrb_define_global_const(mrb, "ARGV", ARGV);
+
if (args.verbose)
codedump_all(mrb, n);
if (!args.check_syntax) {
- mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_nil_value());
+ mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));
if (mrb->exc) {
- mrb_funcall(mrb, mrb_nil_value(), "p", 1, mrb_obj_value(mrb->exc));
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
}
}
}
- cleanup(&args);
+ cleanup(mrb, &args);
- return n;
+ return n > 0 ? 0 : 1;
}