Пример #1
0
func main() {
	filename := os.Args[1]
	source, err := ioutil.ReadFile(filename)
	if err != nil {
		panic(err)
	}

	root, err := parse.ParseFile(source, filename)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(pretty.SyntaxTree(root, 2))

	code, err := went.Compile(root, filename)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(pretty.Disasm(code))

	state := went.NewState()
	val, err := state.LoadProto(code)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(val)
}
Пример #2
0
func (state *State) LoadString(source []byte, filename string) (Value, error) {
	nodes, err := parse.ParseFile(source, filename)
	if err != nil {
		return nil, err
	}

	proto, err := Compile(nodes, filename)
	if err != nil {
		return nil, err
	}

	return state.LoadProto(proto)
}