Leo clarified this as a problem with backward branch circa 3/12/03:
Sorry to be a pain in the butt, but I need to be told that there has been no improvement in the last two months on this ;-(
..sub _main goto L1 test: $I1 = 1 ret L1: $I2 = 2 call test print $I2 # prints 1, not 2 end ..end
Surely it can't just be me that thinks this is rather fundamental? How fundamental *is* the problem, can it *ever* be fixed?
Again, sorry to be a pain, but I'd like the truth/an update, please! Or some hints... file level variables... better ways to code this...
Pete PS use parrot -o and examine the output .pasm:, $I1 and $I2 (or ..local int i, .local int j) get assigned the same register.
Not sure if this answers your question. At the bottom of this email there is a bit taken from the IMCC.faq, I have pointed to the bit that I think may tell us what has happened. When the above piece of code gets converted to pasm we get
1 _main: 2 branch L1 3 test: 4 set I16, 1 5 ret 6 L1: 7 set I16, 2 8 bsr test 9 print I16 10 end 11 12
This is a branch not a subroutine call so IMCC as per the spec does not take care of the scoping in this case.
To code it using subs we could use
1 .sub _main prototyped 2 .sym Sub connect 3 newsub connect, .Sub, _connect 4 5 $I1 = 2 6 .pcc_begin prototyped 7 .pcc_call connect 8 retconnect: 9 .pcc_end 10 print $I1 11 end 12 .end 13 14 .sub _connect 15 $I1 = 1 16 print $I1 17 .pcc_begin_return 18 .pcc_end_return 19 .end
This prints
12
as expected.
Harry
Taken from the IMCC.faq
What are IMC variables?
IMC has 2 classes of variables, symbolic registers and named variables. Both are mapped to real registers, but there are a few minor differences. Named variables must be declared. They may be global or local, and may be qualified by a namespace. Symbolic registers, on the other hand, do not need declaration,
----->but their scope never extends outside of a subroutine unit.
Symbolics registers basically give compiler front ends an easy way to generate code from their parse trees or AST. To generate expressions compilers have to create temporaries.
Symbolic Registers (or Temporaries)
Symbolic registers have a $ sign for the first character, have single letter (S,N,I,P) for the second character, and 1 or more digits for the rest. By the 2nd character IMCC determines which set of Parrot registers it belongs to.