Skip to content

Commit

Permalink
Flesh out backend compilation stages.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Feb 27, 2013
1 parent fd60679 commit 9819d20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 15 additions & 1 deletion lib/QAST/JASTCompiler.nqp
Expand Up @@ -1117,9 +1117,17 @@ sub process_args($qastcomp, $node, $il, $first, :$inv_temp) {
# Return callsite index (which may create it if needed).
return $*CODEREFS.get_callsite_idx(@callsite, @argnames);
}
QAST::OperationsJAST.add_core_op('call', -> $qastcomp, $node {
QAST::OperationsJAST.add_core_op('call', sub ($qastcomp, $node) {
my $il := JAST::InstructionList.new();

# Small hack for JVM-specific ops until we have a better way.
if $node.name ne "" && nqp::substr($node.name, 0, 8) eq '&__JVM__' {
return $qastcomp.as_jast(QAST::Op.new(
:op(nqp::substr($node.name, 8)),
|$node.list
));
}

# Get thing to call.
my $invokee;
if $node.name ne "" {
Expand Down Expand Up @@ -1853,6 +1861,12 @@ QAST::OperationsJAST.map_classlib_core_op('nfarunalt', $TYPE_OPS, 'nfarunalt', [
QAST::OperationsJAST.map_classlib_core_op('exit', $TYPE_OPS, 'exit', [$RT_INT], $RT_INT);
QAST::OperationsJAST.map_classlib_core_op('sleep', $TYPE_OPS, 'sleep', [$RT_NUM], $RT_NUM);

# JVM-specific ops for compilation unit handling
QAST::OperationsJAST.map_classlib_core_op('compilejast', $TYPE_OPS, 'compilejast', [$RT_STR], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('loadcompunit', $TYPE_OPS, 'loadcompunit', [$RT_OBJ], $RT_OBJ, :tc);
QAST::OperationsJAST.map_classlib_core_op('iscompunit', $TYPE_OPS, 'iscompunit', [$RT_OBJ], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('compunitmainline', $TYPE_OPS, 'compunitmainline', [$RT_OBJ], $RT_OBJ, :tc);

class QAST::CompilerJAST {
# Responsible for handling issues around code references, building the
# switch statement dispatcher, etc.
Expand Down
16 changes: 8 additions & 8 deletions nqp-src/NQPHLL.pm
Expand Up @@ -910,24 +910,23 @@ class HLL::Backend::JVM {
}

method jast($qast, *%adverbs) {
nqp::getcomp('qast').jast($qast, :classname(%*COMPILING<%?OPTIONS><javaclass>));
nqp::getcomp('qast').jast($qast, :classname(nqp::sha1('eval-at-' ~ nqp::time_n())));
}

method classfile($jast, *%adverbs) {
say($jast.dump());
nqp::die("NYI");
__JVM__compilejast($jast.dump());
}

method jvm($class, *%adverbs) {
nqp::die("NYI");
method jvm($cu, *%adverbs) {
__JVM__loadcompunit($cu)
}

method is_compunit($cuish) {
0
__JVM__iscompunit($cuish)
}

method compunit_mainline($cu) {
nqp::die("NYI");
__JVM__compunitmainline($cu)
}

method compunit_coderefs($cu) {
Expand Down Expand Up @@ -1072,8 +1071,9 @@ class HLL::Compiler does HLL::Backend::Default {

if $!backend.is_compunit($output) && %adverbs<target> eq '' {
my $outer_ctx := %adverbs<outer_ctx>;
$output := $!backend.compunit_mainline($output);
if nqp::defined($outer_ctx) {
nqp::forceouterctx($!backend.compunit_mainline($output), $outer_ctx);
nqp::forceouterctx($output, $outer_ctx);
}

if (%adverbs<profile>) {
Expand Down

0 comments on commit 9819d20

Please sign in to comment.