From 9577371b26a374ad3ff73a914546701c1ae138cf Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 28 Jan 2014 11:34:39 +0200 Subject: [PATCH] Support multiple languages --- gruntmaster-compile | 21 ++++++++++++++------- lib/Gruntmaster/Daemon/Format.pm | 12 ++++++++++-- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/gruntmaster-compile b/gruntmaster-compile index 0414e4f..2d98d14 100755 --- a/gruntmaster-compile +++ b/gruntmaster-compile @@ -2,15 +2,22 @@ use v5.14; no if $] > 5.017011, warnings => 'experimental::smartmatch'; +use File::Copy qw/copy/; + my ($format, $basename, $name) = @ARGV; my $ret = fork // die $!; if ($ret) { - $SIG{ALRM} = sub {kill KILL => $ret}; - alarm 5; - wait; - exit $? >> 8 + $SIG{ALRM} = sub {kill KILL => $ret}; + alarm 5; + wait; + exit $? >> 8 } else { - given ($format){ - exec 'g++', '-o', $basename, $name when 'CPP'; - } + given ($format){ + exec 'gcc', qw/-DONLINE_JUDGE -std=gnu11 -Wextra -O2 -o/, $basename, $name when 'C'; + exec 'g++', qw/-DONLINE_JUDGE -std=gnu++11 -fabi-version=6 -Wextra -O2 -o/, $basename, $name when 'CPP'; + exec 'gmcs', '-d:ONLINE_JUDGE', $name when 'MONO'; + exec 'javac', $name when 'JAVA'; + exec 'fpc', qw/-dONLINE_JUDGE -O2 -n/, $name when 'PASCAL'; + copy $name, $basename when ['PERL', 'PYTHON'] + } } diff --git a/lib/Gruntmaster/Daemon/Format.pm b/lib/Gruntmaster/Daemon/Format.pm index 948e25a..5f34a33 100644 --- a/lib/Gruntmaster/Daemon/Format.pm +++ b/lib/Gruntmaster/Daemon/Format.pm @@ -4,6 +4,7 @@ use 5.014000; use strict; use warnings; use parent qw/Exporter/; +no if $] > 5.017011, warnings => 'experimental::smartmatch'; use POSIX qw//; use File::Basename qw/fileparse/; @@ -23,8 +24,15 @@ our @EXPORT_OK = qw/mkrun/; sub command_and_args{ my ($format, $basename) = @_; - return "./$basename" if $format eq 'CPP'; - die + + given($format) { + "./$basename" when [qw/C CPP PASCAL/]; + "./$basename.exe" when 'MONO'; + "java $basename" when 'JAVA'; + "perl $basename" when 'PERL'; + "python $basename" when 'PYTHON'; + default { die "Don't know how to execute format $format" } + } } sub mkrun{ -- 2.39.2