Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Another small task for the interested
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dan Sugalski  
View profile  
 More options Jun 11 2004, 3:35 pm
Newsgroups: perl.perl6.internals
From: d...@sidhe.org (Dan Sugalski)
Date: Fri, 11 Jun 2004 15:35:22 -0400
Local: Fri, Jun 11 2004 3:35 pm
Subject: Another small task for the interested
I checked in more of PDD 17, detailing parrot's base types. Some of
those types definitely don't exist (like, say, the string and bignum
type...) and could definitely use implementing. Should be fairly
straightforward, and would be a good way to get up to speed on
writing PMC classes.
--
                                Dan

--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
d...@sidhe.org                         have teddy bears and even
                                       teddy bears get drunk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ion Alexandru Morega  
View profile  
 More options Jun 20 2004, 4:58 am
Newsgroups: perl.perl6.internals
From: al...@iem.pub.ro (Ion Alexandru Morega)
Date: Sun, 20 Jun 2004 10:58:13 +0200
Local: Sun, Jun 20 2004 4:58 am
Subject: Re: Another small task for the interested

Dan Sugalski wrote:
> I checked in more of PDD 17, detailing parrot's base types. Some of
> those types definitely don't exist (like, say, the string and bignum
> type...) and could definitely use implementing. Should be fairly
> straightforward, and would be a good way to get up to speed on writing
> PMC classes.

Hello, i'm new to this list and to parrot programming, so i decided to
start with something simple. I implemented a String PMC that is pretty
much complete, it compiles, but i haven't tested it yet. It would be
great if someone had a look at it, and later when i write some tests
i'll check in a patch. The .pmc is attached.

[ string.pmc 12K ]
/*
Copyright: 2003 The Perl Foundation.  All Rights Reserved.
$Id: float.pmc,v 1.8 2004/04/09 20:31:57 dan Exp $

=head1 NAME

classes/string.pmc - String PMC Class

=head1 DESCRIPTION

C<String> extends C<mmd_default> to provide a string for languages
that want a C<string> type without going to an S register. Acts as a
wrapper for the functions in /src/string.c

=head2 Functions

=over 4

=cut

*/

#include "parrot/parrot.h"

