Skip to content

Commit 4849dde

Browse files
authored
Add “Fortran” Lang (#175)
* Add “Fortran” Lang * args.t: Add Brainfuck, Fortran, Haskell, J, and Lisp. build-langs: code review feedback. * Fortran: reduce image size to 400 MB. * Update J URL.
1 parent 0e35884 commit 4849dde

File tree

14 files changed

+305
-4
lines changed

14 files changed

+305
-4
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ FROM scratch
2727
COPY --from=codegolf/lang-bash / /langs/bash/rootfs/
2828
COPY --from=codegolf/lang-brainfuck / /langs/brainfuck/rootfs/
2929
COPY --from=codegolf/lang-c / /langs/c/rootfs/
30+
COPY --from=codegolf/lang-fortran / /langs/fortran/rootfs/
3031
COPY --from=codegolf/lang-go / /langs/go/rootfs/
3132
COPY --from=codegolf/lang-haskell / /langs/haskell/rootfs/
3233
COPY --from=codegolf/lang-j / /langs/j/rootfs/
@@ -49,6 +50,8 @@ COPY --from=0 /empty /langs/brainfuck/rootfs/proc/
4950
COPY --from=0 /empty /langs/brainfuck/rootfs/tmp/
5051
COPY --from=0 /empty /langs/c/rootfs/proc/
5152
COPY --from=0 /empty /langs/c/rootfs/tmp/
53+
COPY --from=0 /empty /langs/fortran/rootfs/proc/
54+
COPY --from=0 /empty /langs/fortran/rootfs/tmp/
5255
COPY --from=0 /empty /langs/go/rootfs/proc/
5356
COPY --from=0 /empty /langs/go/rootfs/tmp/
5457
COPY --from=0 /empty /langs/haskell/rootfs/proc/

assets/common.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ thead th {
371371
#matrix input.bash:not(:checked) ~ .bash,
372372
#matrix input.brainfuck:not(:checked) ~ .brainfuck,
373373
#matrix input.c:not(:checked) ~ .c,
374+
#matrix input.fortran:not(:checked) ~ .fortran,
374375
#matrix input.go:not(:checked) ~ .go,
375376
#matrix input.haskell:not(:checked) ~ .haskell,
376377
#matrix input.j:not(:checked) ~ .j,
@@ -417,7 +418,7 @@ thead th {
417418
}
418419
#matrix {
419420
/* Increase this number when adding a language. */
420-
grid-template-columns: 3fr repeat(18,1fr);
421+
grid-template-columns: 3fr repeat(19,1fr);
421422
}
422423
#matrix a {
423424
display: initial;

assets/hole.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/* include vendor/codemirror-bash.js */
88
/* include vendor/codemirror-brainfuck.js */
9+
/* include vendor/codemirror-fortran.js */
910
/* include vendor/codemirror-go.js */
1011
/* include vendor/codemirror-haskell.js */
1112
/* include vendor/codemirror-javascript.js */
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
mod(CodeMirror);
6+
})(function(CodeMirror) {
7+
"use strict";
8+
9+
CodeMirror.defineMode("fortran", function() {
10+
function words(array) {
11+
var keys = {};
12+
for (var i = 0; i < array.length; ++i) {
13+
keys[array[i]] = true;
14+
}
15+
return keys;
16+
}
17+
18+
var keywords = words([
19+
"abstract", "accept", "allocatable", "allocate",
20+
"array", "assign", "asynchronous", "backspace",
21+
"bind", "block", "byte", "call", "case",
22+
"class", "close", "common", "contains",
23+
"continue", "cycle", "data", "deallocate",
24+
"decode", "deferred", "dimension", "do",
25+
"elemental", "else", "encode", "end",
26+
"endif", "entry", "enumerator", "equivalence",
27+
"exit", "external", "extrinsic", "final",
28+
"forall", "format", "function", "generic",
29+
"go", "goto", "if", "implicit", "import", "include",
30+
"inquire", "intent", "interface", "intrinsic",
31+
"module", "namelist", "non_intrinsic",
32+
"non_overridable", "none", "nopass",
33+
"nullify", "open", "optional", "options",
34+
"parameter", "pass", "pause", "pointer",
35+
"print", "private", "program", "protected",
36+
"public", "pure", "read", "recursive", "result",
37+
"return", "rewind", "save", "select", "sequence",
38+
"stop", "subroutine", "target", "then", "to", "type",
39+
"use", "value", "volatile", "where", "while",
40+
"write"]);
41+
var builtins = words(["abort", "abs", "access", "achar", "acos",
42+
"adjustl", "adjustr", "aimag", "aint", "alarm",
43+
"all", "allocated", "alog", "amax", "amin",
44+
"amod", "and", "anint", "any", "asin",
45+
"associated", "atan", "besj", "besjn", "besy",
46+
"besyn", "bit_size", "btest", "cabs", "ccos",
47+
"ceiling", "cexp", "char", "chdir", "chmod",
48+
"clog", "cmplx", "command_argument_count",
49+
"complex", "conjg", "cos", "cosh", "count",
50+
"cpu_time", "cshift", "csin", "csqrt", "ctime",
51+
"c_funloc", "c_loc", "c_associated", "c_null_ptr",
52+
"c_null_funptr", "c_f_pointer", "c_null_char",
53+
"c_alert", "c_backspace", "c_form_feed",
54+
"c_new_line", "c_carriage_return",
55+
"c_horizontal_tab", "c_vertical_tab", "dabs",
56+
"dacos", "dasin", "datan", "date_and_time",
57+
"dbesj", "dbesj", "dbesjn", "dbesy", "dbesy",
58+
"dbesyn", "dble", "dcos", "dcosh", "ddim", "derf",
59+
"derfc", "dexp", "digits", "dim", "dint", "dlog",
60+
"dlog", "dmax", "dmin", "dmod", "dnint",
61+
"dot_product", "dprod", "dsign", "dsinh",
62+
"dsin", "dsqrt", "dtanh", "dtan", "dtime",
63+
"eoshift", "epsilon", "erf", "erfc", "etime",
64+
"exit", "exp", "exponent", "extends_type_of",
65+
"fdate", "fget", "fgetc", "float", "floor",
66+
"flush", "fnum", "fputc", "fput", "fraction",
67+
"fseek", "fstat", "ftell", "gerror", "getarg",
68+
"get_command", "get_command_argument",
69+
"get_environment_variable", "getcwd",
70+
"getenv", "getgid", "getlog", "getpid",
71+
"getuid", "gmtime", "hostnm", "huge", "iabs",
72+
"iachar", "iand", "iargc", "ibclr", "ibits",
73+
"ibset", "ichar", "idate", "idim", "idint",
74+
"idnint", "ieor", "ierrno", "ifix", "imag",
75+
"imagpart", "index", "int", "ior", "irand",
76+
"isatty", "ishft", "ishftc", "isign",
77+
"iso_c_binding", "is_iostat_end", "is_iostat_eor",
78+
"itime", "kill", "kind", "lbound", "len", "len_trim",
79+
"lge", "lgt", "link", "lle", "llt", "lnblnk", "loc",
80+
"log", "logical", "long", "lshift", "lstat", "ltime",
81+
"matmul", "max", "maxexponent", "maxloc", "maxval",
82+
"mclock", "merge", "move_alloc", "min", "minexponent",
83+
"minloc", "minval", "mod", "modulo", "mvbits",
84+
"nearest", "new_line", "nint", "not", "or", "pack",
85+
"perror", "precision", "present", "product", "radix",
86+
"rand", "random_number", "random_seed", "range",
87+
"real", "realpart", "rename", "repeat", "reshape",
88+
"rrspacing", "rshift", "same_type_as", "scale",
89+
"scan", "second", "selected_int_kind",
90+
"selected_real_kind", "set_exponent", "shape",
91+
"short", "sign", "signal", "sinh", "sin", "sleep",
92+
"sngl", "spacing", "spread", "sqrt", "srand", "stat",
93+
"sum", "symlnk", "system", "system_clock", "tan",
94+
"tanh", "time", "tiny", "transfer", "transpose",
95+
"trim", "ttynam", "ubound", "umask", "unlink",
96+
"unpack", "verify", "xor", "zabs", "zcos", "zexp",
97+
"zlog", "zsin", "zsqrt"]);
98+
99+
var dataTypes = words(["c_bool", "c_char", "c_double", "c_double_complex",
100+
"c_float", "c_float_complex", "c_funptr", "c_int",
101+
"c_int16_t", "c_int32_t", "c_int64_t", "c_int8_t",
102+
"c_int_fast16_t", "c_int_fast32_t", "c_int_fast64_t",
103+
"c_int_fast8_t", "c_int_least16_t", "c_int_least32_t",
104+
"c_int_least64_t", "c_int_least8_t", "c_intmax_t",
105+
"c_intptr_t", "c_long", "c_long_double",
106+
"c_long_double_complex", "c_long_long", "c_ptr",
107+
"c_short", "c_signed_char", "c_size_t", "character",
108+
"complex", "double", "integer", "logical", "real"]);
109+
var isOperatorChar = /[+\-*&=<>\/\:]/;
110+
var litOperator = new RegExp("(\.and\.|\.or\.|\.eq\.|\.lt\.|\.le\.|\.gt\.|\.ge\.|\.ne\.|\.not\.|\.eqv\.|\.neqv\.)", "i");
111+
112+
function tokenBase(stream, state) {
113+
114+
if (stream.match(litOperator)){
115+
return 'operator';
116+
}
117+
118+
var ch = stream.next();
119+
if (ch == "!") {
120+
stream.skipToEnd();
121+
return "comment";
122+
}
123+
if (ch == '"' || ch == "'") {
124+
state.tokenize = tokenString(ch);
125+
return state.tokenize(stream, state);
126+
}
127+
if (/[\[\]\(\),]/.test(ch)) {
128+
return null;
129+
}
130+
if (/\d/.test(ch)) {
131+
stream.eatWhile(/[\w\.]/);
132+
return "number";
133+
}
134+
if (isOperatorChar.test(ch)) {
135+
stream.eatWhile(isOperatorChar);
136+
return "operator";
137+
}
138+
stream.eatWhile(/[\w\$_]/);
139+
var word = stream.current().toLowerCase();
140+
141+
if (keywords.hasOwnProperty(word)){
142+
return 'keyword';
143+
}
144+
if (builtins.hasOwnProperty(word) || dataTypes.hasOwnProperty(word)) {
145+
return 'builtin';
146+
}
147+
return "variable";
148+
}
149+
150+
function tokenString(quote) {
151+
return function(stream, state) {
152+
var escaped = false, next, end = false;
153+
while ((next = stream.next()) != null) {
154+
if (next == quote && !escaped) {
155+
end = true;
156+
break;
157+
}
158+
escaped = !escaped && next == "\\";
159+
}
160+
if (end || !escaped) state.tokenize = null;
161+
return "string";
162+
};
163+
}
164+
165+
// Interface
166+
167+
return {
168+
startState: function() {
169+
return {tokenize: null};
170+
},
171+
172+
token: function(stream, state) {
173+
if (stream.eatSpace()) return null;
174+
var style = (state.tokenize || tokenBase)(stream, state);
175+
if (style == "comment" || style == "meta") return style;
176+
return style;
177+
}
178+
};
179+
});
180+
});

