Beispiel #1
0
Datei: std.go Projekt: kpmy/lomo
func precompile() {
	buf := bytes.NewBufferString(STD)
	sc := lss.ConnectTo(bufio.NewReader(buf))
	var err error
	for err == nil {
		p := lpp.ConnectToUnit(sc, func(string) ir.ForeignType { panic(0) })
		var u *ir.Unit
		if u, err = p.Unit(); u != nil && err == nil {
			lpp.Std[u.Name] = ir.NewForeign(u)
		}
	}

}
Beispiel #2
0
Datei: loco.go Projekt: kpmy/lomo
func main() {
	log.Println("Lomo compiler, pk, 20150716")
	flag.Parse()
	if sname := name + ".lomo"; name != "" {
		if f, err := os.Open(sname); err == nil {
			sc := lss.ConnectTo(bufio.NewReader(f))
			for err == nil {
				p := lpp.ConnectToUnit(sc, resolve)
				var u *ir.Unit
				if u, err = p.Unit(); err == nil {
					if f, err := os.Create(u.Name + ".ui"); err == nil {
						target.Impl.NewCode(u, f)
						f.Close()
					}
					if f, err := os.Create(u.Name + ".ud"); err == nil {
						target.Impl.NewDef(ir.NewForeign(u), f)
						f.Close()
					}
					if u.Name == "Top" {
						cache := make(map[string]*ir.Unit)
						ld := func(name string) (ret *ir.Unit) {
							if ret = cache[name]; ret == nil {
								if f, err := os.Open(name + ".ui"); err == nil {
									ret = target.Impl.OldCode(f)
									cache[name] = ret
								}
								f.Close()
							}
							return
						}
						var old loom.Cluster
						for i := 0; i < 1; i++ {
							mm := loom.Init("Top", ld)
							loom.Do(mm, nil, old).Wait()
							loom.Close(mm).Wait()
							old = mm
						}
					}
				}
			}
		}
	}
	loom.Exit()
}
Beispiel #3
0
func TestBasics(t *testing.T) {
	runtime.GOMAXPROCS(runtime.NumCPU())
	if f, err := os.Open("Basic.lomo"); err == nil {
		sc := lss.ConnectTo(bufio.NewReader(f))
		for err == nil {
			p := lpp.ConnectToUnit(sc, resolve)
			var u *ir.Unit
			if u, err = p.Unit(); err == nil {
				if f, err := os.Create(u.Name + ".ui"); err == nil {
					target.Impl.NewCode(u, f)
					f.Close()
				}
				if f, err := os.Create(u.Name + ".ud"); err == nil {
					target.Impl.NewDef(ir.NewForeign(u), f)
					f.Close()
				}
				if u.Name == "Top" {
					cache := make(map[string]*ir.Unit)
					ld := func(name string) (ret *ir.Unit) {
						if ret = cache[name]; ret == nil {
							if f, err := os.Open(name + ".ui"); err == nil {
								ret = target.Impl.OldCode(f)
								cache[name] = ret
							}
							f.Close()
						}
						return
					}
					var old loom.Cluster
					for i := 0; i < 100; i++ {
						mm := loom.Init("Top", ld)
						loom.Do(mm, nil, old).Wait()
						loom.Close(mm).Wait()
						old = mm
					}
				}
			}
		}
	}
}