Пример #1
0
func buildBareFunc(b *builder, stmts []ast.Stmt) *link8.Pkg {
	b.f = b.p.NewFunc(":start", ir.VoidFuncSig)
	b.fretNamed = false
	b.fretRef = nil
	b.f.SetAsMain()
	b.b = b.f.NewBlock(nil)

	b.scope.Push()
	b.buildStmts(stmts)
	b.scope.Pop()

	// write this to log file
	if b.irLog != nil {
		ir.PrintPkg(b.irLog, b.p)
	}

	return ir.BuildPkg(b.p) // do the code gen
}
Пример #2
0
func (lang) Compile(pinfo *build8.PkgInfo) (
	compiled build8.Linkable, es []*lex8.Error,
) {
	asts, es := parsePkg(pinfo)
	if es != nil {
		return nil, es
	}

	// need to load these two builtin functions here
	b := newBuilder(pinfo.Path)
	initBuilder(b, pinfo.Import)
	if es = b.Errs(); es != nil {
		return nil, es
	}

	b.scope.Push() // package scope
	defer b.scope.Pop()
	for _, fileAST := range asts {
		buildFile(b, fileAST)
	}

	if es = b.Errs(); es != nil {
		return nil, es
	}

	addStart(b)

	irLog := pinfo.CreateLog("ir")
	ir.PrintPkg(irLog, b.p)
	if e := irLog.Close(); e != nil {
		return nil, lex8.SingleErr(e)
	}

	lib := ir.BuildPkg(b.p)
	return &pkg{lib}, nil
}