Permalink
Browse files

Perlito5 - set exit code on error

  • Loading branch information...
1 parent eab75f8 commit 7c5dd3bcbf26523a9daba1f8fa80d57d76418032 @fglock committed Apr 20, 2012
Showing with 14 additions and 4 deletions.
  1. +2 −2 ChangeLog
  2. +4 −0 html/perlito5.js
  3. +1 −1 lib5/Perlito5/Javascript/IO.pm
  4. +2 −1 perlito5.pl
  5. +4 −0 src5/lib/Perlito5/Javascript/IO.pm
  6. +1 −0 src5/util/perlito5.pl
View
@@ -15,8 +15,8 @@ dev 2012-04-12
- javascript backend:
-- negative index in array
--- more file operations: chdir, unlink, close
--- functions: rand
+-- more file and process operations: chdir, unlink, close, exit
+-- more functions: rand
* Perlito6 (Perl 6 compiler):
View
@@ -1015,6 +1015,10 @@ if (isNode) {
}
};
+ CORE.exit = function(List__) {
+ process.exit(List__[0]);
+ };
+
CORE.rename = function(List__) {
try {
fs.renameSync(p5str(List__[0]), p5str(List__[1]));
@@ -5,7 +5,7 @@ package main;
use v5;
package Perlito5::Javascript::IO;
sub Perlito5::Javascript::IO::emit_javascript {
- return ((('//' . chr(10) . '//' . chr(10) . '// lib/Perlito5/Javascript/IO.js' . chr(10) . '//' . chr(10) . '// I/O functions for "Perlito" Perl5-in-Javascript' . chr(10) . '//' . chr(10) . '// AUTHORS' . chr(10) . '//' . chr(10) . '// Flavio Soibelmann Glock fglock@gmail.com' . chr(10) . '//' . chr(10) . '// COPYRIGHT' . chr(10) . '//' . chr(10) . '// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.' . chr(10) . '//' . chr(10) . '// This program is free software; you can redistribute it and/or modify it' . chr(10) . '// under the same terms as Perl itself.' . chr(10) . '//' . chr(10) . '// See http://www.perl.com/perl/misc/Artistic.html' . chr(10) . chr(10) . 'var isNode = typeof require != "undefined";' . chr(10) . 'if (isNode) {' . chr(10) . chr(10) . ' var fs = require("fs");' . chr(10) . chr(10) . ' p5atime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["atime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5mtime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["mtime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5ctime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["ctime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5size = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["size"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5is_file = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat.isFile() ? 1 : 0;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5is_directory = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat.isDirectory() ? 1 : 0;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5file_exists = function(s) {' . chr(10) . ' return p5is_file(s) || p5is_directory(s);' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.chdir = function(List__) {' . chr(10) . ' try {' . chr(10) . ' process.chdir(p5str(List__[0]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.close = function(List__) {' . chr(10) . ' try {' . chr(10) . ' fs.closeSync(p5str(List__[0]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.rename = function(List__) {' . chr(10) . ' try {' . chr(10) . ' fs.renameSync(p5str(List__[0]), p5str(List__[1]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.unlink = function(List__) {' . chr(10) . ' var count = 0;' . chr(10) . ' try {' . chr(10) . ' for(var i = 0; i < List__.length; i++) {' . chr(10) . ' fs.unlinkSync(p5str(List__[i]));' . chr(10) . ' count++;' . chr(10) . ' }' . chr(10) . ' return count;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return count;' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . '}' . chr(10) . chr(10))))
+ return ((('//' . chr(10) . '//' . chr(10) . '// lib/Perlito5/Javascript/IO.js' . chr(10) . '//' . chr(10) . '// I/O functions for "Perlito" Perl5-in-Javascript' . chr(10) . '//' . chr(10) . '// AUTHORS' . chr(10) . '//' . chr(10) . '// Flavio Soibelmann Glock fglock@gmail.com' . chr(10) . '//' . chr(10) . '// COPYRIGHT' . chr(10) . '//' . chr(10) . '// Copyright 2009, 2010, 2011, 2012 by Flavio Soibelmann Glock and others.' . chr(10) . '//' . chr(10) . '// This program is free software; you can redistribute it and/or modify it' . chr(10) . '// under the same terms as Perl itself.' . chr(10) . '//' . chr(10) . '// See http://www.perl.com/perl/misc/Artistic.html' . chr(10) . chr(10) . 'var isNode = typeof require != "undefined";' . chr(10) . 'if (isNode) {' . chr(10) . chr(10) . ' var fs = require("fs");' . chr(10) . chr(10) . ' p5atime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["atime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5mtime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["mtime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5ctime = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["ctime"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5size = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat["size"];' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5is_file = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat.isFile() ? 1 : 0;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5is_directory = function(s) {' . chr(10) . ' try {' . chr(10) . ' var stat = fs.statSync(s); return stat.isDirectory() ? 1 : 0;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . ' p5file_exists = function(s) {' . chr(10) . ' return p5is_file(s) || p5is_directory(s);' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.chdir = function(List__) {' . chr(10) . ' try {' . chr(10) . ' process.chdir(p5str(List__[0]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.close = function(List__) {' . chr(10) . ' try {' . chr(10) . ' fs.closeSync(p5str(List__[0]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.exit = function(List__) {' . chr(10) . ' process.exit(List__[0]);' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.rename = function(List__) {' . chr(10) . ' try {' . chr(10) . ' fs.renameSync(p5str(List__[0]), p5str(List__[1]));' . chr(10) . ' return 1;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return ' . chr(39) . chr(39) . ';' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . ' CORE.unlink = function(List__) {' . chr(10) . ' var count = 0;' . chr(10) . ' try {' . chr(10) . ' for(var i = 0; i < List__.length; i++) {' . chr(10) . ' fs.unlinkSync(p5str(List__[i]));' . chr(10) . ' count++;' . chr(10) . ' }' . chr(10) . ' return count;' . chr(10) . ' }' . chr(10) . ' catch(err) {' . chr(10) . ' p5pkg["main"]["v_!"] = err;' . chr(10) . ' return count;' . chr(10) . ' }' . chr(10) . ' };' . chr(10) . chr(10) . '}' . chr(10) . chr(10))))
};
1;
View
@@ -132,7 +132,8 @@ package Perlito;
(do { my $m = Perlito5::Grammar->exp_stmts("do {" . ('package main; no strict; ' . $source . ' ; $ok = 1') . "}", 0);my $source = Perlito5::Match::flat($m)->[0]->emit_perl5(0, "scalar");eval $source;});
if (!($ok)) {
((my $error) = ($@ || 'Unknown error'));
- warn($error)
+ warn($error);
+ exit(255)
}
}
else {
@@ -102,6 +102,10 @@ if (isNode) {
}
};
+ CORE.exit = function(List__) {
+ process.exit(List__[0]);
+ };
+
CORE.rename = function(List__) {
try {
fs.renameSync(p5str(List__[0]), p5str(List__[1]));
@@ -144,6 +144,7 @@ package Perlito;
my $error = $@
|| "Unknown error";
warn $error;
+ exit(255);
}
}
else {

0 comments on commit 7c5dd3b

Please sign in to comment.