pmclass String extends mmd_default {

/*

=back

=head2 Methods

=over 4

=item C<void init()>

Initializes the string.

=cut

*/

    void init () {
        PObj_custom_mark_SET(SELF);
        PMC_str_val(SELF) = string_make_empty(INTERP, enum_stringrep_one, 0);
    }

/*

=item C<void mark()>

Marks the string as live.

=cut

*/
    void mark () {
        if(PMC_str_val(SELF))
            pobject_lives(INTERP, (PObj *)PMC_str_val(SELF));
    }

/*

=item C<PMC* clone()>

Creates a copy of the string.

=cut

*/
    PMC* clone () {
        PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
        PObj_custom_mark_SET(dest);
        PMC_str_val(dest) = string_copy(INTERP,PMC_str_val(SELF));
        return dest;
    }

/*

=item C<INTVAL get_integer()>

Returns the integer representation of the string.

=cut

*/
    INTVAL get_integer () {
        STRING *s = (STRING*) PMC_str_val(SELF);
        return string_to_int(INTERP, s);
    }

/*

=item C<FLOATVAL get_number()>

Returns the floating-point representation of the string.

=cut

*/
    FLOATVAL get_number () {
        STRING *s = (STRING*) PMC_str_val(SELF);
        return string_to_num(INTERP, s);
    }

/*

=item C<BIGNUM* get_bignum()>

Returns the big numbers representation of the string.
(unimplemented, returns NULL)

=cut

*/
    BIGNUM* get_bignum () {
        /* XXX */
        return (BIGNUM*)0;
    }

/*

=item C<STRING* get_string()>

Returns the string itself.

=cut

*/
    STRING* get_string () {
        return (STRING*) PMC_str_val(SELF);
    }

/*

=item C<INTVAL get_bool()>

Returns the boolean value of the string.

=cut

*/
    INTVAL get_bool () {
        STRING *s = (STRING*) PMC_str_val(SELF);
        return string_bool(INTERP, s);
    }

/*

=item C<VOID set_integer_native(INTVAL value)>

Sets the value of the string to the integer C<value>.

=cut

*/
    void set_integer_native (INTVAL value) {
        PMC_str_val(SELF) = string_from_int(INTERP, value);
    }

/*

=item C<VOID set_number_native(FLOATVAL value)>

Sets the value of the string to the floating-point C<value>.

=cut

*/
    void set_number_native (FLOATVAL value) {
        PMC_str_val(SELF) = string_from_num(INTERP, value);
    }

/*

=item C<VOID set_bignum_native(BIGNUM* value)>

Sets the value of the string to the big number C<value>.
(unimplemented, no-op)

=cut

*/
    void set_bignum_native (BIGNUM* value) {
        /* XXX */
    }

/*

=item C<VOID set_string_native(STRING* value)>

Sets the value of the string to that of the specified C<string>.

=cut

*/
    void set_string_native (STRING* value) {
        PMC_str_val(SELF) = value;
    }

/*

=item C<VOID assign_string_native(STRING* value)>

Sets the value of the string to a copy of the specified C<string>.

=cut

*/
    void assign_string_native (STRING* value) {
        PMC_str_val(SELF) = string_copy(INTERP, value);
    }

/*

=item C<VOID set_string_same(PMC* value)>

Sets the value of the string to the value of
the specified C<String> PMC.

=cut

*/
    void set_string_same (PMC* value) {
        PMC_str_val(SELF) = PMC_str_val(value);
    }

/*

=item C<VOID set_pmc(PMC* value)>

Sets the value of the string to the value of
the specified C<PMC>.

=cut

*/
    void set_pmc (PMC* value) {
        PMC_str_val(SELF) = VTABLE_get_string(INTERP, value);
    }

/*

=item C<VOID assign_pmc(PMC* value)>

Sets the value of the string to the value of
the specified C<PMC>.

=cut

*/
    void assign_pmc (PMC* value) {
        STRING *s = VTABLE_get_string(INTERP, value);
        PMC_str_val(SELF) = string_copy(INTERP, s);
    }

/*

=item C<VOID bitwise_or(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_and(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_xor(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_ors(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_ors_str(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_ands(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_ands_str(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_xors(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_xors_str(PMC* value, PMC* dest)>
=cut
=item C<VOID bitwise_nots(PMC* value)>
=cut
These functions perform bitwise operations on entire
strings, and place the result in C<dest>.

=cut

*/
    void bitwise_or (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_or(INTERP, s, v, NULL));
    }

    void bitwise_and (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_and(INTERP, s, v, NULL));
    }

    void bitwise_xor (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_xor(INTERP, s, v, NULL));
    }

    void bitwise_ors (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_or(INTERP, s, v, NULL));
    }

    void bitwise_ors_str (STRING* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_or(INTERP, s, value, NULL));
    }

    void bitwise_ands (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_or(INTERP, s, v, NULL));
    }

    void bitwise_ands_str (STRING* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_or(INTERP, s, value, NULL));
    }

    void bitwise_xors (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_xor(INTERP, s, v, NULL));
    }

    void bitwise_xors_str (STRING* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_xor(INTERP, s, value, NULL));
    }

    void bitwise_nots (PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        VTABLE_set_string_native(INTERP, dest, string_bitwise_not(INTERP, s, NULL));
    }

/*

=item C<VOID concatenate(PMC* value, PMC* dest)>

Concatenates the string with C<value> and places the result
in C<dest>.

=cut

*/
    void concatenate (PMC* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        VTABLE_set_string_native(INTERP, dest, string_concat(INTERP, s, v, 0));
    }

/*

=item C<VOID concatenate_str(STRING* value, PMC* dest)>

Concatenates the string with C<value> and places the result
in C<dest>.

=cut

*/
    void concatenate_str (STRING* value, PMC* dest) {
        STRING *s = PMC_str_val(SELF);
        VTABLE_set_string_native(INTERP, dest, string_concat(INTERP, s, value, 0));
    }

