mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-29 23:39:24 +01:00
Refactoring compiler_vm a bit (2/2)
This commit is contained in:
parent
069522f154
commit
3b4a6c929a
@ -96,8 +96,14 @@ sub run_server {
|
|||||||
|
|
||||||
my $compile_in = decode_json($line);
|
my $compile_in = decode_json($line);
|
||||||
|
|
||||||
|
$compile_in->{arguments} //= '';
|
||||||
|
$compile_in->{input} //= '';
|
||||||
|
|
||||||
print "Attempting compile [$compile_in->{lang}] ...\n";
|
print "Attempting compile [$compile_in->{lang}] ...\n";
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
print Dumper $compile_in;
|
||||||
|
|
||||||
my $pid = fork;
|
my $pid = fork;
|
||||||
|
|
||||||
if (not defined $pid) {
|
if (not defined $pid) {
|
||||||
@ -180,8 +186,6 @@ sub run_server {
|
|||||||
sub interpret {
|
sub interpret {
|
||||||
my %h = @_;
|
my %h = @_;
|
||||||
|
|
||||||
print "lang: [$h{lang}], sourcefile: [$h{sourcefile}], execfile [$h{execfile}], code: [$h{code}], cmdline: [$h{cmdline}], input: [$h{input}], date: [$h{date}]\n";
|
|
||||||
|
|
||||||
$h{lang} = '_default' if not exists $languages{$h{lang}};
|
$h{lang} = '_default' if not exists $languages{$h{lang}};
|
||||||
|
|
||||||
chdir("/home/compiler");
|
chdir("/home/compiler");
|
||||||
|
@ -27,6 +27,12 @@ my ($main_start, $main_end);
|
|||||||
sub flushall;
|
sub flushall;
|
||||||
sub gdb;
|
sub gdb;
|
||||||
|
|
||||||
|
my $cmdlineargs = '';
|
||||||
|
foreach my $arg (@ARGV) {
|
||||||
|
$arg =~ s/'/'"'"'/g;
|
||||||
|
$cmdlineargs .= "'$arg' ";
|
||||||
|
}
|
||||||
|
|
||||||
my ($out, $in);
|
my ($out, $in);
|
||||||
|
|
||||||
sub getlocals {
|
sub getlocals {
|
||||||
@ -79,7 +85,7 @@ sub execute {
|
|||||||
next if not length $line;
|
next if not length $line;
|
||||||
<$out> and next if $line =~ m/^\(gdb\) No line \d+ in/;
|
<$out> and next if $line =~ m/^\(gdb\) No line \d+ in/;
|
||||||
next if $line =~ m/^\(gdb\) No symbol table/;
|
next if $line =~ m/^\(gdb\) No symbol table/;
|
||||||
next if $line =~ m/^\[Detaching from/;
|
next if $line =~ m/^\[Detaching after/;
|
||||||
next if $line =~ m/^\[New Thread/;
|
next if $line =~ m/^\[New Thread/;
|
||||||
next if $line =~ m/^\(gdb\) Continuing/;
|
next if $line =~ m/^\(gdb\) Continuing/;
|
||||||
next if $line =~ m/^\(gdb\) \$\d+ = "~Ok\.~"/;
|
next if $line =~ m/^\(gdb\) \$\d+ = "~Ok\.~"/;
|
||||||
@ -138,7 +144,7 @@ sub execute {
|
|||||||
gdb $in, "set height 0\n";
|
gdb $in, "set height 0\n";
|
||||||
# gdb $in, "set auto-solib-add off\n";
|
# gdb $in, "set auto-solib-add off\n";
|
||||||
gdb $in, "catch exec\n";
|
gdb $in, "catch exec\n";
|
||||||
gdb $in, "run @ARGV < .input\n";
|
gdb $in, "run $cmdlineargs < .input\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +158,7 @@ sub execute {
|
|||||||
my $sep = '';
|
my $sep = '';
|
||||||
foreach my $var (keys %$locals_end) {
|
foreach my $var (keys %$locals_end) {
|
||||||
print "checking local $var...\n" if $debug >= 4;
|
print "checking local $var...\n" if $debug >= 4;
|
||||||
|
$locals_start->{$var} //= '';
|
||||||
if ($locals_start->{$var} ne $locals_end->{$var}) {
|
if ($locals_start->{$var} ne $locals_end->{$var}) {
|
||||||
$local_vars .= "$sep$var = $locals_end->{$var}";
|
$local_vars .= "$sep$var = $locals_end->{$var}";
|
||||||
$sep = '; ';
|
$sep = '; ';
|
||||||
|
@ -222,11 +222,6 @@ sub show_output {
|
|||||||
$pretty_code .= $output_closing_comment;
|
$pretty_code .= $output_closing_comment;
|
||||||
|
|
||||||
my $uri = $self->paste_ixio($pretty_code);
|
my $uri = $self->paste_ixio($pretty_code);
|
||||||
|
|
||||||
if (not $uri =~ m/^http/) {
|
|
||||||
$uri = $self->paste_ptpb($pretty_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
print "$uri\n";
|
print "$uri\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
@ -283,30 +278,6 @@ sub paste_ixio {
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub paste_ptpb {
|
|
||||||
my $self = shift;
|
|
||||||
my $text = join(' ', @_);
|
|
||||||
|
|
||||||
$text =~ s/(.{120})\s/$1\n/g;
|
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new();
|
|
||||||
$ua->agent("Mozilla/5.0");
|
|
||||||
$ua->requests_redirectable([ ]);
|
|
||||||
$ua->timeout(10);
|
|
||||||
|
|
||||||
my %post = ( 'c' => $text, 'submit' => 'Submit' );
|
|
||||||
my $response = $ua->post("https://ptpb.pw/?u=1", \%post);
|
|
||||||
|
|
||||||
if(not $response->is_success) {
|
|
||||||
return "error pasting: " . $response->status_line;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $result = $response->content;
|
|
||||||
$result =~ s/^\s+//;
|
|
||||||
$result =~ s/\s+$//;
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub execute {
|
sub execute {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
@ -14,10 +14,6 @@ sub initialize {
|
|||||||
$self->{default_options} = '';
|
$self->{default_options} = '';
|
||||||
$self->{cmdline} = 'sh $options $sourcefile';
|
$self->{cmdline} = 'sh $options $sourcefile';
|
||||||
|
|
||||||
if (length $self->{arguments}) {
|
|
||||||
$self->{cmdline} .= " $self->{arguments}";
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n";
|
$self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n";
|
||||||
$self->{cmdline_closing_comment} = "____CMDLINE____\n";
|
$self->{cmdline_closing_comment} = "____CMDLINE____\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user