Example #1
0
File: main.go Project: mrG7/escher
func main() {
	// parse flags
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %v [-src Dir] [-d NetAddress] MainCircuit Arguments...\n", os.Args[0])
		flag.PrintDefaults()
	}
	flag.Parse()
	var flagMain string
	var flagArgs = flag.Args()
	if len(flagArgs) > 0 {
		flagMain, flagArgs = flagArgs[0], flagArgs[1:]
	}
	// parse env
	if *flagSrc == "" {
		*flagSrc = os.Getenv("ESCHER")
	}

	// initialize faculties
	fos.Init(flagArgs)
	test.Init(*flagSrc)
	circuit.Init(*flagDiscover)
	//
	index := Root()
	if *flagSrc != "" {
		index.Merge(Load(*flagSrc))
	}
	// run main
	if flagMain != "" {
		verb := see.ParseVerb(flagMain)
		if Circuit(verb).IsNil() {
			fmt.Fprintf(os.Stderr, "verb not recognized\n")
			os.Exit(1)
		}
		exec(index, Circuit(verb), false)
	}
	// standard loop
	r := kio.NewChunkReader(os.Stdin)
	for {
		chunk, err := r.Read()
		if err != nil {
			fmt.Fprintf(os.Stderr, "end of session (%v)\n", err)
			if err == io.EOF || err == io.ErrUnexpectedEOF {
				break
			}
		}
		src := NewSrcString(string(chunk))
		for src.Len() > 0 {
			u := see.SeeChamber(src)
			if u == nil || u.(Circuit).Len() == 0 {
				break
			}
			fmt.Fprintf(os.Stderr, "MATERIALIZING %v\n", u)
			exec(index, u.(Circuit), true)
		}
	}
}
Example #2
0
func main() {
	flag.Parse()
	if *flagX == "" && *flagY == "" && *flagZ == "" {
		fatalf("at least one source directory, X, Y or Z, must be specified with -x, -y or -z, respectively")
	}
	// Initialize faculties
	facos.Init(*flagArg)
	loadCircuitFaculty(*flagName, *flagDiscover, *flagX, *flagY, *flagZ)
	//
	switch {
	case *flagSvg != "":
		walk := strings.Split(*flagSvg, ".")
		if len(walk) == 2 && walk[0] == "" && walk[1] == "" { // -svg .
			walk = nil
		}
		_, cd := compile(*flagX, *flagY, *flagZ).Lookup(walk...)
		switch t := cd.(type) {
		case Circuit:
			println("drawing not supported")
		// case Faulty:
		default:
			println(fmt.Sprintf("SVG display available only for circuits (%T)", t))
		}

	case *flagShow != "":
		walk := strings.Split(*flagShow, ".")
		if len(walk) == 2 && walk[0] == "" && walk[1] == "" { // -show .
			walk = nil
		}
		_, cd := compile(*flagX, *flagY, *flagZ).Lookup(walk...)
		switch t := cd.(type) {
		case Circuit:
			fmt.Println(t.Print("", "\t"))
		// case Faculty:
		default:
			fmt.Printf("%T/%v\n", t, t)
		}

	default:
		b := &Being{compile(*flagX, *flagY, *flagZ)}
		b.MaterializeAddress("main")
		select {} // wait forever
	}
}