[前][次][番号順一覧][スレッド一覧]

ruby-changes:7553

From: ko1 <ko1@a...>
Date: Wed, 3 Sep 2008 10:07:22 +0900 (JST)
Subject: [ruby-changes:7553] Ruby:r19074 (mvm): * mvm.c, eval.c, ruby.c, vm.c, vm_core.h: pass "make test".

ko1	2008-09-03 10:07:04 +0900 (Wed, 03 Sep 2008)

  New Revision: 19074

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19074

  Log:
    * mvm.c, eval.c, ruby.c, vm.c, vm_core.h: pass "make test".

  Modified files:
    branches/mvm/ChangeLog
    branches/mvm/eval.c
    branches/mvm/mvm.c
    branches/mvm/ruby.c
    branches/mvm/version.h
    branches/mvm/vm.c
    branches/mvm/vm_core.h

Index: mvm/ChangeLog
===================================================================
--- mvm/ChangeLog	(revision 19073)
+++ mvm/ChangeLog	(revision 19074)
@@ -1,3 +1,7 @@
+Wed Sep  3 10:04:46 2008  Koichi Sasada  <ko1@a...>
+
+	* mvm.c, eval.c, ruby.c, vm.c, vm_core.h: pass "make test".
+
 Mon Sep  1 11:31:49 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/fileutils.rb (copy_stream, fu_copy_stream0, copy_file): use
Index: mvm/vm_core.h
===================================================================
--- mvm/vm_core.h	(revision 19073)
+++ mvm/vm_core.h	(revision 19074)
@@ -350,6 +350,9 @@
 
     int src_encoding_index;
 
+    int argc;
+    char **argv;
+
 #ifdef RUBY_DEBUG_ENV
     int enable_coredump;
 #endif
Index: mvm/eval.c
===================================================================
--- mvm/eval.c	(revision 19073)
+++ mvm/eval.c	(revision 19074)
@@ -13,20 +13,12 @@
 
 #include "eval_intern.h"
 
-VALUE proc_invoke(VALUE, VALUE, VALUE, VALUE);
-VALUE rb_binding_new(void);
-NORETURN(void rb_raise_jump(VALUE));
-
-ID rb_frame_callee(void);
-
 #define exception_error rb_errReenterError
 
 #include "eval_error.c"
 #include "eval_safe.c"
 #include "eval_jump.c"
 
-/* initialize ruby */
-
 #if defined(__APPLE__)
 #define environ (*_NSGetEnviron())
 #elif !defined(_WIN32) && !defined(__MACOS__) || defined(_WIN32_WCE)
@@ -34,14 +26,22 @@
 #endif
 char **rb_origenviron;
 
-void rb_clear_trace_func(void);
 void rb_thread_stop_timer_thread(void);
+void rb_vm_clear_trace_func(rb_vm_t *vm);
 
 void rb_call_inits(void);
 void Init_heap(void);
 void Init_ext(void);
 void Init_BareVM(void);
 
+VALUE ruby_vm_process_options(rb_vm_t *vm, int argc, char **argv);
+
+VALUE rb_binding_new(void);
+ID rb_frame_callee(void);
+NORETURN(void rb_raise_jump(VALUE));
+
+static int ruby_vm_cleanup(rb_vm_t *vm, int ex);
+
 void
 ruby_init(void)
 {
@@ -84,8 +84,70 @@
     GET_VM()->running = 1;
 }
 
-extern void rb_clear_trace_func(void);
+static VALUE
+vm_parse_options(rb_vm_t *vm)
+{
+    int state;
+    VALUE code = 0;
 
+    Init_stack((void *)&state);
+    PUSH_TAG();
+    if ((state = EXEC_TAG()) == 0) {
+	SAVE_ROOT_JMPBUF(vm->main_thread,
+			 code = ruby_vm_process_options(vm, vm->argc, vm->argv));
+    }
+    else {
+	rb_vm_clear_trace_func(vm);
+	state = error_handle(state);
+	code = INT2FIX(state);
+    }
+    POP_TAG();
+    return code;
+}
+
+static int
+th_exec_iseq(rb_thread_t *th, VALUE iseq)
+{
+    int state;
+
+    if (!iseq) return 0;
+
+    PUSH_TAG();
+    if ((state = EXEC_TAG()) == 0) {
+	SAVE_ROOT_JMPBUF(th, {
+	    th->base_block = 0;
+	    rb_iseq_eval(iseq);
+	});
+    }
+    POP_TAG();
+    return state;
+}
+
+int
+ruby_vm_run(rb_vm_t *vm)
+{
+    VALUE iseq;
+    int status;
+
+    Init_stack((void *)&vm);
+    rb_thread_set_current_raw(vm->main_thread);
+
+    ruby_init();
+    iseq = vm_parse_options(vm);
+
+    switch (iseq) {
+      case Qtrue:  return EXIT_SUCCESS; /* -v */
+      case Qfalse: return EXIT_FAILURE;
+    }
+
+    if (FIXNUM_P(iseq)) {
+	return FIX2INT(iseq);
+    }
+
+    status = th_exec_iseq(vm->main_thread, iseq);
+    return ruby_vm_cleanup(vm, status);
+}
+
 static void
 ruby_finalize_0(rb_vm_t *vm)
 {
@@ -95,7 +157,7 @@
     }
     POP_TAG();
     rb_exec_end_proc(vm->end_procs);
