yarv-diff:349
From: ko1 atdot.net
Date: 12 Jul 2006 05:10:08 +0900
Subject: [yarv-diff:349] r515 - in trunk: . rb template
Author: ko1
Date: 2006-07-12 05:10:08 +0900 (Wed, 12 Jul 2006)
New Revision: 515
Modified:
trunk/
trunk/ChangeLog
trunk/eval_proc.c
trunk/iseq.c
trunk/rb/allload.rb
trunk/rb/compile.rb
trunk/rb/parse.rb
trunk/template/insnstbl.html
trunk/thread.c
trunk/vm.c
trunk/yarvcore.c
Log:
r800@lermite: ko1 | 2006-07-12 05:06:34 +0900
* yarvcore.c : undef alloc funcs
* eval_proc.c : ditto (use factory faction)
* thread.c : ditto
* vm.c : ditto
* iseq.c : fix compile option creation
* rb/allload.rb : use compile_file method
* rb/compile.rb : ditto
* rb/parse.rb : ditto
* template/insnstbl.html : hide mail addr
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:798
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:800
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/ChangeLog 2006-07-11 20:10:08 UTC (rev 515)
@@ -4,6 +4,28 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+
+2006-07-12(Wed) 05:01:23 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * yarvcore.c : undef alloc funcs
+
+ * eval_proc.c : ditto (use factory faction)
+
+ * thread.c : ditto
+
+ * vm.c : ditto
+
+ * iseq.c : fix compile option creation
+
+ * rb/allload.rb : use compile_file method
+
+ * rb/compile.rb : ditto
+
+ * rb/parse.rb : ditto
+
+ * template/insnstbl.html : hide mail addr
+
+
2006-07-11(Tue) 21:34:29 +0900 Minero Aoki <aamine loveruby.net>
* test/ruby/test_dir.rb: new test test_JVN_13947696.
Modified: trunk/eval_proc.c
===================================================================
--- trunk/eval_proc.c 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/eval_proc.c 2006-07-11 20:10:08 UTC (rev 515)
@@ -42,12 +42,14 @@
* eval("param", b) #=> "hello"
*/
+VALUE yarv_binding_alloc(VALUE klass);
+
VALUE
rb_f_binding(VALUE self)
{
yarv_thread_t *th = GET_THREAD();
yarv_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp);
- VALUE bindval = rb_obj_alloc(cYarvBinding);
+ VALUE bindval = yarv_binding_alloc(cYarvBinding);
yarv_binding_t *bind;
GetBindingPtr(bindval, bind);
@@ -142,18 +144,10 @@
* proc.call #=> "hello"
*/
-static VALUE
-proc_s_new(int argc, VALUE *argv, VALUE klass)
-{
- VALUE block = proc_alloc(klass, Qfalse);
- rb_obj_call_init(block, argc, argv);
- return block;
-}
-
VALUE
-rb_proc_s_new(int argc, VALUE *argv, VALUE klass)
+rb_proc_s_new(VALUE klass)
{
- return proc_s_new(argc, argv, klass);
+ return proc_alloc(klass, Qfalse);
}
/*
@@ -1069,8 +1063,7 @@
* Returns the exit value associated with this +LocalJumpError+.
*/
static VALUE
-localjump_xvalue(exc)
- VALUE exc;
+localjump_xvalue(VALUE exc)
{
return rb_iv_get(exc, "@exit_value");
}
@@ -1084,8 +1077,7 @@
*/
static VALUE
-localjump_reason(exc)
- VALUE exc;
+localjump_reason(VALUE exc)
{
return rb_iv_get(exc, "@reason");
}
Modified: trunk/iseq.c
===================================================================
--- trunk/iseq.c 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/iseq.c 2006-07-11 20:10:08 UTC (rev 515)
@@ -196,7 +196,7 @@
make_compile_option(yarv_compile_option_t *option, VALUE opt)
{
if (opt == Qnil) {
- /* default */
+ *option = COMPILE_OPTION_DEFAULT;
}
else if (opt == Qfalse) {
*option = COMPILE_OPTION_FALSE;
@@ -368,9 +368,8 @@
rb_scan_args(argc, argv, "13", &str, &file, &line, &opt);
- if (file == Qnil) {
- file = rb_str_new2("<compiled>");
- }
+ file = file == Qnil ? rb_str_new2("<compiled>") : file;
+ line = line == Qnil ? INT2FIX(1) : line;
node = compile_string(str, file, line);
make_compile_option(&option, opt);
Modified: trunk/rb/allload.rb
===================================================================
--- trunk/rb/allload.rb 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/rb/allload.rb 2006-07-11 20:10:08 UTC (rev 515)
@@ -1,4 +1,4 @@
-ignores = %w(/dl/import.rb)
+ignores = %w()
# $DEBUG = true
@@ -19,7 +19,7 @@
r = Regexp.compile(Regexp.escape(e))
r !~ file
}
- parsed = YARVCore::parse(File.read(file), file, 1)
+ parsed = YARVCore::InstructionSequence.compile_file(file)
puts parsed.disasm if $DEBUG
else
puts "ignore: #{file}"
Modified: trunk/rb/compile.rb
===================================================================
--- trunk/rb/compile.rb 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/rb/compile.rb 2006-07-11 20:10:08 UTC (rev 515)
@@ -1,21 +1,21 @@
require 'optparse'
require 'pp'
+OutputCompileOption = {
+ # enable
+ :peephole_optimization =>true,
+ :inline_const_cache =>true,
+
+ # disable
+ :specialized_instruction =>false,
+ :operands_unification =>false,
+ :instructions_unification =>false,
+ :stack_caching =>false,
+}
+
def compile_to_rb infile, outfile
- opt = {
- # enable
- :peephole_optimization =>true,
- :inline_const_cache =>true,
+ iseq = YARVCore::InstructionSequence.compile_file(infile, OutputCompileOption)
- # disable
- :specialized_instruction =>false,
- :operands_unification =>false,
- :instructions_unification =>false,
- :stack_caching =>false,
- }
-
- iseq = YARVCore::InstructionSequence::compile_file(infile, opt)
-
open(outfile, 'w'){|f|
f.puts "YARVCore::InstructionSequence.load(" +
"Marshal.load(<<EOS____.unpack('m*')[0])).eval"
@@ -24,22 +24,31 @@
}
end
-def compile_to_rbc infile, outfile
- iseq = YARVCore::parse(IO.read(infile), infile, 1)
-
- open(outfile, 'wb'){|f|
- f.puts Marshal.dump(iseq.to_a, f)
- }
+def compile_to_rbc infile, outfile, type
+ iseq = YARVCore::InstructionSequence.compile_file(infile, OutputCompileOption)
+
+ case type
+ when 'm'
+ open(outfile, 'wb'){|f|
+ f.print "RBCM"
+ f.puts Marshal.dump(iseq.to_a, f)
+ }
+ else
+ raise "Unsupported compile type: #{type}"
+ end
end
## main
outfile = 'a.rb'
-
+type = 'm'
opt = OptionParser.new{|opt|
opt.on('-o file'){|o|
outfile = o
}
+ opt.on('-t type', '--type type'){|o|
+ type = o
+ }
opt.version = '0.0.1'
}
@@ -50,7 +59,7 @@
when /\.rb\Z/
compile_to_rb file, outfile
when /\.rbc\Z/
- compile_to_rbc file, outfile
+ compile_to_rbc file, outfile, type
else
raise
end
Modified: trunk/rb/parse.rb
===================================================================
--- trunk/rb/parse.rb 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/rb/parse.rb 2006-07-11 20:10:08 UTC (rev 515)
@@ -1,5 +1,5 @@
$file = ARGV[0]
$str = ARGF.read
puts $str
-$parsed = YARVCore::parse($str, $file, 1)
+$parsed = YARVCore::InstructionSequence.compile_file($file)
puts $parsed.disasm
Modified: trunk/template/insnstbl.html
===================================================================
--- trunk/template/insnstbl.html 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/template/insnstbl.html 2006-07-11 20:10:08 UTC (rev 515)
@@ -12,7 +12,7 @@
<title>YARV: Yet another RubyVM / Instruction Table</title>
- <link href='mailto:ko1 atdot.net' rev='made'/>
+ <link href='mailto:ko1 at atdot.net' rev='made'/>
<link href='../index.html' rel='index'/>
</head>
<body>
@@ -29,7 +29,7 @@
</table>
<address>
- SASADA Koichi / ko1 atdot.net
+ SASADA Koichi / ko1 at atdot.net
</address>
</div>
</body>
Modified: trunk/thread.c
===================================================================
--- trunk/thread.c 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/thread.c 2006-07-11 20:10:08 UTC (rev 515)
@@ -283,6 +283,7 @@
return 0;
}
+VALUE yarv_thread_alloc(VALUE klass);
static VALUE
yarv_thread_s_new(VALUE klass, VALUE args)
@@ -291,7 +292,7 @@
VALUE thval;
/* create thread object */
- thval = rb_class_new_instance(0, 0, cYarvThread);
+ thval = yarv_thread_alloc(cYarvThread);
GetThreadPtr(thval, th);
/* setup thread environment */
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/vm.c 2006-07-11 20:10:08 UTC (rev 515)
@@ -226,7 +226,7 @@
//SDR2(cfp);
//fprintf(stderr, "lfp: %p, cfp: %p, endptr: %p\n", cfp->lfp, cfp->dfp, endptr);
/* allocate env */
- envval = rb_obj_alloc(cYarvEnv);
+ envval = yarv_env_alloc(cYarvEnv);
GetEnvPtr(envval, env);
if (!YARV_NORMAL_ISEQ_P(cfp->iseq)) {
@@ -409,7 +409,7 @@
if (PROCDEBUG) {
check_env_value(envval);
}
- procval = rb_obj_alloc(cYarvProc);
+ procval = yarv_proc_alloc();
GetProcPtr(procval, proc);
proc->blockprocval = blockprocval;
proc->block.self = block->self;
Modified: trunk/yarvcore.c
===================================================================
--- trunk/yarvcore.c 2006-07-11 12:34:45 UTC (rev 514)
+++ trunk/yarvcore.c 2006-07-11 20:10:08 UTC (rev 515)
@@ -215,15 +215,6 @@
return yarvcore_eval_parsed(node, file);
}
-static VALUE
-yarvcore_parse(VALUE self, VALUE str, VALUE file, VALUE line)
-{
- NODE *node = compile_string(str, file, line);
- return yarv_iseq_new(node, rb_str_new2("<main>"), file, Qfalse,
- ISEQ_TYPE_TOP);
-}
-
-
/******/
/* VM */
/******/
@@ -274,6 +265,10 @@
VALUE volatile obj;
yarv_vm_t *vm;
obj = Data_Make_Struct(klass, yarv_vm_t, vm_mark, vm_free, vm);
+
+ vm->self = obj;
+ vm->mark_object_ary = rb_ary_new();
+
return obj;
}
@@ -283,24 +278,7 @@
MEMZERO(vm, yarv_vm_t, 1);
}
-static VALUE
-vm_init(VALUE self, VALUE node)
-{
- /* allocate vm stack */
- yarv_vm_t *vm;
- GetVMPtr(self, vm);
- vm->self = self;
- vm->mark_object_ary = rb_ary_new();
- return self;
-}
-static VALUE
-vm_eval(VALUE self, VALUE iseq)
-{
- return yarv_th_eval(GET_THREAD(), iseq);
-}
-
-
/**********/
/* Thread */
/**********/
@@ -442,6 +420,14 @@
return self;
}
+VALUE
+yarv_thread_alloc(VALUE klass)
+{
+ VALUE self = thread_alloc(klass);
+ thread_init(self);
+ return self;
+}
+
VALUE th_eval_body(yarv_thread_t *th);
void th_set_top_stack(yarv_thread_t *, VALUE iseq);
VALUE rb_f_binding(VALUE);
@@ -507,8 +493,8 @@
MARK_REPORT_LEAVE("env");
}
-static VALUE
-env_alloc(VALUE klass)
+VALUE
+yarv_env_alloc(VALUE klass)
{
VALUE obj;
yarv_env_t *env;
@@ -561,6 +547,12 @@
return obj;
}
+VALUE
+yarv_proc_alloc(VALUE klass)
+{
+ return proc_alloc(cYarvProc);
+}
+
static VALUE
proc_call(int argc, VALUE *argv, VALUE procval)
{
@@ -746,10 +738,16 @@
return obj;
}
+VALUE
+yarv_binding_alloc(VALUE klass)
+{
+ return binding_alloc(klass);
+}
+
static VALUE
binding_dup(VALUE self)
{
- VALUE bindval = rb_obj_alloc(cYarvBinding);
+ VALUE bindval = binding_alloc(cYarvBinding);
yarv_binding_t *src, *dst;
GetBindingPtr(self, src);
GetBindingPtr(bindval, dst);
@@ -796,7 +794,7 @@
VALUE Init_yarvthread(void);
extern VALUE *rb_gc_stack_start;
-VALUE rb_proc_s_new(int argc, VALUE *argv, VALUE klass);
+VALUE rb_proc_s_new(VALUE klass);
VALUE
sdr(void)
@@ -867,29 +865,26 @@
rb_define_const(mYarvCore, "InsnNameArray", insns_name_array());
rb_define_singleton_method(mYarvCore, "eval", yarvcore_eval, 3);
- rb_define_singleton_method(mYarvCore, "parse", yarvcore_parse, 3);
/* declare YARVCore::VM */
cYarvVM = rb_define_class_under(mYarvCore, "VM", rb_cObject);
- rb_define_alloc_func(cYarvVM, vm_alloc);
- rb_define_method(cYarvVM, "initialize", vm_init, 0);
- rb_define_method(cYarvVM, "eval", vm_eval, 1);
+ rb_undef_alloc_func(cYarvVM);
/* declare YARVCore::VM::Thread */
cYarvThread = rb_define_class_under(cYarvVM, "Thread", rb_cObject);
rb_define_global_const("Thread", cYarvThread);
- rb_define_alloc_func(cYarvThread, thread_alloc);
+ rb_undef_alloc_func(cYarvThread);
rb_define_method(cYarvThread, "initialize", thread_init, 0);
/* declare YARVCore::VM::Env */
cYarvEnv = rb_define_class_under(cYarvVM, "Env", rb_cObject);
- rb_define_alloc_func(cYarvEnv, env_alloc);
+ rb_undef_alloc_func(cYarvEnv);
/* declare YARVCore::VM::Proc */
rb_cProc = cYarvProc = rb_define_class_under(cYarvVM, "Proc", rb_cObject);
rb_const_set(rb_cObject, rb_intern("Proc"), cYarvProc);
- rb_define_alloc_func(cYarvProc, proc_alloc);
- rb_define_singleton_method(cYarvProc, "new", rb_proc_s_new, -1);
+ rb_undef_alloc_func(cYarvProc);
+ rb_define_singleton_method(cYarvProc, "new", rb_proc_s_new, 0);
rb_define_method(cYarvProc, "call", proc_call, -1);
rb_define_method(cYarvProc, "[]", proc_call, -1);
rb_define_method(cYarvProc, "to_proc", proc_to_proc, 0);
@@ -905,7 +900,7 @@
/* declare YARVCore::VM::Binding */
cYarvBinding = rb_define_class_under(cYarvVM, "Binding", rb_cObject);
rb_const_set(rb_cObject, rb_intern("Binding"), cYarvBinding);
- rb_define_alloc_func(cYarvBinding, binding_alloc);
+ rb_undef_alloc_func(cYarvBinding);
rb_undef_method(CLASS_OF(cYarvBinding), "new");
rb_define_method(cYarvBinding, "clone", binding_clone, 0);
rb_define_method(cYarvBinding, "dup", binding_dup, 0);
@@ -967,7 +962,7 @@
// make vm
{
/* create vm object */
- VALUE vmval = rb_class_new_instance(0, 0, cYarvVM);
+ VALUE vmval = vm_alloc(cYarvVM);
yarv_vm_t *vm;
yarv_thread_t *th;
vm = theYarvVM;
@@ -981,7 +976,7 @@
rb_ary_push(yarvVMArray, vm->self);
/* create main thread */
- vm->main_thread_val = rb_class_new_instance(0, 0, cYarvThread);
+ vm->main_thread_val = yarv_thread_alloc(cYarvThread);
GetThreadPtr(vm->main_thread_val, th);
vm->main_thread = th;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml