-
Notifications
You must be signed in to change notification settings - Fork 41
/
shell.ngs
54 lines (44 loc) · 1.21 KB
/
shell.ngs
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
# WIP
# XXX: Ugly hack to prevent direct output to stdout.
F '$()'(cp:CommandsPipeline) {
cp.options .= without('top_level')
if cp.options.get('x_top_level') {
cp.options.top_level = cp.options.x_top_level
}
guard false
}
PROXY_DIR = Dir(".." / "ngs-web-ui-proxy").assert()
# Hack - names, because parameters' types can only be identifiers
ServerHandler = net::ServerHandler
Server = net::Server
# Hack - on_listen() can happen for any ServerHandler, not necessarily the one used below.
F on_listen(sh:ServerHandler, s:Server) {
super(sh, s)
p = $(x_top_level:: cd:PROXY_DIR npx ts-node src/server.ts ../ngs/ngs-shell.sock &)
echo("Proxy PID: ${p.processes[0].pid}")
# TODO: open the web app
}
net::unix_json_rpc_server("ngs-shell.sock", ns {
F eval(line:Str) {
fname = '<shell line file>'
bytecode = compile(line, fname)
# TODO: pass warnings
#bytecode.meta().warnings.each(F(w) {
# wl = w.location
# warn("${fname}:${wl.first_line}:${wl.first_column} warning: ${w.message}")
#})
func = load(bytecode, "<shell line func>")
result = ui::JsonData(func())
}
section "tests" {
F test() {
"test method active"
}
F test_add_one(n:Int) {
n + 1
}
F test_div_by_zero() {
1 / 0
}
}
})