-    rb_clear_trace_func();
+    rb_vm_clear_trace_func(vm);
 }
 
 static void
@@ -116,7 +178,7 @@
 
 void rb_thread_stop_timer_thread(void);
 
-int
+static int
 ruby_vm_cleanup(rb_vm_t *vm, int ex)
 {
     int state;
Index: mvm/mvm.c
===================================================================
--- mvm/mvm.c	(revision 19073)
+++ mvm/mvm.c	(revision 19074)
@@ -17,7 +17,7 @@
 static void vmmgr_add(rb_vm_t *vm);
 static void vmmgr_del(rb_vm_t *vm);
 static rb_vm_t *vm_new(int argc, char *argv[]);
-static void vm_cleanup();
+static void vm_cleanup(rb_vm_t *vm);
 
 /* core API */
 
@@ -31,12 +31,6 @@
 }
 
 int
-ruby_vm_run(rb_vm_t *vm)
-{
-    return 0;
-}
-
-int
 ruby_vm_start(rb_vm_t *vm)
 {
     rb_bug("unsupporeted");
@@ -236,25 +230,24 @@
 static void
 vmmgr_del(rb_vm_t *vm)
 {
-    struct vm_list_struct *entry, *prev = 0;
+    struct vm_list_struct *entry = vm_manager.list, *prev = 0;
 
-    for (entry = vm_manager.list;
-	 entry && entry->vm != vm;
-	 prev = entry, entry = entry->next) {
-	/* nop */
-    }
+    MVM_CRITICAL(vm_manager.lock, {
+	while (entry && entry->vm != vm) {
+	    prev = entry;
+	    entry = entry->next;
+	}
 
-    if (entry) {
-	MVM_CRITICAL(vm_manager.lock, {
-	    if (entry == vm_manager.list) {
-		vm_manager.list = entry->next;
+	if (entry) {
+	    if (prev) {
+		prev->next = entry->next;
 	    }
 	    else {
-		prev->next = entry->next;
+		vm_manager.list = entry->next;
 	    }
-	});
-    }
-    free(entry);
+	    free(entry);
+	}
+    });
 }
 
 void
@@ -266,22 +259,42 @@
 
 	    while (entry) {
 		if (func(entry->vm, arg) == 0) {
+		    printf("ruby_vm_foreach: break\n");
 		    break;
 		}
+		entry = entry->next;
 	    }
 	});
     }
 }
 
+rb_vm_t *ruby_make_bare_vm();
+
 static rb_vm_t *
 vm_new(int argc, char *argv[])
 {
-    /* place holder */
-    return 0;
+    rb_vm_t *vm = ruby_make_bare_vm();
+    vm->argc = argc;
+    vm->argv = argv;
+    return vm;
 }
 
 static void
-vm_cleanup()
+vm_free(void *ptr)
 {
-    /* place holder */
+    if (ptr) {
+	rb_vm_t *vmobj = ptr;
+
+	st_free_table(vmobj->living_threads);
+	vmobj->living_threads = 0;
+	ruby_native_thread_unlock(&vmobj->global_vm_lock);
+	ruby_native_thread_lock_destroy(&vmobj->global_vm_lock);
+	ruby_xfree(ptr);
+    }
 }
+
+static void
+vm_cleanup(rb_vm_t *vm)
+{
+    vm_free(vm);
+}
Index: mvm/vm.c
===================================================================
--- mvm/vm.c	(revision 19073)
+++ mvm/vm.c	(revision 19074)
@@ -1396,22 +1396,6 @@
     RUBY_MARK_LEAVE("vm");
 }
 
-static void
-vm_free(void *ptr)
-{
-    RUBY_FREE_ENTER("vm");
-    if (ptr) {
-	rb_vm_t *vmobj = ptr;
-
-	st_free_table(vmobj->living_threads);
-	vmobj->living_threads = 0;
-	ruby_native_thread_unlock(&vmobj->global_vm_lock);
-	ruby_native_thread_lock_destroy(&vmobj->global_vm_lock);
-	ruby_xfree(ptr);
-    }
-    RUBY_FREE_LEAVE("vm");
-}
-
 #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
 struct rb_objspace *rb_objspace_alloc(void);
 #endif
@@ -1890,7 +1874,7 @@
 	rb_iseq_t *iseq;
 
 	/* create vm object */
-	vm->self = Data_Wrap_Struct(rb_cRubyVM, rb_vm_mark, vm_free, vm);
+	vm->self = Data_Wrap_Struct(rb_cRubyVM, rb_vm_mark, 0, vm);
 
 	/* create main thread */
 	th_self = th->self = Data_Wrap_Struct(rb_cThread, rb_thread_mark, thread_free, th);
@@ -1922,25 +1906,37 @@
 
 void ruby_thread_init_stack(rb_thread_t *th);
 
-void
-Init_BareVM(void)
+rb_vm_t *
+ruby_make_bare_vm(void)
 {
     /* VM bootstrap: phase 1 */
-    rb_vm_t * vm = malloc(sizeof(*vm));
-    rb_thread_t * th = malloc(sizeof(*th));
+    rb_vm_t *vm = malloc(sizeof(*vm));
+    rb_thread_t *th = malloc(sizeof(*th));
+    rb_thread_t *old_th = GET_THREAD();
+
     if (!vm || !th) {
 	fprintf(stderr, "[FATAL] failed to allocate memory\n");
 	exit(EXIT_FAILURE);
     }
     MEMZERO(th, rb_thread_t, 1);
+    vm_init2(vm);
+    vm->main_thread = th;
 
     rb_thread_set_current_raw(th);
+    {
+	th->vm = vm;
+	th_init2(th, 0);
+	ruby_thread_init_stack(th);
+    }
+    rb_thread_set_current_raw(old_th);
 
-    vm_init2(vm);
-    th->vm = vm;
+    return vm;
+}
 
-    th_init2(th, 0);
-    ruby_thread_init_stack(th);
+void
+Init_BareVM(void)
+{
+    ruby_make_bare_vm();
 }
 
 /* top self */
Index: mvm/version.h
===================================================================
--- mvm/version.h	(revision 19073)
+++ mvm/version.h	(revision 19074)
@@ -1,7 +1,7 @@
 #define RUBY_VERSION "1.9.0"
-#define RUBY_RELEASE_DATE "2008-09-01"
+#define RUBY_RELEASE_DATE "2008-09-03"
 #define RUBY_VERSION_CODE 190
-#define RUBY_RELEASE_CODE 20080901
+#define RUBY_RELEASE_CODE 20080903
 #define RUBY_PATCHLEVEL 0
 
 #define RUBY_VERSION_MAJOR 1
@@ -9,7 +9,7 @@
 #define RUBY_VERSION_TEENY 0
 #define RUBY_RELEASE_YEAR 2008
 #define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 1
+#define RUBY_RELEASE_DAY 3
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: mvm/ruby.c
===================================================================
--- mvm/ruby.c	(revision 19073)
+++ mvm/ruby.c	(revision 19074)
@@ -1541,7 +1541,7 @@
 {
     struct cmdline_arguments args;
     struct cmdline_options opt;
-    NODE *tree;
+    VALUE tree;
 
     if (argv[0]) {		/* for the time being */
 	RUBY_VM_OBJECT(vm, progname) = rb_tainted_str_new2(argv[0]);
@@ -1551,14 +1551,14 @@
     args.argv = argv;
     args.opt = cmdline_options_init(&opt);
     opt.ext.enc.index = -1;
-    tree = (NODE *)rb_vm_call_cfunc(vm->top_self,
+    tree = rb_vm_call_cfunc(vm->top_self,
 				    process_options, (VALUE)&args,
 				    0, RUBY_VM_OBJECT(vm, progname));
 
     rb_define_readonly_boolean("$-p", opt.do_print);
     rb_define_readonly_boolean("$-l", opt.do_line);
     rb_define_readonly_boolean("$-a", opt.do_split);
-    return (VALUE)tree;
+    return tree;
 }
 
 void *

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]