build-langs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ declare -A urls=(
1212
["Brainfuck"]="//github.com/code-golf/code-golf/tree/master/langs/brainfuck/"
1313
["C"]="//bellard.org/tcc/"
1414
["Go"]="//golang.org"
15+
["Fortran"]="//gcc.gnu.org/fortran/"
1516
["Haskell"]="//www.haskell.org/ghc/"
16-
["J"]="http://jsoftware.com"
17+
["J"]="//www.jsoftware.com"
1718
["JavaScript"]="//v8.dev"
1819
["Julia"]="//julialang.org"
1920
["Lisp"]="//clisp.sourceforge.io"
@@ -67,6 +68,7 @@ for name in "${sorted_names[@]}"; do
6768
ver=${ver#rustc }
6869
ver=${ver/go version go/}
6970
ver=${ver/ linux\/amd64/}
71+
ver=${ver/GNU Fortran \(GCC\) /}
7072
ver=${ver/ation/er}
7173
ver=${ver/built /}
7274
ver=${ver/System, /}
@@ -77,6 +79,7 @@ for name in "${sorted_names[@]}"; do
7779
ver=${ver% d8> }
7880
ver=${ver% Copyright (C) 1994-2019 Lua.org, PUC-Rio}
7981
ver=${ver/ (*/}
82+
ver=${ver/ Copyright/}
8083

8184
html+="+
8285
\"<tr><th class=$lang>$name<td>$ver<td class=wide><a href=${urls[$name]}>website</a>\""

db/0.schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CREATE TYPE hole AS ENUM (
1414
);
1515

1616
CREATE TYPE lang AS ENUM (
17-
'bash', 'brainfuck', 'c', 'go', 'haskell', 'j', 'javascript', 'julia', 'lisp',
17+
'bash', 'brainfuck', 'c', 'fortran', 'go', 'haskell', 'j', 'javascript', 'julia', 'lisp',
1818
'lua', 'nim', 'perl', 'php', 'python', 'raku', 'ruby', 'rust', 'swift'
1919
);
2020

langs/fortran/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!/fortran

langs/fortran/Dockerfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
FROM alpine:3.11 as builder
2+
3+
RUN apk add --no-cache curl g++ libexecinfo-dev \
4+
linux-headers m4 make patch tar xz
5+
6+
WORKDIR /src
7+
8+
RUN curl -L ftp://ftp.gnu.org/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz | tar xzf -
9+
RUN curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2 | tar xjf -
10+
RUN curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2 | tar xjf -
11+
RUN curl -L ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz | tar xzf -
12+
13+
WORKDIR /src/gmp-4.3.2
14+
15+
RUN ./configure --disable-shared --enable-static --prefix=/tmp/gcc
16+
RUN make
17+
RUN make install
18+
19+
WORKDIR /src/mpfr-2.4.2
20+
21+
RUN ./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc
22+
RUN make
23+
RUN make install
24+
25+
WORKDIR /src/mpc-0.8.1
26+
27+
RUN ./configure --disable-shared --enable-static --prefix=/tmp/gcc --with-gmp=/tmp/gcc --with-mpfr=/tmp/gcc
28+
RUN make
29+
RUN make install
30+
31+
WORKDIR /scratch
32+
33+
RUN /src/gcc-9.3.0/configure \
34+
--disable-shared \
35+
--disable-bootstrap \
36+
--disable-libstdcxx-pch \
37+
--disable-multilib \
38+
--enable-languages=fortran \
39+
--enable-libgomp \
40+
--enable-lto \
41+
--enable-static \
42+
--enable-threads=posix \
43+
--enable-tls \
44+
--with-gmp=/tmp/gcc \
45+
--with-mpfr=/tmp/gcc \
46+
--with-mpc=/tmp/gcc \
47+
--with-fpmath=sse \
48+
--prefix=/fortran
49+
50+
RUN make
51+
RUN make install
52+
53+
RUN mkdir /empty
54+
55+
FROM scratch
56+
57+
COPY --from=0 /fortran/bin/ /fortran/bin/
58+
COPY --from=0 /fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/f951 \
59+
/fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/liblto_plugin.la \
60+
/fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/liblto_plugin.so \
61+
/fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/liblto_plugin.so.0 \
62+
/fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/liblto_plugin.so.0.0.0 /fortran/libexec/gcc/x86_64-pc-linux-musl/9.3.0/
63+
COPY --from=0 /fortran/lib/ /fortran/lib/
64+
COPY --from=0 /fortran/lib64/ /fortran/lib64/
65+
COPY --from=0 /usr/bin/ /usr/bin/
66+
COPY --from=0 /usr/lib/ /usr/lib/
67+
COPY --from=0 /bin/cat \
68+
/bin/sh \
69+
/bin/rm /bin/
70+
COPY --from=0 /lib/ld-musl-x86_64.so.1 \
71+
/lib/libz.so.1 /lib/
72+
COPY --from=0 /empty /tmp/
73+
74+
COPY fortran /usr/bin/
75+
76+
ENTRYPOINT ["/fortran/bin/gfortran", "--version"]

langs/fortran/fortran

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh -e
2+
3+
export PATH
4+
cat - > /tmp/code.f90
5+
/fortran/bin/gfortran /tmp/code.f90 -o /tmp/code
6+
rm /tmp/code.f90
7+
shift
8+
/tmp/code "$@"

latest-langs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ constant @langs = (
77
'http://download.savannah.gnu.org/releases/tinycc/?C=M&O=D',
88
/ 'tcc-' (<[\d.]>+) '.tar.bz2' /,
99

10+
'Fortran',
11+
'https://gcc.gnu.org/releases.html',
12+
/ 'GCC ' (\d<[\d.]>+) /,
13+
1014
'Go',
1115
'https://golang.org/project/',
1216
/ 'var goVersion = "go' (<[\d.]>+) '"' /,

0 commit comments

Comments
 (0)