예제 #1
0
func (p *ConfigParser) Init() {
	p.conf = new(conf.Conf)
	p.port = gelo.NewChan()
	p.vm = gelo.NewVM(p.port)

	p.vm.RegisterBundle(p.commands())
}
예제 #2
0
파일: gelrun.go 프로젝트: catb0t/gelo
func main() {
	flag.Parse()

	if flag.NArg() == 0 {
		fmt.Println("No input file to process")
		os.Exit(1)
	}

	file_name := flag.Arg(0)

	vm := gelo.NewVM(extensions.Stdio)
	defer vm.Destroy()

	vm.RegisterBundle(gelo.Core)
	vm.RegisterBundles(commands.All)

	if !*no_prelude {
		prelude, err := os.Open("prelude.gel")
		defer prelude.Close()
		check("Could not open prelude.gel", err)

		_, err = vm.Run(prelude, nil)
		check("Could not load prelude", err)
	}

	file, err := os.Open(file_name)
	defer file.Close()
	check("Could not open: "+file_name, err)
	reader := io.Reader(file)

	if *lit || file_name[len(file_name)-3:] == "lit" {
		reader = NewLiterateReader(reader)
		t := make([]byte, 64)
		for {
			n, err := reader.Read(t)
			fmt.Println(string(t), "n:", n, "err", err == nil)
		}
	}

	tracer := extensions.Stderr

	if *logit {
		out, err := os.Create(flag.Arg(0) + ".log")
		defer out.Close()
		check("Could not create log file", err)
		logger := extensions.Logger(out, log.Ldate|log.Ltime)
		tracer = extensions.Tee(tracer, logger)
	}

	gelo.SetTracer(tracer)

	if *trace || *logit {
		gelo.TraceOn(gelo.All_traces)
	}

	ret, err := vm.Run(reader, flag.Args()[1:])
	check("===PROGRAM=ERROR===", err)
	vm.API.Trace("The ultimate result of the program was", ret)
}