Exemple #1
0
Fichier : do2.go Projet : kpmy/lomo
func Init(_top string, ld Loader) (ret map[string]*Unit) {
	assert.For(ld != nil, 20, _top)
	ret = make(map[string]*Unit)
	var run func(*Unit)
	run = func(u *Unit) {
		u.imps = ret
		for _, v := range u.code.Variables {
			if !v.Type.Basic {
				if dep := ld(v.Type.Foreign.Name()); dep != nil {
					ret[imp(v)] = &Unit{code: dep, loader: ld}
					v.Type.Foreign = ir.NewForeign(dep)
					run(ret[imp(v)])
				}
			}
		}
	}
	if std := lpp.Std[_top]; std != nil {
		ret[_top] = stdUnit(std, ld)
		run(ret[_top])
	} else if top := ld(_top); top != nil {
		ret[_top] = &Unit{code: top, loader: ld}
		run(ret[_top])
	}
	return
}
Exemple #2
0
Fichier : std.go Projet : 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)
		}
	}

}
Exemple #3
0
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()
}
Exemple #4
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
					}
				}
			}
		}
	}
}