Skip to content

Commit

Permalink
Merge branch 'assign'
Browse files Browse the repository at this point in the history
Conflicts:
	src/binder/bind.c
  • Loading branch information
pmichaud committed Feb 16, 2010
2 parents 9267d1e + 2bb2172 commit 04f3504
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/binder/bind.c
Expand Up @@ -290,8 +290,8 @@ Rakudo_binding_bind_one_param(PARROT_INTERP, PMC *lexpad, llsig_element *sig_inf
/* Read only. Wrap it into a ObjectRef, mark readonly and bind it. */
if (sig_info->variable_name) {
PMC *ref = pmc_new_init(interp, or_id, value);
if (sig_info->flags & (SIG_ELEM_ARRAY_SIGIL | SIG_ELEM_HASH_SIGIL))
VTABLE_setprop(interp, ref, string_from_literal(interp, "flatten"), ref);
if (!(sig_info->flags & (SIG_ELEM_ARRAY_SIGIL | SIG_ELEM_HASH_SIGIL)))
VTABLE_setprop(interp, ref, string_from_literal(interp, "scalar"), ref);
VTABLE_set_pmc_keyed_str(interp, lexpad, sig_info->variable_name, ref);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/builtins/Array.pir
Expand Up @@ -64,7 +64,9 @@ Arrays are the mutable form of Lists.
$P0 = new ['Array']
transform_to_p6opaque $P0
$P0.'!STORE'(parcel)
$P1 = new ['Perl6Scalar'], $P0
$P1 = new ['ObjectRef'], $P0
$P2 = get_hll_global ['Bool'], 'True'
setprop $P1, 'scalar', $P2
.return ($P1)
.end

Expand All @@ -85,9 +87,10 @@ Create an element for the Array (has the 'rw' property set).
.param pmc item
.local pmc elem, true
true = get_hll_global ['Bool'], 'True'
elem = new ['Perl6Scalar']
item = descalarref item
elem = new ['ObjectRef'], item
setprop elem, 'scalar', true
setprop elem, 'rw', true
elem.'!STORE'(item)
.return (elem)
.end

Expand Down
4 changes: 2 additions & 2 deletions src/builtins/List.pir
Expand Up @@ -48,8 +48,8 @@ Returns the next element of the list.
unless rpa goto rpa_done
value = shift rpa
# If the value doesn't flatten, we return it directly.
$I0 = isa value, ['Perl6Scalar']
if $I0 goto get_done
$P0 = getprop 'scalar', value
unless null $P0 goto get_done
# If the value is a RPA/Parcel, it always flattens directly
$I0 = isa value, ['ResizablePMCArray']
if $I0 goto rpa_flatten
Expand Down
11 changes: 11 additions & 0 deletions src/builtins/Parcel.pir
Expand Up @@ -22,6 +22,17 @@ elements and can be flattened into Captures or Lists.
parcelproto = p6meta.'new_class'('Parcel', 'parent'=>'parrot;ResizablePMCArray Iterable', 'does_role'=>pos_role)
.end

=item item()

A Parcel in item context becomes a Seq.

=cut

.sub 'item' :method
.tailcall self.'Seq'()
.end


=item iterator()

Construct an iterator for the Parcel.
Expand Down
17 changes: 14 additions & 3 deletions src/builtins/Proxy.pir
Expand Up @@ -52,9 +52,20 @@ container.
# now bind self into the base container
base[key] = self

# and complete the STORE on self
.const 'Sub' $P0 = 'Mu::!STORE'
.tailcall self.$P0(source)
# get the item to be stored
source = descalarref source
$I0 = can source, 'item'
unless $I0 goto have_source
source = source.'item'()
have_source:

# convert self into a scalar
$P0 = new ['ObjectRef'], source
copy self, $P0
$P0 = get_hll_global ['Bool'], 'True'
setprop self, 'scalar', $P0

.return (self)
.end


Expand Down
12 changes: 7 additions & 5 deletions src/builtins/Seq.pir
Expand Up @@ -92,9 +92,11 @@ wish to make other property changes on individual elements.
.namespace ['Seq']
.sub '!elem' :method
.param pmc item
.local pmc elem
elem = new ['Perl6Scalar']
elem.'!STORE'(item)
.local pmc elem, true
item = descalarref item
elem = new ['ObjectRef'], item
true = get_hll_global ['Bool'], 'True'
setprop elem, 'scalar', true
.return (elem)
.end

Expand Down Expand Up @@ -159,8 +161,8 @@ Performs list assignment using the values from C<source>.
items = new ['Parcel']
null rest

$I0 = isa source, ['Perl6Scalar']
if $I0 goto source_item
$P0 = getprop 'scalar', source
unless null $P0 goto source_item
$I0 = isa source, ['Iterable']
unless $I0 goto source_item
$P0 = source.'iterator'()
Expand Down
56 changes: 43 additions & 13 deletions src/builtins/assign.pir
Expand Up @@ -13,22 +13,52 @@ src/builtins/assign.pir - assignment operations
.param pmc cont
.param pmc source

cont_loop:
# If the lhs isn't marked rw, throw exception
.local pmc rw
getprop rw, 'rw', cont
unless null rw goto cont_store
die 'Cannot assign to readonly value'
rw = getprop 'rw', cont
unless null rw goto rw_ok
'&die'('Cannot assign to readonly value')
rw_ok:

# If the lhs isn't a scalar container, delegate to
# object's STORE method.
$P0 = getprop 'scalar', cont
if null $P0 goto cont_store

scalar_store:
# perform any needed typecheck
.local pmc type
type = getprop 'type', cont
if null type goto type_ok
$P0 = type.'ACCEPTS'(source)
if $P0 goto type_ok
'&die'('Type check failed for assignment')
type_ok:

# Dereference the scalar LHS. If the thing we're
# currently referencing is itself an ObjectRef, delegate
# the assignment to it.
.local pmc tgt
tgt = deref cont
$I0 = isa tgt, ['ObjectRef']
unless $I0 goto scalar_assign
cont = tgt
goto cont_loop

scalar_assign:
# fully dereference the source, put it in item context, and set the
# lhs objectref to it
source = descalarref source
$I0 = can source, 'item'
unless $I0 goto have_source
source = source.'item'()
have_source:
setref cont, source
.return (cont)

cont_store:
# if container is a scalar, force item assignment
$I0 = isa cont, ['Perl6Scalar']
if $I0 goto obj_store
# if container doesn't know how to store, force item assignment
$I0 = can cont, '!STORE'
unless $I0 goto obj_store
# let the container handle storing of source
.tailcall cont.'!STORE'(source)
obj_store:
.const 'Sub' $P0 = 'Mu::!STORE'
.tailcall cont.$P0(source)
.end


Expand Down
8 changes: 3 additions & 5 deletions src/core/Iterator.pm
Expand Up @@ -8,13 +8,11 @@ augment class Iterator {
}

multi method Seq() {
my $seq = Seq.new;
$seq = self;
$seq;
Seq.new!STORE(self);
}

multi method Str() {
self.Seq.Str;
pir::join(' ', self.eager);
}

# TimToady suggests this should be on Cool,
Expand All @@ -32,4 +30,4 @@ augment class Iterator {
self.get.say;
}
}
}
}
4 changes: 4 additions & 0 deletions src/core/Num.pm
Expand Up @@ -61,6 +61,10 @@ augment class Num {
pir::log10__Nn(self);
}

multi method perl() {
~self;
}

multi method sqrt() {
pir::sqrt__Nn(self);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/Range.pm
Expand Up @@ -64,11 +64,11 @@ class Range is Iterable {
}

our Str multi method Str() {
$.iterator.join(" ");
$.iterator.Str;
}

our multi method Num() {
$.iterator.Seq.elems;
$.iterator.elems;
}
}

Expand Down

0 comments on commit 04f3504

Please sign in to comment.