Example #1
0
// can't re-use the legacy native function resolver because it's a method of a
// type that provides its own helpers and contextual data, all of which would
// be too hard to reproduce
func (pkgr *Packager) resolveNativeDeclaration(f *tp.Function, path string) {
	// first we should check that the signature refers to something that actually exists
	sigStr := strings.Replace(f.Stub(pkgr.Package), ",", ".", -1)
	if whale.LookupBuiltIn(sigStr) == nil {
		panic(fmt.Sprintf("attempt to provide signature for nonexistent native function `%s` in `%s`", sigStr, path))
	}

	// now turn the type names into the appropriate numeric ids
	if returnType := f.GetReturnType(); len(returnType) > 0 {
		f.ReturnTypeId = proto.Int32(int32(pkgr.TypeMap[returnType]))
		f.ReturnType = nil
	}
	if scopeType := f.GetScopeType(); len(scopeType) > 0 {
		f.ScopeTypeId = proto.Int32(int32(pkgr.TypeMap[scopeType]))
		f.ScopeType = nil
	}
	if opensType := f.GetOpensType(); len(opensType) > 0 {
		f.OpensTypeId = proto.Int32(int32(pkgr.TypeMap[opensType]))
		f.OpensType = nil
	}
	for _, arg := range f.Args {
		if typeName := arg.GetTypeString(); len(typeName) > 0 {
			arg.TypeId = proto.Int32(int32(pkgr.TypeMap[typeName]))
			arg.TypeString = nil
		}
	}
}
Example #2
0
func (pkg *Package) readHeaderFile(location string) {
	//	println("READING FUNCTION HEADER FILE")
	// TODO : plug in new go parser to do this
	input_file := filepath.Join(location, "headers.tf")

	if _, err := os.Open(input_file); err != nil {
		pkg.Log.Infof("Warning -- found no headers.tf")
		return
	}

	stubs := parser.ParseFile(location, ".", "headers.tf", false, make([]string, 0))
	for _, function := range stubs.Functions {
		// Verify that signatures for primitives refer to things that actually exist
		// println("HEY, LINKING BUILTIN:", function.Stub(pkg.Package))
		stubStr := strings.Replace(function.Stub(pkg.Package), ",", ".", -1)
		if whale.LookupBuiltIn(stubStr) == nil {
			// TODO: figure out why the panic string is suppressed so that we can remove the println
			// println("in " + input_file + " -- attempt to provide signature for nonexistent built-in " + stubStr)
			panic("in " + input_file + " -- attempt to provide signature for nonexistent built-in " + stubStr)
		}

		pkg.resolveHeader(function)

		function.BuiltIn = proto.Bool(true)

		pkg.Package.Functions = append(pkg.Package.Functions, function)
	}

}