-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (45 loc) · 906 Bytes
/
main.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
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"runtime"
)
const DEFAULT_FILE_PATH = "/var/rinha/source.rinha.json"
func main() {
var stdin []byte
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
stdin = append(stdin, scanner.Bytes()...)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
} else {
args := os.Args
var file []byte
var err error
if len(args) < 2 {
file, err = os.ReadFile(DEFAULT_FILE_PATH)
} else {
file, err = os.ReadFile(os.Args[1])
}
if err != nil {
panic(err)
}
stdin = file
}
var ast File
if err := json.Unmarshal(stdin, &ast); err != nil {
fmt.Println("Error decoding JSON:", err)
return
}
SCOPE_DEFAULT_SIZE := 8
scope := make(Scope, SCOPE_DEFAULT_SIZE)
runtime.GOMAXPROCS(10000)
Eval(scope, ast.Expression)
}