* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17755 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2008-07-01 03:05:58 +00:00
Родитель 5c8ab4d9c2
Коммит eb33f91cb7
8 изменённых файлов: 150 добавлений и 88 удалений

Просмотреть файл

@ -1,3 +1,14 @@
Tue Jul 1 12:01:16 2008 Koichi Sasada <ko1@atdot.net>
* 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 <drbrain@segment7.net>
* 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;
}

6
id.c
Просмотреть файл

@ -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");
}

7
id.h
Просмотреть файл

@ -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 */

103
insns.def
Просмотреть файл

@ -308,20 +308,6 @@ putself
val = GET_SELF();
}
/**
@c put
@e put cbase.
@j cbase
*/
DEFINE_INSN
putcbase
()
()
(VALUE val)
{
val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP());
}
/**
@c put
@e put some object.
@ -338,6 +324,44 @@ putobject
/* */
}
/**
@c put
@e put special object. "value_type" is for expansion.
@j val
value_type
*/
DEFINE_INSN
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;
}
/**
@c put
@e put string val. string will be copied.
@ -712,57 +736,6 @@ adjuststack
/* deal with setting */
/**********************************************************/
/**
@c setting
@e define (singleton) method id as body
@j id body
*/
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 v_p Qtrue valias (global variable)
*/
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
*/
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?

Просмотреть файл

@ -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

52
vm.c
Просмотреть файл

@ -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