/*

=item C<INTVAL is_equal(PMC* value)>

Compares the string with C<value>; returns true if
they match.

=cut

*/
    INTVAL is_equal (PMC* value) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        return (INTVAL)(0 == string_equal(INTERP, s, v));
    }

/*

=item C<INTVAL is_equal_num(PMC* value)>

Compares the numerical value of the string with that of
C<value>; returns true if they match.

=cut

*/
    INTVAL is_equal_num (PMC* value) {
        FLOATVAL sf = string_to_num(INTERP, PMC_str_val(SELF));
        FLOATVAL vf = VTABLE_get_number(INTERP, value);
        return (INTVAL)(sf == vf);
    }

/*

=item C<INTVAL is_equal_str(PMC* value)>

Compares the string with C<value>; returns true if
they match.

=cut

*/
    INTVAL is_equal_str (PMC* value) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        return (INTVAL)(0 == string_equal(INTERP, s, v));
    }

/*

=item C<INTVAL is_same(PMC* value)>

Compares the string PMC with the C<value> PMC and returns
true if they are identical.

=cut

*/
    INTVAL is_same (PMC* value) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = PMC_str_val(value);
        /* XXX is this the right way to check for is_same? */
        return (INTVAL)(
                value->vtable == SELF->vtable &&
                string_equal(INTERP, s, v)
            );
    }

/*

=item C<INTVAL cmp(PMC* value)>

Compares the string with C<value>; returns -1 if the
string is smaller, 0 if they are equal, and 1 if C<value>
is smaller.

=cut

*/
    INTVAL cmp (PMC* value) {
        STRING *s = PMC_str_val(SELF);
        STRING *v = VTABLE_get_string(INTERP, value);
        return string_compare(INTERP, s, v);
    }

/*

=item C<INTVAL cmp_num(PMC* value)>

Compares the numerical value of the string with that of
C<value>; returns -1 if the string is smaller, 0 if they
are equal, and 1 if C<value> is smaller.

=cut

*/
    INTVAL cmp_num (PMC* value) {
        FLOATVAL sf = string_to_num(INTERP, PMC_str_val(SELF));
        FLOATVAL vf = VTABLE_get_number(INTERP, value);
        if(sf < vf)
            return (INTVAL)(-1);
        if(sf > vf)
            return (INTVAL)(1);
        return (INTVAL)(0);
    }

/*

=item C<INTVAL cmp_string(PMC* value)>

Compares the string with C<value>; returns -1 if the
string is smaller, 0 if they are equal, and 1 if C<value>
is smaller.

=cut

*/
    INTVAL cmp_string (PMC*
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leopold Toetsch  
View profile  
 More options Jun 21 2004, 3:00 am
Newsgroups: perl.perl6.internals
From: l...@toetsch.at (Leopold Toetsch)
Date: Mon, 21 Jun 2004 09:00:30 +0200
Local: Mon, Jun 21 2004 3:00 am
Subject: Re: Another small task for the interested
Ion Alexandru Morega <al...@iem.pub.ro> wrote:

> Hello, i'm new to this list and to parrot programming, so i decided to
> start with something simple. I implemented a String PMC that is pretty
> much complete, it compiles, but i haven't tested it yet. It would be
> great if someone had a look at it, and later when i write some tests
> i'll check in a patch. The .pmc is attached.

Looks quite good. Some notes:
- (you mentioned it) needs tests
- "extends mmd_default" isn't needed anymore, we do MMD anyway
- the patch duplicates a lot of PerlString's behaviour. So it would
  probably be best to:
  1) rename perlstring.pmc -> string.pmc
  2) create: pmclass PerlString extends String
  3) then duplicate the differing functions namely the set_<type>_native
     funcs that morph a PerlString and don't in the String PMC.

leo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Sugalski  
View profile  
 More options Jun 21 2004, 8:52 am
