forked from tidwall/GoSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·31 lines (27 loc) · 868 Bytes
/
run.sh
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
#!/bin/bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
if [[ "$@" == "" ]]; then
echo "usage: $0 [file (.swift | .go)]"
echo ""
echo "examples:"
echo " $0 examples/goroutines.swift"
echo " $0 examples/goroutines.go"
exit -1
fi
f="$@"
ext=${f##*.}
if [[ "$ext" == "swift" ]]; then
cat GoSwift/go.swift > /tmp/go-main.swift
echo "private var printmut = Mutex();func print(value: Any){let str=\"\\(value)\"; printmut.lock {try! str.writeToFile(\"/dev/stdout\", atomically:false, encoding:NSUTF8StringEncoding)}}" >> /tmp/go-main.swift
echo "func println(value: Any){print(\"\\(value)\\n\")}" >> /tmp/go-main.swift
cat "$f" >> /tmp/go-main.swift
echo "" >> /tmp/go-main.swift
echo "main()" >> /tmp/go-main.swift
swift /tmp/go-main.swift
elif [[ "$ext" == "go" ]]; then
GOMAXPROCS=4 go run "$f"
else
echo "$f: invalid file type"
exit -1
fi