Skip to content

Commit c960e70

Browse files
committed
Add C lang
Fixes #74
1 parent 3a39b26 commit c960e70

File tree

11 files changed

+92
-23
lines changed

11 files changed

+92
-23
lines changed

assets/common.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ tr.me { background: #5cf }
202202
}
203203

204204
.bash { background: svg(bash#000) center right 7px / 26px no-repeat }
205+
.c { background: svg(c#000) center right 7px / 26px no-repeat }
205206
.haskell { background: svg(haskell#000) center right 7px / 26px no-repeat }
206207
.j { background: svg(j#000) center right 7px / 26px no-repeat }
207208
.javascript { background: svg(javascript#000) center right 7px / 26px no-repeat }

assets/hole.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ main nav a:nth-child(3):before {
258258
#tabs {
259259
clear: both;
260260
display: grid;
261-
grid-template-columns: repeat(12, 1fr);
261+
grid-template-columns: repeat(13, 1fr);
262262
position: relative;
263263
-moz-user-select: none;
264264
-ms-user-select: none;
@@ -287,6 +287,7 @@ main nav a:nth-child(3):before {
287287
}
288288

289289
#tabs a[href="#bash"] { background-image: svg(bash#fff) }
290+
#tabs a[href="#c"] { background-image: svg(c#fff) }
290291
#tabs a[href="#haskell"] { background-image: svg(haskell#fff) }
291292
#tabs a[href="#j"] { background-image: svg(j#fff) }
292293
#tabs a[href="#javascript"] { background-image: svg(javascript#fff) }
@@ -301,4 +302,4 @@ main nav a:nth-child(3):before {
301302

302303
@keyframes spin { 100% { transform: rotate(1turn) } }
303304

304-
@media(max-width: 450px) { #tabs { grid-template-columns: repeat(6, 1fr) } }
305+
@media(max-width: 450px) { #tabs { grid-template-columns: repeat(7, 1fr) } }

assets/hole.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ onload = function() {
5050
let editors = [];
5151

5252
for (let langName of [
53-
'Bash', 'Haskell', 'J', 'JavaScript', 'Julia', 'Lisp',
54-
'Lua', 'Perl', 'Perl 6', 'PHP', 'Python', 'Ruby',
53+
'Bash', 'C', 'Haskell', 'J', 'JavaScript', 'Julia', 'Lisp', 'Lua',
54+
'Perl', 'Perl 6', 'PHP', 'Python', 'Ruby',
5555
]) {
5656
let lang = langName.replace(/ /, '').toLowerCase();
5757

5858
let editor = CodeMirror(wrapper, {
5959
lineNumbers: true,
6060
lineWrapping: true,
61-
mode: { name: lang, startOpen: true },
61+
mode: { name: lang === 'c' ? 'clike' : lang, startOpen: true },
6262
value: data.hasOwnProperty(lang) ? data[lang] : '',
6363
});
6464

@@ -94,18 +94,24 @@ onload = function() {
9494

9595
( onhashchange = function() {
9696
// Kick 'em to Perl 6 if we don't know the chosen language.
97-
if (!/^#(?:bash|haskell|j|javascript|julia|lisp|lua|perl6?|php|python|ruby)$/.exec(location.hash))
97+
if (!/^#(?:bash|c|haskell|j|javascript|julia|lisp|lua|perl6?|php|python|ruby)$/.exec(location.hash))
9898
location.hash = 'perl6';
9999

100100
let lang = location.hash.slice(1);
101101

102102
localStorage.setItem(hole, lang);
103103

104-
for (let editor of editors)
105-
if (editor.options.mode.name === lang)
104+
for (let editor of editors) {
105+
let mode = editor.options.mode.name;
106+
107+
if (mode === 'clike')
108+
mode = 'c';
109+
110+
if (mode === lang)
106111
( activeEditor = editor ).display.wrapper.style.display = '';
107112
else
108113
editor.display.wrapper.style.display = 'none';
114+
}
109115

110116
for (let info of document.querySelectorAll('.info'))
111117
info.style.display = info.classList.contains(lang) ? 'block' : '';
@@ -118,13 +124,14 @@ onload = function() {
118124
status.style.display = 'none';
119125
this.classList.add('on');
120126

121-
const res = await fetch('/solution', {
127+
const mode = activeEditor.options.mode.name;
128+
const res = await fetch('/solution', {
122129
credentials: 'include',
123130
method: 'POST',
124131
body: JSON.stringify({
125132
Code: activeEditor.getValue(),
126133
Hole: hole,
127-
Lang: activeEditor.options.mode.name,
134+
Lang: mode === 'clike' ? 'c' : mode,
128135
}),
129136
});
130137

assets/includes/c.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/user.css

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,18 @@ tr {
101101
}
102102

103103
#matrix tr:first-child th:nth-child(2) { background-image: svg(bash#222) }
104-
#matrix tr:first-child th:nth-child(3) { background-image: svg(haskell#222) }
105-
#matrix tr:first-child th:nth-child(4) { background-image: svg(j#222) }
106-
#matrix tr:first-child th:nth-child(5) { background-image: svg(javascript#222) }
107-
#matrix tr:first-child th:nth-child(6) { background-image: svg(julia#222) }
108-
#matrix tr:first-child th:nth-child(7) { background-image: svg(lisp#222) }
109-
#matrix tr:first-child th:nth-child(8) { background-image: svg(lua#222) }
110-
#matrix tr:first-child th:nth-child(9) { background-image: svg(perl#222) }
111-
#matrix tr:first-child th:nth-child(10) { background-image: svg(perl6#222) }
112-
#matrix tr:first-child th:nth-child(11) { background-image: svg(php#222) }
113-
#matrix tr:first-child th:nth-child(12) { background-image: svg(python#222) }
114-
#matrix tr:first-child th:nth-child(13) { background-image: svg(ruby#222) }
104+
#matrix tr:first-child th:nth-child(3) { background-image: svg(c#222) }
105+
#matrix tr:first-child th:nth-child(4) { background-image: svg(haskell#222) }
106+
#matrix tr:first-child th:nth-child(5) { background-image: svg(j#222) }
107+
#matrix tr:first-child th:nth-child(6) { background-image: svg(javascript#222) }
108+
#matrix tr:first-child th:nth-child(7) { background-image: svg(julia#222) }
109+
#matrix tr:first-child th:nth-child(8) { background-image: svg(lisp#222) }
110+
#matrix tr:first-child th:nth-child(9) { background-image: svg(lua#222) }
111+
#matrix tr:first-child th:nth-child(10) { background-image: svg(perl#222) }
112+
#matrix tr:first-child th:nth-child(11) { background-image: svg(perl6#222) }
113+
#matrix tr:first-child th:nth-child(12) { background-image: svg(php#222) }
114+
#matrix tr:first-child th:nth-child(13) { background-image: svg(python#222) }
115+
#matrix tr:first-child th:nth-child(14) { background-image: svg(ruby#222) }
115116

116117
#matrix,
117118
#trophies {

build-langs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare -A urls=(
44
["bash"]="//www.gnu.org/software/bash/"
5+
["c"]="//bellard.org/tcc/"
56
["haskell"]="//www.haskell.org/ghc/"
67
["j"]="http://jsoftware.com"
78
["javascript"]="//v8.dev"
@@ -19,7 +20,7 @@ docker pull alpine:edge
1920

2021
cd containers
2122

22-
for name in Bash Haskell J JavaScript Julia Lisp Lua Perl Perl\ 6 PHP Python Ruby; do
23+
for name in Bash C Haskell J JavaScript Julia Lisp Lua Perl Perl\ 6 PHP Python Ruby; do
2324
lang=${name,,} # lowercase
2425
lang=${lang// /} # trim space
2526

@@ -48,6 +49,7 @@ for name in Bash Haskell J JavaScript Julia Lisp Lua Perl Perl\ 6 PHP Python Rub
4849
ver=${ver/ation/er}
4950
ver=${ver/built /}
5051
ver=${ver/System, /}
52+
ver=${ver/tcc /Tiny C Compiler }
5153
ver=${ver//$'\n'/ }
5254
ver=${ver//version /}
5355
ver=${ver%.}

containers/c/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM alpine:edge as builder
2+
3+
RUN apk add --no-cache curl gcc make musl-dev
4+
5+
RUN curl -L https://download.savannah.nongnu.org/releases/tinycc/tcc-0.9.27.tar.bz2 | tar xjf -
6+
7+
RUN cd tcc-0.9.27 \
8+
&& ./configure \
9+
--config-musl \
10+
--prefix=/usr \
11+
--strip-binaries \
12+
&& make \
13+
&& make install
14+
15+
FROM scratch
16+
17+
COPY --from=0 /lib/ld-musl-x86_64.so.1 /lib/
18+
COPY --from=0 /usr/bin/tcc /usr/bin/
19+
COPY --from=0 /usr/include/assert.h \
20+
/usr/include/complex.h \
21+
/usr/include/ctype.h \
22+
/usr/include/errno.h \
23+
/usr/include/features.h \
24+
/usr/include/fenv.h \
25+
/usr/include/float.h \
26+
/usr/include/inttypes.h \
27+
/usr/include/iso646.h \
28+
/usr/include/limits.h \
29+
/usr/include/locale.h \
30+
/usr/include/math.h \
31+
/usr/include/setjmp.h \
32+
/usr/include/signal.h \
33+
/usr/include/stdalign.h \
34+
/usr/include/stdarg.h \
35+
/usr/include/stdbool.h \
36+
/usr/include/stddef.h \
37+
/usr/include/stdint.h \
38+
/usr/include/stdio.h \
39+
/usr/include/stdlib.h \
40+
/usr/include/stdnoreturn.h \
41+
/usr/include/string.h \
42+
/usr/include/tgmath.h \
43+
/usr/include/threads.h \
44+
/usr/include/time.h \
45+
/usr/include/uchar.h \
46+
/usr/include/wchar.h \
47+
/usr/include/wctype.h /usr/include/
48+
COPY --from=0 /usr/include/bits /usr/include/bits/
49+
COPY --from=0 /usr/lib/libc.so /usr/lib/
50+
COPY --from=0 /usr/lib/tcc/libtcc1.a /usr/lib/tcc/
51+
52+
ENTRYPOINT ["/usr/bin/tcc", "-v"]

db.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ CREATE TYPE public.hole AS ENUM (
6464

6565
CREATE TYPE public.lang AS ENUM (
6666
'bash',
67+
'c',
6768
'haskell',
6869
'j',
6970
'javascript',

routes/solution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ func runCode(hole, lang, code string, args []string) (string, string) {
208208
switch lang {
209209
case "bash":
210210
cmd.Args = []string{"/usr/bin/bash", "-s", "-"}
211+
case "c":
212+
cmd.Args = []string{"/usr/bin/tcc", "-run", "-"}
211213
case "haskell", "javascript", "php":
212214
cmd.Args = []string{"/usr/bin/" + lang, "--"}
213215
case "j":

routes/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Hole struct{ Prev, Next, ID, Name, Difficulty, Preamble string }
77

88
var langs = []Lang{
99
{"bash", "Bash"},
10+
{"c", "C"},
1011
{"haskell", "Haskell"},
1112
{"j", "J"},
1213
{"javascript", "JavaScript"},

0 commit comments

Comments
 (0)