-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (52 loc) · 1.6 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"syscall/js"
"github.com/VadimZvf/golang/parser"
"github.com/VadimZvf/golang/parser_error_printer"
"github.com/VadimZvf/golang/runtime"
"github.com/VadimZvf/golang/runtime_bridge_web"
"github.com/VadimZvf/golang/runtime_error_printer"
"github.com/VadimZvf/golang/source_string"
"github.com/VadimZvf/golang/stdout_web"
)
type iStdout interface {
Print(line string)
PrintError(line string)
}
func main() {
// if len(os.Args) > 0 {
// filePath := os.Args[1]
// TlengRunFile(filePath)
// }
js.Global().Set("TlengRun", js.FuncOf(TlengWebRun))
<-make(chan bool)
}
func TlengWebRun(this js.Value, args []js.Value) interface{} {
codeText := args[0].String() // get the parameters
var src = source_string.GetSource(codeText)
var bridge = runtime_bridge_web.CreateBridge()
var stdout = stdout_web.CreateStdoutWeb()
Run(src, &stdout, &bridge)
return nil
}
// func TlengRunFile(filePath string) interface{} {
// var src = source_file.GetSource(filePath)
// var bridge = runtime_bridge_cli.CreateBridge()
// var stdout = stdout.CreateStdout()
// Run(src, &stdout, &bridge)
// return nil
// }
func Run(source parser.ISource, stdout iStdout, bridge runtime.IBridge) interface{} {
var parser = parser.CreateParser(source, stdout)
var astRoot, astError = parser.Parse(false)
if astError != nil {
parser_error_printer.PrintError(parser.GetSourceCode(), stdout, astError)
return nil
}
var rt = runtime.CreateRuntime(bridge)
var runtimeErr = rt.Run(astRoot)
if runtimeErr != nil {
runtime_error_printer.PrintError(parser.GetSourceCode(), stdout, runtimeErr)
}
return nil
}