Skip to content

Support for Go 1.6. #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func importWithSrcDir(path string, srcDir string, mode build.ImportMode, install

switch path {
case "runtime":
pkg.GoFiles = []string{"error.go", fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
pkg.GoFiles = []string{"error.go"}
case "runtime/internal/sys":
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
case "runtime/pprof":
pkg.GoFiles = nil
case "crypto/rand":
Expand Down Expand Up @@ -316,7 +318,7 @@ func NewSession(options *Options) *Session {
options: options,
Packages: make(map[string]*PackageData),
}
s.Types = map[string]*types.Package{"unsafe": types.Unsafe}
s.Types = make(map[string]*types.Package)
if options.Watch {
if out, err := exec.Command("ulimit", "-n").Output(); err == nil {
if n, err := strconv.Atoi(strings.TrimSpace(string(out))); err == nil && n < 1024 {
Expand Down
6 changes: 3 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ machine:

dependencies:
pre:
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
post:
- mv ./gopherjs $HOME/bin
- npm install --global node-gyp
Expand All @@ -16,6 +16,6 @@ test:
override:
- diff -u <(echo -n) <(gofmt -d .)
- go tool vet *.go # Go package in root directory.
- for d in */; do echo $d; done | grep -v tests/ | xargs go tool vet # All subdirectories except "tests".
- gopherjs test --short --minify github.com/gopherjs/gopherjs/tests github.com/gopherjs/gopherjs/tests/main github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle crypto/x509 database/sql database/sql/driver debug/dwarf debug/elf debug/gosym debug/macho debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors expvar flag fmt go/ast go/constant go/doc go/format go/parser go/printer go/scanner go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime mime/multipart mime/quotedprintable net/http/cookiejar net/http/fcgi net/mail net/rpc/jsonrpc net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync sync/atomic testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8
- for d in */; do echo $d; done | grep -v tests/ | grep -v third_party/ | xargs go tool vet # All subdirectories except "tests", "third_party".
- gopherjs test --short --minify github.com/gopherjs/gopherjs/tests github.com/gopherjs/gopherjs/tests/main github.com/gopherjs/gopherjs/js archive/tar archive/zip bufio bytes compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib container/heap container/list container/ring crypto/aes crypto/cipher crypto/des crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 crypto/sha512 crypto/subtle crypto/x509 database/sql database/sql/driver debug/dwarf debug/elf debug/macho debug/pe encoding/ascii85 encoding/asn1 encoding/base32 encoding/base64 encoding/binary encoding/csv encoding/gob encoding/hex encoding/json encoding/pem encoding/xml errors expvar flag fmt go/ast go/constant go/doc go/format go/parser go/printer go/scanner go/token hash/adler32 hash/crc32 hash/crc64 hash/fnv html html/template image image/color image/draw image/gif image/jpeg image/png index/suffixarray io io/ioutil math math/big math/cmplx math/rand mime mime/multipart mime/quotedprintable net/http/cookiejar net/http/fcgi net/mail net/rpc/jsonrpc net/textproto net/url path path/filepath reflect regexp regexp/syntax sort strconv strings sync sync/atomic testing/quick text/scanner text/tabwriter text/template text/template/parse time unicode unicode/utf16 unicode/utf8
- go test -v -race ./...
2 changes: 1 addition & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
var reservedKeywords = make(map[string]bool)
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_5___ // compile error on earlier Go versions
var _ = ___GOPHERJS_REQUIRES_GO_VERSION_1_6___ // compile error on earlier Go versions

func init() {
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} {
Expand Down
14 changes: 7 additions & 7 deletions compiler/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
case isInteger(basic):
if is64Bit(basic) {
if basic.Kind() == types.Int64 {
d, ok := constant.Int64Val(value)
d, ok := constant.Int64Val(constant.ToInt(value))
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10))
}
d, ok := constant.Uint64Val(value)
d, ok := constant.Uint64Val(constant.ToInt(value))
if !ok {
panic("could not get exact uint")
}
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10))
}
d, ok := constant.Int64Val(value)
d, ok := constant.Int64Val(constant.ToInt(value))
if !ok {
panic("could not get exact int")
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
zero := c.translateExpr(c.zeroValue(elementType)).String()
for _, element := range e.Elts {
if kve, isKve := element.(*ast.KeyValueExpr); isKve {
key, ok := constant.Int64Val(c.p.Types[kve.Key].Value)
key, ok := constant.Int64Val(constant.ToInt(c.p.Types[kve.Key].Value))
if !ok {
panic("could not get exact int")
}
Expand Down Expand Up @@ -1313,7 +1313,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
case 'f':
e := a[n].(ast.Expr)
if val := c.p.Types[e].Value; val != nil {
d, _ := constant.Int64Val(val)
d, _ := constant.Int64Val(constant.ToInt(val))
out.WriteString(strconv.FormatInt(d, 10))
return
}
Expand All @@ -1327,7 +1327,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
case 'h':
e := a[n].(ast.Expr)
if val := c.p.Types[e].Value; val != nil {
d, _ := constant.Uint64Val(val)
d, _ := constant.Uint64Val(constant.ToInt(val))
if c.p.TypeOf(e).Underlying().(*types.Basic).Kind() == types.Int64 {
out.WriteString(strconv.FormatInt(int64(d)>>32, 10))
return
Expand All @@ -1338,7 +1338,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
writeExpr(".$high")
case 'l':
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
d, _ := constant.Uint64Val(val)
d, _ := constant.Uint64Val(constant.ToInt(val))
out.WriteString(strconv.FormatUint(d&(1<<32-1), 10))
return
}
Expand Down
11 changes: 11 additions & 0 deletions compiler/natives/io/io_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build js

package io_test

import (
"testing"
)

func TestMultiWriter_WriteStringSingleAlloc(t *testing.T) {
t.Skip()
}
7 changes: 3 additions & 4 deletions compiler/natives/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var posInf = 1 / zero
var negInf = -1 / zero
var nan = 0 / zero

func Abs(x float64) float64 {
return abs(x)
}

func Acos(x float64) float64 {
return math.Call("acos", x).Float()
}
Expand Down Expand Up @@ -146,6 +142,9 @@ func Modf(f float64) (float64, float64) {
if f == posInf || f == negInf {
return f, nan
}
if 1/f == negInf {
return f, f
}
frac := Mod(f, 1)
return f - frac, frac
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/natives/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ package net
import (
"errors"
"syscall"

"github.com/gopherjs/gopherjs/js"
)

func byteIndex(s string, c byte) int {
return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int()
}

func Listen(net, laddr string) (Listener, error) {
panic(errors.New("network access is not supported by GopherJS"))
}
Expand Down
32 changes: 27 additions & 5 deletions compiler/natives/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (t *uncommonType) Method(i int) (m Method) {
fl := flag(Func)
if p.pkgPath != nil {
m.PkgPath = *p.pkgPath
fl |= flagRO
fl |= flagStickyRO
}
mt := p.typ
m.Type = mt
Expand Down Expand Up @@ -812,11 +812,14 @@ func (v Value) Field(i int) Value {
field := &tt.fields[i]
typ := field.typ

fl := v.flag & (flagRO | flagIndir | flagAddr)
fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind())
if field.pkgPath != nil {
fl |= flagRO
if field.name == nil {
fl |= flagEmbedRO
} else {
fl |= flagStickyRO
}
}
fl |= flag(typ.Kind())

if tag := tt.fields[i].tag; tag != nil && i != 0 {
if jsTag := getJsTag(*tag); jsTag != "" {
Expand Down Expand Up @@ -1024,6 +1027,23 @@ func (v Value) Set(x Value) {
v.ptr = x.ptr
}

func (v Value) SetBytes(x []byte) {
v.mustBeAssignable()
v.mustBe(Slice)
if v.typ.Elem().Kind() != Uint8 {
panic("reflect.Value.SetBytes of non-byte slice")
}
slice := js.InternalObject(x)
if v.typ.Name() != "" || v.typ.Elem().Name() != "" {
typedSlice := jsType(v.typ).New(slice.Get("$array"))
typedSlice.Set("$offset", slice.Get("$offset"))
typedSlice.Set("$length", slice.Get("$length"))
typedSlice.Set("$capacity", slice.Get("$capacity"))
slice = typedSlice
}
js.InternalObject(v.ptr).Call("$set", slice)
}

func (v Value) SetCap(n int) {
v.mustBeAssignable()
v.mustBe(Slice)
Expand Down Expand Up @@ -1234,7 +1254,9 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
return false
}
for _, k := range keys {
if !deepValueEqualJs(v1.MapIndex(k), v2.MapIndex(k), visited) {
val1 := v1.MapIndex(k)
val2 := v2.MapIndex(k)
if !val1.IsValid() || !val2.IsValid() || !deepValueEqualJs(val1, val2, visited) {
return false
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/natives/reflect/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ func TestTypelinksSorted(t *testing.T) {
func TestGCBits(t *testing.T) {
t.Skip()
}

func TestChanAlloc(t *testing.T) {
t.Skip()
}
16 changes: 12 additions & 4 deletions compiler/natives/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

package runtime

import "github.com/gopherjs/gopherjs/js"
import (
"runtime/internal/sys"

const GOOS = theGoos
"github.com/gopherjs/gopherjs/js"
)

const GOOS = sys.TheGoos
const GOARCH = "js"
const Compiler = "gopherjs"

Expand Down Expand Up @@ -37,7 +41,7 @@ func GOROOT() string {
if goroot != js.Undefined {
return goroot.String()
}
return defaultGoroot
return sys.DefaultGoroot
}

func Breakpoint() {
Expand Down Expand Up @@ -169,7 +173,7 @@ func LockOSThread() {}
func UnlockOSThread() {}

func Version() string {
return theVersion
return sys.TheVersion
}

func StartTrace() error { return nil }
Expand All @@ -180,3 +184,7 @@ func ReadTrace() []byte
func NumCgoCall() int64 {
return 0
}

func efaceOf(ep *interface{}) *eface {
panic("efaceOf: not supported")
}
10 changes: 8 additions & 2 deletions compiler/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@ type packageImporter struct {
}

func (pi packageImporter) Import(path string) (*types.Package, error) {
if _, err := pi.importContext.Import(path); err != nil {
if path == "unsafe" {
return types.Unsafe, nil
}

a, err := pi.importContext.Import(path)
if err != nil {
if *pi.importError == nil {
// If import failed, show first error of import only (https://github.com/gopherjs/gopherjs/issues/119).
*pi.importError = err
}
return nil, err
}
return pi.importContext.Packages[path], nil

return a.types, nil
}

func Compile(importPath string, files []*ast.File, fileSet *token.FileSet, importContext *ImportContext, minify bool) (*Archive, error) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/version_check.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build go1.5
// +build go1.6

package compiler

const ___GOPHERJS_REQUIRES_GO_VERSION_1_5___ = true
const ___GOPHERJS_REQUIRES_GO_VERSION_1_6___ = true
2 changes: 1 addition & 1 deletion doc/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ On each commit, Circle CI automatically compiles all supported packages with Gop
| debug | | |
| -- dwarf | yes | |
| -- elf | yes | |
| -- gosym | yes | |
| -- gosym | partially | on binaries generated by gc |
| -- macho | yes | |
| -- pe | yes | |
| encoding | | |
Expand Down
7 changes: 7 additions & 0 deletions tests/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"
"time"
"vendored"

"github.com/gopherjs/gopherjs/tests/otherpkg"
)
Expand Down Expand Up @@ -502,3 +503,9 @@ func TestGoexit(t *testing.T) {
runtime.Goexit()
}()
}

func TestVendoring(t *testing.T) {
if vendored.Answer != 42 {
t.Fail()
}
}
15 changes: 8 additions & 7 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ var knownFails = map[string]failReason{
"fixedbugs/issue8047b.go": {desc: "Error: [object Object]"},

// Failing due to use of os/exec.Command, which is unsupported. Now skipped via !nacl build tag.
/*"fixedbugs/bug248.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
"fixedbugs/bug302.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
"fixedbugs/bug345.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
"fixedbugs/bug369.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
"fixedbugs/bug429_run.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
"fixedbugs/issue9862_run.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},*/
"fixedbugs/issue10607.go": {desc: "Error: Native function not implemented: syscall.runtime_BeforeFork"},
/*"fixedbugs/bug248.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/bug302.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/bug345.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/bug369.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/bug429_run.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/issue9862_run.go": {desc: "os/exec.Command unsupported"},*/
"fixedbugs/issue10607.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"},
}

type failCategory uint8
Expand Down
3 changes: 3 additions & 0 deletions tests/vendor/vendored/vendored.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package vendored

var Answer = 42