In the Ruby C source code, where is the Ruby `=` operator?

I would like to read the logical code = , but I can not find it.

UPDATE:

I found the text of the test_multi method text / ruby ​​/test_assignment.rb. This is Ruby code, but it looks like I will get to the destination.

The reason I want to test the code is because it handles multitasking. Like a,b,c = [1,2,3] .

UPDATE:

I found the keywords "MASGN" and led me to

compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped) in the compile.c file

http://github.com/ruby/ruby/commit/e39eb9dab50eaa681467e51145b37cdc11667830#diff-2

+4
source share
3 answers

I do not know what you mean by "C Ruby source code." Ruby is a programming language. Programming languages ​​do not have source code (only for compilers and interpreters), they have specifications.

The multiple assignment specification is given in clause 11.3.1.3. Several assignments on pages 59 and 62 of the current (2009-12-01) ISO Ruby Draft Specification and language/variables_spec.rb (search for "several", unfortunately, the tests are a little scattered across the file) into the RubySpec executable.

A good overview of the possible implementation can be found in the Rubinius compiler (sorry, there is no C source code here) on lines 482 - 607 of lib/compiler/ast/variables.rb .

+1
source

I do not think you will find the code for = .

= will be part of the grammar rules that define the Ruby language, and the parser (written in C) will use the grammar.

+2
source

http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_2/parse.y line 1088-1116

 | var_lhs tOP_ASGN command_call { /*%%%*/ value_expr($3); if ($1) { ID vid = $1->nd_vid; if ($2 == tOROP) { $1->nd_value = $3; $$ = NEW_OP_ASGN_OR(gettable(vid), $1); if (is_asgn_or_id(vid)) { $$->nd_aid = vid; } } else if ($2 == tANDOP) { $1->nd_value = $3; $$ = NEW_OP_ASGN_AND(gettable(vid), $1); } else { $$ = $1; $$->nd_value = NEW_CALL(gettable(vid), $2, NEW_LIST($3)); } } else { $$ = NEW_BEGIN(0); } /*% $$ = dispatch3(opassign, $1, $2, $3); %*/ } 
+1
source

All Articles