Permalink
Browse files

First cut at an implementation of 'gist' (from specs commit 669e0dd).

  • Loading branch information...
pmichaud committed Jun 18, 2011
1 parent de6c43d commit ba6af41de599c8eda493c5d91903139cd813e67a
Showing with 33 additions and 15 deletions.
  1. +7 −5 src/core/IO.pm
  2. +2 −0 src/core/Iterable.pm
  3. +11 −4 src/core/List.pm
  4. +6 −6 src/core/Mu.pm
  5. +7 −0 src/core/Parcel.pm
View
@@ -1,12 +1,14 @@
# XXX Relatively cheaty, just to get us able to output something.
# But you should see what USED to be here! O.O
-sub say(*@list) {
+sub print(*@list) {
pir::print(@list.shift) while @list.gimme(1);
- pir::print("\n");
1.Bool
}
-sub print(*@list) {
- pir::print(@list.shift) while @list.gimme(1);
- 1.Bool
+sub say(|$) {
+ print pir__perl6_box_rpa__PP(pir::perl6_current_args_rpa__P()).gist, "\n"
+}
+
+sub gist(|$) {
+ pir__perl6_box_rpa__PP(pir::perl6_current_args_rpa__P()).gist
}
View
@@ -1,3 +1,5 @@
my class Iterable {
# Has parent Cool declared in BOOTSTRAP
+
+ method item($self:) { $self }
}
View
@@ -5,10 +5,11 @@ class List {
# has $!flattens; # true if this list flattens its parcels
# has $!nextiter; # iterator for generating remaining elements
- method Bool() { self.gimme(1).Bool }
- method Int() { self.elems }
- method Numeric() { self.elems }
- method Parcel() { self.gimme(*); pir__perl6_box_rpa__PP(self.RPA) }
+ method Bool() { self.gimme(1).Bool }
+ method Int() { self.elems }
+ method Numeric() { self.elems }
+ method Parcel() { self.gimme(*); pir__perl6_box_rpa__PP(self.RPA) }
+ method Str(List:D:) { self.join(' ') }
method list() { self }
method flattens() { $!flattens }
@@ -74,6 +75,12 @@ class List {
pir__perl6_box_rpa__PP($rpa)
}
+ method push(*@values) {
+ my $pos = self.elems;
+ fail '.push on infinite lists NYI' if $!nextiter.defined;
+ self.STORE_AT_POS($pos++, @values.shift) while @values;
+ }
+
method shift() {
# make sure we have at least one item, then shift+return it
self.gimme(1) && pir::shift__PP($!items)
View
@@ -30,22 +30,22 @@ my class Mu {
proto method Str(|$) { * }
multi method Str(Mu:U:) {
- self.HOW.name(self) ~ '()'
+ '' # TODO: should be a warning of some sort
}
multi method Str(Mu:D:) {
self.HOW.name(self) ~ '<' ~ self.WHERE ~ '>'
}
- proto method Stringy(|$) { * }
- multi method Stringy(Mu:U:) {
- '' # TODO: should be a warning of some sort
- }
- multi method Stringy(Mu:D:) { self.Str }
+ method Stringy(Mu:D:) { self.Str }
method item() { self }
method say() { say(self) }
+ proto method gist(|$) { * }
+ multi method gist(Mu:U:) { self.HOW.name(self) ~ '()' }
+ multi method gist(Mu:D:) { self.Stringy }
+
proto method perl(|$) { * }
multi method perl(Mu:D:) { self.Str }
multi method perl(Mu:U:) { self.HOW.name(self) }
View
@@ -9,6 +9,13 @@ my class Parcel {
pir::perl6_list_from_rpa__PPPP(List, pir::clone__PP($!storage), Mu)
}
+ multi method gist(Parcel:D:) {
+ my @gist;
+ my Mu $rpa := pir::clone__PP($!storage);
+ @gist.push( pir::shift__PP($rpa).gist ) while $rpa;
+ @gist;
+ }
+
multi method perl(Parcel:D:) {
my Mu $rpa := pir::clone($!storage);
my $perl = '(';

0 comments on commit ba6af41

Please sign in to comment.