Skip to content

Commit

Permalink
Convert 'deref_objectref' dynop to 'deobjectref' and 'descalarref'.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jun 4, 2009
1 parent 77db80c commit 5745c6b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/builtins/op.pir
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ src/builtins/op.pir - Perl 6 builtin operators

.sub 'postfix:++' :multi(Integer)
.param pmc a
$P0 = deref_objectref a
$P0 = deobjectref a
$P0 = clone $P0
.const 'Sub' $P1 = '!prefix:++Int'
$P1(a)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Code.pir
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Gets the signature for the block, or returns Failure if it lacks one.
=cut

.sub 'signature' :method
$P0 = deref_objectref self
$P0 = descalarref self
$P0 = getprop '$!signature', $P0
if null $P0 goto no_sig
.return ($P0)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Object.pir
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ like this.

# Make a clone.
.local pmc result
self = deref_objectref self
self = deobjectref self
result = clone self

# Set any new attributes.
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Role.pir
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Checks if the given topic does the role.

# If the topic is the same as self, then we're done.
$I0 = 1
topic = deref_objectref topic
topic = descalarref topic
eq_addr self, topic, done
$I0 = 0

Expand Down
4 changes: 2 additions & 2 deletions src/classes/Signature.pir
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ lexicals as needed and performing type checks.
param_array:
$P0 = type.'ACCEPTS'(orig)
unless $P0 goto err_param_type_non_scalar
var = deref_objectref orig
var = descalarref orig
var = '!CALLMETHOD'('Array', var)
goto param_val_done
param_hash:
$P0 = type.'ACCEPTS'(orig)
unless $P0 goto err_param_type_non_scalar
var = deref_objectref orig
var = descalarref orig
var = '!CALLMETHOD'('Hash', var)
goto param_val_done
param_val_done:
Expand Down
41 changes: 34 additions & 7 deletions src/ops/perl6.ops
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,49 @@ inline op transform_to_p6opaque(inout PMC) :base_core {

/*

=item deref_objectref(out PMC, in PMC)
=item deobjectref(out PMC, in PMC)

If $2 is an ObjectRef or Perl6Scalar, then dereferences it recursively until we get
to the real underlying value.
If $2 is an ObjectRef, then follow the chain of ObjectRef
references until we get to a value of some sort (which could be
a Perl6Scalar).

=cut

*/
inline op deref_objectref(out PMC, in PMC) :base_core {
inline op deobjectref(out PMC, in PMC) :base_core {
PMC * ref;
if (!p6s_id) {
p6s_id = pmc_type(interp, string_from_literal(interp, "Perl6Scalar"));
or_id = pmc_type(interp, string_from_literal(interp, "ObjectRef"));
}
$1 = $2;
while ($1->vtable->base_type == p6s_id || $1->vtable->base_type == or_id)
$1 = VTABLE_get_pmc(interp, $1);
ref = $2;
while (ref->vtable->base_type == or_id)
ref = VTABLE_get_pmc(interp, ref);
$1 = ref;
goto NEXT();
}

/*

=item descalarref(out PMC, in PMC)

If $2 is an ObjectRef or Perl6Scalar, then follow the chain of
ObjectRef/Perl6Scalar references until we get to the real
underlying value.

=cut

*/
inline op descalarref(out PMC, in PMC) :base_core {
PMC * ref;
if (!p6s_id) {
p6s_id = pmc_type(interp, string_from_literal(interp, "Perl6Scalar"));
or_id = pmc_type(interp, string_from_literal(interp, "ObjectRef"));
}
ref = $2;
while (ref->vtable->base_type == or_id || ref->vtable->base_type == p6s_id)
ref = VTABLE_get_pmc(interp, ref);
$1 = ref;
goto NEXT();
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,7 @@ sub make_attr_init_closure($init_value) {


sub deref_invocant($inv) {
PAST::Op.new( :inline(' %r = deref_objectref %0'), $inv )
PAST::Op.new( :inline(' %r = descalarref %0'), $inv )
}


Expand Down

0 comments on commit 5745c6b

Please sign in to comment.