Skip to content

Commit 058b32e

Browse files
committed
set input line seperator because separately
Also, map the nqp::setinputlinesep op on parrot for convenience.
1 parent 3047e97 commit 058b32e

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/HLL/Compiler.nqp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ class HLL::Compiler does HLL::Backend::Default {
373373
my $result := $source;
374374
my $stderr := nqp::getstderr();
375375
my $stdin := nqp::getstdin();
376+
#?if moar
377+
nqp::setinputlinesep($stdin, "\n");
378+
#?endif
376379
my $stagestats := %adverbs<stagestats>;
377380
unless $from eq '' || self.exists_stage($from) {
378381
nqp::die("Unknown compilation input '$from'");

src/core/IO.nqp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Open file.
1111
sub open($filename, :$r, :$w, :$a, :$bin) {
1212
my $mode := $w ?? 'w' !! ($a ?? 'wa' !! 'r');
1313
my $handle := nqp::open($filename, $mode);
14+
#?if !parrot
15+
nqp::setinputlinesep($handle, "\n") if $r;
16+
#?endif
1417
nqp::setencoding($handle, 'utf8') unless $bin;
1518
$handle;
1619
}

src/vm/parrot/QAST/Operations.nqp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,16 @@ QAST::Operations.add_core_op('closefh', -> $qastcomp, $op {
18541854
$op[0]
18551855
))
18561856
});
1857+
QAST::Operations.add_core_op('setinputlinesep', -> $qastcomp, $op {
1858+
if +$op.list != 2 {
1859+
nqp::die("The 'setinputlinesep' op expects two operands");
1860+
}
1861+
$qastcomp.as_post(QAST::Op.new(
1862+
:op('callmethod'), :name('record_separator'),
1863+
$op[0],
1864+
$op[1]
1865+
))
1866+
});
18571867
QAST::Operations.add_core_op('readfh', -> $qastcomp, $op {
18581868
if +@($op) != 3 {
18591869
nqp::die('readfh requires 3 operands');

t/nqp/19-file-ops.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ok( nqp::stat('CREDITS', nqp::const::STAT_ISREG) == 1, 'nqp::stat is regular fil
1414
ok( nqp::stat('t', nqp::const::STAT_ISREG) == 0, 'nqp::stat not regular file');
1515

1616
my $credits := nqp::open('CREDITS', 'r');
17+
nqp::setinputlinesep($credits, "\n");
1718
ok( $credits, 'nqp::open for read');
1819
ok( nqp::tellfh($credits) == 0, 'nqp::tellfh start of file');
1920
ok( !nqp::eoffh($credits), 'Not at EOF after open');

0 commit comments

Comments
 (0)