Refactoring compiler_vm a bit (2/2)

This commit is contained in:
Pragmatic Software 2019-06-14 18:49:33 -07:00
parent 069522f154
commit 3b4a6c929a
4 changed files with 15 additions and 37 deletions

View File

@ -96,8 +96,14 @@ sub run_server {
my $compile_in = decode_json($line);
$compile_in->{arguments} //= '';
$compile_in->{input} //= '';
print "Attempting compile [$compile_in->{lang}] ...\n";
use Data::Dumper;
print Dumper $compile_in;
my $pid = fork;
if (not defined $pid) {
@ -180,8 +186,6 @@ sub run_server {
sub interpret {
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}};
chdir("/home/compiler");

View File

@ -27,6 +27,12 @@ my ($main_start, $main_end);
sub flushall;
sub gdb;
my $cmdlineargs = '';
foreach my $arg (@ARGV) {
$arg =~ s/'/'"'"'/g;
$cmdlineargs .= "'$arg' ";
}
my ($out, $in);
sub getlocals {
@ -79,7 +85,7 @@ sub execute {
next if not length $line;
<$out> and next if $line =~ m/^\(gdb\) No line \d+ in/;
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/^\(gdb\) Continuing/;
next if $line =~ m/^\(gdb\) \$\d+ = "~Ok\.~"/;
@ -138,7 +144,7 @@ sub execute {
gdb $in, "set height 0\n";
# gdb $in, "set auto-solib-add off\n";
gdb $in, "catch exec\n";
gdb $in, "run @ARGV < .input\n";
gdb $in, "run $cmdlineargs < .input\n";
next;
}
@ -152,6 +158,7 @@ sub execute {
my $sep = '';
foreach my $var (keys %$locals_end) {
print "checking local $var...\n" if $debug >= 4;
$locals_start->{$var} //= '';
if ($locals_start->{$var} ne $locals_end->{$var}) {
$local_vars .= "$sep$var = $locals_end->{$var}";
$sep = '; ';

View File

@ -222,11 +222,6 @@ sub show_output {
$pretty_code .= $output_closing_comment;
my $uri = $self->paste_ixio($pretty_code);
if (not $uri =~ m/^http/) {
$uri = $self->paste_ptpb($pretty_code);
}
print "$uri\n";
exit 0;
}
@ -283,30 +278,6 @@ sub paste_ixio {
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 {
my ($self) = @_;

View File

@ -14,10 +14,6 @@ sub initialize {
$self->{default_options} = '';
$self->{cmdline} = 'sh $options $sourcefile';
if (length $self->{arguments}) {
$self->{cmdline} .= " $self->{arguments}";
}
$self->{cmdline_opening_comment} = ": <<'____CMDLINE____'\n";
$self->{cmdline_closing_comment} = "____CMDLINE____\n";