Skip to content

Commit 3887f45

Browse files
committed
Fix compilation of \n on JVM
1 parent f88d35c commit 3887f45

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4440,21 +4440,12 @@ class QAST::CompilerJAST {
44404440
$il.append($L2I);
44414441
$il.append(JAST::Instruction.new( :op($node.negate ?? 'ifne' !! 'ifeq'), %*REG<fail> ));
44424442

4443-
if $subtype == nqp::const::CCLASS_NEWLINE {
4443+
if $cclass == nqp::const::CCLASS_NEWLINE && !$node.negate {
44444444
$il.append(JAST::Instruction.new( :op('aload'), %*REG<tgt> ));
44454445
$il.append(JAST::Instruction.new( :op('lload'), %*REG<pos> ));
4446-
$il.append($L2I);
4447-
$il.append($DUP);
4448-
$il.append(JAST::PushIndex.new( :value(2) ));
4449-
$il.append($IADD);
4450-
$il.append(JAST::Instruction.new( :op('invokevirtual'),
4451-
$TYPE_STR, 'substring', $TYPE_STR, 'Integer', 'Integer' ));
4452-
$il.append(JAST::PushSVal.new( :value("\r\n") ));
4453-
$il.append(JAST::Instruction.new( :op('invokevirtual'),
4454-
$TYPE_STR, 'equals', 'Z', $TYPE_OBJ ));
4455-
$il.append($I2L);
4456-
$il.append(JAST::Instruction.new( :op('lload'), %*REG<pos> ));
4457-
$il.append($LADD);
4446+
$il.append(JAST::Instruction.new( :op('lload'), %*REG<eos> ));
4447+
$il.append(JAST::Instruction.new( :op('invokestatic'),
4448+
$TYPE_OPS, 'checkcrlf', 'Long', $TYPE_STR, 'Long', 'Long' ));
44584449
$il.append(JAST::Instruction.new( :op('lstore'), %*REG<pos> ));
44594450
}
44604451
}

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,11 @@ public static long iscclass(long cclass, String target, long offset) {
26432643
return 0;
26442644
}
26452645
}
2646-
2646+
2647+
public static long checkcrlf(String tgt, long pos, long eos) {
2648+
return (pos <= eos-2 && tgt.substring((int)pos, ((int) pos)+2).equals("\r\n")) ? pos+1 : pos;
2649+
}
2650+
26472651
public static long findcclass(long cclass, String target, long offset, long count) {
26482652
long length = target.length();
26492653
long end = offset + count;

0 commit comments

Comments
 (0)