Currently, instead of pushing the contents of fixed registers onto the 
stack, the registers themselves float on top of the stack.  That doesn't 
preserve register contents on a push_x, as the registers are now in a new 
memory location.  After toying with fixed registers per interpreter, I 
decided that it probably wasn't worth it in the long haul.  (Since it's 
doubtful, given the size of our register sets, that this would need to be 
done often.)  Instead, I'm proposing a parallel set of data-preserving 
push_x ops, save_x.  Patch after .sig.

-- 
Bryan C. Warnock
[EMAIL PROTECTED]


Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.33
diff -u -r1.33 basic_opcodes.ops
--- basic_opcodes.ops   2001/10/07 15:27:42     1.33
+++ basic_opcodes.ops   2001/10/08 14:52:17
@@ -383,6 +383,26 @@
   Parrot_push_p(interpreter);
 }
 
+/* SAVE_I */
+AUTO_OP save_i {
+  Parrot_save_i(interpreter);
+}
+
+/* SAVE_N */
+AUTO_OP save_n {
+  Parrot_save_n(interpreter);
+}
+
+/* SAVE_S */
+AUTO_OP save_s {
+  Parrot_save_s(interpreter);
+}
+
+/* SAVE_P */
+AUTO_OP save_p {
+  Parrot_save_p(interpreter);
+}
+
 /* POP_I */
 AUTO_OP pop_i {
   Parrot_pop_i(interpreter);
Index: opcheck.pl
===================================================================
RCS file: /home/perlcvs/parrot/opcheck.pl,v
retrieving revision 1.1
diff -u -r1.1 opcheck.pl
--- opcheck.pl  2001/09/17 12:29:41     1.1
+++ opcheck.pl  2001/10/08 14:52:17
@@ -66,6 +66,11 @@
   push_n => 1,
   push_p => 1,
   push_s => 1,
+
+  save_i => 1,
+  save_n => 1,
+  save_p => 1,
+  save_s => 1,
 );
 
 my $error_count;
Index: opcode_table
===================================================================
RCS file: /home/perlcvs/parrot/opcode_table,v
retrieving revision 1.23
diff -u -r1.23 opcode_table
--- opcode_table        2001/10/07 15:27:42     1.23
+++ opcode_table        2001/10/08 14:52:18
@@ -120,6 +120,10 @@
 push_s 0
 push_n 0
 push_p 0
+save_i 0
+save_s 0
+save_n 0
+save_p 0
 pop_i  0
 pop_s  0
 pop_n  0
Index: register.c
===================================================================
RCS file: /home/perlcvs/parrot/register.c,v
retrieving revision 1.10
diff -u -r1.10 register.c
--- register.c  2001/10/02 14:01:30     1.10
+++ register.c  2001/10/08 14:52:18
@@ -38,6 +38,21 @@
     }
 }
 
+/*=for api register Parrot_save_i
+  pushes a new integer register frame on the frame stack,
+  'preserving' the register contents.
+*/
+void
+Parrot_save_i(struct Parrot_Interp *interpreter) {
+    INTVAL *current_set = interpreter->int_reg->registers;
+    
+    Parrot_push_i(interpreter);
+    
+    mem_sys_memcopy(interpreter->int_reg->registers, current_set,
+                    sizeof(INTVAL) * NUM_REGISTERS);
+    
+}
+
 /*=for api register Parrot_pop_i
   pops an integer register frame off of the frame stack
 */
@@ -107,6 +122,21 @@
     }
 }
 
+/*=for api register Parrot_save_s
+  pushes a new integer register frame on the frame stack,
+  'preserving' the register contents.
+*/
+void
+Parrot_save_s(struct Parrot_Interp *interpreter) {
+    STRING **current_set = interpreter->string_reg->registers;
+    
+    Parrot_push_s(interpreter);
+    
+    mem_sys_memcopy(interpreter->string_reg->registers, current_set,
+                    sizeof(STRING *) * NUM_REGISTERS);
+    
+}
+
 /*=for api register Parrot_pop_s
   pops a string register frame off of the frame stack
 */
@@ -173,6 +203,21 @@
     }
 }
 
+/*=for api register Parrot_save_n
+  pushes a new integer register frame on the frame stack,
+  'preserving' the register contents.
+*/
+void
+Parrot_save_n(struct Parrot_Interp *interpreter) {
+    FLOATVAL *current_set = interpreter->num_reg->registers;
+    
+    Parrot_push_n(interpreter);
+    
+    mem_sys_memcopy(interpreter->num_reg->registers, current_set,
+                    sizeof(FLOATVAL) * NUM_REGISTERS);
+    
+}
+
 /*=for api register Parrot_pop_n
   pops a numeric register frame off of the frame stack
 */
@@ -241,6 +286,20 @@
     }
 }
 
+/*=for api register Parrot_save_p
+  pushes a new integer register frame on the frame stack,
+  'preserving' the register contents.
+*/
+void
+Parrot_save_p(struct Parrot_Interp *interpreter) {
+    PMC **current_set = interpreter->pmc_reg->registers;
+    
+    Parrot_push_p(interpreter);
+    
+    mem_sys_memcopy(interpreter->pmc_reg->registers, current_set,
+                    sizeof(PMC *) * NUM_REGISTERS);
+    
+}
 /*=for api register Parrot_pop_p
   pops a pmc register frame off of the frame stack
 */
Index: include/parrot/register.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/register.h,v
retrieving revision 1.6
diff -u -r1.6 register.h
--- include/parrot/register.h   2001/10/06 01:04:47     1.6
+++ include/parrot/register.h   2001/10/08 14:52:19
@@ -77,6 +77,11 @@
 void Parrot_push_s(struct Parrot_Interp *);
 void Parrot_push_p(struct Parrot_Interp *);
 
+void Parrot_save_i(struct Parrot_Interp *);
+void Parrot_save_n(struct Parrot_Interp *);
+void Parrot_save_s(struct Parrot_Interp *);
+void Parrot_save_p(struct Parrot_Interp *);
+
 void Parrot_pop_i(struct Parrot_Interp *);
 void Parrot_pop_n(struct Parrot_Interp *);
 void Parrot_pop_s(struct Parrot_Interp *);
Index: t/op/stacks.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/stacks.t,v
retrieving revision 1.2
diff -u -r1.2 stacks.t
--- t/op/stacks.t       2001/09/26 18:13:50     1.2
+++ t/op/stacks.t       2001/10/08 14:52:19
@@ -10,15 +10,25 @@
 
 use Parrot::Test tests => 9;
 
-output_is( <<"CODE", <<'OUTPUT', "push_i & pop_i" );
+output_is( <<"CODE", <<'OUTPUT', "push_i, save_i, & pop_i" );
 @{[ set_int_regs( sub { $_[0]} )]}
        push_i
 @{[ set_int_regs( sub {-$_[0]} )]}
 @{[ print_int_regs() ]}
+    save_i
+@{[ print_int_regs() ]}    
        pop_i
+    pop_i
 @{[ print_int_regs() ]}
        end
 CODE
+0-1-2-3-4
+-5-6-7-8-9
+-10-11-12-13-14
+-15-16-17-18-19
+-20-21-22-23-24
+-25-26-27-28-29
+-30-31
 0-1-2-3-4
 -5-6-7-8-9
 -10-11-12-13-14

Reply via email to