Skip to content

Commit f394bee

Browse files
committed
NQP-level support for --target=jar
1 parent cfe397c commit f394bee

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/vm/jvm/HLL/Backend.nqp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HLL::Backend::JVM {
3636
}
3737

3838
method stages() {
39-
'jast classfile jvm'
39+
'jast classfile jar jvm'
4040
}
4141

4242
method is_precomp_stage($stage) {
@@ -60,14 +60,18 @@ class HLL::Backend::JVM {
6060
}
6161

6262
method classfile($jast, *%adverbs) {
63-
if %adverbs<target> eq 'classfile' && %adverbs<output> {
63+
if (%adverbs<target> eq 'classfile' || %adverbs<target> eq 'jar') && %adverbs<output> {
6464
nqp::compilejasttofile($jast.dump(), %adverbs<output>);
6565
nqp::null()
6666
}
6767
else {
6868
nqp::compilejast($jast.dump());
6969
}
7070
}
71+
72+
method jar($cu, *%adverbs) {
73+
$cu; # the actual work is done in classfile and compilejast...
74+
}
7175

7276
method jvm($cu, *%adverbs) {
7377
nqp::loadcompunit($cu, , %adverbs<bootstrap> ?? 1 !! 0)

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,11 @@ class QAST::CompilerJAST {
29422942
# Serialize it.
29432943
my $sh := nqp::list_s();
29442944
my $serialized := nqp::serialize($sc, $sh);
2945+
2946+
if %*COMPILING<%?OPTIONS><target> eq 'jar' {
2947+
$*JCLASS.serialized($serialized);
2948+
$serialized := nqp::null();
2949+
}
29452950

29462951
# Now it's serialized, pop this SC off the compiling SC stack.
29472952
nqp::popcompsc();
@@ -2994,7 +2999,7 @@ class QAST::CompilerJAST {
29942999
),
29953000
QAST::Op.new(
29963001
:op('deserialize'),
2997-
QAST::SVal.new( :value($serialized) ),
3002+
nqp::isnull($serialized) ?? QAST::Op.new( :op('null_s') ) !! QAST::SVal.new( :value($serialized) ),
29983003
QAST::Var.new( :name('cur_sc'), :scope('local') ),
29993004
$sh_ast,
30003005
QAST::Op.new( :op('null') ),

src/vm/jvm/QAST/JASTNodes.nqp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class JAST::Class is JAST::Node {
55
has str $!name;
66
has str $!super;
77
has str $!filename;
8+
has str $!serialized;
89
has @!methods;
910
has @!fields;
1011

@@ -26,13 +27,15 @@ class JAST::Class is JAST::Node {
2627

2728
method name(*@value) { @value ?? ($!name := @value[0]) !! $!name }
2829
method super(*@value) { @value ?? ($!super := @value[0]) !! $!super }
30+
method serialized(*@value) { @value ?? ($!serialized := @value[0]) !! $!serialized }
2931
method methods() { @!methods }
3032

3133
method dump() {
3234
my @dumped;
3335
nqp::push(@dumped, "+ class $!name");
3436
nqp::push(@dumped, "+ super $!super");
3537
nqp::push(@dumped, "+ filename $!filename");
38+
nqp::push(@dumped, "+ serialized $!serialized") unless nqp::isnull_s($!serialized);
3639
for @!fields {
3740
$_.dump(@dumped);
3841
}

0 commit comments

Comments
 (0)