Skip to content

Commit

Permalink
Make "my @A is Blob / Buf = ..." work
Browse files Browse the repository at this point in the history
The Buf/Blob roles did not directly support the .STORE(:INITIALIZE) mechanism
yet.  Fixes R#2509
  • Loading branch information
lizmat committed Nov 27, 2018
1 parent 43ac327 commit 762c708
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
31 changes: 27 additions & 4 deletions src/core/Buf.pm6
@@ -1,3 +1,4 @@
my class X::Assignment::RO { ... }
my class X::Buf::AsStr { ... }
my class X::Buf::Pack { ... }
my class X::Buf::Pack::NonASCII { ... }
Expand Down Expand Up @@ -41,11 +42,20 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is
nqp::splice(nqp::create(self),@values,0,0)
}
multi method new(Blob: @values) {
@values.is-lazy
?? Failure.new(X::Cannot::Lazy.new(:action<new>,:what(self.^name)))
!! self!push-list("initializ",nqp::create(self),@values)
nqp::create(self).STORE(@values, :INITIALIZE)
}
multi method new(Blob: *@values) {
nqp::create(self).STORE(@values, :INITIALIZE)
}

proto method STORE(Blob:D: |) {*}
multi method STORE(Blob:D: Iterable:D \iterable, :$INITIALIZE) {
$INITIALIZE
?? iterable.is-lazy
?? X::Cannot::Lazy.new(:action<store>,:what(self.^name)).throw
!! self!push-list("initializ",self,iterable)
!! X::Assignment::RO.new(:value(self)).throw
}
multi method new(Blob: *@values) { self.new(@values) }

proto method allocate(|) {*}
multi method allocate(Blob:U: Int:D $elements) {
Expand Down Expand Up @@ -527,6 +537,19 @@ my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
!! nqp::bindpos_i(self,$pos,assignee)
}

multi method STORE(Buf:D: Blob:D $blob) {
nqp::splice(nqp::setelems(self,0),$blob,0,0)
}
# The "is default" is needed to prevent runtime dispatch errors
multi method STORE(Buf:D: int @values) is default {
nqp::splice(nqp::setelems(self,0),@values,0,0)
}
multi method STORE(Buf:D: Iterable:D \iterable) {
iterable.is-lazy
?? X::Cannot::Lazy.new(:action<store>,:what(self.^name)).throw
!! self!push-list("initializ",nqp::setelems(self,0),iterable);
}

multi method list(Buf:D:) {
Seq.new(class :: does Rakudo::Iterator::Blobby {
method pull-one() is raw {
Expand Down
2 changes: 0 additions & 2 deletions src/core/Nil.pm6
@@ -1,5 +1,3 @@
class X::Assignment::RO { ... }

my class Nil is Cool { # declared in BOOTSTRAP
method new(*@ --> Nil) { }
multi method gist(Nil:) { 'Nil' }
Expand Down

1 comment on commit 762c708

@soundart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.