From 9f6e1b707aefbaa88be6bd67aa76781737f18f3c Mon Sep 17 00:00:00 2001 From: visualfc Date: Mon, 11 Mar 2024 10:02:07 +0800 Subject: [PATCH] gop support --- cmd/igop/{gox_support.go => gop_support.go} | 11 +++++++++++ context.go | 3 +++ 2 files changed, 14 insertions(+) rename cmd/igop/{gox_support.go => gop_support.go} (65%) diff --git a/cmd/igop/gox_support.go b/cmd/igop/gop_support.go similarity index 65% rename from cmd/igop/gox_support.go rename to cmd/igop/gop_support.go index 56092c18..7160d0c7 100644 --- a/cmd/igop/gox_support.go +++ b/cmd/igop/gop_support.go @@ -8,6 +8,9 @@ import ( "go/constant" "go/token" "go/types" + "io" + "net/http" + "time" _ "unsafe" "github.com/goplus/igop" @@ -34,7 +37,15 @@ type positioner interface { //go:linkname checker_infer go/types.(*Checker).infer func checker_infer(check *types.Checker, posn positioner, tparams []*types.TypeParam, targs []types.Type, params *types.Tuple, args []*operand) (result []types.Type) +//go:linkname serveContent net/http.serveContent +func serveContent(w http.ResponseWriter, r *http.Request, name string, modtime time.Time, sizeFunc func() (int64, error), content io.ReadSeeker) + +//go:linkname toHTTPError net/http.toHTTPError +func toHTTPError(err error) (msg string, httpStatus int) + func init() { // support github.com/goplus/gogen.checker_infer igop.RegisterExternal("go/types.(*Checker).infer", checker_infer) + igop.RegisterExternal("net/http.serveContent", serveContent) + igop.RegisterExternal("net/http.toHTTPError", toHTTPError) } diff --git a/context.go b/context.go index e99e8231..6d0d5edd 100644 --- a/context.go +++ b/context.go @@ -343,6 +343,9 @@ func (ctx *Context) loadPackage(bp *build.Package, path string, dir string) (*so if embed != nil { files = append(files, embed) } + if bp.Name == "main" { + path = "main" + } tp := &sourcePackage{ Package: types.NewPackage(path, bp.Name), Files: files,