Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fish'
Browse files Browse the repository at this point in the history
  • Loading branch information
JRaspass committed Nov 17, 2020
2 parents b92f4d1 + 84063e0 commit 0f4c022
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 435 deletions.
32 changes: 22 additions & 10 deletions hole/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,18 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {

var stderr, stdout bytes.Buffer

if langID == "php" {
code = "<?php " + code + " ;"
}

ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

cmd := exec.CommandContext(ctx, "/usr/bin/run-lang")
cmd.Dir = "/langs/" + langID
cmd.Stderr = &stderr
if langID != "javascript" {
cmd.Stdin = strings.NewReader(code)
}
cmd.Stdout = &stdout
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWIPC | syscall.CLONE_NEWNET | syscall.CLONE_NEWNS | syscall.CLONE_NEWPID | syscall.CLONE_NEWUTS,
}

// Interpreter
switch langID {
case "bash":
cmd.Args = []string{"/usr/bin/bash", "-s", "-"}
Expand All @@ -100,7 +94,7 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
case "c-sharp", "f-sharp":
cmd.Args = []string{"/compiler/Compiler", "-"}
case "fish":
cmd.Args = []string{"/usr/bin/fish", "-c", code, "-i"}
cmd.Args = []string{"/usr/bin/fish", "-c", code, "-u"}
case "haskell", "php":
cmd.Args = []string{"/usr/bin/" + langID, "--"}
case "j":
Expand All @@ -111,8 +105,9 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
cmd.Args = []string{"/usr/bin/run-julia", "/tmp/code.jl"}
case "powershell":
cmd.Args = []string{"/interpreter/Interpreter"}

// Require explicit output for Quine to prevent trivial solutions.
if holeID == "quine" {
// Require explicit output for the Quine hole to prevent trivial solutions.
cmd.Args = append(cmd.Args, "--explicit")
}
case "nim":
Expand All @@ -123,7 +118,24 @@ func Play(ctx context.Context, holeID, langID, code string) (score Scorecard) {
cmd.Args = []string{"/usr/bin/" + langID, "-"}
}

cmd.Args = append(cmd.Args, score.Args...)
// Args
switch langID {
case "fish":
cmd.Stdin = strings.NewReader(strings.Join(score.Args, "\x00"))
default:
cmd.Args = append(cmd.Args, score.Args...)
}

// Code
switch langID {
case "fish", "javascript":
// For these code is passed as an argument above.
case "php":
code = "<?php " + code + " ;"
fallthrough
default:
cmd.Stdin = strings.NewReader(code)
}

err := cmd.Run()

Expand Down
18 changes: 16 additions & 2 deletions langs/fish/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
FROM codegolf/lang-python
FROM alpine:3.12 as builder

COPY fish /usr/bin/
RUN apk add --no-cache curl gcc linux-headers make musl-dev python2

RUN curl https://downloads.python.org/pypy/pypy3.7-v7.3.2-src.tar.bz2 \
| tar xj

RUN curl -L https://github.com/primo-ppcg/fish-jit/tarball/cee89b7 \
| tar xz

RUN LDFLAGS=-static python pypy3.7-v7.3.2-src/rpython/bin/rpython \
--lto primo-ppcg-fish-jit-cee89b7/fish-jit.py \
&& strip fish-jit-c

FROM scratch

COPY --from=0 fish-jit-c /usr/bin/fish

ENTRYPOINT ["/usr/bin/fish", "-c", "1n'.'o0n;"]
Loading

0 comments on commit 0f4c022

Please sign in to comment.