Skip to content

Commit

Permalink
Add GolfScript (#687)
Browse files Browse the repository at this point in the history
* Add GolfScript

* Simplify Dockerfile

* Bump version, copy to /usr/bin/golfscript

* Flags for running GolfScript

* I/O notices for GolfScript

* CSS fixes

* GolfScript code comes from argv

* Update Dockerfile
  • Loading branch information
lynn committed Jul 21, 2022
1 parent 79e65f3 commit 7ccb56c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
15 changes: 15 additions & 0 deletions config/langs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ func main() {
}
'''

[GolfScript]
size = '24.2 MiB'
version = '2206dbe'
website = 'http://www.golfscript.com/golfscript/'
example = '''
# Printing
"Hello, World!"puts
# Looping
10,{p}/
# The stack is initialized with one element, an array of arguments:
n*
'''

[Haskell]
size = '309 MiB'
version = 'Glasgow Haskell Compiler 9.0.1'
Expand Down
3 changes: 2 additions & 1 deletion css/golfer/holes.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ input.f-sharp:not(:checked) ~ .f-sharp,
input.fish:not(:checked) ~ .fish,
input.fortran:not(:checked) ~ .fortran,
input.go:not(:checked) ~ .go,
input.golfscript:not(:checked) ~ .golfscript,
input.haskell:not(:checked) ~ .haskell,
input.hexagony:not(:checked) ~ .hexagony,
input.j:not(:checked) ~ .j,
Expand Down Expand Up @@ -111,7 +112,7 @@ main svg:nth-of-type(2) {

@media (min-width: 95rem) {
/* Increase this number when adding a language. */
main { grid-template-columns: 6fr repeat(40, 1fr) }
main { grid-template-columns: 6fr repeat(41, 1fr) }

main a { height: 1.9rem }

Expand Down
1 change: 1 addition & 0 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COPY --from=codegolf/lang-prolog ["/", "/langs/prolog/rootfs/" ] # 31.7 M
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 30.9 MiB
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 24.2 MiB
COPY --from=codegolf/lang-golfscript ["/", "/langs/golfscript/rootfs" ] # 24.2 MiB
COPY --from=codegolf/lang-viml ["/", "/langs/viml/rootfs/" ] # 22.3 MiB
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 21.5 MiB
COPY --from=codegolf/lang-nim ["/", "/langs/nim/rootfs/" ] # 13.5 MiB
Expand Down
1 change: 1 addition & 0 deletions docker/live.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ COPY --from=codegolf/lang-prolog ["/", "/langs/prolog/rootfs/" ] # 31.7 M
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 30.9 MiB
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 24.2 MiB
COPY --from=codegolf/lang-golfscript ["/", "/langs/golfscript/rootfs" ] # 24.2 MiB
COPY --from=codegolf/lang-viml ["/", "/langs/viml/rootfs/" ] # 22.3 MiB
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 21.5 MiB
COPY --from=codegolf/lang-nim ["/", "/langs/nim/rootfs/" ] # 13.5 MiB
Expand Down
8 changes: 7 additions & 1 deletion hole/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ func play(ctx context.Context, holeID, langID, code string, score *Scorecard) {
cmd.Env = []string{"LANG=C.UTF-8", "PATH=/usr/local/bin:/usr/bin:/bin"}
case "fish":
cmd.Args = []string{"/usr/bin/fish", "--no-prng", "-c", code, "-u"}
case "golfscript":
cmd.Args = []string{"/usr/bin/golfscript", "-n", "-e", code}
if holeID == "quine" {
cmd.Args = append(cmd.Args, "-q")
}
cmd.Args = append(cmd.Args, "--")
case "haskell", "php":
cmd.Args = []string{"/usr/bin/" + langID, "--"}
case "hexagony":
Expand Down Expand Up @@ -266,7 +272,7 @@ func play(ctx context.Context, holeID, langID, code string, score *Scorecard) {

// Code
switch langID {
case "brainfuck", "elixir", "fish", "javascript", "perl", "sed":
case "brainfuck", "elixir", "fish", "golfscript", "javascript", "perl", "sed":
// For these code is passed as an argument above.
case "k":
code = preprocessKCode(holeID, code)
Expand Down
15 changes: 15 additions & 0 deletions langs/golfscript/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM alpine:3.16 as builder

RUN apk add --no-cache build-base curl openssl-dev

ENV VERSION=802e45e

RUN curl -L https://github.com/lynn/golfscript/tarball/$VERSION | tar xz \
&& cd /lynn-golfscript-$VERSION && mv golfscript.rb /

FROM codegolf/lang-ruby

COPY --from=0 /golfscript.rb /usr/bin/golfscript

ENTRYPOINT ["golfscript"]

53 changes: 53 additions & 0 deletions svg/golfscript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions views/hole.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ <h1>
Arguments are available via STDIN, each argument is NULL terminated.
<b>x</b> is a no-op.
</div>
{{ if eq .Data.Hole.ID "quine" }}
<div class="hide info golfscript">
Implicit output is disabled for this hole.
</div>
{{ else }}
<div class="hide info golfscript">
The stack is initialized with an array containing arguments, rather
than the contents of STDIN.
</div>
{{ end }}
<div class="hide info hexagony">
Arguments are available via STDIN, each argument is NULL terminated.
</div>
Expand Down

0 comments on commit 7ccb56c

Please sign in to comment.