From cf63d9d46a2412bc96d5fd025e3367c2d41a1095 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 23 Jul 2014 21:27:09 +0000 Subject: [PATCH] compiler_vm: maintain original ordering of statements before, after and between functions instead of shoving everything to the top or into main --- PBot/VERSION.pm | 2 +- modules/compiler_vm/compiler_vm_client.pl | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index fadb6c11..f87a6d27 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 748, + BUILD_REVISION => 749, BUILD_DATE => "2014-07-23", }; diff --git a/modules/compiler_vm/compiler_vm_client.pl b/modules/compiler_vm/compiler_vm_client.pl index a6f1e7c3..299a4e12 100755 --- a/modules/compiler_vm/compiler_vm_client.pl +++ b/modules/compiler_vm/compiler_vm_client.pl @@ -121,7 +121,6 @@ sub compile { my $date = time; - sleep 1; print $compiler "compile:$lang:$args:$input:$date\n"; print $compiler "$code\n"; print $compiler "compile:end\n"; @@ -896,6 +895,7 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { # look for potential functions to extract while($preprecode =~ /$func_regex/ms) { my ($pre_ret, $pre_ident, $pre_params, $pre_potential_body) = ($1, $2, $3, $4); + my $precode_code; print "looking for functions, found [$pre_ret][$pre_ident][$pre_params][$pre_potential_body], has main: $has_main\n" if $debug >= 1; @@ -912,6 +912,7 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { $precode = substr($precode, 0, $extract_pos); print "precode: [$precode]\n" if $debug; + $precode_code = $precode; $tmpcode =~ m/$func_regex/ms; my ($ret, $ident, $params, $potential_body) = ($1, $2, $3, $4); @@ -945,12 +946,18 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { exit; } else { $body = $extract[0]; - $preprecode .= $extract[1]; - $precode .= $extract[1]; + $preprecode = $extract[1]; + $precode = $extract[1]; } print "final extract: [$ret][$ident][$params][$body]\n" if $debug; - $code .= "$ret $ident($params) $body\n\n"; + $code .= "$precode_code\n$ret $ident($params) $body\n\n"; + + if($debug >= 2) { print '-' x 20 . "\n" } + print " code: [$code]\n" if $debug >= 2; + if($debug >= 2) { print '-' x 20 . "\n" } + print " precode: [$precode]\n" if $debug >= 2; + $has_main = 1 if $ident =~ m/^\s*\(?\s*main\s*\)?\s*$/; } @@ -960,11 +967,10 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { $precode =~ s/^{(.*)}$/$1/s; if(not $has_main and not $got_nomain) { - $code = "$prelude\n$code" . "int main(void) {\n$precode\n;\nreturn 0;\n}\n"; + $code = "$prelude\n$code\n" . "int main(void) {\n$precode\n;\nreturn 0;\n}\n"; $nooutput = "No warnings, errors or output."; } else { - print "code: [$code]; precode: [$precode]\n" if $debug; - $code = "$prelude\n$precode\n\n$code\n"; + $code = "$prelude\n$code\n"; $nooutput = "No warnings, errors or output."; } } else {