Skip to content
Permalink
Browse files

Make "my @A is Blob / Buf = ..." work

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 762c708fdcef3e52f49800ba9a621d29449e82fa
Showing with 27 additions and 6 deletions.
  1. +27 −4 src/core/Buf.pm6
  2. +0 −2 src/core/Nil.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 { ... }
@@ -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) {
@@ -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 {
@@ -1,5 +1,3 @@
class X::Assignment::RO { ... }

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

1 comment on commit 762c708

@soundart

This comment has been minimized.

Copy link

commented on 762c708 Feb 8, 2019

Please sign in to comment.
You can’t perform that action at this time.