It seems odd to have the chopn_s_ic and not a chopn_s_i op, this
patch adds this, and simillar ops (+ tests!) for shr and shl.
I don't know if these count as new features or not...
Also, string_chopn was not checking for OOB values for n, this is fixed
and the (currenlty skipped) jump test in basic.t expected the wrong output.

Alex Gough
-- 
History teaches us that men and nations behave wisely
once they have exhausted all other alternatives.

######

diff -urN clean/parrot/basic_opcodes.ops parrot/basic_opcodes.ops
--- clean/parrot/basic_opcodes.ops      Wed Sep 26 20:00:00 2001
+++ parrot/basic_opcodes.ops    Sat Sep 29 13:20:25 2001
@@ -452,6 +452,11 @@
    string_chopn(STR_REG(P1), P2);
 }
 
+/* CHOPN Sx, Ix */
+AUTO_OP chopn_s_i {
+   string_chopn(STR_REG(P1), INT_REG(P2));
+}
+
 /* SUBSTR Sx, Sx, Ix, Ix */
 AUTO_OP substr_s_s_i {
     STRING *s = string_substr(STR_REG(P2), INT_REG(P3), INT_REG(P4), &STR_REG(P1));
@@ -690,9 +695,19 @@
   INT_REG(P1) = INT_REG(P2) << P3;
 }
 
+/* SHL_i_i */
+AUTO_OP shl_i_i {
+  INT_REG(P1) = INT_REG(P2) << INT_REG(P3);
+}
+
 /* SHR_i_ic */
 AUTO_OP shr_i_ic {
   INT_REG(P1) = INT_REG(P2) >> P3;
+}
+
+/* SHR_i_i */
+AUTO_OP shr_i_i {
+  INT_REG(P1) = INT_REG(P2) >> INT_REG(P3);
 }
 
 /* XOR_i */
diff -urN clean/parrot/opcode_table parrot/opcode_table
--- clean/parrot/opcode_table   Mon Sep 24 20:00:01 2001
+++ parrot/opcode_table Sat Sep 29 13:22:17 2001
@@ -61,6 +61,7 @@
 print_sc       1       s
 length_i_s     2       I S
 chopn_s_ic     2       S i
+chopn_s_i      2       S I
 substr_s_s_i   4       S S I I
 concat_s       2       S S
 
@@ -178,6 +179,8 @@
 not_i  2       I I
 or_i   3       I I I
 shl_i_ic       3       I I i
+shl_i_i        3       I I I
 shr_i_ic       3       I I i
+shr_i_i        3       I I I
 xor_i  3       I I I
 
diff -urN clean/parrot/string.c parrot/string.c
--- clean/parrot/string.c       Mon Sep 24 20:00:01 2001
+++ parrot/string.c     Sat Sep 29 12:54:31 2001
@@ -143,6 +143,7 @@
     if (n > s->strlen) {
         n = s->strlen;
     }
+    if (n < 0) n = 0;
     return (ENC_VTABLE(s)->chopn)(s, n);
 }
 
diff -urN clean/parrot/t/op/basic.t parrot/t/op/basic.t
--- clean/parrot/t/op/basic.t   Tue Sep 25 14:00:01 2001
+++ parrot/t/op/basic.t Sat Sep 29 12:45:35 2001
@@ -29,7 +29,7 @@
 
 SKIP: {
     skip( "label constants unimplemented in assembler", 1 );
-output_is( <<'CODE', <<OUTPUT, "jump" );
+output_is( <<'CODE', '42', "jump" );
        set     I4, 42
        set     I5, HERE
        jump    I5
@@ -38,6 +38,4 @@
        print   I4
        end
 CODE
-I reg 4 is 42
-OUTPUT
 }
diff -urN clean/parrot/t/op/bitwise.t parrot/t/op/bitwise.t
--- clean/parrot/t/op/bitwise.t Wed Sep 26 08:00:01 2001
+++ parrot/t/op/bitwise.t       Sat Sep 29 13:23:24 2001
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 5;
 
 output_is(<<'CODE', <<'OUTPUT', "shr_i_ic (>>)");
        set     I0, 0b001100
@@ -20,6 +20,26 @@
 12
 OUTPUT
 
+output_is(<<'CODE', <<'OUTPUT', "shr_i_i (>>)");
+       set     I0, 0b001100
+       set     I1, 0b010100
+       set     I4, 1
+       set     I5, 2
+       shr     I2, I0, I4
+       shr     I1, I1, I5
+       print   I2
+       print   "\n"
+       print   I1
+       print   "\n"
+       print   I0
+       print   "\n"
+       end
+CODE
+6
+5
+12
+OUTPUT
+
 output_is(<<'CODE', <<'OUTPUT', "xor_i");
        set     I0, 0b001100
        set     I1, 0b100110
@@ -78,3 +98,6 @@
 12
 OUTPUT
 1;
+
+
+
diff -urN clean/parrot/t/op/string.t parrot/t/op/string.t
--- clean/parrot/t/op/string.t  Tue Sep 25 14:00:02 2001
+++ parrot/t/op/string.t        Sat Sep 29 13:24:27 2001
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 10;
+use Parrot::Test tests => 13;
 
 output_is( <<'CODE', <<OUTPUT, "set_s_sc" );
        set     S4, "JAPH\n"
@@ -10,11 +10,15 @@
 JAPH
 OUTPUT
 
-output_is( <<'CODE', '4', "length_i_s" );
+output_is( <<'CODE', '40', "length_i_s" );
        set     I4, 0
+       set     I5, 1
        set     S4, "JAPH"
+       set     S5, ""
        length  I4, S4
+       length  I5, S5
        print   I4
+       print   I5
        end
 CODE
 
@@ -33,6 +37,51 @@
 CODE
 JAPH
 japh
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "chop_s_ic - len>len(s)");
+       set     S0, "String of length 19"
+       print   S0
+       chopn   S0, 99
+       print   S0
+       print   "\n"
+       end
+CODE
+String of length 19
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "chop_s_i");
+       set     S0, "String of length 19"
+       set     I0, 10
+       chopn   S0, I0
+       print   S0
+       print   "\n"
+       set     I0, -1
+       chopn   S0, I0
+       print   S0
+       print   "\n"
+       set     I0, 99
+       chopn   S0, I0
+       print   S0
+       print   "\n"
+       end
+CODE
+String of
+String of
+
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "chop_s_ic - -ve len");
+       set     S0, "String of length 19"
+       print   S0
+       print   "\n"
+       chopn   S0, -1
+       print   S0
+       print   "\n"
+       end
+CODE
+String of length 19
+String of length 19
 OUTPUT
 
 output_is( <<'CODE', 'JAPH', "substr_s_s_i_i" );








Reply via email to