Permalink
Browse files

[core] WIP fix morph [GH #372]

pass the correct type info to pmc_reuse
allow the 2nd argument to be a Object PMC, so
use Parrot_pmc_reuse_init instead.

TODO:
- non-builtin types via PARROT_CLASS(type)->id
  and Parrot_pmc_reuse_by_class

- morph old values into new type (pmc specific).
  e.g. *Array => Integer needs to assign the elements to the get_integer iv
  • Loading branch information...
Reini Urban
Reini Urban committed Mar 9, 2014
1 parent 8ff72da commit 0db521192241ce0b12fba83aab296997899c8a39
Showing with 14 additions and 5 deletions.
  1. +2 −0 src/pmc.c
  2. +5 −1 src/pmc/default.pmc
  3. +7 −4 t/src/extend_vtable.t
View
@@ -305,6 +305,8 @@ and the PMC will be inited.
Cannot currently handle converting a non-Object PMC into an Object. Use
C<pmc_reuse_by_class> for that.
The flags argument is currently ignored. The flags of the vtable of the
new_type is used instead.
=cut
View
@@ -442,7 +442,11 @@ Changes the PMC to a PMC of a new type
*/
VTABLE void morph(PMC* type) {
Parrot_pmc_reuse(INTERP, SELF, VTABLE_get_integer(INTERP, type), 0);
/* XXX: on a Class PMC omit the init part.
Need to seperate builtin classes from external ones.
On seperate: Parrot_pmc_reuse_by_class */
Parrot_pmc_reuse_init(INTERP, SELF,
type->vtable->base_type, type, 0);
}
/*
View
@@ -295,13 +295,16 @@ CODE
Done!
OUTPUT
# TODO: Should it really return 'default' here?
extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_morph");
# TODO Should return 'Integer', not 'default' here, and the value should be the length
# of the array fpa
extend_vtable_output_is(<<'CODE', <<'OUTPUT', "Parrot_PMC_morph", todo => 'GH #372 morph returns default');
Parrot_PMC_init_int(interp, fpa, 10);
Parrot_PMC_morph(interp, fpa, pmc);
string = Parrot_PMC_name(interp, fpa);
Parrot_printf(interp, "%S\n", string);
integer = Parrot_PMC_get_integer(interp, fpa);
Parrot_printf(interp, "%S %d\n", string, integer);
CODE
default
Integer 10
Done!
OUTPUT

0 comments on commit 0db5211

Please sign in to comment.