Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support long string literals.
Turns out the serialization blob hit the limit.
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent fb2d288 commit 37e267c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/QAST/JASTCompiler.nqp
Expand Up @@ -3119,7 +3119,31 @@ class QAST::CompilerJAST {
}

multi method as_jast(QAST::SVal $node, :$want) {
result(JAST::PushSVal.new( :value($node.value) ), $RT_STR)
if nqp::chars($node.value) <= 65535 {
result(JAST::PushSVal.new( :value($node.value) ), $RT_STR)
}
else {
my @chunks;
my $value := $node.value;
while nqp::chars($value) > 65535 {
nqp::push(@chunks, nqp::substr($value, 0, 65535));
$value := nqp::substr($value, 65535);
}
nqp::push(@chunks, $value);
my $il := JAST::InstructionList.new();
$il.append(JAST::PushIndex.new( :value(nqp::elems(@chunks)) ));
$il.append(JAST::Instruction.new( :op('newarray'), $TYPE_STR ));
my int $i := 0;
for @chunks {
$il.append(JAST::Instruction.new( :op('dup') ));
$il.append(JAST::PushIndex.new( :value($i++) ));
$il.append(JAST::PushSVal.new( :value($_) ));
$il.append(JAST::Instruction.new( :op('aastore') ));
}
$il.append(JAST::Instruction.new( :op('invokestatic'),
$TYPE_OPS, 'join_literal', $TYPE_STR, "[$TYPE_STR" ));
result($il, $RT_STR)
}
}

multi method as_jast(QAST::BVal $node, :$want) {
Expand Down
8 changes: 8 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -3077,4 +3077,12 @@ public static String coerce_i2s(long in) {
public static String coerce_n2s(double in) {
return in == (long)in ? Long.toString((long)in) : Double.toString(in);
}

/* Long literal workaround. */
public static String join_literal(String[] parts) {
StringBuilder retval = new StringBuilder(parts.length * 65535);
for (int i = 0; i < parts.length; i++)
retval.append(parts[i]);
return retval.toString();
}
}

0 comments on commit 37e267c

Please sign in to comment.