Skip to content

Commit 75dddd8

Browse files
committed
support fot Go 1.6 (fixes #355)
1 parent 9e79153 commit 75dddd8

File tree

12 files changed

+78
-27
lines changed

12 files changed

+78
-27
lines changed

build/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags
7373

7474
switch path {
7575
case "runtime":
76-
pkg.GoFiles = []string{"error.go", fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
76+
pkg.GoFiles = []string{"error.go"}
77+
case "runtime/internal/sys":
78+
pkg.GoFiles = []string{fmt.Sprintf("zgoos_%s.go", buildContext.GOOS), "zversion.go"}
7779
case "runtime/pprof":
7880
pkg.GoFiles = nil
7981
case "crypto/rand":

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ machine:
66

77
dependencies:
88
pre:
9-
- 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
9+
- cd /usr/local && sudo rm -rf go && curl https://storage.googleapis.com/golang/go1.6beta2.linux-amd64.tar.gz | sudo tar -xz && sudo chmod a+w go/src/path/filepath
1010
post:
1111
- mv ./gopherjs $HOME/bin
1212
- npm install --global node-gyp

compiler/compiler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

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

2222
func init() {
2323
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"} {

compiler/expressions.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
4242
case isInteger(basic):
4343
if is64Bit(basic) {
4444
if basic.Kind() == types.Int64 {
45-
d, ok := constant.Int64Val(value)
45+
d, ok := constant.Int64Val(constant.ToInt(value))
4646
if !ok {
4747
panic("could not get exact uint")
4848
}
4949
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatInt(d>>32, 10), strconv.FormatUint(uint64(d)&(1<<32-1), 10))
5050
}
51-
d, ok := constant.Uint64Val(value)
51+
d, ok := constant.Uint64Val(constant.ToInt(value))
5252
if !ok {
5353
panic("could not get exact uint")
5454
}
5555
return c.formatExpr("new %s(%s, %s)", c.typeName(exprType), strconv.FormatUint(d>>32, 10), strconv.FormatUint(d&(1<<32-1), 10))
5656
}
57-
d, ok := constant.Int64Val(value)
57+
d, ok := constant.Int64Val(constant.ToInt(value))
5858
if !ok {
5959
panic("could not get exact int")
6060
}
@@ -110,7 +110,7 @@ func (c *funcContext) translateExpr(expr ast.Expr) *expression {
110110
zero := c.translateExpr(c.zeroValue(elementType)).String()
111111
for _, element := range e.Elts {
112112
if kve, isKve := element.(*ast.KeyValueExpr); isKve {
113-
key, ok := constant.Int64Val(c.p.Types[kve.Key].Value)
113+
key, ok := constant.Int64Val(constant.ToInt(c.p.Types[kve.Key].Value))
114114
if !ok {
115115
panic("could not get exact int")
116116
}
@@ -1313,7 +1313,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13131313
case 'f':
13141314
e := a[n].(ast.Expr)
13151315
if val := c.p.Types[e].Value; val != nil {
1316-
d, _ := constant.Int64Val(val)
1316+
d, _ := constant.Int64Val(constant.ToInt(val))
13171317
out.WriteString(strconv.FormatInt(d, 10))
13181318
return
13191319
}
@@ -1327,7 +1327,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13271327
case 'h':
13281328
e := a[n].(ast.Expr)
13291329
if val := c.p.Types[e].Value; val != nil {
1330-
d, _ := constant.Uint64Val(val)
1330+
d, _ := constant.Uint64Val(constant.ToInt(val))
13311331
if c.p.TypeOf(e).Underlying().(*types.Basic).Kind() == types.Int64 {
13321332
out.WriteString(strconv.FormatInt(int64(d)>>32, 10))
13331333
return
@@ -1338,7 +1338,7 @@ func (c *funcContext) formatExprInternal(format string, a []interface{}, parens
13381338
writeExpr(".$high")
13391339
case 'l':
13401340
if val := c.p.Types[a[n].(ast.Expr)].Value; val != nil {
1341-
d, _ := constant.Uint64Val(val)
1341+
d, _ := constant.Uint64Val(constant.ToInt(val))
13421342
out.WriteString(strconv.FormatUint(d&(1<<32-1), 10))
13431343
return
13441344
}

compiler/natives/io/io_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build js
2+
3+
package io_test
4+
5+
import (
6+
"testing"
7+
)
8+
9+
func TestMultiWriter_WriteStringSingleAlloc(t *testing.T) {
10+
t.Skip()
11+
}

compiler/natives/math/math.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ var posInf = 1 / zero
1212
var negInf = -1 / zero
1313
var nan = 0 / zero
1414

15-
func Abs(x float64) float64 {
16-
return abs(x)
17-
}
18-
1915
func Acos(x float64) float64 {
2016
return math.Call("acos", x).Float()
2117
}
@@ -146,6 +142,9 @@ func Modf(f float64) (float64, float64) {
146142
if f == posInf || f == negInf {
147143
return f, nan
148144
}
145+
if 1/f == negInf {
146+
return f, f
147+
}
149148
frac := Mod(f, 1)
150149
return f - frac, frac
151150
}

compiler/natives/net/net.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ package net
55
import (
66
"errors"
77
"syscall"
8+
9+
"github.com/gopherjs/gopherjs/js"
810
)
911

12+
func byteIndex(s string, c byte) int {
13+
return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int()
14+
}
15+
1016
func Listen(net, laddr string) (Listener, error) {
1117
panic(errors.New("network access is not supported by GopherJS"))
1218
}

compiler/natives/reflect/reflect.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (t *uncommonType) Method(i int) (m Method) {
606606
fl := flag(Func)
607607
if p.pkgPath != nil {
608608
m.PkgPath = *p.pkgPath
609-
fl |= flagRO
609+
fl |= flagStickyRO
610610
}
611611
mt := p.typ
612612
m.Type = mt
@@ -812,11 +812,14 @@ func (v Value) Field(i int) Value {
812812
field := &tt.fields[i]
813813
typ := field.typ
814814

815-
fl := v.flag & (flagRO | flagIndir | flagAddr)
815+
fl := v.flag&(flagStickyRO|flagIndir|flagAddr) | flag(typ.Kind())
816816
if field.pkgPath != nil {
817-
fl |= flagRO
817+
if field.name == nil {
818+
fl |= flagEmbedRO
819+
} else {
820+
fl |= flagStickyRO
821+
}
818822
}
819-
fl |= flag(typ.Kind())
820823

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

1030+
func (v Value) SetBytes(x []byte) {
1031+
v.mustBeAssignable()
1032+
v.mustBe(Slice)
1033+
if v.typ.Elem().Kind() != Uint8 {
1034+
panic("reflect.Value.SetBytes of non-byte slice")
1035+
}
1036+
slice := js.InternalObject(x)
1037+
if v.typ.Name() != "" || v.typ.Elem().Name() != "" {
1038+
typedSlice := jsType(v.typ).New(slice.Get("$array"))
1039+
typedSlice.Set("$offset", slice.Get("$offset"))
1040+
typedSlice.Set("$length", slice.Get("$length"))
1041+
typedSlice.Set("$capacity", slice.Get("$capacity"))
1042+
slice = typedSlice
1043+
}
1044+
js.InternalObject(v.ptr).Call("$set", slice)
1045+
}
1046+
10271047
func (v Value) SetCap(n int) {
10281048
v.mustBeAssignable()
10291049
v.mustBe(Slice)
@@ -1234,7 +1254,9 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
12341254
return false
12351255
}
12361256
for _, k := range keys {
1237-
if !deepValueEqualJs(v1.MapIndex(k), v2.MapIndex(k), visited) {
1257+
val1 := v1.MapIndex(k)
1258+
val2 := v2.MapIndex(k)
1259+
if !val1.IsValid() || !val2.IsValid() || !deepValueEqualJs(val1, val2, visited) {
12381260
return false
12391261
}
12401262
}

compiler/natives/reflect/reflect_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ func TestTypelinksSorted(t *testing.T) {
3333
func TestGCBits(t *testing.T) {
3434
t.Skip()
3535
}
36+
37+
func TestChanAlloc(t *testing.T) {
38+
t.Skip()
39+
}

compiler/natives/runtime/runtime.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
package runtime
44

5-
import "github.com/gopherjs/gopherjs/js"
5+
import (
6+
"runtime/internal/sys"
67

7-
const GOOS = theGoos
8+
"github.com/gopherjs/gopherjs/js"
9+
)
10+
11+
const GOOS = sys.TheGoos
812
const GOARCH = "js"
913
const Compiler = "gopherjs"
1014

@@ -37,7 +41,7 @@ func GOROOT() string {
3741
if goroot != js.Undefined {
3842
return goroot.String()
3943
}
40-
return defaultGoroot
44+
return sys.DefaultGoroot
4145
}
4246

4347
func Breakpoint() {
@@ -168,9 +172,13 @@ func LockOSThread() {}
168172
func UnlockOSThread() {}
169173

170174
func Version() string {
171-
return theVersion
175+
return sys.TheVersion
172176
}
173177

174178
func StartTrace() error { return nil }
175179
func StopTrace() {}
176180
func ReadTrace() []byte
181+
182+
func efaceOf(ep *interface{}) *eface {
183+
panic("efaceOf: not supported")
184+
}

compiler/version_check.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// +build go1.5
1+
// +build go1.6
22

33
package compiler
44

5-
const ___GOPHERJS_REQUIRES_GO_VERSION_1_5___ = true
5+
const ___GOPHERJS_REQUIRES_GO_VERSION_1_6___ = true

tests/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ var knownFails = map[string]failReason{
5858
"fixedbugs/bug433.go": {desc: "Error: [object Object]"},
5959
"fixedbugs/issue10353.go": {desc: "incorrect output"},
6060
"fixedbugs/issue11656.go": {desc: "Error: Native function not implemented: runtime/debug.setPanicOnFault"},
61+
"fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"},
6162
"fixedbugs/issue4085b.go": {desc: "Error: got panic JavaScript error: Invalid typed array length, want len out of range"},
6263
"fixedbugs/issue4316.go": {desc: "Error: runtime error: invalid memory address or nil pointer dereference"},
6364
"fixedbugs/issue4388.go": {desc: "Error: expected <autogenerated>:1 have anonymous function:0"},
64-
"fixedbugs/issue4562.go": {desc: "Error: cannot find issue4562.go on stack"},
6565
"fixedbugs/issue4620.go": {desc: "map[0:1 1:2], Error: m[i] != 2"},
66-
"fixedbugs/issue5856.go": {desc: "BUG: defer called from /private/var/folders/tw/kgz4v2kn4n7d7ryg5k_z3dk40000gn/T/issue5856.go.931062983:15135, want issue5856.go:28"},
6766
"fixedbugs/issue6899.go": {desc: "incorrect output -0"},
6867
"fixedbugs/issue7550.go": {desc: "FATAL ERROR: invalid table size Allocation failed - process out of memory"},
6968
"fixedbugs/issue7690.go": {desc: "Error: runtime error: slice bounds out of range"},

0 commit comments

Comments
 (0)