mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 11:12:42 +01:00
compiler_vm: restored stdin input, improved error output, reset vm only on timed-out for improved speed
This commit is contained in:
parent
38166bd14d
commit
b30216d8ec
@ -13,8 +13,8 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 363,
|
BUILD_REVISION => 364,
|
||||||
BUILD_DATE => "2012-02-25",
|
BUILD_DATE => "2012-02-28",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -115,6 +115,7 @@ sub compiler_server {
|
|||||||
while (my $client = $server->accept()) {
|
while (my $client = $server->accept()) {
|
||||||
$client->autoflush(1);
|
$client->autoflush(1);
|
||||||
my $hostinfo = gethostbyaddr($client->peeraddr);
|
my $hostinfo = gethostbyaddr($client->peeraddr);
|
||||||
|
print '-' x 20, "\n";
|
||||||
printf "[Connect from %s]\n", $client->peerhost;
|
printf "[Connect from %s]\n", $client->peerhost;
|
||||||
my $timed_out;
|
my $timed_out;
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ my %languages = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
my %preludes = (
|
my %preludes = (
|
||||||
'C99' => "#define _XOPEN_SOURCE\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdarg.h>\n#include <ctype.h>\n#include <inttypes.h>\n#include <float.h>\n#include <errno.h>\n#include <time.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
'C99' => "#define _XOPEN_SOURCE\n#define __USE_XOPEN\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdarg.h>\n#include <ctype.h>\n#include <inttypes.h>\n#include <float.h>\n#include <errno.h>\n#include <time.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
||||||
'C11' => "#define _XOPEN_SOURCE\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdarg.h>\n#include <stdnoreturn.h>\n#include <stdalign.h>\n#include <ctype.h>\n#include <inttypes.h>\n#include <float.h>\n#include <errno.h>\n#include <time.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
'C11' => "#define _XOPEN_SOURCE\n#define __USE_XOPEN\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <stdbool.h>\n#include <stddef.h>\n#include <stdarg.h>\n#include <stdnoreturn.h>\n#include <stdalign.h>\n#include <ctype.h>\n#include <inttypes.h>\n#include <float.h>\n#include <errno.h>\n#include <time.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
||||||
'C' => "#define _XOPEN_SOURCE\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <errno.h>\n#include <ctype.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
'C' => "#define _XOPEN_SOURCE\n#define __USE_XOPEN\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <math.h>\n#include <limits.h>\n#include <sys/types.h>\n#include <stdint.h>\n#include <errno.h>\n#include <ctype.h>\n#include <assert.h>\n#include <prelude.h>\n\n",
|
||||||
);
|
);
|
||||||
|
|
||||||
sub pretty {
|
sub pretty {
|
||||||
@ -655,7 +655,7 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
|
|||||||
$ret =~ s/^\s+//;
|
$ret =~ s/^\s+//;
|
||||||
$ret =~ s/\s+$//;
|
$ret =~ s/\s+$//;
|
||||||
|
|
||||||
if($ret eq "else" or $ret eq "while") {
|
if(not length $ret or $ret eq "else" or $ret eq "while" or $ret eq "if" or $ret eq "for" or $ident eq "for" or $ident eq "while" or $ident eq "if") {
|
||||||
$precode .= "$ret $ident ($params) $potential_body";
|
$precode .= "$ret $ident ($params) $potential_body";
|
||||||
next;
|
next;
|
||||||
} else {
|
} else {
|
||||||
@ -681,6 +681,8 @@ if($lang eq 'C' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') {
|
|||||||
$precode =~ s/^\s+//;
|
$precode =~ s/^\s+//;
|
||||||
$precode =~ s/\s+$//;
|
$precode =~ s/\s+$//;
|
||||||
|
|
||||||
|
$precode =~ s/^{(.*)}$/$1/s;
|
||||||
|
|
||||||
if(not $has_main) {
|
if(not $has_main) {
|
||||||
$code = "$prelude\n\n$code\n\nint main(int argc, char **argv) {\n$precode\n;\nreturn 0;\n}\n";
|
$code = "$prelude\n\n$code\n\nint main(int argc, char **argv) {\n$precode\n;\nreturn 0;\n}\n";
|
||||||
$nooutput = "No warnings, errors or output.";
|
$nooutput = "No warnings, errors or output.";
|
||||||
@ -704,6 +706,7 @@ my $single_quote = 0;
|
|||||||
my $double_quote = 0;
|
my $double_quote = 0;
|
||||||
my $parens = 0;
|
my $parens = 0;
|
||||||
my $escaped = 0;
|
my $escaped = 0;
|
||||||
|
my $cpp = 0; # preprocessor
|
||||||
|
|
||||||
while($code =~ m/(.)/msg) {
|
while($code =~ m/(.)/msg) {
|
||||||
my $ch = $1;
|
my $ch = $1;
|
||||||
@ -713,6 +716,8 @@ while($code =~ m/(.)/msg) {
|
|||||||
|
|
||||||
if($ch eq '\\') {
|
if($ch eq '\\') {
|
||||||
$escaped = not $escaped;
|
$escaped = not $escaped;
|
||||||
|
} elsif($ch eq '#' and not $cpp and not $escaped and not $single_quote and not $double_quote) {
|
||||||
|
$cpp = 1;
|
||||||
} elsif($ch eq '"') {
|
} elsif($ch eq '"') {
|
||||||
$double_quote = not $double_quote unless $escaped;
|
$double_quote = not $double_quote unless $escaped;
|
||||||
$escaped = 0;
|
$escaped = 0;
|
||||||
@ -731,13 +736,14 @@ while($code =~ m/(.)/msg) {
|
|||||||
$escaped = 0;
|
$escaped = 0;
|
||||||
} elsif($ch eq 'n' and $escaped) {
|
} elsif($ch eq 'n' and $escaped) {
|
||||||
substr ($code, $pos - 2, 2) = "\n" and pos $code = $pos unless $single_quote or $double_quote;
|
substr ($code, $pos - 2, 2) = "\n" and pos $code = $pos unless $single_quote or $double_quote;
|
||||||
|
$cpp = 0 unless $single_quote or $double_quote;
|
||||||
$escaped = 0;
|
$escaped = 0;
|
||||||
} elsif($ch eq '{' and not $single_quote and not $double_quote) {
|
} elsif($ch eq '{' and not $cpp and not $single_quote and not $double_quote) {
|
||||||
if(not substr($code, $pos, 1) =~ m/[\n\r]/) {
|
if(not substr($code, $pos, 1) =~ m/[\n\r]/) {
|
||||||
substr ($code, $pos, 0) = "\n";
|
substr ($code, $pos, 0) = "\n";
|
||||||
pos $code = $pos + 1;
|
pos $code = $pos + 1;
|
||||||
}
|
}
|
||||||
} elsif($ch eq '}' and not $single_quote and not $double_quote) {
|
} elsif($ch eq '}' and not $cpp and not $single_quote and not $double_quote) {
|
||||||
if(not substr($code, $pos, 1) =~ m/[\n\r;]/) {
|
if(not substr($code, $pos, 1) =~ m/[\n\r;]/) {
|
||||||
substr ($code, $pos, 0) = "\n";
|
substr ($code, $pos, 0) = "\n";
|
||||||
pos $code = $pos + 1;
|
pos $code = $pos + 1;
|
||||||
@ -752,7 +758,7 @@ $code =~ s/(?:\n\n)+/\n\n/g;
|
|||||||
print "final code: [$code]\n" if $debug;
|
print "final code: [$code]\n" if $debug;
|
||||||
|
|
||||||
if(defined $got_run and $got_run eq "paste") {
|
if(defined $got_run and $got_run eq "paste") {
|
||||||
my $uri = paste_codepad(pretty($code));
|
my $uri = paste_sprunge(pretty($code));
|
||||||
print "$nick: $uri\n";
|
print "$nick: $uri\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
@ -770,6 +776,7 @@ if($output =~ m/^\s*$/) {
|
|||||||
print FILE localtime() . "\n";
|
print FILE localtime() . "\n";
|
||||||
print FILE "$output\n";
|
print FILE "$output\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$output =~ s/cc1: warnings being treated as errors//;
|
$output =~ s/cc1: warnings being treated as errors//;
|
||||||
$output =~ s/ Line \d+ ://g;
|
$output =~ s/ Line \d+ ://g;
|
||||||
$output =~ s/ \(first use in this function\)//g;
|
$output =~ s/ \(first use in this function\)//g;
|
||||||
@ -782,7 +789,6 @@ if($output =~ m/^\s*$/) {
|
|||||||
$output =~ s/\(\.text\+[^)]+\)://g;
|
$output =~ s/\(\.text\+[^)]+\)://g;
|
||||||
$output =~ s/\[ In/[In/;
|
$output =~ s/\[ In/[In/;
|
||||||
$output =~ s/warning: Can't read pathname for load map: Input.output error.//g;
|
$output =~ s/warning: Can't read pathname for load map: Input.output error.//g;
|
||||||
|
|
||||||
my $left_quote = chr(226) . chr(128) . chr(152);
|
my $left_quote = chr(226) . chr(128) . chr(152);
|
||||||
my $right_quote = chr(226) . chr(128) . chr(153);
|
my $right_quote = chr(226) . chr(128) . chr(153);
|
||||||
$output =~ s/$left_quote/'/g;
|
$output =~ s/$left_quote/'/g;
|
||||||
@ -810,6 +816,10 @@ if($output =~ m/^\s*$/) {
|
|||||||
$output =~ s/^======= Backtrace.*\[vsyscall\]\s*$//ms;
|
$output =~ s/^======= Backtrace.*\[vsyscall\]\s*$//ms;
|
||||||
$output =~ s/glibc detected \*\*\* \/home\/compiler\/prog: //;
|
$output =~ s/glibc detected \*\*\* \/home\/compiler\/prog: //;
|
||||||
$output =~ s/: \/home\/compiler\/prog terminated//;
|
$output =~ s/: \/home\/compiler\/prog terminated//;
|
||||||
|
$output =~ s/<Defined at \/home\/compiler\/>/<Defined at \/home\/compiler\/prog.c:0>/g;
|
||||||
|
$output =~ s/\s*In file included from\s+\/usr\/include\/.*?:\d+:\d+:\s*/, /g;
|
||||||
|
$output =~ s/\s*collect2: error: ld returned 1 exit status//g;
|
||||||
|
$output =~ s/In function\s*`main':\s*\/home\/compiler\/ undefined reference to/error: undefined reference to/g;
|
||||||
}
|
}
|
||||||
|
|
||||||
unless($got_run) {
|
unless($got_run) {
|
||||||
|
@ -5,7 +5,10 @@ use strict;
|
|||||||
|
|
||||||
use IPC::Open2;
|
use IPC::Open2;
|
||||||
|
|
||||||
my $stdin_input = join ' ', @ARGV;
|
my $stdin_input = (join ' ', @ARGV) || "Lorem ipsum dolor sit amet.\n";
|
||||||
|
open my $fh, '>', '.input' or die "Couldn't open .input: $!";
|
||||||
|
print $fh $stdin_input;
|
||||||
|
close $fh;
|
||||||
|
|
||||||
my $debug = 0;
|
my $debug = 0;
|
||||||
|
|
||||||
@ -80,7 +83,7 @@ sub execute {
|
|||||||
gdb $in, "break $break\n";
|
gdb $in, "break $break\n";
|
||||||
gdb $in, "set width 0\n";
|
gdb $in, "set width 0\n";
|
||||||
gdb $in, "set height 0\n";
|
gdb $in, "set height 0\n";
|
||||||
gdb $in, "run\n";
|
gdb $in, "run < .input\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user