Skip to content

Commit

Permalink
Initial implementation of Array, List, and Parcel.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jun 10, 2011
1 parent 30faa78 commit ac26106
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/CORE.setting/Array.pm
@@ -0,0 +1,12 @@
class Array is List {
method BIND_POS(\$n, $x is copy) {
pir::find_method__PPs(List, 'BIND_POS')(self, $n, $x);
}

method at_pos(\$n) {
self.exists($n)
?? pir::find_method__PPs(List, 'at_pos')(self, $n)
!! pir::find_method__PPs(List, 'BIND_POS')(self, $n, my $x)
}
}

43 changes: 41 additions & 2 deletions src/CORE.setting/List.pm
@@ -1,5 +1,44 @@
my class List is Iterable {
has $!flat;
class Parcel { ... }

class List is Iterable {
has $!items;
has $!rest;
has $!flat;

method exists(\$n) {
self.gimme($n+1);
pir::perl6_booleanize__PI(
pir::exists__IQI($!items, pir::repr_unbox_int__IP($n))
)
}

method gimme(\$n) {
pir::defined($!items) ||
pir::setattribute__vPPsP(self, List, '$!items',
pir::new__Ps('ResizablePMCArray'));
my $i = pir::perl6_box_int__PI(pir::elements($!items));
my $a;
while $!rest && $i < $n {
$a := pir::shift__PP($!rest);
if Parcel.ACCEPTS($a) {
pir::splice__vPPii($!rest, $a.rpa, 0, 0);
}
else {
self.BIND_POS($i, $a);
$i = $i + 1;
}
}
pir::perl6_box_int__PI(pir::elements($!items));
}

method at_pos(\$n) {
self.exists($n)
?? pir::set__PQi($!items, pir::repr_unbox_int__IP($n))
!! Any
}

method BIND_POS(\$n, \$x) {
pir::set__2QiP($!items, pir::repr_unbox_int__IP($n), $x)
}
}

9 changes: 6 additions & 3 deletions src/CORE.setting/Parcel.pm
Expand Up @@ -6,13 +6,16 @@ my class Parcel is Iterable {
pir::repr_instance_of__PP(List),
List,
'$!rest',
pir::clone__PP($!storage)
)
$!storage)
}

method rpa() {
pir::getattribute__PPPs(self, Parcel, '$!storage')
}
}


sub infix:<,>(|$) {
my sub infix:<,>(|$) {
pir::setattribute__0PPsP(
pir::repr_instance_of__PP(Parcel),
Parcel,
Expand Down
3 changes: 3 additions & 0 deletions tools/build/Makefile.in
Expand Up @@ -131,6 +131,9 @@ CORE_SOURCES = \
src/CORE.setting/Str.pm \
src/CORE.setting/Iterable.pm \
src/CORE.setting/Iterator.pm \
src/CORE.setting/List.pm \
src/CORE.setting/Array.pm \
src/CORE.setting/Parcel.pm \
src/CORE.setting/Parameter.pm \
src/CORE.setting/Signature.pm \
src/CORE.setting/Block.pm \
Expand Down

0 comments on commit ac26106

Please sign in to comment.