Skip to content

Commit

Permalink
remove native declared functions from imports.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 24, 2025
1 parent a143041 commit 5ba1914
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 241 deletions.
16 changes: 15 additions & 1 deletion gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,22 @@ func go2GnoValue(alloc *Allocator, rv reflect.Value) (tv TypedValue) {
tv.SetFloat32(softfloat.F64to32(math.Float64bits(rv.Float())))
case reflect.Float64:
tv.SetFloat64(math.Float64bits(rv.Float()))
case reflect.Array:
panic("not yet implemented")
case reflect.Slice:
panic("not yet implemented")
case reflect.Chan:
panic("not yet implemented")
case reflect.Func:
panic("New function")
panic("not yet implemented")
case reflect.Interface:
panic("not yet implemented")
case reflect.Map:
panic("not yet implemented")
case reflect.Ptr:
panic("not yet implemented")
case reflect.Struct:
panic("not yet implemented")
case reflect.UnsafePointer:
panic("not yet implemented")
default:
Expand Down
70 changes: 0 additions & 70 deletions gnovm/pkg/test/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,76 +54,6 @@ func Store(
}
}

// gonative exceptions.
// These are values available using gonative; eventually they should all be removed.
/*switch pkgPath {
case "os":
pkg := gno.NewPackageNode("os", pkgPath, nil)
pkg.DefineGoNativeValue("Stdin", stdin)
pkg.DefineGoNativeValue("Stdout", stdout)
pkg.DefineGoNativeValue("Stderr", stderr)
return pkg, pkg.NewPackage()
case "fmt":
pkg := gno.NewPackageNode("fmt", pkgPath, nil)
pkg.DefineGoNativeValue("Println", func(a ...interface{}) (n int, err error) {
// NOTE: uncomment to debug long running tests
// fmt.Println(a...)
res := fmt.Sprintln(a...)
return stdout.Write([]byte(res))
})
pkg.DefineGoNativeValue("Printf", func(format string, a ...interface{}) (n int, err error) {
res := fmt.Sprintf(format, a...)
return stdout.Write([]byte(res))
})
pkg.DefineGoNativeValue("Print", func(a ...interface{}) (n int, err error) {
res := fmt.Sprint(a...)
return stdout.Write([]byte(res))
})
pkg.DefineGoNativeValue("Sprint", fmt.Sprint)
pkg.DefineGoNativeValue("Sprintf", fmt.Sprintf)
pkg.DefineGoNativeValue("Sprintln", fmt.Sprintln)
pkg.DefineGoNativeValue("Sscanf", fmt.Sscanf)
pkg.DefineGoNativeValue("Errorf", fmt.Errorf)
pkg.DefineGoNativeValue("Fprintln", fmt.Fprintln)
pkg.DefineGoNativeValue("Fprintf", fmt.Fprintf)
pkg.DefineGoNativeValue("Fprint", fmt.Fprint)
return pkg, pkg.NewPackage()
case "encoding/json":
pkg := gno.NewPackageNode("json", pkgPath, nil)
pkg.DefineGoNativeValue("Unmarshal", json.Unmarshal)
pkg.DefineGoNativeValue("Marshal", json.Marshal)
return pkg, pkg.NewPackage()
case "internal/os_test":
pkg := gno.NewPackageNode("os_test", pkgPath, nil)
pkg.DefineNative("Sleep",
gno.Flds( // params
"d", gno.AnyT(), // NOTE: should be time.Duration
),
gno.Flds( // results
),
func(m *gno.Machine) {
// For testing purposes here, nanoseconds are separately kept track.
arg0 := m.LastBlock().GetParams1().TV
d := arg0.GetInt64()
sec := d / int64(time.Second)
nano := d % int64(time.Second)
ctx := m.Context.(*teststd.TestExecContext)
ctx.Timestamp += sec
ctx.TimestampNano += nano
if ctx.TimestampNano >= int64(time.Second) {
ctx.Timestamp += 1
ctx.TimestampNano -= int64(time.Second)
}
m.Context = ctx
},
)
return pkg, pkg.NewPackage()
case "math/big":
pkg := gno.NewPackageNode("big", pkgPath, nil)
pkg.DefineGoNativeValue("NewInt", big.NewInt)
return pkg, pkg.NewPackage()
}*/

