yarv-dev-en:221
From: Charles Oliver Nutter <charles.nutter sun.com>
Date: Wed, 25 Oct 2006 22:05:27 -0500
Subject: [yarv-dev-en:221] Re: Questions about instruction set
SASADA Koichi wrote: > Charles Oliver Nutter wrote: >> 1. What do getspecial/setspecial manipulate in the VM? I understand the >> other get/set instructions. > > to access $_, $~, and other variables. In current Ruby prepare > variables for $_ and $~ each stack frame. But most of method invocation > doesn't need it. So $_ or $~ variable are created on demand. Ok, I understand. This is a good optimization to make those variables optional; I have considered the same change in JRuby. >> 4. What is the declp operand to setclassvariable? > > Ah, it is obsolete variable. rb_cvar_set C API need it, but not affect > any behavior. How does the new getclassvariable/setclassvariable determine the class in which to look? Does it only look in the "current" class or the class of "self"? >> 5. I see putnil and putself. Why no puttrue, putfalse, as in the 1.8 AST? > > "puttrue" => "putobject true" > "putfalse" => "putobject false" > > putself can not be represented by "putobject ??". > And putnil can be represented by "putobject nil", but many times this > patterns are occurred (in compiler). So I prepare it. > > Motivation of this decision is to small VM as possible as I can. And > puttrue and putfalse can be made by operand unification optimization. Ok, I think this is a reasonable change. I will probably try to port your compiler, so it should work fine. >> 6. putundef takes no operands and returns a val; what does it do, and >> what is it returning? > > putundef return Qundef. This instruction is made for block inlining, > but I think it is bad idea. So I will remove it. Ok, I understand. We have something similar for method inlining...the concept of an "UndefinedMethod". I agree it could be removed. >> 9. Shouldn't duparray take an array from the top of the stack and push >> it and a copy back down? Online it looks like it takes an array operand, >> which seems odd. > > Ah, I see. This instruction means "putarray" (like "putstring"). This > instruction works like putstring. Maybe name should change? I understand now. >> 10. What is the difference between expandarray and splatarray? Is >> expandarray equivalent to multi-assignment in 1.8? Does num specify the >> number of values to multi-assign? What is flag for? > > This is because ruby's strange massign behavior :) > > And I can't describe now enough ^^; Too complicated. If you can > eliminate something around this, please teach me. You are right, massign is complicated. I understand how expandarray implements massign in the simple case (num specifies the number of args it is assigning to), but I'm not sure what flag is. >> 11. I assume concatarray and checkincludearray are for internal use and >> not used directly as the implementation of Array#include? and Array#<< >> or concat, correct? > > Almost same. But Array#include? can be replaced. So these are used for manipulating internal arrays, such as those used for passing arguments, etc. They can also provide the base implementation of Array methods, though at least include? can be replaced. I think I understand. >> 12. newhash pulls keys/values off the stack. What is the sequence of >> keys and values? > > You can check with YARV easily: > > 1. write some program to "yarvsrc/test.rb" > 2. do "make parse" on build directory > 3. you can see disassembled result > > > For example, "p({:a=>:b, :c=>:d})" program is disassembled as followed. > > == disasm: <ISeq:<main> c:/ko1/src/rubyext/trunk/test.rb>=============== > local scope table (size: 1, argc: 0) > > 0000 putself (1) > 0001 putobject :a > 0003 putobject :b > 0005 putobject :c > 0007 putobject :d > 0009 newhash 4 > 0011 send :p, 1, nil, 4, <ic> > 0017 leave Ok, easy. I will get YARV built and working for future questions like this. Perhaps there is a wiki I could update in English for English speakers interested in the same information? >> 13. When the "stack" column on the YARV instruction table lists multiple >> elements, is the top of the stack on the left or right? > > I can't understand what is your question, but you can check translated C > code in builddirectory/vm.inc. I think that makes you clear than my > poor English. I will look at the code and compiled bytecodes, thank you. >> 14. Is there a specification for the format of a compiled YARV script? I >> would like to start generating some test scripts and building a machine >> to execute them. > > What format? YARVCore::InstructionSequence.compile or compile_file > methods help you? Yes, they will help me...I will look at them. If there is a wiki somewhere, I can also write entries on compiled file format. Do you have a binary specification written down anywhere yet? -- Charles Oliver Nutter, JRuby Core Developer headius headius.com -- charles.nutter sun.com Blogging at headius.blogspot.com -- ML: yarv-dev-en quickml.atdot.net Info: http://www.atdot.net/~ko1/quickml
213 2006-10-25 20:35 [charles.nutter sun.c] Questions about instruction set 214 2006-10-25 21:35 ┗[ko1 atdot.net ] -> 221 2006-10-26 12:05 ┗[charles.nutter sun.c] 225 2006-10-26 18:02 ┗[ko1 atdot.net ]