Skip to content

Commit 52d818c

Browse files
authored
Add Prolog language (#533)
* Add Prolog language Add Prolog language, including dockerfile, wrapper for swipl, svg for swipl logo, and hint about reading from argv * Ensure unicode characters can be printed. * Update dockerfile to fix unicode ARGV error. Update size accordingly.
1 parent 0a26896 commit 52d818c

File tree

11 files changed

+104
-3
lines changed

11 files changed

+104
-3
lines changed

config/langs.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,23 @@ ForEach ($arg in $args) {
541541
}
542542
'''
543543

544+
[Prolog]
545+
size = '30.8 MiB'
546+
version = 'SWI-Prolog 8.4.0'
547+
website = 'https://www.swi-prolog.org/'
548+
example = '''
549+
% Printing
550+
:- writeln("Hello, world").
551+
552+
% Looping
553+
:- numlist(0, 9, List),
554+
maplist(writeln, List).
555+
556+
% Accessing arguments
557+
:- current_prolog_flag(argv, [_| Args]),
558+
maplist(writeln, Args).
559+
'''
560+
544561
[Python]
545562
size = '58.4 MiB'
546563
version = '3.10.0'

css/golfer/holes.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ input.pascal:not(:checked) ~ .pascal,
5656
input.perl:not(:checked) ~ .perl,
5757
input.php:not(:checked) ~ .php,
5858
input.powershell:not(:checked) ~ .powershell,
59+
input.prolog:not(:checked) ~ .prolog,
5960
input.python:not(:checked) ~ .python,
6061
input.raku:not(:checked) ~ .raku,
6162
input.ruby:not(:checked) ~ .ruby,
@@ -89,7 +90,7 @@ main svg:nth-of-type(2) {
8990

9091
@media (min-width: 95rem) {
9192
/* Increase this number when adding a language. */
92-
main { grid-template-columns: 4fr repeat(33, 1fr) }
93+
main { grid-template-columns: 4fr repeat(34, 1fr) }
9394

9495
main a { height: 1.9rem }
9596

db/a-schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CREATE TYPE lang AS ENUM (
4040
'assembly', 'bash', 'brainfuck', 'c', 'c-sharp', 'cobol', 'crystal',
4141
'f-sharp', 'fish', 'fortran', 'go', 'haskell', 'hexagony', 'j', 'java',
4242
'javascript', 'julia', 'lisp', 'lua', 'nim', 'pascal', 'perl', 'php',
43-
'powershell', 'python', 'raku', 'ruby', 'rust', 'sql', 'swift', 'v',
43+
'powershell', 'prolog', 'python', 'raku', 'ruby', 'rust', 'sql', 'swift', 'v',
4444
'viml', 'zig'
4545
);
4646

docker/dev.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ COPY --from=codegolf/lang-raku ["/", "/langs/raku/rootfs/" ] # 46.6 M
2525
COPY --from=codegolf/lang-v ["/", "/langs/v/rootfs/" ] # 35.4 MiB
2626
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 33.6 MiB
2727
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
28+
COPY --from=codegolf/lang-prolog ["/", "/langs/prolog/rootfs/" ] # 30.8 MiB
2829
COPY --from=codegolf/lang-viml ["/", "/langs/viml/rootfs/" ] # 21.3 MiB
2930
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 20.7 MiB
3031
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 14.4 MiB
@@ -39,7 +40,6 @@ COPY --from=codegolf/lang-c ["/", "/langs/c/rootfs/" ] # 1.61 M
3940
COPY --from=codegolf/lang-bash ["/", "/langs/bash/rootfs/" ] # 1.14 MiB
4041
COPY --from=codegolf/lang-sql ["/", "/langs/sql/rootfs/" ] # 1.03 MiB
4142
COPY --from=codegolf/lang-lua ["/", "/langs/lua/rootfs/" ] # 338 KiB
42-
4343
COPY run-lang.c ./
4444

4545
RUN gcc -Wall -Werror -Wextra -o /usr/bin/run-lang -s -static run-lang.c

docker/live.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ COPY --from=codegolf/lang-raku ["/", "/langs/raku/rootfs/" ] # 46.6 M
3838
COPY --from=codegolf/lang-v ["/", "/langs/v/rootfs/" ] # 35.4 MiB
3939
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 33.6 MiB
4040
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
41+
COPY --from=codegolf/lang-prolog ["/", "/langs/prolog/rootfs/" ] # 30.8 MiB
4142
COPY --from=codegolf/lang-viml ["/", "/langs/viml/rootfs/" ] # 21.3 MiB
4243
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 20.7 MiB
4344
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 14.4 MiB

js/_codemirror.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const extensions = {
110110
'perl': StreamLanguage.define(perl),
111111
'php': php({ plain: true }),
112112
'powershell': StreamLanguage.define(powerShell),
113+
// TODO prolog
113114
'python': python(),
114115
// TODO raku
115116
'ruby': StreamLanguage.define(ruby),

langs/prolog/Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM swipl:8.4.0 as builder
2+
3+
RUN mkdir /empty
4+
5+
RUN rm -rf /usr/lib/swipl/doc
6+
7+
FROM scratch
8+
9+
COPY --from=0 /bin/sh \
10+
/bin/cat /bin/
11+
COPY --from=0 /usr/bin/swipl /usr/bin/
12+
COPY --from=0 /lib /lib
13+
COPY --from=0 /lib64 /lib64
14+
COPY --from=0 /empty /proc
15+
COPY --from=0 /empty /tmp
16+
COPY --from=0 /usr/lib/swipl /usr/lib/swipl
17+
COPY --from=0 /usr/lib/locale /usr/lib/locale
18+
COPY --from=0 /usr/lib/libtcmalloc_minimal.so.4 \
19+
/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
20+
/usr/lib/x86_64-linux-gnu/libform.so.5 \
21+
/usr/lib/x86_64-linux-gnu/libgmp.so.10 /usr/lib/
22+
23+
COPY prolog /usr/bin/
24+
25+
ENTRYPOINT ["/usr/bin/prolog"]
26+
27+
CMD ["--version"]

langs/prolog/prolog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh -e
2+
export LC_ALL=C.UTF-8
3+
4+
# Check for version
5+
if [ "$1" = "--version" ]; then
6+
/usr/bin/swipl --version
7+
exit 0
8+
fi
9+
10+
# Put user-defined predicates in file
11+
cd /tmp
12+
cat - > code.pl
13+
14+
# Ensure interpreter never shows its face in the output box.
15+
# Concatenate 'halt' as a goal to every program.
16+
17+
swipl --quiet --on-error=halt -g 'halt.' code.pl "$@"

svg/prolog.svg

Lines changed: 31 additions & 0 deletions
Loading

views/hole-ng.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ <h1>{{ .Data.Hole.Name }}</h1>
117117
<b>$args</b> to access the arguments.
118118
</div>
119119
{{ end }}
120+
<div class="info prolog">
121+
Your code will be passed to <b>swipl</b> as an external file. <b>current_prolog_flag(argv, [_|Args])</b> to access the arguments.
122+
</div>
120123
<div class="info sql">
121124
<b>SELECT arg FROM argv</b> to access the arguments, only the first
122125
column of the first result set will be printed, NULL values will be

0 commit comments

Comments
 (0)