[前][次][番号順一覧][スレッド一覧][生データ]

yarv-diff:324

From: ko1 atdot.net
Date: 18 Apr 2006 09:38:39 -0000
Subject: [yarv-diff:324] r491 - trunk

Author: ko1
Date: 2006-04-18 18:38:38 +0900 (Tue, 18 Apr 2006)
New Revision: 491

Modified:
   trunk/ChangeLog
   trunk/compile.c
   trunk/disasm.c
   trunk/yarvcore.h
Log:
	* compile.c, disasm.c : support export/import exception
	information

	* yarvcore.h : change "struct catch_table_entry" member variable
	order



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-04-13 08:18:48 UTC (rev 490)
+++ trunk/ChangeLog	2006-04-18 09:38:38 UTC (rev 491)
@@ -4,6 +4,15 @@
 #  from Mon, 03 May 2004 01:24:19 +0900
 #
 
+2006-04-18(Tue) 18:37:08 +0900  Koichi Sasada  <ko1 atdot.net>
+
+	* compile.c, disasm.c : support export/import exception
+	information
+
+	* yarvcore.h : change "struct catch_table_entry" member variable
+	order
+
+
 2006-04-13(Thu) 17:11:30 +0900  Koichi Sasada  <ko1 atdot.net>
 
 	* bignum.c : import ruby 1.9 HEAD (Ruby 1.9.0 2006-04-08)

Modified: trunk/compile.c
===================================================================
--- trunk/compile.c	2006-04-13 08:18:48 UTC (rev 490)
+++ trunk/compile.c	2006-04-18 09:38:38 UTC (rev 491)
@@ -4562,19 +4562,97 @@
     return ary;
 }
 
