-
Notifications
You must be signed in to change notification settings - Fork 0
/
shiba.go
69 lines (54 loc) · 989 Bytes
/
shiba.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
package main
import (
"os"
)
// target is a filename such as xxx/yyy.sb
func interpret(target string) int {
printer = os.Stdout
modname := filetomod(target)
mod, err := newmodule(modname)
if err != nil {
werr("cannot load module %s: %s", modname, err)
return 1
}
if err := runmod(mod); err != nil {
loc := err.loc()
if loc != nil {
werr("%s:%d:%d %s", loc.mod, loc.line, loc.col, err)
} else {
werr("%s", err)
}
return 1
}
return 0
}
func runmod(mod *module) shibaErr {
env.register(mod)
p := newparser(mod)
for {
stmt, err := p.parsestmt()
if err != nil {
return err
}
if _, ok := stmt.(*ndEof); ok {
break
}
pr, err := process(mod, stmt)
if err != nil {
return err
}
if pr == nil {
continue
}
switch result := pr.(type) {
case *prNop, *prObj:
continue
case *prExit, *prReturn:
goto finish
default:
return newsberr(stmt, "invalid %s in outside function", result)
}
}
finish:
return nil
}