Skip to content

Commit

Permalink
Merge branch 'vtable_substr'
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Jun 30, 2011
2 parents f33bce0 + 286326f commit d1cbeb0
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 56 deletions.
2 changes: 0 additions & 2 deletions docs/embed.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,6 @@ The list may also be augmented if additional functionality is required.

=item C<Parrot_PMC_substr>

=item C<Parrot_PMC_substr_str>

=item C<Parrot_PMC_subtract>

=item C<Parrot_PMC_subtract_float>
Expand Down
3 changes: 1 addition & 2 deletions docs/pdds/pdd17_pmc.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,7 @@ modifying the value of I<self>.

=item substr

void substr(INTERP, PMC *self, INTVAL offset, INTVAL length, PMC *dest)
STRING* substr_str(INTERP, PMC *self, INTVAL offset, INTVAL length)
STRING* substr(INTERP, PMC *self, INTVAL offset, INTVAL length)

Extracts the string starting at I<offset> with size I<length> and return
it as a PMC in I<dest> or as a string return value.
Expand Down
5 changes: 0 additions & 5 deletions docs/pdds/pdd28_strings.pod
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,6 @@ strings, and -1 if the passed in string argument is shorter.

=item substr

Extract a substring of a given length starting from a given offset (in
graphemes) and store the result in the string argument.

=item substr_str

Extract a substring of a given length starting from a given offset (in
graphemes) and return the string.

