diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | compile.c | 53 | ||||
-rw-r--r-- | id.c | 6 | ||||
-rw-r--r-- | id.h | 7 | ||||
-rw-r--r-- | insns.def | 99 | ||||
-rw-r--r-- | tool/parse.rb | 2 | ||||
-rw-r--r-- | vm.c | 52 | ||||
-rw-r--r-- | vm_core.h | 4 |
8 files changed, 148 insertions, 86 deletions
@@ -1,3 +1,14 @@ +Tue Jul 1 12:01:16 2008 Koichi Sasada <[email protected]> + + * compile.c, insns.def, vm.c, vm_core.h: remove some insns + (undef, alias, definemethod). + Call RubyVM::FrozenCore's singleton method instead. + Add "putiseq" and "putspecialobject" instructions. + + * id.c, id.h: add ids for above. + + * tool/parse.rb: "VM" no longer exists. Use RubyVM instead. + Tue Jul 1 03:28:16 2008 Eric Hodel <[email protected]> * test/rubygems/test_ext_configure_builder.rb: Apply locale-free @@ -2291,7 +2291,7 @@ compile_cpath(LINK_ANCHOR *ret, rb_iseq_t *iseq, NODE *cpath) } else { /* class at cbase Foo */ - ADD_INSN(ret, nd_line(cpath), putcbase); + ADD_INSN1(ret, nd_line(cpath), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); return Qtrue; } } @@ -3436,7 +3436,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } if (node->nd_vid) { - ADD_INSN (ret, nd_line(node), putcbase); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); ADD_INSN1(ret, nd_line(node), setconstant, ID2SYM(node->nd_vid)); } else { @@ -4227,12 +4227,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) debugp_param("defn/iseq", iseqval); - ADD_INSN (ret, nd_line(node), putnil); - ADD_INSN3(ret, nd_line(node), definemethod, - ID2SYM(node->nd_mid), iseqval, INT2FIX(0)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); + ADD_INSN1(ret, nd_line(node), putobject, ID2SYM(node->nd_mid)); + ADD_INSN1(ret, nd_line(node), putiseq, iseqval); + ADD_SEND (ret, nd_line(node), ID2SYM(id_core_define_method), INT2FIX(3)); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); } + debugp_param("defn", iseqval); break; } @@ -4243,41 +4247,48 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) debugp_param("defs/iseq", iseqval); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); COMPILE(ret, "defs: recv", node->nd_recv); - ADD_INSN3(ret, nd_line(node), definemethod, - ID2SYM(node->nd_mid), iseqval, INT2FIX(1)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); + ADD_INSN1(ret, nd_line(node), putobject, ID2SYM(node->nd_mid)); + ADD_INSN1(ret, nd_line(node), putiseq, iseqval); + ADD_SEND (ret, nd_line(node), ID2SYM(id_core_define_singleton_method), INT2FIX(3)); + + if (poped) { + ADD_INSN(ret, nd_line(node), pop); } break; } case NODE_ALIAS:{ + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); COMPILE(ret, "alias arg1", node->u1.node); COMPILE(ret, "alias arg2", node->u2.node); + ADD_SEND(ret, nd_line(node), ID2SYM(id_core_set_method_alias), INT2FIX(3)); - ADD_INSN1(ret, nd_line(node), alias, Qfalse); - - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); } break; } case NODE_VALIAS:{ + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); ADD_INSN1(ret, nd_line(node), putobject, ID2SYM(node->u1.id)); ADD_INSN1(ret, nd_line(node), putobject, ID2SYM(node->u2.id)); - ADD_INSN1(ret, nd_line(node), alias, Qtrue); + ADD_SEND(ret, nd_line(node), ID2SYM(id_core_set_variable_alias), INT2FIX(2)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); } break; } case NODE_UNDEF:{ + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); + ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_CBASE)); COMPILE(ret, "undef arg", node->u2.node); - ADD_INSN(ret, nd_line(node), undef); + ADD_SEND(ret, nd_line(node), ID2SYM(id_core_undef_method), INT2FIX(2)); - if (!poped) { - ADD_INSN(ret, nd_line(node), putnil); + if (poped) { + ADD_INSN(ret, nd_line(node), pop); } break; } @@ -68,4 +68,10 @@ Init_id(void) idRespond_to = rb_intern("respond_to?"); idInitialize = rb_intern("initialize"); + + id_core_set_method_alias = rb_intern("core_set_method_alias"); + id_core_set_variable_alias = rb_intern("core_set_variable_alias"); + id_core_undef_method = rb_intern("core_undef_method"); + id_core_define_method = rb_intern("core_define_method"); + id_core_define_singleton_method = rb_intern("core_define_singleton_method"); } @@ -52,4 +52,11 @@ extern ID idSend; extern ID id__send__; extern ID idRespond_to; extern ID idInitialize; + +extern ID id_core_set_method_alias; +extern ID id_core_set_variable_alias; +extern ID id_core_undef_method; +extern ID id_core_define_method; +extern ID id_core_define_singleton_method; + #endif /* RUBY_ID_H */ @@ -310,32 +310,56 @@ putself /** @c put - @e put cbase. - @j �X�^�b�N�� cbase ���v�b�V������B + @e put some object. + i.e. Fixnum, true, false, nil, and so on. + @j �I�u�W�F�N�g val ���X�^�b�N�Ƀv�b�V������B + i.e. Fixnum, true, false, nil, and so on. */ DEFINE_INSN -putcbase -() +putobject +(VALUE val) () (VALUE val) { - val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); + /* */ } /** @c put - @e put some object. - i.e. Fixnum, true, false, nil, and so on. - @j �I�u�W�F�N�g val ���X�^�b�N�Ƀv�b�V������B - i.e. Fixnum, true, false, nil, and so on. + @e put special object. "value_type" is for expansion. + @j ���ʂȃI�u�W�F�N�g val ���X�^�b�N�Ƀv�b�V������B + �I�u�W�F�N�g�̎�ނ� value_type �ɂ��D */ DEFINE_INSN -putobject -(VALUE val) +putspecialobject +(rb_num_t value_type) () (VALUE val) { - /* */ + switch (value_type) { + case VM_SPECIAL_OBJECT_VMCORE: + val = rb_mRubyVMFrozenCore; + break; + case VM_SPECIAL_OBJECT_CBASE: + val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); + break; + default: + rb_bug("putspecialobject insn: unknown value_type"); + } +} + +/** + @c put + @e put iseq value. + @j put iseq value. + */ +DEFINE_INSN +putiseq +(ISEQ iseq) +() +(VALUE ret) +{ + ret = iseq->self; } /** @@ -714,57 +738,6 @@ adjuststack /** @c setting - @e define (singleton) method id as body - @j �i���فj���\�b�h id �� body �Ƃ��Ē�`����B - */ -DEFINE_INSN -definemethod -(ID id, ISEQ body, rb_num_t is_singleton) -(VALUE obj) -() -{ - NODE *cref = vm_get_cref(GET_ISEQ(), GET_LFP(), GET_DFP()); - vm_define_method(th, obj, id, body, is_singleton, cref); -} - -/** - @c setting - @e make alias (if v_p is Qtrue, make valias) - @j alias �����B���� v_p �� Qtrue �Ȃ�Avalias (global variable) �����B - */ -DEFINE_INSN -alias -(VALUE v_p) -(VALUE sym1, VALUE sym2) -() -{ - if (v_p == Qtrue) { - rb_alias_variable(SYM2ID(sym1), SYM2ID(sym2)); - } - else { - const VALUE klass = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); - rb_alias(klass, SYM2ID(sym1), SYM2ID(sym2)); - } -} - -/** - @c setting - @e undef - @j undef ���s���B - */ -DEFINE_INSN -undef -() -(VALUE sym) -() -{ - const VALUE klass = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); - rb_undef(klass, SYM2ID(sym)); - INC_VM_STATE_VERSION(); -} - -/** - @c setting @e defined? @j defined? ���s���B */ diff --git a/tool/parse.rb b/tool/parse.rb index bf0bbc30af..6243d7aa8e 100644 --- a/tool/parse.rb +++ b/tool/parse.rb @@ -6,7 +6,7 @@ puts '# ' + '-' * 70 puts $str puts '# ' + '-' * 70 -$parsed = VM::InstructionSequence.compile_file($file) +$parsed = RubyVM::InstructionSequence.compile_file($file) puts "# disasm result: " puts '# ' + '-' * 70 puts $parsed.disasm @@ -24,6 +24,7 @@ VALUE rb_cRubyVM; VALUE rb_cThread; VALUE rb_cEnv; +VALUE rb_mRubyVMFrozenCore; VALUE ruby_vm_global_state_version = 1; rb_thread_t *ruby_current_thread = 0; @@ -1628,6 +1629,46 @@ rb_thread_alloc(VALUE klass) return self; } +static VALUE +m_core_set_method_alias(VALUE self, VALUE cbase, VALUE sym1, VALUE sym2) +{ + rb_alias(cbase, SYM2ID(sym1), SYM2ID(sym2)); + return Qnil; +} + +static VALUE +m_core_set_variable_alias(VALUE self, VALUE sym1, VALUE sym2) +{ + rb_alias_variable(SYM2ID(sym1), SYM2ID(sym2)); + return Qnil; +} + +static VALUE +m_core_undef_method(VALUE self, VALUE cbase, VALUE sym) +{ + rb_undef(cbase, SYM2ID(sym)); + INC_VM_STATE_VERSION(); + return Qnil; +} + +static VALUE +m_core_define_method(VALUE self, VALUE cbase, VALUE sym, VALUE iseqval) +{ + rb_iseq_t *iseq; + GetISeqPtr(iseqval, iseq); + vm_define_method(GET_THREAD(), cbase, SYM2ID(sym), iseq, 0, vm_cref()); + return Qnil; +} + +static VALUE +m_core_define_singleton_method(VALUE self, VALUE cbase, VALUE sym, VALUE iseqval) +{ + rb_iseq_t *iseq; + GetISeqPtr(iseqval, iseq); + vm_define_method(GET_THREAD(), cbase, SYM2ID(sym), iseq, 1, vm_cref()); + return Qnil; +} + VALUE insns_name_array(void); extern VALUE *rb_gc_stack_start; extern size_t rb_gc_stack_maxsize; @@ -1677,7 +1718,16 @@ Init_VM(void) rb_cRubyVM = rb_define_class("RubyVM", rb_cObject); rb_undef_alloc_func(rb_cRubyVM); - /* Env */ + /* ::VM::FrozenCore */ + rb_mRubyVMFrozenCore = rb_define_module_under(rb_cRubyVM, "FrozenCore"); + rb_define_singleton_method(rb_mRubyVMFrozenCore, "core_set_method_alias", m_core_set_method_alias, 3); + rb_define_singleton_method(rb_mRubyVMFrozenCore, "core_set_variable_alias", m_core_set_variable_alias, 2); + rb_define_singleton_method(rb_mRubyVMFrozenCore, "core_undef_method", m_core_undef_method, 2); + rb_define_singleton_method(rb_mRubyVMFrozenCore, "core_define_method", m_core_define_method, 3); + rb_define_singleton_method(rb_mRubyVMFrozenCore, "core_define_singleton_method", m_core_define_singleton_method, 3); + rb_obj_freeze(rb_mRubyVMFrozenCore); + + /* ::VM::Env */ rb_cEnv = rb_define_class_under(rb_cRubyVM, "Env", rb_cObject); rb_undef_alloc_func(rb_cEnv); @@ -505,6 +505,7 @@ const char *ruby_node_name(int node); RUBY_EXTERN VALUE rb_cISeq; RUBY_EXTERN VALUE rb_cRubyVM; RUBY_EXTERN VALUE rb_cEnv; +RUBY_EXTERN VALUE rb_mRubyVMFrozenCore; /* each thread has this size stack : 128KB */ #define RUBY_VM_THREAD_STACK_SIZE (128 * 1024) @@ -556,6 +557,9 @@ typedef struct { #define VM_CALL_SUPER_BIT (0x01 << 7) #define VM_CALL_SEND_BIT (0x01 << 8) +#define VM_SPECIAL_OBJECT_VMCORE 0x01 +#define VM_SPECIAL_OBJECT_CBASE 0x02 + #define VM_FRAME_MAGIC_METHOD 0x11 #define VM_FRAME_MAGIC_BLOCK 0x21 #define VM_FRAME_MAGIC_CLASS 0x31 |