Skip to content

Commit

Permalink
NQP-level support for --target=jar
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jun 21, 2013
1 parent cfe397c commit f394bee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/vm/jvm/HLL/Backend.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HLL::Backend::JVM {
}

method stages() {
'jast classfile jvm'
'jast classfile jar jvm'
}

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

method classfile($jast, *%adverbs) {
if %adverbs<target> eq 'classfile' && %adverbs<output> {
if (%adverbs<target> eq 'classfile' || %adverbs<target> eq 'jar') && %adverbs<output> {
nqp::compilejasttofile($jast.dump(), %adverbs<output>);
nqp::null()
}
else {
nqp::compilejast($jast.dump());
}
}

method jar($cu, *%adverbs) {
$cu; # the actual work is done in classfile and compilejast...
}

method jvm($cu, *%adverbs) {
nqp::loadcompunit($cu, , %adverbs<bootstrap> ?? 1 !! 0)
Expand Down
7 changes: 6 additions & 1 deletion src/vm/jvm/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2942,6 +2942,11 @@ class QAST::CompilerJAST {
# Serialize it.
my $sh := nqp::list_s();
my $serialized := nqp::serialize($sc, $sh);

if %*COMPILING<%?OPTIONS><target> eq 'jar' {
$*JCLASS.serialized($serialized);
$serialized := nqp::null();
}

# Now it's serialized, pop this SC off the compiling SC stack.
nqp::popcompsc();
Expand Down Expand Up @@ -2994,7 +2999,7 @@ class QAST::CompilerJAST {
),
QAST::Op.new(
:op('deserialize'),
QAST::SVal.new( :value($serialized) ),
nqp::isnull($serialized) ?? QAST::Op.new( :op('null_s') ) !! QAST::SVal.new( :value($serialized) ),
QAST::Var.new( :name('cur_sc'), :scope('local') ),
$sh_ast,
QAST::Op.new( :op('null') ),
Expand Down
3 changes: 3 additions & 0 deletions src/vm/jvm/QAST/JASTNodes.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class JAST::Class is JAST::Node {
has str $!name;
has str $!super;
has str $!filename;
has str $!serialized;
has @!methods;
has @!fields;

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

method name(*@value) { @value ?? ($!name := @value[0]) !! $!name }
method super(*@value) { @value ?? ($!super := @value[0]) !! $!super }
method serialized(*@value) { @value ?? ($!serialized := @value[0]) !! $!serialized }
method methods() { @!methods }

method dump() {
my @dumped;
nqp::push(@dumped, "+ class $!name");
nqp::push(@dumped, "+ super $!super");
nqp::push(@dumped, "+ filename $!filename");
nqp::push(@dumped, "+ serialized $!serialized") unless nqp::isnull_s($!serialized);
for @!fields {
$_.dump(@dumped);
}
Expand Down

0 comments on commit f394bee

Please sign in to comment.