library: os.ProcessState.String
This commit is contained in:
72
cl/import.go
72
cl/import.go
@@ -500,41 +500,6 @@ func (p *context) ensureLoaded(pkgTypes *types.Package) *types.Package {
|
|||||||
return pkgTypes
|
return pkgTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
func pkgKindByPath(pkgPath string) int {
|
|
||||||
switch pkgPath {
|
|
||||||
case "runtime/cgo", "unsafe":
|
|
||||||
return PkgDeclOnly
|
|
||||||
}
|
|
||||||
return PkgNormal
|
|
||||||
}
|
|
||||||
|
|
||||||
func replaceGoName(v string, pos int) string {
|
|
||||||
switch v[:pos] {
|
|
||||||
case "runtime":
|
|
||||||
return "github.com/goplus/llgo/internal/runtime" + v[pos:]
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
func ignoreName(name string) bool {
|
|
||||||
/* TODO(xsw): confirm this is not needed more
|
|
||||||
if name == "unsafe.init" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
const internal = "internal/"
|
|
||||||
return (strings.HasPrefix(name, internal) && !supportedInternal(name[len(internal):])) ||
|
|
||||||
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
|
|
||||||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
|
||||||
strings.HasPrefix(name, "plugin.")
|
|
||||||
}
|
|
||||||
|
|
||||||
func supportedInternal(name string) bool {
|
|
||||||
return strings.HasPrefix(name, "abi.") || strings.HasPrefix(name, "bytealg.") ||
|
|
||||||
strings.HasPrefix(name, "oserror.") || strings.HasPrefix(name, "reflectlite.") ||
|
|
||||||
strings.HasPrefix(name, "syscall/unix.") || strings.HasPrefix(name, "syscall/execenv.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -600,3 +565,40 @@ func toBackground(bg string) llssa.Background {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func pkgKindByPath(pkgPath string) int {
|
||||||
|
switch pkgPath {
|
||||||
|
case "runtime/cgo", "unsafe":
|
||||||
|
return PkgDeclOnly
|
||||||
|
}
|
||||||
|
return PkgNormal
|
||||||
|
}
|
||||||
|
|
||||||
|
func replaceGoName(v string, pos int) string {
|
||||||
|
switch v[:pos] {
|
||||||
|
case "runtime":
|
||||||
|
return "github.com/goplus/llgo/internal/runtime" + v[pos:]
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func ignoreName(name string) bool {
|
||||||
|
/* TODO(xsw): confirm this is not needed more
|
||||||
|
if name == "unsafe.init" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
const internal = "internal/"
|
||||||
|
return (strings.HasPrefix(name, internal) && !supportedInternal(name[len(internal):])) ||
|
||||||
|
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
|
||||||
|
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
||||||
|
strings.HasPrefix(name, "plugin.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func supportedInternal(name string) bool {
|
||||||
|
return strings.HasPrefix(name, "abi.") || strings.HasPrefix(name, "bytealg.") ||
|
||||||
|
strings.HasPrefix(name, "itoa.") || strings.HasPrefix(name, "oserror.") || strings.HasPrefix(name, "reflectlite.") ||
|
||||||
|
strings.HasPrefix(name, "syscall/unix.") || strings.HasPrefix(name, "syscall/execenv.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -750,6 +750,7 @@ var hasAltPkg = map[string]none{
|
|||||||
"fmt": {},
|
"fmt": {},
|
||||||
"internal/abi": {},
|
"internal/abi": {},
|
||||||
"internal/bytealg": {},
|
"internal/bytealg": {},
|
||||||
|
"internal/itoa": {},
|
||||||
"internal/oserror": {},
|
"internal/oserror": {},
|
||||||
"internal/reflectlite": {},
|
"internal/reflectlite": {},
|
||||||
"internal/syscall/execenv": {},
|
"internal/syscall/execenv": {},
|
||||||
|
|||||||
34
internal/lib/internal/itoa/itoa.go
Normal file
34
internal/lib/internal/itoa/itoa.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2021 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Simple conversions to avoid depending on strconv.
|
||||||
|
|
||||||
|
// llgo:skipall
|
||||||
|
package itoa
|
||||||
|
|
||||||
|
// Itoa converts val to a decimal string.
|
||||||
|
func Itoa(val int) string {
|
||||||
|
if val < 0 {
|
||||||
|
return "-" + Uitoa(uint(-val))
|
||||||
|
}
|
||||||
|
return Uitoa(uint(val))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uitoa converts val to a decimal string.
|
||||||
|
func Uitoa(val uint) string {
|
||||||
|
if val == 0 { // avoid string allocation
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
var buf [20]byte // big enough for 64bit value base 10
|
||||||
|
i := len(buf) - 1
|
||||||
|
for val >= 10 {
|
||||||
|
q := val / 10
|
||||||
|
buf[i] = byte('0' + val - q*10)
|
||||||
|
i--
|
||||||
|
val = q
|
||||||
|
}
|
||||||
|
// val < 10
|
||||||
|
buf[i] = byte('0' + val)
|
||||||
|
return string(buf[i:])
|
||||||
|
}
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
package os
|
package os
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/internal/lib/internal/itoa"
|
||||||
"github.com/goplus/llgo/internal/lib/internal/syscall/execenv"
|
"github.com/goplus/llgo/internal/lib/internal/syscall/execenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,7 +98,6 @@ func (p *ProcessState) sysUsage() any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessState) String() string {
|
func (p *ProcessState) String() string {
|
||||||
/* TODO(xsw):
|
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return "<nil>"
|
return "<nil>"
|
||||||
}
|
}
|
||||||
@@ -124,8 +125,6 @@ func (p *ProcessState) String() string {
|
|||||||
res += " (core dumped)"
|
res += " (core dumped)"
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
*/
|
|
||||||
panic("todo: os.ProcessState.String")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExitCode returns the exit code of the exited process, or -1
|
// ExitCode returns the exit code of the exited process, or -1
|
||||||
|
|||||||
39
internal/lib/os/str.go
Normal file
39
internal/lib/os/str.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Simple conversions to avoid depending on strconv.
|
||||||
|
|
||||||
|
package os
|
||||||
|
|
||||||
|
// itox converts val (an int) to a hexadecimal string.
|
||||||
|
func itox(val int) string {
|
||||||
|
if val < 0 {
|
||||||
|
return "-" + uitox(uint(-val))
|
||||||
|
}
|
||||||
|
return uitox(uint(val))
|
||||||
|
}
|
||||||
|
|
||||||
|
const hex = "0123456789abcdef"
|
||||||
|
|
||||||
|
// uitox converts val (a uint) to a hexadecimal string.
|
||||||
|
func uitox(val uint) string {
|
||||||
|
if val == 0 { // avoid string allocation
|
||||||
|
return "0x0"
|
||||||
|
}
|
||||||
|
var buf [20]byte // big enough for 64bit value base 16 + 0x
|
||||||
|
i := len(buf) - 1
|
||||||
|
for val >= 16 {
|
||||||
|
q := val / 16
|
||||||
|
buf[i] = hex[val%16]
|
||||||
|
i--
|
||||||
|
val = q
|
||||||
|
}
|
||||||
|
// val < 16
|
||||||
|
buf[i] = hex[val%16]
|
||||||
|
i--
|
||||||
|
buf[i] = 'x'
|
||||||
|
i--
|
||||||
|
buf[i] = '0'
|
||||||
|
return string(buf[i:])
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user