Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implements nqp::exit
  • Loading branch information
thecabinet committed Jan 14, 2013
1 parent 488ad0f commit f76ad1b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/LHF.md
Expand Up @@ -33,8 +33,7 @@ and use the lexical name info as in the contextuals task (this may actually be
a bit easier).

## Process related opcodes
Implement nqp::exit (takes integer exit code) and nqp::sleep (takes double
number of seconds).
Implement nqp::sleep (takes double number of seconds).

## Work out build stuff
At the moment, there's nothing really set up for building the Java bit of
Expand Down
3 changes: 3 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -1148,6 +1148,9 @@ QAST::OperationsJAST.map_classlib_core_op('takeclosure', $TYPE_OPS, 'takeclosure
# language/compiler ops
QAST::OperationsJAST.map_classlib_core_op('sethllconfig', $TYPE_OPS, 'sethllconfig', [$RT_STR, $RT_OBJ], $RT_OBJ, :tc);

# process related opcodes
QAST::OperationsJAST.map_classlib_core_op('exit', $TYPE_OPS, 'exit', [$RT_INT], $RT_INT);

class QAST::CompilerJAST {
# Responsible for handling issues around code references, building the
# switch statement dispatcher, etc.
Expand Down
6 changes: 6 additions & 0 deletions src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -1004,6 +1004,12 @@ public static SixModelObject takeclosure(SixModelObject code, ThreadContext tc)
throw new RuntimeException("takeclosure can only be used with a CodeRef");
}
}

/* process related opcodes */
public static long exit(final long status) {
System.exit((int) status);
return status;
}

/* HLL configuration and compiler related options. */
public static SixModelObject sethllconfig(String language, SixModelObject configHash, ThreadContext tc) {
Expand Down
44 changes: 44 additions & 0 deletions t/qast_process.t
@@ -0,0 +1,44 @@
use helper;

plan(1);

{
my $expected-exit := 123;

my $block := QAST::Block.new(
QAST::Op.new(
:op('exit'),
QAST::IVal.new( :value($expected-exit) )
));
my $jast := QAST::CompilerJAST.jast(
QAST::CompUnit.new(
$block,
:main(QAST::Op.new(
:op('call'),
QAST::BVal.new( :value($block) )
)))
);
my $dump := $jast.dump();
spurt('QAST2JASTOutput.dump', $dump);
my $cps := is_windows() ?? ";" !! ":";
run('java',
'-cp bin' ~ $cps ~ '3rdparty/bcel/bcel-5.2.jar',
'org/perl6/nqp/jast2bc/JASTToJVMBytecode',
'QAST2JASTOutput.dump', 'QAST2JASTOutput.class');
run('java',
'-cp .' ~ $cps ~ 'bin' ~ $cps ~ '3rdparty/bcel/bcel-5.2.jar',
'QAST2JASTOutput');
my $output := pir::spawnw__Is('java -cp .' ~ $cps ~ 'bin' ~ $cps ~ '3rdparty/bcel/bcel-5.2.jar QAST2JASTOutput');
my $exit := pir::shr__Iii($output, 8);

if $exit == $expected-exit {
ok(1, 'exit');
}
else {
ok(0, 'exit');
say("# got: exit $exit");
say("# expected: exit $expected-exit");
}
#unlink('QAST2JASTOutput.dump');
#unlink('QAST2JASTOutput.class');
}

0 comments on commit f76ad1b

Please sign in to comment.