Parrot seems to be missing the bitwise-not for strings. Attached patch adds a
string_bitwise_not function, bitwise_nots vtable, and "bnots" ops.
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html
? config_lib.pasm
? examples/tetris
? examples/sdl/tetris
? examples/sdl/tetris.imc
? library/config.fpmc
? library/sdl.imc
Index: vtable.tbl
===================================================================
RCS file: /cvs/public/parrot/vtable.tbl,v
retrieving revision 1.54
diff -u -d -r1.54 vtable.tbl
--- vtable.tbl 14 Jan 2004 13:10:18 -0000 1.54
+++ vtable.tbl 23 Mar 2004 01:14:25 -0000
@@ -193,6 +193,8 @@
void bitwise_not(PMC* dest)
+void bitwise_nots(PMC* dest)
+
void bitwise_shl(PMC* value, PMC* dest)
void bitwise_shl_int(INTVAL value, PMC* dest)
Index: classes/perlstring.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/perlstring.pmc,v
retrieving revision 1.65
diff -u -d -r1.65 perlstring.pmc
--- classes/perlstring.pmc 6 Mar 2004 08:43:52 -0000 1.65
+++ classes/perlstring.pmc 23 Mar 2004 01:14:25 -0000
@@ -463,6 +463,22 @@
/*
+=item C<void bitwise_nots(PMC *dest)>
+
+Calculates the string bitwise C<NOT> for the string and returns the result
+in C<*dest>.
+
+=cut
+
+*/
+
+ void bitwise_nots (PMC* dest) {
+ VTABLE_set_string_native(INTERP, dest,
+ string_bitwise_not(interpreter, PMC_str_val(SELF), NULL));
+ }
+
+/*
+
=item C<void concatenate(PMC *value, PMC *dest)>
Concatenates the string and the stringified form of C<*value> and
Index: include/parrot/string_funcs.h
===================================================================
RCS file: /cvs/public/parrot/include/parrot/string_funcs.h,v
retrieving revision 1.34
diff -u -d -r1.34 string_funcs.h
--- include/parrot/string_funcs.h 12 Feb 2004 18:42:56 -0000 1.34
+++ include/parrot/string_funcs.h 23 Mar 2004 01:14:26 -0000
@@ -70,6 +70,8 @@
STRING *s2, STRING **dest);
STRING *string_bitwise_xor(struct Parrot_Interp *interpreter, STRING *s1,
STRING *s2, STRING **dest);
+STRING *string_bitwise_not(struct Parrot_Interp *interpreter, STRING *s,
+ STRING **dest);
void string_iterator_init(struct string_iterator_t *i, const STRING *s);
UINTVAL string_decode_and_advance(struct string_iterator_t *i);
Index: ops/bit.ops
===================================================================
RCS file: /cvs/public/parrot/ops/bit.ops,v
retrieving revision 1.6
diff -u -d -r1.6 bit.ops
--- ops/bit.ops 23 Oct 2003 17:41:55 -0000 1.6
+++ ops/bit.ops 23 Mar 2004 01:14:30 -0000
@@ -137,6 +137,24 @@
goto NEXT();
}
+=item B<bnots>(out STR, in STR)
+
+=item B<bnots>(in PMC, in PMC)
+
+Set the bits of $1 to the B<not> of the corresponding bits from $2.
+
+=cut
+
+inline op bnots(out STR, in STR) {
+ string_bitwise_not(interpreter, $2, &$1);
+ goto NEXT();
+}
+
+inline op bnots(in PMC, in PMC) {
+ $2->vtable->bitwise_nots(interpreter, $2, $1);
+ goto NEXT();
+}
+
########################################
=item B<bor>(inout INT, in INT)
Index: ops/ops.num
===================================================================
RCS file: /cvs/public/parrot/ops/ops.num,v
retrieving revision 1.30
diff -u -d -r1.30 ops.num
--- ops/ops.num 20 Mar 2004 12:15:02 -0000 1.30
+++ ops/ops.num 23 Mar 2004 01:14:30 -0000
@@ -1423,3 +1423,6 @@
callmethodcc_s 1396
callmethodcc_sc 1397
set_addr_p_i 1398
+bnots_s_s 1399
+bnots_s_sc 1400
+bnots_p_p 1401
Index: src/string.c
===================================================================
RCS file: /cvs/public/parrot/src/string.c,v
retrieving revision 1.177
diff -u -d -r1.177 string.c
--- src/string.c 18 Mar 2004 08:57:18 -0000 1.177
+++ src/string.c 23 Mar 2004 01:14:31 -0000
@@ -1638,6 +1638,61 @@
/*
+=item C<STRING *
+string_bitwise_not(struct Parrot_Interp *interpreter, STRING *s,
+ STRING **dest)>
+
+Perform a bitwise C<not> on a string. If C<*dest != NULL> then C<**dest>
+is reused, otherwise a new string is created.
+
+=cut
+
+*/
+
+STRING *
+string_bitwise_not(struct Parrot_Interp *interpreter, STRING *s,
+ STRING **dest)
+{
+ const char *sp;
+ char *dp;
+ STRING *res = NULL;
+ size_t len;
+
+ if (dest && *dest)
+ res = *dest;
+ else if (!s)
+ res = string_make(interpreter, NULL, 0, NULL, 0, NULL);
+
+ if (!s) {
+ res->bufused = 0;
+ res->strlen = 0;
+ return res;
+ }
+
+ /* trigger GC for debug */
+ if (interpreter && GC_DEBUG(interpreter))
+ Parrot_do_dod_run(interpreter, DOD_trace_stack_FLAG);
+
+ len = s->bufused;
+ make_writable(interpreter, &res, len, s->encoding, s->type);
+
+ res->strlen = s->strlen;
+ res->bufused = len;
+
+ sp = s->strstart;
+ dp = res->strstart;
+
+ for ( ; len ; --len)
+ *dp++ = ~ *sp++;
+
+ if (dest)
+ *dest = res;
+
+ return res;
+}
+
+/*
+
=item C<INTVAL
string_bool(const STRING *s)>
Index: t/op/string.t
===================================================================
RCS file: /cvs/public/parrot/t/op/string.t,v
retrieving revision 1.67
diff -u -d -r1.67 string.t
--- t/op/string.t 16 Mar 2004 20:29:01 -0000 1.67
+++ t/op/string.t 23 Mar 2004 01:14:32 -0000
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 127;
+use Parrot::Test tests => 130;
use Test::More;
output_is( <<'CODE', <<OUTPUT, "set_s_s|sc" );
@@ -2169,6 +2169,64 @@
set S1, "foo"
substr S2, S1, 0, 3
bxors S1, "bar"
+ print S2
+ print "\n"
+ end
+CODE
+foo
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "bnots NULL string");
+ null S1
+ null S2
+ bnots S1, S2
+ null S3
+ eq S1, S3, OK1
+ print "not "
+OK1: print "ok 1\n"
+
+ null S1
+ set S2, ""
+ bnots S1, S2
+ null S3
+ eq S1, S3, OK2
+ print "not "
+OK2: print "ok 2\n"
+ bnots S2, S1
+ eq S2, S3, OK3
+ print "not "
+OK3: print "ok 3\n"
+CODE
+ok 1
+ok 2
+ok 3
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "bnots 2");
+ set S1, "a2c"
+ bnots S2, S1
+ print S1
+ print "\n"
+ print S2
+ print "\n"
+ bnots S1, S1
+ print S1
+ print "\n"
+ bnots S1, S1
+ print S1
+ print "\n"
+ end
+CODE
+a2c
+\x9E\xCD\x9C
+\x9E\xCD\x9C
+a2c
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "bnots COW");
+ set S1, "foo"
+ substr S2, S1, 0, 3
+ bnots S1, S1
print S2
print "\n"
end
Index: t/pmc/perlstring.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/perlstring.t,v
retrieving revision 1.17
diff -u -d -r1.17 perlstring.t
--- t/pmc/perlstring.t 18 Mar 2004 02:27:36 -0000 1.17
+++ t/pmc/perlstring.t 23 Mar 2004 01:14:32 -0000
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 31;
+use Parrot::Test tests => 33;
use Test::More; # Included for skip().
my $fp_equality_macro = <<'ENDOFMACRO';
@@ -943,6 +943,61 @@
ABCY
abc
Y
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "bnots NULL string");
+ new P1, .PerlString
+ new P2, .PerlString
+ new P3, .PerlString
+ null S1
+ null S2
+ set P1, S1
+ set P2, S2
+ bnots P1, P2
+ null S3
+ eq P1, S3, OK1
+ print "not "
+OK1: print "ok 1\n"
+
+ null S1
+ set P1, S1
+ set P2, ""
+ bnots P1, P2
+ null S3
+ eq P1, S3, OK2
+ print "not "
+OK2: print "ok 2\n"
+ bnots P2, P1
+ eq S2, S3, OK3
+ print "not "
+OK3: print "ok 3\n"
+CODE
+ok 1
+ok 2
+ok 3
+OUTPUT
+
+output_is( <<'CODE', <<OUTPUT, "bnots 2");
+ new P1, .PerlString
+ new P2, .PerlString
+ set P1, "a2c"
+ bnots P2, P1
+ print P1
+ print "\n"
+ print P2
+ print "\n"
+ bnots P1, P1
+ print P1
+ print "\n"
+ bnots P1, P1
+ print P1
+ print "\n"
+ end
+CODE
+a2c
+\x9E\xCD\x9C
+\x9E\xCD\x9C
+a2c
OUTPUT
output_is( <<'CODE', <<OUTPUT, "eq_str");