yarv-dev-en:214
From: SASADA Koichi <ko1 atdot.net>
Date: Wed, 25 Oct 2006 21:35:45 +0900
Subject: [yarv-dev-en:214] Re: Questions about instruction set
Hi, Thank you! There are no person who read YARV in detail :) I'm very glad to describe YARV internal. 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. > 2. I see that getdynamic/setdynamic take idx and level. I assume this > means that in YARV block variable scoping is determined statically. We > have planned to make this change in JRuby as well. Am I correct about > how this works? Yes. > 3. If I am correct in #2, Is the level zero-based? Is the first > (topmost) block index zero, and the first nested block inside it index 1? Yes. > 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. > 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. > 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. > 7. putobject pushes an object on the stack, correct? Is pushstring just > doing the same thing with a string value? What's the difference between > putobject with a string val and putstring with a string val? putstring insn duplicate value. Try it: # putstring loop{ obj = "" break if obj.respond_to? :foo def obj.foo; end p :continue } p :exit ---- # putobject // loop{ obj = // break if obj.respond_to? :foo def obj.foo; end p :continue } p :exit > 8. I assume concatstrings concatenates the topmost "num" strings from > the stack and pushes the result back. Is the topmost string the base > (leftmost) string for concatenation? I.e. does the first string popped > sit at the front of the resulting string? Try it: a = b = c = 'xyz' puts "#{a}#{b}#{c}", a > 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. > 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. > 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. > 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 > 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. > 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? -- // SASADA Koichi at atdot dot net -- 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 ]