Skip to content

Commit

Permalink
judge: Add R language
Browse files Browse the repository at this point in the history
  • Loading branch information
klenin committed Sep 7, 2022
1 parent 70b4cf7 commit a6712d0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/autodetect.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<define name="#nodejs" de_code_autodetect="507" value="C:\Lang\nodejs\node.exe" />
<define name="#prolog" de_code_autodetect="509" value="C:\Lang\swipl\bin\swipl.exe" />
<define name="#pypy" de_code_autodetect="510" value="C:\Lang\pypy\pypy3.exe" />
<define name="#R_lang" de_code_autodetect="511" value="C:\Lang\r\bin\R.exe" />

<define name="#qbasic" de_code_autodetect="301" value="C:\Lang\QBasic\1.0\QBASIC.EXE" />
<define name="#freeBasic" de_code_autodetect="302" value="C:\Lang\freebasic\fbc.exe" />
Expand Down Expand Up @@ -76,6 +77,7 @@
<de code="507" enabled="0" />
<de code="509" enabled="0" />
<de code="510" enabled="0" />
<de code="511" enabled="0" />
<de code="602" enabled="0" />
<de code="604" enabled="0" />
<de code="605" enabled="0" />
Expand Down
11 changes: 11 additions & 0 deletions config/devenv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,17 @@
check='"#pypy" %full_name %checker_args'
extension='pypy'/>

<!-- R -->
<de
code="511"
compile='"#R_lang" --slave --vanilla -e "x&lt;-parse(&apos;%full_name&apos;)" LANG=C'
run='"#R_lang" --slave --vanilla -f "%full_name" LANG=C'
run_interactive='"#R_lang" --slave --vanilla -f "%full_name" LANG=C'
generate='"#R_lang" --slave --vanilla -f "%full_name" LANG=C --args %args'
validate='"#R_lang" --slave --vanilla -f "%full_name" LANG=C --args "%test_input" %args'
check='"#R_lang" --slave --vanilla -f "%full_name" LANG=C --args %checker_args'
extension='r'/>

<!-- Unity -->
<de
code="602"
Expand Down
3 changes: 3 additions & 0 deletions install/install-de-pbox.bat
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ choco install erlang -ia "'/D=C:\Lang\erlang'"
rem Change Prolog's assocated extension, since default .pl conflicts with Perl.
%TEMP%\swi-prolog.exe /S /EXT=pro /INSTDIR=C:\Lang\swipl

%PBOX_HOME%\bin\wget.exe --output-document %TEMP%\R-win.exe https://mirror.truenetwork.ru/CRAN/bin/windows/base/R-4.2.1-win.exe
if exist %TEMP%\R-win.exe %TEMP%\R-win.exe /verysilent /dir=C:\Lang\r

mkdir C:\git\
call pbox install git --homedir=C:\git

Expand Down
35 changes: 35 additions & 0 deletions lib/CATS/DevEnv/Detector/R.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package CATS::DevEnv::Detector::R;

use strict;
use warnings;

use CATS::DevEnv::Detector::Utils;
use parent qw(CATS::DevEnv::Detector::Base);

sub name { 'R' }
sub code { '511' }

sub _detect {
my ($self) = @_;
env_path($self, 'R');
which($self, 'R');
registry_glob($self, 'R-core/R/*/InstallPath', 'bin', 'R');
drives($self, 'R/bin', 'R');
lang_dirs($self, 'R', 'bin', 'R');
folder($self, '/usr/bin/', 'R');
}

sub hello_world {
my ($self, $R) = @_;
return `"$R" --slave --vanilla -e "cat('Hello world')"` eq 'Hello world';
}

sub get_version {
my ($self, $path) = @_;

my ($ok, $err, $buf) = run command => [ $path, '--version', '-q' ];
$ok or return 0;
$buf->[0] =~ /R version ([\d.?]+)/ ? $1 : 0;
}

1;

0 comments on commit a6712d0

Please sign in to comment.