Skip to content

Commit

Permalink
Fix HaxeFoundation#23 go lint code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
elliott5 committed Feb 15, 2014
1 parent 8512efb commit 2603541
Show file tree
Hide file tree
Showing 28 changed files with 481 additions and 240 deletions.
18 changes: 7 additions & 11 deletions golibruntime/bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Runtime functions for the Go "bytes" standard library package when used by TARDIS Go
// Package bytes contains runtime functions for the Go "bytes" standard library package when used by TARDIS Go
package bytes

//****go:noescape
Expand All @@ -30,9 +30,8 @@ func Equal(a, b []byte) bool {
if a == nil {
if b == nil {
return true
} else {
return len(b) == 0
}
return len(b) == 0
}
if b == nil {
return len(a) == 0
Expand All @@ -57,20 +56,17 @@ func Compare(a, b []byte) int {
if a == nil {
if b == nil {
return 0
} else {
if len(b) == 0 {
return 0
} else {
return 1
}
}
if len(b) == 0 {
return 0
}
return 1
}
if b == nil {
if len(a) == 0 {
return 0
} else {
return 1
}
return 1
}
i := 0
for (i < len(a)) && (i < len(b)) {
Expand Down
7 changes: 6 additions & 1 deletion golibruntime/golibruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

// Runtime functions for the Go standard libraries
// Package golibruntime provides runtime functions for the Go standard libraries.
// This overall package is incomplete and only compiles on OSX.
// Some individual sub-packages do work in some circumstances, see the example code.
package golibruntime

import (
_ "github.com/tardisgo/tardisgo/golibruntime/bytes"
_ "github.com/tardisgo/tardisgo/golibruntime/math"
_ "github.com/tardisgo/tardisgo/golibruntime/os"
_ "github.com/tardisgo/tardisgo/golibruntime/reflect"
_ "github.com/tardisgo/tardisgo/golibruntime/runtime"
_ "github.com/tardisgo/tardisgo/golibruntime/strings"
_ "github.com/tardisgo/tardisgo/golibruntime/sync"
_ "github.com/tardisgo/tardisgo/golibruntime/sync/atomic"
_ "github.com/tardisgo/tardisgo/golibruntime/syscall"
_ "github.com/tardisgo/tardisgo/golibruntime/time"
_ "runtime" // TODO currently fails with a MStats vs MemStatsType size mis-match on 32-bit Ubuntu/Win7, works on OSX
)
2 changes: 1 addition & 1 deletion golibruntime/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// Implementation and documentation of math functions overloaded by TARDIS Go->Haxe transpiler
// Package math provides implementation and documentation of math functions overloaded by TARDIS Go->Haxe transpiler
package math

import "math"
Expand Down
7 changes: 7 additions & 0 deletions golibruntime/os/os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Package os is not implemented for TARDIS Go, this code is only as a TEST for OSX
package os

// dummy
func sigpipe() {
panic("os.sigpipe() NOT IMPLEMENTED")
}
152 changes: 151 additions & 1 deletion golibruntime/reflect/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,163 @@
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

// DUMMY FOR NOW
// Package reflect is not implemented in TARDIS Go, this code a set of non-working TEST routines
package reflect

import "unsafe"

// An iword is the word that would be stored in an
// interface to represent a given value v. Specifically, if v is
// bigger than a pointer, its word is a pointer to v's data.
// Otherwise, its word holds the data stored
// in its leading bytes (so is not a pointer).
// Because the value sometimes holds a pointer, we use
// unsafe.Pointer to represent it, so that if iword appears
// in a struct, the garbage collector knows that might be
// a pointer.
type iword unsafe.Pointer

// Method on non-interface type
type method struct {
name *string // name of method
pkgPath *string // nil for exported Names; otherwise import path
mtyp *rtype // method type (without receiver)
typ *rtype // .(*FuncType) underneath (with receiver)
ifn unsafe.Pointer // fn used in interface call (one-word receiver)
tfn unsafe.Pointer // fn used for normal method call
}

// uncommonType is present only for types with names or methods
// (if T is a named type, the uncommonTypes for T and *T have methods).
// Using a pointer to this struct reduces the overall size required
// to describe an unnamed type with no methods.
type uncommonType struct {
name *string // name of type
pkgPath *string // import path; nil for built-in types like int, string
methods []method // methods associated with type
}

// rtype is the common implementation of most values.
// It is embedded in other, public struct types, but always
// with a unique tag like `reflect:"array"` or `reflect:"ptr"`
// so that code cannot convert from, say, *arrayType to *ptrType.
type rtype struct {
size uintptr // size in bytes
hash uint32 // hash of type; avoids computation in hash tables
_ uint8 // unused/padding
align uint8 // alignment of variable with this type
fieldAlign uint8 // alignment of struct field with this type
kind uint8 // enumeration for C
alg *uintptr // algorithm table (../runtime/runtime.h:/Alg)
gc unsafe.Pointer // garbage collection data
string *string // string form; unnecessary but undeniably useful
*uncommonType // (relatively) uncommon fields
ptrToThis *rtype // type for pointer to this type, if used in binary or has methods
}

func methodValueCall() {
panic("reflect.methodValueCall() NOT IMPLEMENTED")
}

func methodFuncStub() {
panic("reflect.methodFuncStub() NOT IMPLEMENTED")
}

// implemented in ../pkg/runtime
func chancap(ch iword) int {
panic("reflect.chancap() NOT IMPLEMENTED")
return 0
}
func chanclose(ch iword) {
panic("reflect.chanclose() NOT IMPLEMENTED")
}
func chanlen(ch iword) int {
panic("reflect.chanlen() NOT IMPLEMENTED")
return 0
}
func chanrecv(t *rtype, ch iword, nb bool) (val iword, selected, received bool) {
panic("reflect.chanrecv() NOT IMPLEMENTED")
}
func chansend(t *rtype, ch iword, val iword, nb bool) bool {
panic("reflect.chansend() NOT IMPLEMENTED")
return false
}

func makechan(typ *rtype, size uint64) (ch iword) {
panic("reflect.makechan() NOT IMPLEMENTED")
}
func makemap(t *rtype) (m iword) {
panic("reflect.makemap() NOT IMPLEMENTED")
}
func mapaccess(t *rtype, m iword, key iword) (val iword, ok bool) {
panic("reflect.mapaccess() NOT IMPLEMENTED")
}
func mapassign(t *rtype, m iword, key, val iword, ok bool) {
panic("reflect.mapassign() NOT IMPLEMENTED")
}
func mapiterinit(t *rtype, m iword) *byte {
panic("reflect.mapiterint() NOT IMPLEMENTED")
}
func mapiterkey(it *byte) (key iword, ok bool) {
panic("reflect.mapiterkey() NOT IMPLEMENTED")
}
func mapiternext(it *byte) {
panic("reflect.mapiternext() NOT IMPLEMENTED")
}
func maplen(m iword) int {
panic("reflect.maplen() NOT IMPLEMENTED")
return 0
}

func call(fn, arg unsafe.Pointer, n uint32) {
panic("reflect.call() NOT IMPLEMENTED")
}
func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer) {
panic("reflect.ifaceE2I() NOT IMPLEMENTED")

}

// implemented in runtime
func ismapkey(*rtype) bool {
panic("reflect.ismapkey() NOT IMPLEMENTED")
return false
}

// implemented in package runtime
func unsafe_New(*rtype) unsafe.Pointer {
panic("reflect.unsafe_New() NOT IMPLEMENTED")
return nil
}
func unsafe_NewArray(*rtype, int) unsafe.Pointer {
panic("reflect.unsafe_NewArray() NOT IMPLEMENTED")
return nil
}

// typelinks is implemented in package runtime.
// It returns a slice of all the 'typelink' information in the binary,
// which is to say a slice of known types, sorted by string.
// Note that strings are not unique identifiers for types:
// there can be more than one with a given string.
// Only types we might want to look up are included:
// channels, maps, slices, and arrays.
func typelinks() []*rtype {
panic("reflect.typelinks() NOT IMPLEMENTED")
return nil
}

// A runtimeSelect is a single case passed to rselect.
// This must match ../runtime/chan.c:/runtimeSelect
type runtimeSelect struct {
dir uintptr // 0, SendDir, or RecvDir
typ *rtype // channel type
ch iword // interface word for channel
val iword // interface word for value (for SendDir)
}

// rselect runs a select. It returns the index of the chosen case,
// and if the case was a receive, the interface word of the received
// value and the conventional OK bool to indicate whether the receive
// corresponds to a sent value.
func rselect([]runtimeSelect) (chosen int, recv iword, recvOK bool) {
panic("reflect.rselect() NOT IMPLEMENTED")
}
48 changes: 40 additions & 8 deletions golibruntime/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

// Runtime functions for the Go "runtime" standard library package when used by TARDIS Go
// Package runtime provdies functions for the Go "runtime" standard library package when used by TARDIS Go.
// Please note, this is an incomplete implementation.
package runtime

// THE GOLANG RUNTIME PACKAGE IS NOT CURRENTLY ALL USABLE

import "github.com/tardisgo/tardisgo/tardisgolib"

func Gosched() { tardisgolib.Gosched() }
// Gosched implements runtime.Goshed
func Gosched() { tardisgolib.Gosched() }

// NumGoroutine emulates runtime.NumGoroutine
func NumGoroutine() int { return tardisgolib.NumGoroutine() }

// EVERYTHING BELOW NOT YET IMPLEMENTED

func Goexit() { panic("runtime.Goexit() not yet implemented") }
func Callers(skip int, pc []uintptr) int { panic("runtime.Callers() not yet implemented"); return 0 }
func FuncForPC(pc uintptr) *uintptr { panic("runtime.FuncForPC() not yet implemented"); return nil }
func SetFinalizer(x, f interface{}) { panic("runtime.SetFinalizer() not yet implemented") }
// Goexit unimplemented
func Goexit() { panic("runtime.Goexit() not yet implemented") }

// FuncForPC not implemented
func FuncForPC(pc uintptr) *uintptr { panic("runtime.FuncForPC() not yet implemented"); return nil }

// SetFinalizer NoOp
func SetFinalizer(x, f interface{}) {
//panic("runtime.SetFinalizer() not yet implemented")
// used in init process, so must be NoOp for now
}

// implemented in symtab.c in GC runtime package
func funcline_go(*uintptr /* should be *runtime.Func*/, uintptr) (string, int) {
Expand All @@ -41,6 +52,27 @@ func cstringToGo(uintptr) string {
}

func getgoroot() string {
panic("runtime.getgoroot() not yet implemented")
return ""
//panic("runtime.getgoroot() not yet implemented")
return "" // GOROOT is empty in TARDIS Go
}

// Caller reports file and line number information about function invocations on
// the calling goroutine's stack. The argument skip is the number of stack frames
// to ascend, with 0 identifying the caller of Caller. (For historical reasons the
// meaning of skip differs between Caller and Callers.) The return values report the
// program counter, file name, and line number within the file of the corresponding
// call. The boolean ok is false if it was not possible to recover the information.
func Caller(skip int) (pc uintptr, file string, line int, ok bool) {
panic("runtime.Caller() not yet implemented")
return 0, "", 0, false
}

// Callers fills the slice pc with the program counters of function invocations
// on the calling goroutine's stack. The argument skip is the number of stack frames
// to skip before recording in pc, with 0 identifying the frame for Callers itself and
// 1 identifying the caller of Callers.
// It returns the number of entries written to pc.
func Callers(skip int, pc []uintptr) int {
panic("runtime.Callers() not yet implemented")
return 0
}
2 changes: 1 addition & 1 deletion golibruntime/strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Runtime function for the Go "strings" standard library package when used by TARDIS Go
// Package strings contains a runtime function for the Go "strings" standard library package when used by TARDIS Go
package strings

// IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
Expand Down
2 changes: 1 addition & 1 deletion golibruntime/sync/atomic/sync_atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Runtime functions for the Go "sync/atomic" standard library package when used by TARDIS Go
// Package atomic contains runtime functions for the Go "sync/atomic" standard library package when used by TARDIS Go
package atomic

import (
Expand Down
2 changes: 1 addition & 1 deletion golibruntime/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Runtime functions for the Go "sync" standard library package when used by TARDIS Go
// Package sync contains runtime functions for the Go "sync" standard library package when used by TARDIS Go
package sync

// THIS PACKAGE ONLY PARTLY USABLE, DOES NOT WORK FOR math/rand
Expand Down
36 changes: 36 additions & 0 deletions golibruntime/syscall/syscall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Package syscall is not implemented for TARDIS Go, this code is a non-functioning TEST, only for OSX
package syscall

import host "syscall"

// Syscall unimplemented
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err host.Errno) {
return 0, 0, host.EBADARCH
}

// Syscall6 unimplemented
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err host.Errno) {
return 0, 0, host.EBADARCH
}

// RawSyscall unimplemented
func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err host.Errno) {
return 0, 0, host.EBADARCH
}

// RawSyscall6 unimplemented
func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err host.Errno) {
return 0, 0, host.EBADARCH
}

// setenv_c is provided by the runtime, but is a no-op if cgo isn't
// loaded.
func setenv_c(k, v string) {}

// should be implemented in runtime package
func runtime_BeforeFork() {
panic("syscall.runtime_BeforeFork() NOT IMPLEMENTED")
}
func runtime_AfterFork() {
panic("syscall.runtime_AfterFork() NOT IMPLEMENTED")
}
Loading

0 comments on commit 2603541

Please sign in to comment.