Expand Down
8 changes: 4 additions & 4 deletions src/ops/core_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -20587,28 +20587,28 @@ Parrot_substr_s_sc_ic_ic(opcode_t *cur_opcode, PARROT_INTERP) {

opcode_t *
Parrot_substr_s_p_i_i(opcode_t *cur_opcode, PARROT_INTERP) {
SREG(1) = VTABLE_substr_str(interp, PREG(2), IREG(3), IREG(4));
SREG(1) = VTABLE_substr(interp, PREG(2), IREG(3), IREG(4));
PARROT_GC_WRITE_BARRIER(interp, CURRENT_CONTEXT(interp));
return (opcode_t *)cur_opcode + 5;
}

opcode_t *
Parrot_substr_s_p_ic_i(opcode_t *cur_opcode, PARROT_INTERP) {
SREG(1) = VTABLE_substr_str(interp, PREG(2), ICONST(3), IREG(4));
SREG(1) = VTABLE_substr(interp, PREG(2), ICONST(3), IREG(4));
PARROT_GC_WRITE_BARRIER(interp, CURRENT_CONTEXT(interp));
return (opcode_t *)cur_opcode + 5;
}

opcode_t *
Parrot_substr_s_p_i_ic(opcode_t *cur_opcode, PARROT_INTERP) {
SREG(1) = VTABLE_substr_str(interp, PREG(2), IREG(3), ICONST(4));
SREG(1) = VTABLE_substr(interp, PREG(2), IREG(3), ICONST(4));
PARROT_GC_WRITE_BARRIER(interp, CURRENT_CONTEXT(interp));
return (opcode_t *)cur_opcode + 5;
}

opcode_t *
Parrot_substr_s_p_ic_ic(opcode_t *cur_opcode, PARROT_INTERP) {
SREG(1) = VTABLE_substr_str(interp, PREG(2), ICONST(3), ICONST(4));
SREG(1) = VTABLE_substr(interp, PREG(2), ICONST(3), ICONST(4));
PARROT_GC_WRITE_BARRIER(interp, CURRENT_CONTEXT(interp));
return (opcode_t *)cur_opcode + 5;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ops/string.ops
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ inline op substr(out STR, in STR, in INT, in INT) :base_core {
}

inline op substr(out STR, invar PMC, in INT, in INT) :base_core {
$1 = VTABLE_substr_str(interp, $2, $3, $4);
$1 = VTABLE_substr(interp, $2, $3, $4);
}

inline op replace(out STR, in STR, in INT, in INT, in STR) :base_core {
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/scalar.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ Always returns true.

/*

=item C<STRING *substr_str(INTVAL offset, INTVAL length)>
=item C<STRING *substr(INTVAL offset, INTVAL length)>

Returns the substring of length C<length> of the scalar starting at
C<offset>.
Expand All @@ -828,7 +828,7 @@ C<offset>.

*/

VTABLE STRING *substr_str(INTVAL offset, INTVAL length) {
VTABLE STRING *substr(INTVAL offset, INTVAL length) {
return STRING_substr(INTERP, VTABLE_get_string(INTERP, SELF),
offset, length);
}
Expand Down
21 changes: 2 additions & 19 deletions src/pmc/string.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -345,32 +345,15 @@ is smaller.

/*

=item C<void substr(INTVAL offset, INTVAL length, PMC *dest)>

Extracts the substring starting at C<offset>, with size
C<length>, and places it in C<dest>.

=cut

*/
VTABLE void substr(INTVAL offset, INTVAL length, PMC *dest) {
STRING *str_val, *s2;
GET_ATTR_str_val(INTERP, SELF, str_val);
s2 = STRING_substr(INTERP, str_val, offset, length);
VTABLE_set_string_native(INTERP, dest, s2);
}

/*

=item C<STRING *substr_str(INTVAL offset, INTVAL length)>
=item C<STRING *substr(INTVAL offset, INTVAL length)>

Extracts the substring starting at C<offset>, with size
C<length>, and returns it.

=cut

*/
VTABLE STRING *substr_str(INTVAL offset, INTVAL length) {
VTABLE STRING *substr(INTVAL offset, INTVAL length) {
STRING *str_val;
GET_ATTR_str_val(INTERP, SELF, str_val);
return STRING_substr(INTERP, str_val, offset, length);
Expand Down
4 changes: 2 additions & 2 deletions src/pmc/stringbuilder.pmc
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ For testing purpose only?

/*

=item C<VTABLE substr_str()>
=item C<VTABLE substr()>

=cut

*/

VTABLE STRING *substr_str(INTVAL offset, INTVAL length) {
VTABLE STRING *substr(INTVAL offset, INTVAL length) {
STRING *buffer;
GET_ATTR_buffer(INTERP, SELF, buffer);
/* We must clone here becase we can reallocate buffer behind the scene... */
Expand Down
3 changes: 1 addition & 2 deletions src/vtable.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ PMC* repeat_int(INTVAL value, PMC* dest)
void i_repeat(PMC* value) :write
void i_repeat_int(INTVAL value) :write

void substr(INTVAL offset, INTVAL length, PMC* dest)
STRING* substr_str(INTVAL offset, INTVAL length)
STRING* substr(INTVAL offset, INTVAL length)

[EXISTS]
INTVAL exists_keyed(PMC* key)
Expand Down
17 changes: 2 additions & 15 deletions t/src/extend_vtable.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use File::Spec::Functions;

plan skip_all => 'src/parrot_config.o does not exist' unless -e catfile(qw/src parrot_config.o/);

plan tests => 140;
plan tests => 139;

=head1 NAME
Expand Down Expand Up @@ -460,25 +460,12 @@ OUTPUT
#Done!
#OUTPUT


extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_substr" );
string = createstring(interp, "FOO");
Parrot_PMC_assign_string_native(interp, pmc_string, string);
Parrot_PMC_substr(interp, pmc_string, 0, 2, pmc_string2);
Parrot_printf(interp, "%P\n", pmc_string2);
CODE
FO
Done!
OUTPUT

extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_substr_str" );
string = createstring(interp, "FOO");
Parrot_PMC_assign_string_native(interp, pmc_string, string);
string2 = Parrot_PMC_substr_str(interp, pmc_string, 0, 1);
string2 = Parrot_PMC_substr(interp, pmc_string, 0, 1);
Parrot_printf(interp, "%S\n", string2);
CODE
F
Expand Down
3 changes: 1 addition & 2 deletions tools/dev/vtablize.pl
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ =head1 SEE ALSO
s/^(\s*)(PMC\s+\*repeat_int\(INTVAL\s+\w*,\s+PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(void\s+i_repeat\(PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(void\s+i_repeat_int\(INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(void\s+substr\(INTVAL\s+\w*,\s+INTVAL\s+\w*,\s+PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(STRING\s+\*substr_str\(INTVAL\s+\w*,\s+INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(STRING\s+\*substr\(INTVAL\s+\w*,\s+INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(INTVAL\s+exists_keyed\(PMC\s+\*\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(INTVAL\s+exists_keyed_int\(INTVAL\s+\w*\)\s+{)/$1VTABLE $2/;
s/^(\s*)(INTVAL\s+exists_keyed_str\(STRING\s+\*\w*\)\s+{)/$1VTABLE $2/;
Expand Down

0 comments on commit d1cbeb0

Please sign in to comment.