-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlanguages.go
158 lines (134 loc) · 6.8 KB
/
languages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"os/exec"
"strconv"
)
// AllLanguages is an array with all the programming languages support by the judge.
var AllLanguages = []Language{&cpp{}, &c{}, &java{}, &pas{}, &py2{}, &py3{}, &js{}}
// Language keeps information and methods related to a single programming
// language, indicating how it should be judged.
type Language interface {
// Returns a name that identifies the language. e.g. C++11 (g++)
Name() string
// Extension to be used
SourceExtension() string
// Mime type
MimeType() string
// Whether this language requires multithreading
RequiresMultithreading() bool
// Whether this language memory usage should be restricted
UseMemoryLimit() bool
// Returns the compilation commands
CompilationCommand(sourceFilenames []string, executableFilename string) []string
// Copies language-specific files to build directory
CopyExtraFiles(location string) error
// Returns the evalutaion command
EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string
}
type cpp struct{}
func (*cpp) Name() string { return "C++11 (g++)" }
func (*cpp) SourceExtension() string { return ".cpp" }
func (*cpp) MimeType() string { return "text/x-c++src" }
func (*cpp) RequiresMultithreading() bool { return false }
func (*cpp) UseMemoryLimit() bool { return true }
func (*cpp) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("g++")
command := []string{path, "-DEVAL", "-std=c++11", "-O2", "-lm", "-pipe", "-static", "-s", "-o", executableFilename}
return append(command, sourceFilenames...)
}
func (*cpp) CopyExtraFiles(location string) error { return nil }
func (*cpp) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
return append([]string{"./" + executableFilename}, args...)
}
type c struct{}
func (*c) Name() string { return "C (gcc)" }
func (*c) SourceExtension() string { return ".c" }
func (*c) MimeType() string { return "text/x-csrc" }
func (*c) RequiresMultithreading() bool { return false }
func (*c) UseMemoryLimit() bool { return true }
func (*c) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("gcc")
command := []string{path, "-DEVAL", "-O2", "-lm", "-pipe", "-static", "-s", "-o", executableFilename}
return append(command, sourceFilenames...)
}
func (*c) CopyExtraFiles(location string) error { return nil }
func (*c) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
return append([]string{"./" + executableFilename}, args...)
}
type java struct{}
func (*java) Name() string { return "Java (JDK)" }
func (*java) SourceExtension() string { return ".java" }
func (*java) MimeType() string { return "text/x-java" }
func (*java) RequiresMultithreading() bool { return true }
func (*java) UseMemoryLimit() bool { return false }
func (*java) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("javac")
command := []string{path, "-encoding", "UTF-8", "-sourcepath", ".", "-d", "."}
return append(command, sourceFilenames...)
}
func (*java) CopyExtraFiles(location string) error { return nil }
func (*java) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
path, _ := exec.LookPath("java")
return append([]string{path, "-Dfile.encoding=UTF-8", "-XX:+UseSerialGC", "-Xss64m", "-Xmx" + strconv.Itoa(memoryLimit) + "k", executableFilename}, args...)
}
type pas struct{}
func (*pas) Name() string { return "Pascal (fpc)" }
func (*pas) SourceExtension() string { return ".pas" }
func (*pas) MimeType() string { return "text/x-pascal" }
func (*pas) RequiresMultithreading() bool { return false }
func (*pas) UseMemoryLimit() bool { return true }
func (*pas) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("fpc")
command := []string{path, "-dEVAL", "-XS", "-Xt", "-O2", "-o" + executableFilename}
return append(command, sourceFilenames...)
}
func (*pas) CopyExtraFiles(location string) error { return nil }
func (*pas) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
return append([]string{"./" + executableFilename}, args...)
}
type py2 struct{}
func (*py2) Name() string { return "Python 2" }
func (*py2) SourceExtension() string { return ".py" }
func (*py2) MimeType() string { return "text/x-python" }
func (*py2) RequiresMultithreading() bool { return false }
func (*py2) UseMemoryLimit() bool { return true }
func (*py2) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("python2")
command := []string{path, "-m", "py_compile"}
return append(command, sourceFilenames...)
}
func (*py2) CopyExtraFiles(location string) error { return nil }
func (*py2) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
path, _ := exec.LookPath("python2")
return append([]string{path, executableFilename + ".pyc"}, args...)
}
type py3 struct{}
func (*py3) Name() string { return "Python 3" }
func (*py3) SourceExtension() string { return ".py" }
func (*py3) MimeType() string { return "text/x-python" }
func (*py3) RequiresMultithreading() bool { return false }
func (*py3) UseMemoryLimit() bool { return true }
func (*py3) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
path, _ := exec.LookPath("python3")
command := []string{path, "-c", "import py_compile as m; m.compile(\"" + sourceFilenames[0] + "\", \"" + executableFilename + "\", doraise=True)"}
return command
}
func (*py3) CopyExtraFiles(location string) error { return nil }
func (*py3) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
path, _ := exec.LookPath("python3")
return append([]string{path, executableFilename}, args...)
}
type js struct{}
func (*js) Name() string { return "JavaScript (Node.js)" }
func (*js) SourceExtension() string { return ".js" }
func (*js) MimeType() string { return "text/javascript" }
func (*js) RequiresMultithreading() bool { return false }
func (*js) UseMemoryLimit() bool { return false }
func (*js) CompilationCommand(sourceFilenames []string, executableFilename string) []string {
return nil
}
func (*js) CopyExtraFiles(location string) error { return nil }
func (*js) EvaluationCommand(executableFilename string, args []string, memoryLimit int) []string {
path, _ := exec.LookPath("node")
return append([]string{path, "--max-old-space-size=" + strconv.Itoa(memoryLimit>>10), executableFilename + ".js"}, args...)
}