+static LABEL *
+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");
+    }
+
+    if (st_lookup(labels_table, obj, (st_data_t *)&label) == 0) {
+	label = NEW_LABEL(0);
+	st_insert(labels_table, obj, (st_data_t)label);
+    }
+    return label;
+}
+
+static VALUE
+get_exception_sym2type(VALUE sym)
+{
+    static VALUE symRescue, symEnsure, symRetry;
+    static VALUE symBreak, symRedo, symNext;
+
+    if (symRescue == 0) {
+	symRescue = ID2SYM(rb_intern("rescue"));
+	symEnsure = ID2SYM(rb_intern("ensure"));
+	symRetry  = ID2SYM(rb_intern("retry"));
+	symBreak  = ID2SYM(rb_intern("break"));
+	symRedo   = ID2SYM(rb_intern("redo"));
+	symNext   = ID2SYM(rb_intern("next"));
+    }
+
+    if (sym == symRescue) return CATCH_TYPE_RESCUE;
+    if (sym == symEnsure) return CATCH_TYPE_ENSURE;
+    if (sym == symRetry)  return CATCH_TYPE_RETRY;
+    if (sym == symBreak)  return CATCH_TYPE_BREAK;
+    if (sym == symRedo)   return  CATCH_TYPE_REDO;
+    if (sym == symNext)   return CATCH_TYPE_NEXT;
+    rb_bug("get_exception_sym2type");
+    return 0;
+}
+
+static int
+insn_simpledata2iseq_exception(yarv_iseq_t *iseq,
+			       struct st_table *labels_table,
+			       VALUE exception)
+{
+    int i;
+    VALUE tmp;
+    
+    for (i=0; i<RARRAY(exception)->len; i++) {
+	VALUE *ptr = RARRAY(rb_ary_entry(exception, i))->ptr;
+	VALUE type = get_exception_sym2type(ptr[0]);
+	VALUE eiseqval;
+	LABEL *lstart, *lend, *lcont;
+	int sp;
+
+	if (ptr[1] == Qnil) {
+	    eiseqval = 0;
+	}
+	else {
+	    eiseqval = iseq_load_simpledata(0, ptr[1], iseq->self);
+	}
+
+	lstart = register_label(iseq, labels_table, ptr[2]);
+	lend   = register_label(iseq, labels_table, ptr[3]);
+	lcont  = register_label(iseq, labels_table, ptr[4]);
+	sp     = NUM2INT(ptr[5]);
+
+	ADD_CATCH_ENTRY(type, lstart, lend, eiseqval, lcont);
+    }
+    return COMPILE_OK;
+}
+
+
 struct st_table *insn_make_insn_table(void);
 
 static int
 insn_simpledata2iseq_body(yarv_iseq_t *iseq, LINK_ANCHOR *anchor,
-			  VALUE body, VALUE line)
+			  VALUE body, VALUE line, VALUE exception)
 {
     /* TODO: body should be freezed */
     VALUE *ptr = RARRAY(body)->ptr;
     int len = RARRAY(body)->len;
     int i, j;
     struct st_table *labels_table = st_init_numtable();
+    /*
+     * index -> LABEL *label
+     */
     static struct st_table *insn_table;
 
+    insn_simpledata2iseq_exception(iseq, labels_table, exception);
+    
     if (insn_table == 0) {
 	insn_table = insn_make_insn_table();
     }
@@ -4583,11 +4661,7 @@
 	VALUE obj = ptr[i];
 
 	if (SYMBOL_P(obj)) {
-	    LABEL *label = 0;
-	    if (st_lookup(labels_table, obj, (st_data_t *)&label) == 0) {
-		label = NEW_LABEL(0);
-		st_insert(labels_table, obj, (st_data_t)label);
-	    }
+	    LABEL *label = register_label(iseq, labels_table, obj);
 	    ADD_LABEL(anchor, label);
 	}
 	else if (TYPE(obj) == T_ARRAY) {
@@ -4611,11 +4685,7 @@
 		    VALUE op = RARRAY(obj)->ptr[j+1];
 		    switch (insn_op_type(insn_id, j)) {
 		      case TS_OFFSET: {
-			  LABEL *label;
-			  if (st_lookup(labels_table, op, (st_data_t *)&label) == 0) {
-			      label = NEW_LABEL(0);
-			      st_insert(labels_table, op, (st_data_t)label);
-			  }
+			  LABEL *label = register_label(iseq, labels_table, op);
 			  argv[j] = (VALUE)label;
 			  break;
 		      }
@@ -4713,6 +4783,6 @@
     }
 
     /* body */
-    insn_simpledata2iseq_body(iseq, anchor, body, line);
+    insn_simpledata2iseq_body(iseq, anchor, body, line, exception);
     return iseq->self;
 }

Modified: trunk/disasm.c
===================================================================
--- trunk/disasm.c	2006-04-13 08:18:48 UTC (rev 490)
+++ trunk/disasm.c	2006-04-18 09:38:38 UTC (rev 491)
@@ -574,6 +574,34 @@
 #define INIT_SYMBOL(name) \
   sym_##name = ID2SYM(rb_intern(#name))
 
+static VALUE
+register_label(struct st_table *table, int idx)
+{
+    VALUE sym;
+    char buff[0x20];
+    snprintf(buff, 0x20, "label_%u", idx);
+    sym = ID2SYM(rb_intern(buff));
+    st_insert(table, idx, sym);
+    return sym;
+}
+
+static VALUE
+exception_type2symbol(VALUE type)
+{
+    ID id;
+    switch(type) {
+      case CATCH_TYPE_RESCUE: id = rb_intern("rescue"); break;
+      case CATCH_TYPE_ENSURE: id = rb_intern("ensure"); break;
+      case CATCH_TYPE_RETRY:  id = rb_intern("retry");  break;
+      case CATCH_TYPE_BREAK:  id = rb_intern("break");  break;
+      case CATCH_TYPE_REDO:   id = rb_intern("redo");   break;
+      case CATCH_TYPE_NEXT:   id = rb_intern("next");   break;
+      default:
+	rb_bug("...");
+    }
+    return ID2SYM(id);
+}
+
 VALUE
 iseq_iseq2simpledata(yarv_iseq_t *iseq)
 {
@@ -649,12 +677,7 @@
 	    switch (insn_op_type(insn, j)) {
 	      case TS_OFFSET: {
 		  unsigned int idx = seq - iseq->iseq + *seq + 1;
-		  char buff[0x20];
-		  VALUE sym;
-		  snprintf(buff, 0x20, "label_%u", idx);
-		  sym = ID2SYM(rb_intern(buff));
-		  rb_ary_push(ary, sym);
-		  st_insert(labels_table, idx, sym);
+		  rb_ary_push(ary, register_label(labels_table, idx));
 		  break;
 	      }
 	      case TS_LINDEX:
@@ -698,6 +721,28 @@
     }
 
     nbody = body;
+
+    /* exception */
+    for (i=0; i<iseq->catch_table_size; i++) {
+	VALUE ary = rb_ary_new();
+	struct catch_table_entry *entry = &iseq->catch_table[i];
+	rb_ary_push(ary, exception_type2symbol(entry->type));
+	if (entry->iseq) {
+	    yarv_iseq_t *eiseq;
+	    GetISeqVal(entry->iseq, eiseq);
+	    rb_ary_push(ary, iseq_iseq2simpledata(eiseq));
+	}
+	else {
+	    rb_ary_push(ary, Qnil);
+	}
+	rb_ary_push(ary, register_label(labels_table, entry->start));
+	rb_ary_push(ary, register_label(labels_table, entry->end));
+	rb_ary_push(ary, register_label(labels_table, entry->cont));
+	rb_ary_push(ary, INT2FIX(entry->sp));
+	rb_ary_push(exception, ary);
+    }
+    
+    /* make body with labels */
     body = rb_ary_new();
 
     for (i=0, pos=0; i<RARRAY(nbody)->len; i++) {

Modified: trunk/yarvcore.h
===================================================================
--- trunk/yarvcore.h	2006-04-13 08:18:48 UTC (rev 490)
+++ trunk/yarvcore.h	2006-04-18 09:38:38 UTC (rev 491)
@@ -152,8 +152,8 @@
     VALUE iseq;
     unsigned long start;
     unsigned long end;
+    unsigned long cont;
     unsigned long sp;
-    unsigned long cont;
 };
 
 #define INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE (512)


-- 
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧][生データ]