Skip to content

Commit

Permalink
Change IO::Handle.*-internal methods to their final names
Browse files Browse the repository at this point in the history
Per 6.d-prep list[^1], these are now named .WRITE/.READ/.EOF.

The spec[^2] for these is currently blocked by R#2039
#2039

[^1] https://github.com/perl6/6.d-prep/blob/master/TODO/FEATURES.md#spec-iohandles-write-internal-read-internal-eof-internal
[^2] Raku/roast@3cefe0dc59
  • Loading branch information
zoffixznet committed Jul 9, 2018
1 parent edf81bf commit 03d7997
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
47 changes: 24 additions & 23 deletions src/core/IO/Handle.pm6
Expand Up @@ -230,15 +230,15 @@ my class IO::Handle {

method eof(IO::Handle:D:) {
nqp::p6bool($!decoder
?? $!decoder.is-empty && self.eof-internal
!! self.eof-internal)
?? $!decoder.is-empty && self.EOF
!! self.EOF)
}

method eof-internal() {
method EOF() {
nqp::eoffh($!PIO)
}

method read-internal(Int:D $bytes) {
method READ(Int:D $bytes) {
nqp::readfh($!PIO,buf8.new,nqp::unbox_i($bytes))
}

Expand All @@ -249,17 +249,17 @@ my class IO::Handle {

method !get-line-slow-path() {
my $line := Nil;
unless self.eof-internal && $!decoder.is-empty {
unless self.EOF && $!decoder.is-empty {
loop {
my $buf := self.read-internal(0x100000);
my $buf := self.READ(0x100000);
if $buf.elems {
$!decoder.add-bytes($buf);
$line := $!decoder.consume-line-chars(:$!chomp);
last if nqp::isconcrete($line);
}
else {
$line := $!decoder.consume-line-chars(:$!chomp, :eof)
unless self.eof-internal && $!decoder.is-empty;
unless self.EOF && $!decoder.is-empty;
last;
}
}
Expand Down Expand Up @@ -468,15 +468,15 @@ my class IO::Handle {
# If we have one, read bytes via. the decoder to support mixed-mode I/O.
$!decoder
?? ($!decoder.consume-exactly-bytes($bytes) // self!read-slow-path($bytes))
!! self.read-internal($bytes)
!! self.READ($bytes)
}

method !read-slow-path($bytes) {
if self.eof-internal && $!decoder.is-empty {
if self.EOF && $!decoder.is-empty {
buf8.new
}
else {
$!decoder.add-bytes(self.read-internal($bytes max 0x100000));
$!decoder.add-bytes(self.READ($bytes max 0x100000));
$!decoder.consume-exactly-bytes($bytes)
// $!decoder.consume-exactly-bytes($!decoder.bytes-available)
// buf8.new
Expand All @@ -490,16 +490,17 @@ my class IO::Handle {

method !readchars-slow-path($chars) {
my $result := '';
unless self.eof-internal && $!decoder.is-empty {
unless self.EOF && $!decoder.is-empty {
loop {
my $buf := self.read-internal(0x100000);
my $buf := self.READ(0x100000);
if $buf.elems {
$!decoder.add-bytes($buf);
$result := $!decoder.consume-exactly-chars($chars);
last if nqp::isconcrete($result);
}
else {
$result := $!decoder.consume-exactly-chars($chars, :eof);
$result := $!decoder.consume-exactly-chars($chars, :eof)
unless self.EOF && $!decoder.is-empty;
last;
}
}
Expand Down Expand Up @@ -558,10 +559,10 @@ my class IO::Handle {
}

method write(IO::Handle:D: Blob:D $buf --> True) {
self.write-internal($buf)
self.WRITE($buf)
}

method write-internal(IO::Handle:D: Blob:D $buf --> True) {
method WRITE(IO::Handle:D: Blob:D $buf --> True) {
nqp::writefh($!PIO, nqp::decont($buf));
}

Expand Down Expand Up @@ -604,7 +605,7 @@ my class IO::Handle {
proto method print(|) {*}
multi method print(IO::Handle:D: Str:D \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<print>);
self.write-internal($!encoder.encode-chars(x));
self.WRITE($!encoder.encode-chars(x));
}
multi method print(IO::Handle:D: **@list is raw --> True) { # is raw gives List, which is cheaper
self.print(@list.join);
Expand All @@ -614,7 +615,7 @@ my class IO::Handle {
proto method put(|) {*}
multi method put(IO::Handle:D: Str:D \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<put>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s(x), nqp::unbox_s($!nl-out))))
}
multi method put(IO::Handle:D: **@list is raw --> True) { # is raw gives List, which is cheaper
Expand All @@ -624,12 +625,12 @@ my class IO::Handle {

multi method say(IO::Handle:D: Str:D $x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<say>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s($x), nqp::unbox_s($!nl-out))));
}
multi method say(IO::Handle:D: \x --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<say>);
self.write-internal($!encoder.encode-chars(
self.WRITE($!encoder.encode-chars(
nqp::concat(nqp::unbox_s(x.gist), nqp::unbox_s($!nl-out))))
}
multi method say(IO::Handle:D: |) {
Expand All @@ -643,7 +644,7 @@ my class IO::Handle {

method print-nl(IO::Handle:D: --> True) {
$!decoder or die X::IO::BinaryMode.new(:trying<print-nl>);
self.write-internal($!encoder.encode-chars($!nl-out));
self.WRITE($!encoder.encode-chars($!nl-out));
}

proto method slurp-rest(|) {*}
Expand Down Expand Up @@ -688,15 +689,15 @@ my class IO::Handle {
nqp::if(
nqp::isfalse($!decoder) || $bin,
nqp::while(
nqp::elems(my $buf := self.read-internal(0x100000)),
nqp::elems(my $buf := self.READ(0x100000)),
$res.append($buf))),
# don't sink result of .close; it might be a failed Proc
nqp::if($close, my $ = self.close),
$res)
}

method !slurp-all-chars() {
while nqp::elems(my $buf := self.read-internal(0x100000)) {
while nqp::elems(my $buf := self.READ(0x100000)) {
$!decoder.add-bytes($buf);
}
$!decoder.consume-all-chars()
Expand All @@ -705,7 +706,7 @@ my class IO::Handle {
proto method spurt(|) {*}
multi method spurt(IO::Handle:D: Blob $data, :$close) {
LEAVE self.close if $close;
self.write-internal($data);
self.WRITE($data);
}
multi method spurt(IO::Handle:D: Cool $data, :$close) {
LEAVE self.close if $close;
Expand Down
6 changes: 3 additions & 3 deletions src/core/IO/Pipe.pm6
Expand Up @@ -22,7 +22,7 @@ my class IO::Pipe is IO::Handle {
}
}

method read-internal($) {
method READ($) {
if $!on-read {
loop {
my \result = $!on-read();
Expand All @@ -40,11 +40,11 @@ my class IO::Pipe is IO::Handle {
}
}

method eof-internal() {
method EOF() {
$!eof
}

method write-internal($data) {
method WRITE($data) {
$!on-write
?? $!on-write($data)
!! die "This pipe was opened for reading, not writing"
Expand Down

0 comments on commit 03d7997

Please sign in to comment.