Newsgroups: perl.perl6.internals
From: d...@sidhe.org (Dan Sugalski)
Date: Mon, 21 Jun 2004 08:52:03 -0400 (EDT)
Local: Mon, Jun 21 2004 8:52 am
Subject: Re: Another small task for the interested

Honestly I'm tempted to throw away all the Perl* PMC classes and redo
them. Some of that code's quite old and a lot of things have changed since
we started with them, and I think we may do well to just start fresh.

If the string class is OK (I'm stuck with a dead machine and backup mail
access, so it's tough to get a good look at it) then let's put it in and
we can fix things up as we go.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
d...@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Sugalski  
View profile  
 More options Jun 23 2004, 11:32 am
Newsgroups: perl.perl6.internals
From: d...@sidhe.org (Dan Sugalski)
Date: Wed, 23 Jun 2004 11:32:17 -0400 (EDT)
Local: Wed, Jun 23 2004 11:32 am
Subject: Re: Another small task for the interested

On Sun, 20 Jun 2004, Ion Alexandru Morega wrote:
> Dan Sugalski wrote:
> > I checked in more of PDD 17, detailing parrot's base types. Some of
> > those types definitely don't exist (like, say, the string and bignum
> > type...) and could definitely use implementing. Should be fairly
> > straightforward, and would be a good way to get up to speed on writing
> > PMC classes.

> Hello, i'm new to this list and to parrot programming, so i decided to
> start with something simple. I implemented a String PMC that is pretty
> much complete, it compiles, but i haven't tested it yet. It would be
> great if someone had a look at it, and later when i write some tests
> i'll check in a patch. The .pmc is attached.

Sorry this one sat so long. (Piers reminded me with the summary) I checked
in the PMC. Tests would be cool, to be sure. :)

Thanks much.

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
d...@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ion Alexandru Morega  
View profile  
 More options Jun 23 2004, 4:48 pm
Newsgroups: perl.perl6.internals
From: al...@iem.pub.ro (Ion Alexandru Morega)
Date: Wed, 23 Jun 2004 22:48:13 +0200
Local: Wed, Jun 23 2004 4:48 pm
Subject: Re: Another small task for the interested

Actually Leo answered pretty quickly, and then you did too... but why
split hairs? :)
In the mean time i fixed some things that were wrong, added a few
functions and the tests. I found some weird things while doing this,
probably bugs. So here's the patch i promised.

The function string_make() in src/string.c reads in the documentation:
"the the string reperesentation will default to enum_stringrep_unknown".
This doesn't happen. I changed a line in classes/undef.pmc which used this.

As i understand, the default implementation for the function
is_equal_str() in a PMC is to fall back to is_equal(). This works OK.
But when i actually tried to implement is_equal_str(), it turns out the
return condition is used backwards (true means false :). BTW i didn't
find any documentation for is_equal_str(), it was generated by
genclass.pl. I commented out my implementation of is_equal_str() and the
tests pass now... it's still there if anyone wants to play with it.

Now back to the String class. I should say that much of the code was
inspired by PerlString, and the tests, well, i just took them from
perlstring.t. There's still some original code there tough :)

Leo suggested to subclass PerlString from String, but it's already
subclassed from PerlScalar, do PMC's have multiple inheritance?

And a noob question: what does the $Id: line at the top of each file do?
Is it generated or do I have to uptade it myself?

alexm

[ string.diff 33K ]
diff -ruN parrot/MANIFEST my_parrot/MANIFEST
--- parrot/MANIFEST     2004-06-23 18:00:09.000000000 +0300
+++ my_parrot/MANIFEST  2004-06-23 21:35:26.000000000 +0300
@@ -94,6 +94,7 @@
 classes/scratchpad.pmc                            []
 classes/sharedref.pmc                             []
 classes/slice.pmc                                 []
+classes/string.pmc                                []
 classes/stringarray.pmc                                  []
 classes/sub.pmc                                   []
 classes/timer.pmc                                 []
@@ -2749,6 +2750,7 @@
 t/pmc/sarray.t                                    []
 t/pmc/scratchpad.t                                []
 t/pmc/signal.t                                    []
