forked from refaktor/rye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_wasm.go
executable file
·80 lines (63 loc) · 1.35 KB
/
main_wasm.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
70
71
72
73
74
75
76
77
78
79
80
//go:build wasm
// +build wasm
package main
import (
"fmt"
"syscall/js"
"github.com/refaktor/rye/contrib"
"github.com/refaktor/rye/env"
"github.com/refaktor/rye/evaldo"
"github.com/refaktor/rye/loader"
)
type TagType int
type RjType int
type Series []any
type anyword struct {
kind RjType
idx int
}
type node struct {
kind RjType
value any
}
var CODE []any
//
// main function. Dispatches to appropriate mode function
//
func main1() {
evaldo.ShowResults = true
// main_rye_string("print $Hello world$", false, false)
}
//
// main for awk like functionality with rye language
//
func main() {
c := make(chan struct{}, 0)
js.Global().Set("RyeEvalString", js.FuncOf(RyeEvalString))
<-c
}
func RyeEvalString(this js.Value, args []js.Value) any {
sig := false
subc := true
code := args[0].String()
//util.PrintHeader()
//defer profile.Start(profile.CPUProfile).Stop()
block, genv := loader.LoadString(code, sig)
switch val := block.(type) {
case env.Block:
es := env.NewProgramState(block.(env.Block).Series, genv)
evaldo.RegisterBuiltins(es)
contrib.RegisterBuiltins(es, &evaldo.BuiltinNames)
if subc {
ctx := es.Ctx
es.Ctx = env.NewEnv(ctx)
}
evaldo.EvalBlock(es)
evaldo.MaybeDisplayFailureOrError(es, genv)
return es.Res.Probe(*es.Idx)
case env.Error:
fmt.Println(val.Message)
return "Error"
}
return "Other"
}