Skip to content

Commit

Permalink
support fot Go 1.6 (fixes #355)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Jan 25, 2016
1 parent 9e79153 commit 55f7660
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 25 deletions.
4 changes: 3 additions & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func Import(path string, mode build.ImportMode, installSuffix string, buildTags

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
2 changes: 1 addition & 1 deletion 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.6beta2.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 Down
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 @@ -168,9 +172,13 @@ func LockOSThread() {}
func UnlockOSThread() {}

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

func StartTrace() error { return nil }
func StopTrace() {}
func ReadTrace() []byte

func efaceOf(ep *interface{}) *eface {
panic("efaceOf: not supported")
}
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
1 change: 1 addition & 0 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var knownFails = map[string]failReason{
"fixedbugs/bug433.go": {desc: "Error: [object Object]"},
"fixedbugs/issue10353.go": {desc: "incorrect output"},
"fixedbugs/issue11656.go": {desc: "Error: Native function not implemented: runtime/debug.setPanicOnFault"},
"fixedbugs/issue13268.go": {desc: "os/exec.Command unsupported"},
"fixedbugs/issue4085b.go": {desc: "Error: got panic JavaScript error: Invalid typed array length, want len out of range"},
"fixedbugs/issue4316.go": {desc: "Error: runtime error: invalid memory address or nil pointer dereference"},
"fixedbugs/issue4388.go": {desc: "Error: expected <autogenerated>:1 have anonymous function:0"},
Expand Down

0 comments on commit 55f7660

Please sign in to comment.