Ejemplo n.º 1
0
Archivo: builtin.go Proyecto: 8l/leaf
func makeBuiltIn() *Package {
	p := newPackage("builtin")
	f := p.NewFile("builtin.leaf")

	f.DeclType("int32", types.Int32)
	f.DeclType("uint32", types.Uint32)
	f.DeclType("int", types.Int32)
	f.DeclType("uint", types.Uint32)
	f.DeclType("int8", types.Int8)
	f.DeclType("uint8", types.Uint8)
	f.DeclType("char", types.Int8)
	f.DeclType("byte", types.Uint8)
	f.DeclType("ptr", types.NewPointer(nil))

	// f.DeclFunc(f.NewFunc("printInt", types.NewFunc(nil, types.Int32)))

	def := func(name string, t *types.Func, fn func(*Func)) {
		ret := f.NewFunc(name, t)
		f.DeclFunc(ret)
		fn(ret)
	}

	def("putc", types.NewFunc(nil, types.Int8), _printChar)
	def("printChar", types.NewFunc(nil, types.Int8), _printChar)

	return p
}
Ejemplo n.º 2
0
Archivo: gen.go Proyecto: 8l/leaf
func (self *Gen) funcDecl(file *ir.File, prog *ast.Program) {
	for _, d := range prog.Decls {
		f, isFunc := d.(*ast.Func)
		if !isFunc {
			continue
		}

		// build the func type
		assert(len(f.Args) == 0) // TODO
		assert(f.Ret == nil)
		var retType types.Type
		ft := types.NewFunc(retType)

		fn, _ := file.DeclNewFunc(f.Name, ft)
		self.tasks = append(self.tasks, &task{fn, f})
	}

	// TODO: now declare all the variables
	// and also add anonymous init functions
}