Permalink
Browse files

use nqp::spawn()

  • Loading branch information...
1 parent 55ff4fc commit ea5c22fa5a66bdd5d9e40c5e61cae792b00d8da5 @FROGGS FROGGS committed Oct 29, 2013
Showing with 36 additions and 26 deletions.
  1. +27 −0 src/core/OS.pm
  2. +9 −26 src/core/control.pm
View
27 src/core/OS.pm
@@ -1,3 +1,30 @@
sub gethostname( --> Str){
return nqp::p6box_s(nqp::gethostname());
}
+
+my class Proc::Status {
+ has $.exit;
+ has $.pid;
+ has $.signal;
+
+ #~ method exit() { $!exit }
+ #~ method pid() { $!pid }
+ #~ method signal() { $!signal }
+
+ proto method status(|) { * }
+ multi method status($new_status) {
+ $!exit = $new_status +> 8;
+ $!signal = $new_status +& 0xFF;
+ }
+ multi method status() {
+ ($!exit +< 8) +| $!signal
+ }
+
+ method Numeric {
+ $!exit
+ }
+
+ method Bool {
+ $!exit == 0
+ }
+}
View
35 src/core/control.pm
@@ -166,43 +166,26 @@ sub exit($status = 0) {
$status;
}
+my class Proc::Status { ... }
+
sub run(*@args ($, *@)) {
- my $error_code;
+ my $status = Proc::Status.new( :exit(255) );
try {
-#?if parrot
- nqp::chdir($*CWD);
- $error_code = nqp::p6box_i(
- pir::spawnw__IP(
- nqp::getattr(
- @args.eager,
- List,
- '$!items'
- )
- )
- ) +> 8;
-#?endif
-#?if !parrot
my Mu $hash := nqp::getattr(%*ENV, EnumMap, '$!storage');
- $error_code = nqp::p6box_i(
+ $status.status( nqp::p6box_i(
nqp::spawn(nqp::getattr(@args.eager, List, '$!items'), $*CWD.Str, $hash)
- ) +> 8;
-#?endif
- CATCH {
- default {
- $error_code = 1;
- }
- }
+ ) );
}
- $error_code but !$error_code;
+ $status
}
sub shell($cmd) {
- my $status = 255;
+ my $status = Proc::Status.new( :exit(255) );
try {
my Mu $hash := nqp::getattr(%*ENV, EnumMap, '$!storage');
- $status = nqp::p6box_i(nqp::shell($cmd, $*CWD.Str, $hash));
+ $status.status( nqp::p6box_i(nqp::shell($cmd, $*CWD.Str, $hash)) );
}
- $status;
+ $status
}
# XXX: Temporary definition of $Inf and $NaN until we have constants ava

0 comments on commit ea5c22f

Please sign in to comment.