// Load normal stdlib.
pn, pv = loadStdlib(rootDir, pkgPath, store, stdout)
if pn != nil {
Expand Down
8 changes: 4 additions & 4 deletions gnovm/stdlibs/net/url/url_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// encodingPkg "encoding"
// "encoding/gob"
"encoding/json"
//"encoding/json"
"fmt"
"io"

Expand Down Expand Up @@ -1870,8 +1870,8 @@ func TestURLHostnameAndPort(t *testing.T) {
// _ encodingPkg.BinaryMarshaler = (*URL)(nil)
// _ encodingPkg.BinaryUnmarshaler = (*URL)(nil)
// )

func TestJSON(t *testing.T) {
// XXX: this require `encoding/json` package
/*func TestJSON(t *testing.T) {
u, err := Parse("https://www.google.com/x?y=z")
if err != nil {
t.Fatal(err)
Expand All @@ -1896,7 +1896,7 @@ func TestJSON(t *testing.T) {
if u1.String() != u.String() {
t.Errorf("json decoded to: %s\nwant: %s\n", u1, u)
}
}
}*/

// XXX: this require `encoding/gob`
// func TestGob(t *testing.T) {
Expand Down
15 changes: 12 additions & 3 deletions gnovm/stdlibs/testing/testing.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package testing

import (
"encoding/json"
"fmt"
"os"
"strconv"
Expand Down Expand Up @@ -217,6 +216,17 @@ type Report struct {
Failed bool
Skipped bool
}
func (r *Report) marshal() string{
failed:="false"
skipped := "false"
if r.Failed{
failed="true"
}
if r.Skipped{
skipped="true"
}
return `{"Failed":`+failed+`,"Skipped":`+skipped+`}`
}

func (t *T) report() Report {
return Report{
Expand Down Expand Up @@ -303,8 +313,7 @@ func RunTest(runFlag string, verbose bool, test InternalTest) (ret string) {
}

report := t.report()
out, _ := json.Marshal(report)
return string(out)
return report.marshal()
}

func formatDur(dur int64) string {
Expand Down
23 changes: 0 additions & 23 deletions gnovm/tests/backup/struct23.gno

This file was deleted.

23 changes: 0 additions & 23 deletions gnovm/tests/backup/struct51.gno

This file was deleted.

27 changes: 0 additions & 27 deletions gnovm/tests/files/addr2b.gno

This file was deleted.

18 changes: 0 additions & 18 deletions gnovm/tests/files/map24.gno

This file was deleted.

26 changes: 0 additions & 26 deletions gnovm/tests/files/map25.gno

This file was deleted.

23 changes: 0 additions & 23 deletions gnovm/tests/files/struct56.gno

This file was deleted.

23 changes: 0 additions & 23 deletions gnovm/tests/files/struct57.gno

This file was deleted.

58 changes: 58 additions & 0 deletions gnovm/tests/stdlibs/fmt/fmt.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fmt



func Println(a ...interface{}) (int, error){
return 0,nil
}

func Printf(format string, a ...interface{}) (int, error){
return 0,nil
}

func Print(a ...interface{}) (int, error){
return 0,nil
}

func Sprint(a ...interface{}) string {
return ""
}

func Sprintf(format string, a ...interface{}) string {
return ""
}

func Sprintln(a ...interface{}) string {
return ""
}

func Sscanf(str string, format string, a ...interface{}) (n int, err error) {
return 0, nil
}

func Errorf(format string, a ...interface{}) error {
return &errorFmt{err:format}
}

func Fprintln(w Writer, a ...interface{}) (n int, err error) {
return 0, nil
}


func Fprintf(w Writer, format string, a ...interface{}) (n int, err error) {
return 0, nil
}

func Fprint(w Writer, a ...interface{}) (n int, err error) {
return 0, nil
}

type errorFmt struct{
err string
}
func (e *errorFmt) Error()string{
return e.err
}
type Writer interface {
Write(p []byte) (n int, err error)
}
Loading

0 comments on commit 5ba1914

Please sign in to comment.