+t/pmc/string.t                                    []
 t/pmc/sub.t                                       []
 t/pmc/sys.t                                       []
 t/pmc/threads.t                                   []
diff -ruN parrot/classes/string.pmc my_parrot/classes/string.pmc
--- parrot/classes/string.pmc   1970-01-01 02:00:00.000000000 +0200
+++ my_parrot/classes/string.pmc        2004-06-23 21:31:07.000000000 +0300
@@ -0,0 +1,668 @@
+/*
+Copyright: 2003 The Perl Foundation.  All Rights Reserved.
+$Id: string.pmc,v 1.0 2004/06/21 20:31:57 alexm Exp $
+
+=head1 NAME
+
+classes/string.pmc - String PMC Class
+
+=head1 DESCRIPTION
+
+C<String> extends C<mmd_default> to provide a string for languages
+that want a C<string> type without going to an S register. Acts as a
+wrapper for the functions in /src/string.c
+
+=head2 Methods
+
+=over 4
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+
+pmclass String {
+
+/*
+
+=item C<void init()>
+
+Initializes the string.
+
+=cut
+
+*/
+
+    void init () {
+        PMC_str_val(SELF) =
+            string_make_empty(INTERP, enum_stringrep_one, 0);
+        PObj_custom_mark_SET(SELF);
+    }
+
+/*
+
+=item C<void mark()>
+
+Marks the string as live.
+
+=cut
+
+*/
+
+    void mark () {
+        if(PMC_str_val(SELF))
+            pobject_lives(INTERP, (PObj *)PMC_str_val(SELF));
+    }
+
+/*
+
+=item C<PMC* clone()>
+
+Creates a copy of the string.
+
+=cut
+
+*/
+
+    PMC* clone () {
+        PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
+        PObj_custom_mark_SET(dest);
+        PMC_str_val(dest) = string_copy(INTERP,PMC_str_val(SELF));
+        return dest;
+    }
+
+/*
+
+=item C<INTVAL get_integer()>
+
+Returns the integer representation of the string.
+
+=cut
+
+*/
+
+    INTVAL get_integer () {
+        STRING *s = (STRING*) PMC_str_val(SELF);
+        return string_to_int(INTERP, s);
+    }
+
+/*
+
+=item C<FLOATVAL get_number()>
+
+Returns the floating-point representation of the string.
+
+=cut
+
+*/
+
+    FLOATVAL get_number () {
+        STRING *s = (STRING*) PMC_str_val(SELF);
+        return string_to_num(INTERP, s);
+    }
+
+/*
+
+=item C<BIGNUM* get_bignum()>
+
+Returns the big numbers representation of the string.
+(unimplemented, returns NULL)
+
+=cut
+
+*/
+
+    BIGNUM* get_bignum () {
+        /* XXX */
+        return (BIGNUM*)0;
+    }
+
+/*
+
+=item C<STRING* get_string()>
+
+Returns the string itself.
+
+=cut
+
+*/
+    /* XXX useless? */
+    STRING* get_string () {
+        return (STRING*) PMC_str_val(SELF);
+    }
+
+/*
+
+=item C<INTVAL get_bool()>
+
+Returns the boolean value of the string.
+
+=cut
+
+*/
+
+    INTVAL get_bool () {
+        STRING *s = (STRING*) PMC_str_val(SELF);
+        return string_bool(INTERP, s);
+    }
+
+/*
+
+=item C<VOID set_integer_native(INTVAL value)>
+
+Sets the value of the string to the integer C<value>.
+
+=cut
+
+*/
+
+    void set_integer_native (INTVAL value) {
+        PMC_str_val(SELF) = string_from_int(INTERP, value);
+    }
+
+/*
+
+=item C<VOID set_number_native(FLOATVAL value)>
+
+Sets the value of the string to the floating-point C<value>.
+
+=cut
+
+*/
+
+    void set_number_native (FLOATVAL value) {
+        PMC_str_val(SELF) = string_from_num(INTERP, value);
+    }
+
+/*
+
+=item C<VOID set_bignum_native(BIGNUM* value)>
+
+Sets the value of the string to the big number C<value>.
+(unimplemented, no-op)
+
+=cut
+
+*/
+
+    void set_bignum_native (BIGNUM* value) {
+        /* XXX */
+    }
+
+/*
+
+=item C<VOID set_string_native(STRING* value)>
+
+Sets the value of the string to that of the specified C<string>.
+
+=cut
+
+*/
+
+    void set_string_native (STRING* value) {
+        PMC_str_val(SELF) = value;
+    }
+
+/*
+
+=item C<VOID assign_string_native(STRING* value)>
+
+Sets the value of the string to a copy of the specified C<string>.
+
+=cut
+
+*/
+
+    void assign_string_native (STRING* value) {
+        PMC_str_val(SELF) =
+            string_set(INTERP, PMC_str_val(SELF), value);
+    }
+
+/*
+
+=item C<VOID set_string_same(PMC* value)>
+
+Sets the value of the string to the value of
+the specified C<String> PMC.
+
+=cut
+
+*/
+
+    void set_string_same (PMC* value) {
+        PMC_str_val(SELF) =
+            string_set(INTERP, PMC_str_val(SELF), PMC_str_val(value));
+    }
+
+/*
+
+=item C<VOID set_pmc(PMC* value)>
+
+Sets the value of the string to the string value of
+the specified C<PMC>.
+
+=cut
+
+*/
+    void set_pmc (PMC* value) {
+        PMC_str_val(SELF) = VTABLE_get_string(INTERP, value);
+    }
+
+/*
+
+=item C<VOID assign_pmc(PMC* value)>
+
+Sets the value of the string to the string value of
+the specified C<PMC>.
+
+=cut
+
+*/
+    void assign_pmc (PMC* value) {
+        STRING *s = VTABLE_get_string(INTERP, value);
+        PMC_str_val(SELF) = string_set(INTERP, PMC_str_val(SELF), s);
+    }
+
+/*
+
+=item C<VOID bitwise_or(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_and(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_xor(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_ors(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_ors_str(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_ands(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_ands_str(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_xors(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_xors_str(PMC* value, PMC* dest)>
+=cut
+=item C<VOID bitwise_nots(PMC* value)>
+
+These functions perform bitwise operations on entire
+strings, and place the result in C<dest>.
+
+=cut
+
+*/
+    void bitwise_or (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_or(INTERP, s, v, NULL));
+    }
+
+    void bitwise_and (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_and(INTERP, s, v, NULL));
+    }
+
+    void bitwise_xor (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_xor(INTERP, s, v, NULL));
+    }
+
+    void bitwise_ors (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_or(INTERP, s, v, NULL));
+    }
+
+    void bitwise_ors_str (STRING* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_or(INTERP, s, value, NULL));
+    }
+
+    void bitwise_ands (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_and(INTERP, s, v, NULL));
+    }
+
+    void bitwise_ands_str (STRING* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_and(INTERP, s, value, NULL));
+    }
+
+    void bitwise_xors (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_xor(INTERP, s, v, NULL));
+    }
+
+    void bitwise_xors_str (STRING* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_xor(INTERP, s, value, NULL));
+    }
+
+    void bitwise_nots (PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        VTABLE_set_string_native(
+            INTERP, dest, string_bitwise_not(INTERP, s, NULL));
+    }
+
+/*
+
+=item C<VOID concatenate(PMC* value, PMC* dest)>
+
+Concatenates the string with C<value> and places the result in C<dest>.
+
+=cut
+
+*/
+    void concatenate (PMC* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        STRING *o = string_concat(INTERP, s, v, 0);
+        VTABLE_set_string_native(
+            INTERP, dest, o);
+    }
+
+/*
+
+=item C<VOID concatenate_str(STRING* value, PMC* dest)>
+
+Concatenates the string with C<value> and places the result in C<dest>.
+
+=cut
+
+*/
+    void concatenate_str (STRING* value, PMC* dest) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *o = string_concat(INTERP, s, value, 0);
+        VTABLE_set_string_native(INTERP, dest, o);
+    }
+
+/*
+
+=item C<INTVAL is_equal(PMC* value)>
+
+Compares the string with C<value>; returns true if
+they match.
+
+=cut
+
+*/
+    INTVAL is_equal (PMC* value) {
+        STRING *s = PMC_str_val(SELF);
+        STRING *v = VTABLE_get_string(INTERP, value);
+        return (INTVAL)(0 == string_equal(INTERP, s, v));
+    }
+
+/*
+
+=item C<INTVAL is_equal_num(PMC* value)>
+
+Compares the numerical value of the string with that of
+C<value>; returns true if they match.
+
+=cut
+
+*/
+    INTVAL is_equal_num (PMC* value) {
+        FLOATVAL sf = string_to_num(INTERP, PMC_str_val(SELF));
+        FLOATVAL vf = VTABLE_get_number(INTERP,
...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leopold Toetsch  
View profile  
 More options Jun 24 2004, 6:51 am
Newsgroups: perl.perl6.internals
From: l...@toetsch.at (Leopold Toetsch)
Date: Thu, 24 Jun 2004 12:51:37 +0200
Local: Thurs, Jun 24 2004 6:51 am
Subject: Re: Another small task for the interested

Ion Alexandru Morega wrote:
> In the mean time i fixed some things that were wrong, added a few
> functions and the tests. I found some weird things while doing this,
> probably bugs. So here's the patch i promised.

Can you please rediff string.pmc - it is in the CVS already, but you did
provide the whole file. I've checked in the other changes though.
(3 tests failing - likely becausof missing pieces from string.pmc)

> The function string_make() in src/string.c reads in the documentation:
> "the the string reperesentation will default to enum_stringrep_unknown".

A new string will get the default / global settings from the
interpreter, which we don't have yet.

> As i understand, the default implementation for the function
> is_equal_str() in a PMC is to fall back to is_equal(). This works OK.

is_equal_str() forces both sides being strings. This is the default for
strings is_equal, so they are the same.

> But when i actually tried to implement is_equal_str(), it turns out the
> return condition is used backwards (true means false :).

Its modeled like strcmp().

> Now back to the String class. I should say that much of the code was
> inspired by PerlString, and the tests, well, i just took them from
> perlstring.t. There's still some original code there tough :)

> Leo suggested to subclass PerlString from String, but it's already
> subclassed from PerlScalar, do PMC's have multiple inheritance?

Not really albeit OrderedHash does it. But for PerlString its totally ok
to inherit from String only. Most of the functionality is the same.

> And a noob question: what does the $Id: line at the top of each file do?
> Is it generated or do I have to uptade it myself?

Its generated by CVS. The variable $Id$ gets expanded to what you see
there -- so no.

> alexm

Thanks,
leo

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Piers Cawley  
View profile  
 More options Jun 24 2004, 3:08 am
Newsgroups: perl.perl6.internals
From: pdcaw...@bofh.org.uk (Piers Cawley)
Date: Thu, 24 Jun 2004 08:08:51 +0100
Local: Thurs, Jun 24 2004 3:08 am
Subject: Re: Another small task for the interested

                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It worked then --------------------------------'


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Sugalski  
View profile  
 More options Jun 24 2004, 2:55 pm
Newsgroups: perl.perl6.internals
From: d...@sidhe.org (Dan Sugalski)
Date: Thu, 24 Jun 2004 14:55:02 -0400 (EDT)
Local: Thurs, Jun 24 2004 2:55 pm
Subject: Re: Another small task for the interested

On Thu, 24 Jun 2004, Piers Cawley wrote:
> Dan Sugalski <d...@sidhe.org> writes:

> > Sorry this one sat so long. (Piers reminded me with the summary)
>                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> It worked then --------------------------------'

And not for the first time either. :)

                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
d...@sidhe.org                         have teddy bears and even
                                      teddy bears get drunk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »