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

ruby-changes:7439

From: ko1 <ko1@a...>
Date: Sun, 31 Aug 2008 00:42:43 +0900 (JST)
Subject: [ruby-changes:7439] Ruby:r18958 (mvm): * sampledriver/main.c: added.

ko1	2008-08-31 00:42:14 +0900 (Sun, 31 Aug 2008)

  New Revision: 18958

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

  Log:
    * sampledriver/main.c: added.

  Added directories:
    branches/mvm/sampledriver/
  Added files:
    branches/mvm/sampledriver/main.c
  Modified files:
    branches/mvm/ChangeLog

Index: mvm/ChangeLog
===================================================================
--- mvm/ChangeLog	(revision 18957)
+++ mvm/ChangeLog	(revision 18958)
@@ -1,3 +1,7 @@
+Sun Aug 31 00:40:45 2008  Koichi Sasada  <ko1@a...>
+
+	* sampledriver/main.c: added.
+
 Sun Aug 31 00:02:49 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_str_wrap_cstr): new function.
Index: mvm/sampledriver/main.c
===================================================================
--- mvm/sampledriver/main.c	(revision 0)
+++ mvm/sampledriver/main.c	(revision 18958)
@@ -0,0 +1,77 @@
+/*
+ * SampleDriver [mruby]
+ * This file is a sample driver of MVM.
+ *
+ * This sample driver [mruby] do:
+ *   - creats (argc-1) VMs.
+ *   - lets each VM run ruby script specified by argv[i]
+ *     in parallel.
+ *   - exit sample driver when all VMs are terminated.
+ *
+ * Terminology:
+ *   - Driver: A generator/controller/manager of VMs with Ruby MVM C API.
+ *   - Virtual Machine (VM): VM executs ruby program which is passed by Driver.
+ *   - Ruby MVM C API: APIs for managing MVMs, which includes generation,
+ *     sending events, sending messages and termination.
+ */
+
+#include <ruby/mvm.h>
+
+/* mruby main */
+
+int
+main(int argc, char *argv[])
+{
+    int i, n = argc - 1;
+    rb_vm_t **vms = alloca(sizeof(rb_vm_t *) * n);
+
+    ruby_sysinit(&argc, &argv); /* process level initialize */
+
+    /* mruby a.rb b.rb c.rb */
+    /* => run parallel as:
+     *    ruby a.rb & ruby b.rb & ruby c.rb
+     */
+    
+    for (i=0; i<n; i++) {
+	rb_vm_t *vm;
+	rb_vm_attr_t *attr;
+	static void IntiVM_mruby(rb_vm_t *vm);
+
+	/* set option */
+	attr = ruby_vm_attr_create(1, &argv[i+1]); /* initaialize with arguments */
+
+	ruby_vm_attr_add_initializ_function(attr, InitVM_mruby);
+	ruby_vm_attr_own_timer(attr, 1);
+	ruby_vm_attr_create_thread(attr, 1); /* default */
+	ruby_vm_attr_add_expression(attr, "p true");
+	ruby_vm_attr_add_option(attr, "baz");
+	ruby_vm_attr_set_verbose(attr, 1);
+	ruby_vm_attr_set_debug(attr, 1);
+
+	/* set stdin, out, err */
+	ruby_vm_attr_set_stdin(attr, 0);  /* default */
+	ruby_vm_attr_set_stdout(attr, 1); /* default */
+	ruby_vm_attr_set_stderr(attr, 2); /* default */
+
+	/* create and invoke virtual machine instance */
+	vm = vms[i] = ruby_vm_new(attr);
+
+	ruby_vm_attr_destruct(attr);
+    }
+
+    for (i=0; i<n; i++) {
+	int err = rb_vm_join(vms[i]);
+	printf("VM %d was terminated with error code %d.\n", i, err);
+    }
+
+    return 0;
+}
+
+#include <ruby/ruby.h>
+
+static void
+IntiVM_mruby(rb_vm_t *vm)
+{
+    rb_define_method(...);
+}
+

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

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