diff --git a/go/ssa/interp/external.go b/go/ssa/interp/external.go index 28c81e64..0a8d6433 100644 --- a/go/ssa/interp/external.go +++ b/go/ssa/interp/external.go @@ -74,6 +74,8 @@ func init() { "math.Float32frombits": ext۰math۰Float32frombits, "math.Float64bits": ext۰math۰Float64bits, "math.Float64frombits": ext۰math۰Float64frombits, + "math.Ldexp": ext۰math۰Ldexp, + "math.Log": ext۰math۰Log, "math.Min": ext۰math۰Min, "reflect.New": ext۰reflect۰New, "reflect.TypeOf": ext۰reflect۰TypeOf, @@ -199,6 +201,14 @@ func ext۰math۰Min(fr *frame, args []value) value { return math.Min(args[0].(float64), args[1].(float64)) } +func ext۰math۰Ldexp(fr *frame, args []value) value { + return math.Ldexp(args[0].(float64), args[1].(int)) +} + +func ext۰math۰Log(fr *frame, args []value) value { + return math.Log(args[0].(float64)) +} + func ext۰runtime۰Breakpoint(fr *frame, args []value) value { runtime.Breakpoint() return nil diff --git a/go/ssa/interp/interp_test.go b/go/ssa/interp/interp_test.go index 19ef001b..3b9b6a0e 100644 --- a/go/ssa/interp/interp_test.go +++ b/go/ssa/interp/interp_test.go @@ -146,15 +146,26 @@ var testdataTests = []string{ "callstack.go", } -// These are files in $GOROOT/src/pkg/. -// These tests exercise the "testing" package. +// These are files and packages in $GOROOT/src/pkg/. var gorootSrcPkgTests = []string{ - "unicode/script_test.go", - "unicode/digit_test.go", - "hash/crc32/crc32.go hash/crc32/crc32_generic.go hash/crc32/crc32_test.go", - "path/path.go path/path_test.go", - // TODO(adonovan): figure out the package loading error here: - // "strings.go strings/search.go strings/search_test.go", + "encoding/ascii85", + "encoding/csv", + "encoding/hex", + "encoding/pem", + "hash/crc32", + "testing", + "text/scanner", + "unicode", + + // Too slow: + // "container/ring", + // "hash/adler32", + + // TODO(adonovan): packages with Examples require os.Pipe (unimplemented): + // "unicode/utf8", + // "log", + // "path", + // "flag", } type successPredicate func(exitcode int, output string) error @@ -166,14 +177,15 @@ func run(t *testing.T, dir, input string, success successPredicate) bool { var inputs []string for _, i := range strings.Split(input, " ") { - inputs = append(inputs, dir+i) + if strings.HasSuffix(i, ".go") { + i = dir + i + } + inputs = append(inputs, i) } conf := loader.Config{SourceImports: true} - // TODO(adonovan): add the following packages' tests, which pass: - // "flag", "unicode", "unicode/utf8", "testing", "log", "path". - if err := conf.CreateFromFilenames("", inputs...); err != nil { - t.Errorf("CreateFromFilenames(%s) failed: %s", inputs, err) + if _, err := conf.FromArgs(inputs, true); err != nil { + t.Errorf("FromArgs(%s) failed: %s", inputs, err) return false } @@ -203,9 +215,17 @@ func run(t *testing.T, dir, input string, success successPredicate) bool { prog := ssa.Create(iprog, ssa.SanityCheckFunctions) prog.BuildAll() - mainPkg := prog.Package(iprog.Created[0].Pkg) - if mainPkg.Func("main") == nil { - testmainPkg := prog.CreateTestMainPackage(mainPkg) + var mainPkg *ssa.Package + var initialPkgs []*ssa.Package + for _, info := range iprog.InitialPackages() { + p := prog.Package(info.Pkg) + initialPkgs = append(initialPkgs, p) + if mainPkg == nil && p.Func("main") != nil { + mainPkg = p + } + } + if mainPkg == nil { + testmainPkg := prog.CreateTestMainPackage(initialPkgs...) if testmainPkg == nil { t.Errorf("CreateTestMainPackage(%s) returned nil", mainPkg) return false diff --git a/go/ssa/interp/reflect.go b/go/ssa/interp/reflect.go index 6d42fd9a..e7f89d7d 100644 --- a/go/ssa/interp/reflect.go +++ b/go/ssa/interp/reflect.go @@ -81,7 +81,7 @@ func ext۰reflect۰rtype۰Bits(fr *frame, args []value) value { if !ok { panic(fmt.Sprintf("reflect.Type.Bits(%T): non-basic type", rt)) } - return fr.i.sizes.Sizeof(basic) * 8 + return int(fr.i.sizes.Sizeof(basic)) * 8 } func ext۰reflect۰rtype۰Elem(fr *frame, args []value) value { @@ -135,7 +135,7 @@ func ext۰reflect۰rtype۰Out(fr *frame, args []value) value { func ext۰reflect۰rtype۰Size(fr *frame, args []value) value { // Signature: func (t reflect.rtype) uintptr - return uint64(fr.i.sizes.Sizeof(args[0].(rtype).t)) + return uintptr(fr.i.sizes.Sizeof(args[0].(rtype).t)) } func ext۰reflect۰rtype۰String(fr *frame, args []value) value {