Esempio n. 1
0
File: yall.go Progetto: yaraki/yall
func loadFiles() {
	env := yall.NewEnv()
	for i := 0; i < flag.NArg(); i++ {
		file, err := os.Open(flag.Arg(i))
		if file == nil {
			fmt.Fprintf(os.Stderr, "Can't open %s: error %s\n",
				flag.Arg(i), err)
			os.Exit(1)
		}
		defer file.Close()
		env.Load(file)
	}
}
Esempio n. 2
0
File: yall.go Progetto: yaraki/yall
func repl() {
	env := yall.NewEnv()
	for {
		prompt()
		reader := bufio.NewReader(os.Stdin)
		line, _, err := reader.ReadLine()
		if nil != err {
			return
		}
		func() {
			defer func() {
				if r := recover(); r != nil {
					fmt.Println(r)
				}
			}()
			if result := env.EvalString(string(line)); result != nil {
				fmt.Println(result.String())
			}
		}()
	}
	fmt.Println()
}