# Backend class for the JVM. use JASTNodes; class HLL::Backend::JVM { our %jvm_config := nqp::backendconfig(); my $compile_count := 0; method config() { %jvm_config } method force_gc() { nqp::force_gc() } method name() { 'jvm' } method nqpevent($spec?) { # Doesn't do anything just yet } method run_profiled($what, $kind, $filename?) { stderr().print("Attach a profiler (e.g. JVisualVM) and press enter"); stdin().get; $what(); } method run_traced($level, $what) { nqp::die("No tracing support"); } method version_string() { "JVM" } method stages() { 'jast classfile jar jvm' } method is_precomp_stage($stage) { $stage eq 'classfile' || $stage eq 'jar' } method is_textual_stage($stage) { 0 } method classname($source, *%adverbs) { unless %*COMPILING<%?OPTIONS> { %*COMPILING<%?OPTIONS> := nqp::sha1(nqp::sha1($source) ~ nqp::time() ~ $compile_count++); } $source } method jast($qast, *%adverbs) { my $classname := %*COMPILING<%?OPTIONS> || nqp::sha1('eval-at-' ~ nqp::time() ~ $compile_count++); nqp::getcomp('QAST').jast($qast, :$classname); } method classfile($jast, *%adverbs) { # TODO: Direct compile ops have to take a hash of name-to-typeobj my %jastnodes := hash(); %jastnodes := JAST::Class; %jastnodes := JAST::Field; %jastnodes := JAST::Method; %jastnodes := JAST::Label; %jastnodes := JAST::Instruction; %jastnodes := JAST::InvokeDynamic; %jastnodes := JAST::InstructionList; %jastnodes := JAST::PushIVal; %jastnodes := JAST::PushNVal; %jastnodes := JAST::PushSVal; %jastnodes := JAST::PushCVal; %jastnodes := JAST::PushIndex; %jastnodes := JAST::TryCatch; %jastnodes := JAST::Annotation; if (%adverbs eq 'classfile' || %adverbs eq 'jar') && %adverbs { nqp::compilejasttofile($jast, %jastnodes, %adverbs); nqp::null() } else { nqp::compilejast($jast, %jastnodes); } } method jar($cu, *%adverbs) { $cu; # the actual work is done in classfile and compilejast... } method jvm($cu, *%adverbs) { nqp::loadcompunit($cu, , %adverbs ?? 1 !! 0) } method is_compunit($cuish) { nqp::iscompunit($cuish) } method compunit_mainline($cu) { nqp::compunitmainline($cu) } method compunit_coderefs($cu) { nqp::compunitcodes($cu) } method supports-op($opname) { 0 # NYI, so give the safe answer } } # Role specifying the default backend for this build. role HLL::Backend::Default { method default_backend() { HLL::Backend::JVM } }