Jason Gloudon <[EMAIL PROTECTED]> writes: [i distincly remember sending this email, but it's not in the web archive or in my gnus archive, so i'm sending it again, pardon me if you've already seen this]
> On Thu, Apr 18, 2002 at 01:49:20PM +0200, Marco Baringer wrote: > > > in trying to make goto ADDRESS($1) work as it should i have come > > across the following doubt: > > How are you interpreting that it "should" work ? I don't know of any > documentation that says what it should do, but currently it is only used to > support the enternative op, which allows programs generated by pbc2c.pl to > combine the execution of ops that have been compiled to native code via C with > the normal interpreted execution. interesting, while making goto ADDRESS() do what i thought it should i couldn't understand why enternative stopped working :) > So thus far, goto ADDRESS(X) means set the program counter to the pointer value > X. ok, but i find this highly counter-intuitive. > > out of core_ops.c, core_ops_cg.c and core_ops_prederef.c which one is > > parrot using? and how do i change it if i want? i notice while > > Just in case you missed it: You should not edit those files, since they are all > generated from core.ops by the various ops2*.pl scripts. > > core_ops_cg is used if your compiler is a version of gcc that supports computed > goto, core_ops.c otherwise. If you are trying to change what goto ADDRESS() > does you potentially have to modify all of the OpTrans modules under > parrot/lib/Parrot/OpTrans in the end i was using core_ops_cg.c. i would mess with the generated ..c files when i wanted to see what would happen if i meddled with cur_opcode, this is hard to do from core.ops :) btw: if anybody out there wants to get a good grasp on how parrot works i suggest you mess with these generated files and use gdb to step through a run of parrot, i found it extremly enlightening. > > p.s. - i think the problem is related to directly setting cur_opcode > > to interpreter->int_reg.registers[cur_opcode[1]] and not something > > like interpreter->code->byte_code + $1, could this be? > > Ok, so you expect goto ADDRESS(X) to jump to the opcode at address X, relative > to the start of the byte code. > > It probably makes sense to rename the current ADDRESS() to something like > OPPOINTER() or a name that gives a better idea of what it does and to document > all the address expressions while 'fixing' ADDRESS. i am attaching a patch to Parrot::OpTrans::CGoto which makes goto ADDRESS(X) jump to the offset X relative to the start of the byte_code (in other words interpreter->code->byte_code + X). given this "new" interpretation of goto ADDRESS() i have found a reason to have jump and jsr :) jump is like branch, but uses goto ADDRESS() as opposed to goto OFFSET(), jsr is like bsr but uses goto ADDRESS() as opposed to goto OFFSET(). relative to this modification of core.ops i have added a test to t/ops/basic.t to test jsr and modified the test of jump since its semantics have changed. i also modified Parrot::Assembler: when label arithmetic involed a label whose name contained digits the label name got mangled. note: this breaks enternative, i'll add goto ABS_ADDRESS() or goto OPPOINTER() tomorow or the day after, which should allow me to fix the bug i'm introducing :) -- -Marco Ring the bells that still can ring. Forget the perfect offering. There's a crack in everything. It's how the light gets in. -Isonard Cohen p.s. - i'm pasting all of the patches into the mail because i'm worried my mailer will mess up again and lose all the text, sorry for the mess. Index: core.ops =================================================================== RCS file: /cvs/public/parrot/core.ops,v retrieving revision 1.123 diff -u -r1.123 core.ops --- core.ops 17 Apr 2002 20:58:18 -0000 1.123 +++ core.ops 18 Apr 2002 20:57:53 -0000 @@ -2601,8 +2601,8 @@ =item B<bsr>(in INT) -Branch to the location specified by $1. Push the current location onto the call -stack for later returning. +Branch forward or backward by the amount in $1. Push the current +location onto the call stack for later returning. =cut @@ -2614,26 +2614,31 @@ ######################################## -=item B<jsr>() +=item B<jsr>(in INT) -Jump to the location specified by register X. Push the current -location onto the call stack for later returning. +Jump to the address held in register $1. Push the current location +onto the call stack for later returning. TODO: Implement this, or delete the entry. +inline op jsr (in INT) { + stack_push(interpreter, interpreter->control_stack, expr NEXT(), +STACK_ENTRY_DESTINATION, STACK_CLEANUP_NULL); + goto ADDRESS($1); +} + =cut ######################################## -=item B<jump>(out INT) +=item B<jump>(in INT) Jump to the address held in register $1. =cut -inline op jump(out INT) { - goto OFFSET($1); +inline op jump(in INT) { + goto ADDRESS($1); } =back @@ -2821,7 +2826,8 @@ } op enternative() { - goto ADDRESS(( run_native(interpreter, CUR_OPCODE, interpreter->code->byte_code) )); + /* XXX: this is REALLY REALLY bad */ + /*goto ADDRESS(( run_native(interpreter, CUR_OPCODE, interpreter->code->byte_code) +));*/ } ######################################## Index: lib/Parrot/OpTrans/CGoto.pm =================================================================== RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/CGoto.pm,v retrieving revision 1.7 diff -u -r1.7 CGoto.pm --- lib/Parrot/OpTrans/CGoto.pm 30 Mar 2002 19:02:30 -0000 1.7 +++ lib/Parrot/OpTrans/CGoto.pm 18 Apr 2002 20:54:07 -0000 @@ -78,8 +78,8 @@ #print STDERR "pbcc: map_ret_abs($addr)\n"; if ($addr eq '0') { return "return (0);" - } else { - return "goto *ops_addr[*(cur_opcode = $addr)]"; + } else { + return "goto *ops_addr[*(cur_opcode = interpreter->code->byte_code + $addr)]"; } } Index: t/op/basic.t =================================================================== RCS file: /cvs/public/parrot/t/op/basic.t,v retrieving revision 1.5 diff -u -r1.5 basic.t --- t/op/basic.t 12 Dec 2001 04:27:21 -0000 1.5 +++ t/op/basic.t 18 Apr 2002 20:55:22 -0000 @@ -1,6 +1,6 @@ #! perl -w -use Parrot::Test tests => 8; +use Parrot::Test tests => 9; # It would be very embarrassing if these didn't work... output_is(<<'CODE', '', "noop, end"); @@ -38,37 +38,34 @@ CODE output_is( <<'CODE', <<OUTPUT, "jump" ); -neg macro R - set I0, R - set R, 0 - sub R, R, I0 -endm - -call macro R, D - set R, [D - @ - 3] - jump R -endm - -return macro R, D - neg R - inc R, [D - @ - 1] - jump R -endm - -MAIN: set I1, 42 - call I31, PRINTIT - set I1, 1234 - call I31, PRINTIT + print "42\n" + jump [SKIP] + print "you can't see me\n" +SKIP: print "1234\n" end - -PRINTIT: print I1 - print "\n" - return I31, PRINTIT CODE 42 1234 OUTPUT +output_is( <<'CODE', <<OUTPUT, "jsr"); + set I0, [CALLIT] + save [PRINT_FOUR] + jsr I0 + end + +CALLIT: # call whatever is on the stack + restore I0 + jsr I0 + ret +PRINT_FOUR: + print "4" + print "\n" + ret +CODE +4 +OUTPUT + output_is(<<'CODE', <<'OUTPUT', "bsr_i"); print "start\n" @@ -85,4 +82,4 @@ done OUTPUT -1; # HONK \ No newline at end of file +1; # HONK Index: lib/Parrot/Assembler.pm =================================================================== RCS file: /cvs/public/parrot/lib/Parrot/Assembler.pm,v retrieving revision 1.20 diff -u -r1.20 Assembler.pm --- lib/Parrot/Assembler.pm 10 Mar 2002 21:15:50 -0000 1.20 +++ lib/Parrot/Assembler.pm 18 Apr 2002 20:58:57 -0000 @@ -752,11 +752,11 @@ ############################################################################### -=head2 handle_label +=head2 handle_pragma -This function handles a label definition by storing the PC where the label was -found and backpatching all previous instances of that label with the correct -offset. This function handles both local labels and global labels. +This function handles an assembler pragma. Currently only the sub +pragma is considered and it is simply trasnformed into a label of the +same name =cut @@ -1160,7 +1160,7 @@ if ($args[$_] =~ m/^\[(.*)\]$/) { my $mult = sizeof('op'); - $args[$_] =~ s/(\d+)/$mult * $1/eg; # Hard-coded opcode_t offsets ---> byte offsets + $args[$_] =~ s/\b(\d+)\b/$mult * $1/eg; # Hard-coded opcode_t +offsets ---> byte offsets $args[$_] =~ s/[\@]/$op_pc/; # Map '@' to $op_pc push @{$fixup{$args[$_]}}, $pc; @@ -1198,7 +1198,7 @@ push( @{ $fixup{ $args[$_] } }, $op_pc, $pc); $args[$_] = 0xffffffff; } - else { + else { $args[$_] = constantize_integer( ($label{$args[$_]}-$op_pc)/sizeof('op') ); } }