Skip to content

Commit b448059

Browse files
author
Donald Hunter
committed
Add block lex values to the CodeRefAnnotation
This unfortunately blows the classfile size for Rakudo CORE.setting
1 parent 81e37a1 commit b448059

File tree

15 files changed

+41
-3
lines changed

15 files changed

+41
-3
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2755,6 +2755,7 @@ class QAST::CompilerJAST {
27552755
has @!lexical_names; # List by type of lexial name lists
27562756
has int $!num_save_sites; # Count of points where a SaveStackException handler is needed
27572757
has %!local2temp; # Maps local names to temporarization info
2758+
has @!blv;
27582759

27592760
method new($qast, $outer) {
27602761
my $obj := nqp::create(self);
@@ -2773,6 +2774,7 @@ class QAST::CompilerJAST {
27732774
%!lexical_idxs := nqp::hash();
27742775
%!local2temp := nqp::hash();
27752776
@!lexical_names := nqp::list([],[],[],[]);
2777+
@!blv := [];
27762778
}
27772779

27782780
method add_param($var) {
@@ -2795,6 +2797,7 @@ class QAST::CompilerJAST {
27952797
my $flags := $is_static ?? 0 !!
27962798
$is_cont ?? 1 !! 2;
27972799
nqp::push(%blv{$!qast.cuid}, [$var.name, $var.value, $flags]);
2800+
nqp::push(@!blv, [$var.name, $var.value, $flags]);
27982801
}
27992802
@!lexicals[+@!lexicals] := $var;
28002803
}
@@ -2868,6 +2871,7 @@ class QAST::CompilerJAST {
28682871
method lexical_type($name) { %!lexical_types{$name} }
28692872
method lexical_idx($name) { %!lexical_idxs{$name} }
28702873
method lexical_names_by_type() { @!lexical_names }
2874+
method block_lexical_values() { @!blv }
28712875
}
28722876

28732877
my class BlockTempAlloc {
@@ -2992,7 +2996,21 @@ class QAST::CompilerJAST {
29922996
# Now compile $source. By the end of this, the various data structures
29932997
# set up above will be fully populated.
29942998
self.as_jast($source);
2995-
2999+
3000+
# Now fixup all the block lexical values to reference the serialization ids.
3001+
# The array of arrays will end up being a flat array of tuples.
3002+
for $*JCLASS.methods() -> $method {
3003+
my @bits := [];
3004+
for $method.block_lexical_values -> $lex {
3005+
nqp::push(@bits, $lex[0]);
3006+
my $sc := nqp::getobjsc($lex[1]);
3007+
nqp::push(@bits, nqp::scgethandle($sc));
3008+
nqp::push(@bits, ~nqp::scgetobjidx($sc, $lex[1]));
3009+
nqp::push(@bits, ~$lex[2]);
3010+
}
3011+
$method.block_lexical_values(@bits);
3012+
}
3013+
29963014
# Make various code-ref/dispatch related things.
29973015
$*CODEREFS.jastify();
29983016

@@ -3849,7 +3867,9 @@ class QAST::CompilerJAST {
38493867
if $node.is_thunk {
38503868
$*JMETH.is_thunk(1);
38513869
}
3852-
3870+
3871+
$*JMETH.block_lexical_values($block.block_lexical_values);
3872+
38533873
# Finalize method and add it to the class.
38543874
$*JCLASS.add_method($*JMETH);
38553875
}

src/vm/jvm/QAST/JASTNodes.nqp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
class JAST::Node {
23
}
34

@@ -116,6 +117,7 @@ class JAST::Method is JAST::Node {
116117
has int $!has_exit_handler;
117118
has int $!args_expectation;
118119
has int $!is_thunk;
120+
has @!block_lexical_values;
119121

120122
method BUILD(:$name!, :$returns!, :$static = 1) {
121123
$!name := $name;
@@ -132,6 +134,7 @@ class JAST::Method is JAST::Node {
132134
@!cr_nlex := [];
133135
@!cr_slex := [];
134136
@!cr_handlers := [];
137+
@!block_lexical_values := [];
135138
}
136139

137140
method add_argument($name, $type) {
@@ -165,6 +168,7 @@ class JAST::Method is JAST::Node {
165168
method has_exit_handler(*@value) { $!has_exit_handler := @value[0] if @value; $!has_exit_handler }
166169
method args_expectation(*@value) { $!args_expectation := @value[0] if @value; $!args_expectation }
167170
method is_thunk(*@value) { $!is_thunk := @value[0] if @value; $!is_thunk }
171+
method block_lexical_values(*@value) { @value ?? (@!block_lexical_values := @value[0]) !! @!block_lexical_values }
168172

169173
method dump(@dumped) {
170174
nqp::push(@dumped, "+ method");

src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTCompiler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ private void compileMethod(JavaClass jcout, JastMethod method, ClassWriter c, St
186186
if (method.hasExitHandler) av.visit("hasExitHandler", method.hasExitHandler);
187187
if (method.argsExpectation > 0) av.visit("argsExpectation", method.argsExpectation);
188188
if (method.isThunk) av.visit("isThunk", method.isThunk);
189+
190+
if (method.blv.size() > 0) {
191+
avLex = av.visitArray("blockLexValues");
192+
for (String s : method.blv) {
193+
avLex.visit(null, s);
194+
}
195+
avLex.visitEnd();
196+
}
197+
189198
av.visitEnd();
190199
}
191200

src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JastMethod.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class JastMethod {
3535
public boolean hasExitHandler = false;
3636
public short argsExpectation = 0;
3737
public boolean isThunk = false;
38+
public List<String> blv = new ArrayList<String>();
3839

3940
Label beginAll, endAll;
4041
Map<String, LabelInfo> labels = new HashMap<String, LabelInfo>();
@@ -101,6 +102,8 @@ public JastMethod(SixModelObject jast, SixModelObject jastMethod, ThreadContext
101102
} catch (Throwable t) {
102103
/* Most likely a version of the node without the field. */
103104
}
105+
106+
fillList(blv, getattr(jast, jastMethod,"@!block_lexical_values", blvHint, tc), tc);
104107
}
105108

106109
private void fillList(List<String> list, SixModelObject smoList, ThreadContext tc) {
@@ -114,7 +117,7 @@ private void fillList(List<String> list, SixModelObject smoList, ThreadContext t
114117
private static long nameHint, staticHint, returnsHint, argumentsHint,
115118
localsHint, instructionsHint, crNameHint, crCuidHint, crOuterHint,
116119
crOlexHint, crIlexHint, crNlexHint, crSlexHint, crHandlersHint,
117-
hasExitHandlerHint, argsExpectationHint, isThunkHint;
120+
hasExitHandlerHint, argsExpectationHint, isThunkHint,blvHint;
118121
public static void setup(SixModelObject jastMethod, ThreadContext tc) {
119122
nameHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "$!name");
120123
staticHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "$!static");
@@ -133,5 +136,6 @@ public static void setup(SixModelObject jastMethod, ThreadContext tc) {
133136
hasExitHandlerHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "$!has_exit_handler");
134137
argsExpectationHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "$!args_expectation");
135138
isThunkHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "$!is_thunk");
139+
blvHint = jastMethod.st.REPR.hint_for(tc, jastMethod.st, jastMethod, "@!block_lexical_values");
136140
}
137141
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
boolean hasExitHandler() default false;
1818
short argsExpectation() default 0;
1919
boolean isThunk() default false;
20+
String[] blockLexValues() default {};
2021
}

src/vm/jvm/stage0/JASTNodes.jar

1.98 KB
Binary file not shown.

src/vm/jvm/stage0/ModuleLoader.jar

-208 Bytes
Binary file not shown.

src/vm/jvm/stage0/NQPCORE.setting.jar

-74 Bytes
Binary file not shown.

src/vm/jvm/stage0/NQPHLL.jar

173 Bytes
Binary file not shown.

src/vm/jvm/stage0/NQPP6QRegex.jar

-13 KB
Binary file not shown.

0 commit comments

Comments
 (0)