yarv-diff:356
From: ko1 atdot.net
Date: 18 Jul 2006 16:51:46 +0900
Subject: [yarv-diff:356] r523 - in trunk: . yarvtest
Author: ko1
Date: 2006-07-18 16:51:45 +0900 (Tue, 18 Jul 2006)
New Revision: 523
Modified:
trunk/
trunk/ChangeLog
trunk/compile.c
trunk/iseq.c
trunk/vm.c
trunk/yarvcore.c
trunk/yarvtest/yarvtest.rb
Log:
r814@lermite: ko1 | 2006-07-18 16:49:50 +0900
* vm.c : remove unused code
* compile.c : add checking value
* iseq.c : ditto
* yarvcore.c : fix yarv_th_eval prototype declaration
* yarvtest/yarvtest.rb : use compile instead of parse method
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:803
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:814
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/ChangeLog 2006-07-18 07:51:45 UTC (rev 523)
@@ -4,6 +4,19 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-07-18(Tue) 16:48:01 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * vm.c : remove unused code
+
+ * compile.c : add checking value
+
+ * iseq.c : ditto
+
+ * yarvcore.c : fix yarv_th_eval prototype declaration
+
+ * yarvtest/yarvtest.rb : use compile instead of parse method
+
+
2006-07-12(Wed) 15:18:58 +0900 Koichi Sasada <ko1 atdot.net>
* yarv_version.h : 0.4.1
Modified: trunk/compile.c
===================================================================
--- trunk/compile.c 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/compile.c 2006-07-18 07:51:45 UTC (rev 523)
@@ -4624,9 +4624,7 @@
register_label(yarv_iseq_t *iseq, struct st_table *labels_table, VALUE obj)
{
LABEL *label = 0;
- if (!SYMBOL_P(obj)) {
- rb_bug("register_label: is not label");
- }
+ obj = rb_convert_type(obj, T_SYMBOL, "Symbol", "to_sym");
if (st_lookup(labels_table, obj, (st_data_t *)&label) == 0) {
label = NEW_LABEL(0);
@@ -4670,7 +4668,8 @@
VALUE tmp;
for (i=0; i<RARRAY(exception)->len; i++) {
- VALUE *ptr = RARRAY(rb_ary_entry(exception, i))->ptr;
+ VALUE v = rb_ary_entry(exception, i);
+ VALUE *ptr = RARRAY(v)->ptr;
VALUE type = get_exception_sym2type(ptr[0]);
VALUE eiseqval;
LABEL *lstart, *lend, *lcont;
@@ -4704,6 +4703,7 @@
VALUE *ptr = RARRAY(body)->ptr;
int len = RARRAY(body)->len;
int i, j;
+ int line_no = 0;
/*
* index -> LABEL *label
*/
@@ -4720,13 +4720,15 @@
LABEL *label = register_label(iseq, labels_table, obj);
ADD_LABEL(anchor, label);
}
+ else if (FIXNUM_P(obj)) {
+ line_no = NUM2INT(obj);
+ }
else if (TYPE(obj) == T_ARRAY) {
VALUE *argv = 0;
int argc = RARRAY(obj)->len - 1;
- int line_no = 0;
VALUE insn_id;
- if (st_lookup(insn_table, RARRAY(obj)->ptr[0], &insn_id) == 0) {
+ if (st_lookup(insn_table, rb_ary_entry(obj, 0), &insn_id) == 0) {
// TODO: exception
rb_bug("unknown instruction: ");
}
@@ -4738,7 +4740,7 @@
if (argc > 0) {
argv = compile_data_alloc(iseq, sizeof(VALUE) * argc);
for (j=0; j<argc; j++) {
- VALUE op = RARRAY(obj)->ptr[j+1];
+ VALUE op = rb_ary_entry(obj, j+1);
switch (insn_op_type(insn_id, j)) {
case TS_OFFSET: {
LABEL *label = register_label(iseq, labels_table, op);
@@ -4748,7 +4750,7 @@
case TS_LINDEX:
case TS_DINDEX:
case TS_NUM:
- argv[j] = op;
+ argv[j] = (NUM2INT(op), op);
break;
case TS_VALUE:
argv[j] = op;
@@ -4778,6 +4780,7 @@
}
break;
case TS_GENTRY:
+ op = rb_convert_type(op, T_SYMBOL, "Symbol", "to_sym");
argv[j] = (VALUE)rb_global_entry(SYM2ID(op));
break;
case TS_IC:
@@ -4785,11 +4788,13 @@
iseq_add_mark_object(iseq, argv[j]);
break;
case TS_ID:
- argv[j] = op;
+ argv[j] = rb_convert_type(op, T_SYMBOL,
+ "Symbol", "to_sym");
break;
case TS_CDHASH:
{
int i;
+ op = rb_convert_type(op, T_ARRAY, "Array", "to_ary");
for (i=0; i<RARRAY(op)->len; i+=2) {
VALUE sym = rb_ary_entry(op, i+1);
LABEL *label =
Modified: trunk/iseq.c
===================================================================
--- trunk/iseq.c 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/iseq.c 2006-07-18 07:51:45 UTC (rev 523)
@@ -269,6 +269,10 @@
VALUE iseq_build_from_ary(yarv_iseq_t *iseq, VALUE line,
VALUE locals, VALUE args, VALUE exception, VALUE body);
+#define CHECK_ARRAY(v) rb_convert_type(v, T_ARRAY, "Array", "to_ary")
+#define CHECK_STRING(v) rb_convert_type(v, T_STRING, "String", "to_str")
+#define CHECK_SYMBOL(v) rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym")
+#define CHECK_INTEGER(v) (NUM2LONG(v), v)
VALUE
iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
{
@@ -287,24 +291,27 @@
* name, filename, line,
* type, locals, args, exception_table, body]
*/
+
+ data = CHECK_ARRAY(data);
- magic = rb_ary_entry(data, 0);
- version1 = rb_ary_entry(data, 1);
- version2 = rb_ary_entry(data, 2);
- format_type = rb_ary_entry(data, 3);
- misc = rb_ary_entry(data, 4);
+ magic = CHECK_STRING(rb_ary_entry(data, 0));
+ version1 = CHECK_INTEGER(rb_ary_entry(data, 1));
+ version2 = CHECK_INTEGER(rb_ary_entry(data, 2));
+ format_type = CHECK_INTEGER(rb_ary_entry(data, 3));
+ misc = rb_ary_entry(data, 4); /* TODO */
- /* TODO: load check */
+ name = CHECK_STRING(rb_ary_entry(data, 5));
+ filename = CHECK_STRING(rb_ary_entry(data, 6));
+ line = CHECK_ARRAY(rb_ary_entry(data, 7));
- name = rb_ary_entry(data, 5);
- filename = rb_ary_entry(data, 6);
- line = rb_ary_entry(data, 7);
-
- type = rb_ary_entry(data, 8);
- locals = rb_ary_entry(data, 9);
+ type = CHECK_SYMBOL(rb_ary_entry(data, 8));
+ locals = CHECK_ARRAY(rb_ary_entry(data, 9));
args = rb_ary_entry(data, 10);
- exception = rb_ary_entry(data, 11);
- body = rb_ary_entry(data, 12);
+ if (FIXNUM_P(args) || (args = CHECK_ARRAY(args))) {
+ /* */
+ }
+ exception = CHECK_ARRAY(rb_ary_entry(data, 11));
+ body = CHECK_ARRAY(rb_ary_entry(data, 12));
GetISeqPtr(iseqval, iseq);
iseq->self = iseqval;
@@ -320,9 +327,7 @@
st_insert(type_map, ID2SYM(rb_intern("eval")), ISEQ_TYPE_EVAL);
}
- if (st_lookup(type_map,
- type, &iseq_type) == 0) {
- dp(type);
+ if (st_lookup(type_map, type, &iseq_type) == 0) {
rb_raise(rb_eTypeError, "unsupport type: %p", type);
}
@@ -427,8 +432,7 @@
static VALUE
iseq_eval(VALUE self)
{
- yarv_iseq_t *iseq = iseq_check(self);
- return yarv_th_eval(GET_THREAD(), iseq);
+ return yarv_th_eval(GET_THREAD(), self);
}
static VALUE
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/vm.c 2006-07-18 07:51:45 UTC (rev 523)
@@ -44,26 +44,6 @@
static VALUE yarv_finish_insn_seq[1] = { BIN(finish) };
#endif
-/* imporeted from eval.c */
-struct cache_entry { /* method hash table. */
- ID mid; /* method's id */
- ID mid0; /* method's original id */
- VALUE klass; /* receiver's class */
- VALUE origin; /* where method defined */
- NODE *method;
- int noex;
-};
-
-#define CACHE_SIZE 0x800
-
-//RUBY_EXTERN struct cache_entry ruby_cache_table[CACHE_SIZE];
-//static struct cache_entry *global_method_cache = &ruby_cache_table[0];
-
-#define cache global_method_cache
-
-#define CACHE_MASK 0x7ff
-#define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
-
#include "call_cfunc.h"
void
@@ -528,22 +508,13 @@
break;
}
default:
- rb_bug("unsupported: thread_call0");
+ rb_bug("unsupported: th_call0");
}
YARV_CHECK_INTS();
return val;
}
VALUE
-thread_call0(VALUE self, VALUE klass, VALUE recv, VALUE id, ID oid,
- int argc, const VALUE *argv, NODE * body, int nosuper)
-{
- yarv_thread_t *th;
- GetThreadPtr(self, th);
- return th_call0(th, klass, recv, id, oid, argc, argv, body, nosuper);
-}
-
-VALUE
th_call_super(yarv_thread_t *th, int argc, const VALUE *argv)
{
VALUE recv = th->cfp->self;
@@ -558,7 +529,7 @@
id = cfp->method_id;
}
else {
- rb_bug("thread_call_super: should not be reached");
+ rb_bug("th_call_super: should not be reached");
}
body = rb_method_node(klass, id); /* this returns NODE_METHOD */
@@ -573,15 +544,6 @@
return th_call0(th, klass, recv, id, id, argc, argv, body, nosuper);
}
-
-VALUE
-thread_call_super(VALUE self, int argc, const VALUE *argv)
-{
- yarv_thread_t *th;
- GetThreadPtr(self, th);
- return th_call_super(th, argc, argv);
-}
-
static inline VALUE
th_invoke_yield_cfunc(yarv_thread_t *th, yarv_block_t *block,
VALUE self, int argc, VALUE *argv)
@@ -1263,37 +1225,8 @@
{
NODE *mn;
-//#undef INLINE_METHOD_CACHE
-//#define FAKE_INLINE_METHOD_CACHE
-//#define FAKE_INLINE_METHOD_CACHE2
-//#define INLINE_METHOD_CACHE
-//#define ONLY_GLOBAL_METHOD_CACHE
-
-#if 0
- 1 error
-#elif 0 // defined(FAKE_INLINE_METHOD_CACHE)
+#if OPT_INLINE_METHOD_CACHE
{
- /* don't support polymorphic method call */
- if (LIKELY(ic->ic_method != 0)) {
- mn = ic->ic_method;
- }
- else {
- ic->ic_method = mn = rb_method_node(klass, id);
- }
- }
-#elif 0 //defined(FAKE_INLINE_METHOD_CACHE2)
- {
- if (LIKELY(klass == ic->ic_klass)) {
- mn = ic->ic_method;
- }
- else {
- mn = rb_method_node(klass, id);
- ic->ic_klass = klass;
- ic->ic_method = mn;
- }
- }
-#elif OPT_INLINE_METHOD_CACHE
- {
if (LIKELY(klass == ic->ic_klass) &&
LIKELY(GET_VM_STATE_VERSION() == ic->ic_vmstat)) {
mn = ic->ic_method;
@@ -1305,26 +1238,6 @@
ic->ic_vmstat = GET_VM_STATE_VERSION();
}
}
-#elif 0
- {
- struct cache_entry *ent = cache + EXPR1(klass, id);
- int noex;
-
- if (LIKELY(ent->mid == id) && LIKELY(ent->klass == klass)) {
- if (LIKELY(ent->method != 0)) {
- // klass = ent->origin;
- // id = ent->mid0;
- // noex = ent->noex;
- mn = ent->method;
- }
- else {
- mn = 0;
- }
- }
- else {
- mn = rb_method_node(klass, id);
- }
- }
#else
mn = rb_method_node(klass, id);
#endif
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/yarvcore.c 2006-07-18 07:51:45 UTC (rev 523)
@@ -71,7 +71,7 @@
#define va_init_list(a,b) va_start(a)
#endif
-VALUE yarv_th_eval(yarv_thread_t *th, VALUE iseq);
+VALUE yarv_th_eval(yarv_thread_t *th, VALUE iseqval);
/************/
/* YARVCore */
Modified: trunk/yarvtest/yarvtest.rb
===================================================================
--- trunk/yarvtest/yarvtest.rb 2006-07-12 06:45:20 UTC (rev 522)
+++ trunk/yarvtest/yarvtest.rb 2006-07-18 07:51:45 UTC (rev 523)
@@ -77,7 +77,7 @@
def dump_and_exec exec_file, str
asmstr = <<-EOASMSTR
- iseq = YARVCore::parse(<<-'EOS__', 'eval', 1)
+ iseq = YARVCore::InstructionSequence.compile(<<-'EOS__')
#{str}
EOS__
p YARVCore::InstructionSequence.load(iseq.to_a).eval
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml