Skip to content

Commit

Permalink
go/ssa/interp: add several intrinsics for Darwin
Browse files Browse the repository at this point in the history
Also: drop all pretense of support for platforms other than darwin and linux.
This package is just a test of go/ssa, not a portable interpreter, and these
are the only platforms to which I have easy access.

Builds on: freebsd darwin plan9 linux windows

Change-Id: I965abc67b1280d33e933b83607a4372d65e070cf
Reviewed-on: https://go-review.googlesource.com/33163
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
adonovan committed Nov 28, 2016
1 parent 167995c commit 89662b0
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 182 deletions.
45 changes: 5 additions & 40 deletions go/ssa/interp/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"runtime"
"strings"
"sync/atomic"
"syscall"
"time"
"unsafe"

Expand All @@ -30,11 +29,11 @@ type externalFn func(fr *frame, args []value) value
// We have not captured that correctly here.

// Key strings are from Function.String().
var externals map[string]externalFn
var externals = make(map[string]externalFn)

func init() {
// That little dot ۰ is an Arabic zero numeral (U+06F0), categories [Nd].
externals = map[string]externalFn{
for k, v := range map[string]externalFn{
"(*sync.Pool).Get": ext۰sync۰Pool۰Get,
"(*sync.Pool).Put": ext۰nop,
"(reflect.Value).Bool": ext۰reflect۰Value۰Bool,
Expand Down Expand Up @@ -86,9 +85,9 @@ func init() {
"math.Log": ext۰math۰Log,
"math.Min": ext۰math۰Min,
"math.hasSSE4": ext۰math۰hasSSE4,
"os.Pipe": ext۰os۰Pipe,
"os.runtime_args": ext۰os۰runtime_args,
"os.runtime_beforeExit": ext۰nop,
"os/signal.init": ext۰nop,
"reflect.New": ext۰reflect۰New,
"reflect.SliceOf": ext۰reflect۰SliceOf,
"reflect.TypeOf": ext۰reflect۰TypeOf,
Expand Down Expand Up @@ -130,25 +129,11 @@ func init() {
"sync/atomic.LoadUint32": ext۰atomic۰LoadUint32,
"sync/atomic.StoreInt32": ext۰atomic۰StoreInt32,
"sync/atomic.StoreUint32": ext۰atomic۰StoreUint32,
"syscall.Close": ext۰syscall۰Close,
"syscall.Exit": ext۰syscall۰Exit,
"syscall.Fstat": ext۰syscall۰Fstat,
"syscall.Getpid": ext۰syscall۰Getpid,
"syscall.Getwd": ext۰syscall۰Getwd,
"syscall.Kill": ext۰syscall۰Kill,
"syscall.Lstat": ext۰syscall۰Lstat,
"syscall.Open": ext۰syscall۰Open,
"syscall.ParseDirent": ext۰syscall۰ParseDirent,
"syscall.RawSyscall": ext۰syscall۰RawSyscall,
"syscall.Read": ext۰syscall۰Read,
"syscall.ReadDirent": ext۰syscall۰ReadDirent,
"syscall.Readlink": ext۰syscall۰Readlink,
"syscall.Stat": ext۰syscall۰Stat,
"syscall.Write": ext۰syscall۰Write,
"syscall.runtime_envs": ext۰runtime۰environ,
"testing.runExample": ext۰testing۰runExample,
"time.Sleep": ext۰time۰Sleep,
"time.now": ext۰time۰now,
} {
externals[k] = v
}
}

Expand Down Expand Up @@ -473,26 +458,6 @@ func ext۰time۰Sleep(fr *frame, args []value) value {
return nil
}

func ext۰syscall۰Exit(fr *frame, args []value) value {
panic(exitPanic(args[0].(int)))
}

func ext۰syscall۰Getwd(fr *frame, args []value) value {
s, err := syscall.Getwd()
return tuple{s, wrapError(err)}
}

func ext۰syscall۰Getpid(fr *frame, args []value) value {
return syscall.Getpid()
}

func ext۰syscall۰Readlink(fr *frame, args []value) value {
path := args[0].(string)
buf := valueToBytes(args[1])
n, err := syscall.Readlink(path, buf)
return tuple{n, wrapError(err)}
}

func valueToBytes(v value) []byte {
in := v.([]value)
b := make([]byte, len(in))
Expand Down
17 changes: 17 additions & 0 deletions go/ssa/interp/external_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ import "syscall"

func init() {
externals["syscall.Sysctl"] = ext۰syscall۰Sysctl

fillStat = func(st *syscall.Stat_t, stat structure) {
stat[0] = st.Dev
stat[1] = st.Mode
stat[2] = st.Nlink
stat[3] = st.Ino
stat[4] = st.Uid
stat[5] = st.Gid
stat[6] = st.Rdev
// TODO(adonovan): fix: copy Timespecs.
// stat[8] = st.Atim
// stat[9] = st.Mtim
// stat[10] = st.Ctim
stat[12] = st.Size
stat[13] = st.Blocks
stat[14] = st.Blksize
}
}

func ext۰syscall۰Sysctl(fr *frame, args []value) value {
Expand Down
24 changes: 0 additions & 24 deletions go/ssa/interp/external_freebsd.go

This file was deleted.

50 changes: 0 additions & 50 deletions go/ssa/interp/external_plan9.go

This file was deleted.

Loading

0 comments on commit 89662b0

Please sign in to comment.