Skip to content

Commit

Permalink
deplace internal/os_test-> os
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 25, 2025
1 parent d7d1800 commit ebbe286
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 204 deletions.
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/flow/io_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

ios_test "os_test"
ios_test "os"
)

// XXX ugh, I can't even sleep milliseconds.
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/tamagotchi/z0_filetest.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"os_test"
"os"
"time"

"gno.land/p/demo/tamagotchi"
Expand Down
2 changes: 1 addition & 1 deletion examples/no_cycles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// XXX: move this into `gno lint`

var injectedTestingLibs = []string{"encoding/json", "fmt", "os", "os_test"}
var injectedTestingLibs = []string{"encoding/json", "fmt", "os"}

// TestNoCycles checks that there is no import cycles in stdlibs and non-draft examples
func TestNoCycles(t *testing.T) {
Expand Down
21 changes: 3 additions & 18 deletions gnovm/pkg/gnolang/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ type Frame struct {
NumBlocks int // number of blocks in stack

// call frame
Func *FuncValue // function value
//GoFunc *NativeValue // go function value
Func *FuncValue // function value
Receiver TypedValue // if bound method
NumArgs int // number of arguments in call
IsVarg bool // is form fncall(???, vargs...)
Expand All @@ -47,17 +46,6 @@ func (fr Frame) String() string {
fr.NumBlocks,
fr.LastPackage.PkgPath,
fr.LastRealm)
/*} else if fr.GoFunc != nil {
return fmt.Sprintf("[FRAME GOFUNC:%v RECV:%s (%d args) %d/%d/%d/%d/%d]",
fr.GoFunc.Value,
fr.Receiver,
fr.NumArgs,
fr.NumOps,
fr.NumValues,
fr.NumExprs,
fr.NumStmts,
fr.NumBlocks)
*/
} else {
return fmt.Sprintf("[FRAME LABEL: %s %d/%d/%d/%d/%d]",
fr.Label,
Expand All @@ -70,7 +58,7 @@ func (fr Frame) String() string {
}

func (fr *Frame) IsCall() bool {
return fr.Func != nil //|| fr.GoFunc != nil
return fr.Func != nil
}

func (fr *Frame) PushDefer(dfr Defer) {
Expand All @@ -91,7 +79,7 @@ func (fr *Frame) PopDefer() (res Defer, ok bool) {

type Defer struct {
Func *FuncValue // function value
//GoFunc *NativeValue // go function value
// GoFunc *NativeValue // go function value
Args []TypedValue // arguments
Source *DeferStmt // source
Parent *Block
Expand Down Expand Up @@ -128,9 +116,6 @@ func (s Stacktrace) String() string {
case call.Frame.Func != nil:
fmt.Fprintf(&builder, "%s\n", toExprTrace(cx))
fmt.Fprintf(&builder, " %s/%s:%d\n", call.Frame.Func.PkgPath, call.Frame.Func.FileName, call.Stmt.GetLine())
//case call.Frame.GoFunc != nil:
// fmt.Fprintf(&builder, "%s\n", toExprTrace(cx))
// fmt.Fprintf(&builder, " gofunction:%s\n", call.Frame.GoFunc.Value.Type())
default:
panic("StacktraceCall has a non-call Frame")
}
Expand Down
88 changes: 9 additions & 79 deletions gnovm/pkg/gnolang/gonative.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ func go2GnoBaseType(rt reflect.Type) Type {
return Float32Type
case reflect.Float64:
return Float64Type
//case reflect.Array:
case reflect.Slice:
return &SliceType{
Elt: go2GnoType(rt.Elem()),
Vrd: false,
}
// return &NativeType{Type: rt}
//case reflect.Chan:
// return &NativeType{Type: rt}
case reflect.Chan:
panic("not yet implemented")
case reflect.Func:
return getFuncType(rt)
case reflect.Interface:
Expand All @@ -86,11 +84,11 @@ func go2GnoBaseType(rt reflect.Type) Type {
it.Methods = fs
fmt.Println("here")
return it
//case reflect.Map:
// case reflect.Map:
// return &NativeType{Type: rt}
//case reflect.Ptr:
// case reflect.Ptr:
// return &NativeType{Type: rt}
//case reflect.Struct:
// case reflect.Struct:
// return &NativeType{Type: rt}
case reflect.UnsafePointer:
panic("not yet implemented")
Expand Down Expand Up @@ -253,6 +251,7 @@ func (ds *defaultStore) go2GnoFuncType(rt reflect.Type) *FuncType {

return ft
}

func getFuncType(rt reflect.Type) *FuncType {
// predefine func type
ft := &FuncType{}
Expand Down Expand Up @@ -364,7 +363,7 @@ func go2GnoValue(alloc *Allocator, rv reflect.Value) (tv TypedValue) {
case reflect.Func:
panic("not yet implemented")
case reflect.Interface:
panic("not yet implemented")
panic("should not happen")
case reflect.Map:
panic("not yet implemented")
case reflect.Ptr:
Expand Down Expand Up @@ -700,22 +699,9 @@ func go2GnoValue2(alloc *Allocator, store Store, rv reflect.Value, recursive boo
case reflect.Chan:
panic("not yet implemented")
case reflect.Func:
// NOTE: the type may be a full gno type, either a
// *FuncType or *DeclaredType. The value may still be a
// *NativeValue though, and the function can be called
// regardless.
//tv.V = alloc.New(rv)
panic("not yet implemented")
case reflect.Interface:
// special case for errors, which are very often used especially in
// native bindings
//if rv.Type() == tError {
// tv.T = gErrorType
// if !rv.IsNil() {
// tv.V = alloc.NewNative(rv.Elem())
// }
// return
//}
panic(rv.Type())
panic("not yet implemented")
case reflect.Map:
panic("not yet implemented")
case reflect.Ptr:
Expand Down Expand Up @@ -1194,7 +1180,6 @@ func gno2GoValue(tv *TypedValue, rv reflect.Value) (ret reflect.Value) {
// PackageNode methods

func (x *PackageNode) DefineGoNativeValue(name Name, nv interface{}) {
fmt.Println("DefineGoNativeValue", name, nv)
x.defineGoNativeValue(false, name, nv)
}

Expand All @@ -1215,61 +1200,6 @@ func (x *PackageNode) defineGoNativeValue(isConst bool, n Name, nv interface{})
x.Define2(isConst, n, tv.T, tv)
}

// ----------------------------------------
// Machine methods

// NOTE: Unlike doOpCall(), doOpCallGoNative() also handles
// conversions, similarly to doOpConvert().
/*func (m *Machine) doOpCallGoNative() {
fr := m.LastFrame()
fv := fr.GoFunc
ft := fv.Value.Type()
hasVarg := ft.IsVariadic()
numParams := ft.NumIn()
isVarg := fr.IsVarg
// pop and convert params.
ptvs := m.PopCopyValues(fr.NumArgs)
m.PopValue() // func value
prvs := make([]reflect.Value, 0, len(ptvs))
for i := 0; i < fr.NumArgs; i++ {
ptv := &ptvs[i]
var it reflect.Type
if hasVarg && numParams-1 <= i && !isVarg {
it = ft.In(numParams - 1)
it = it.Elem()
} else {
it = ft.In(i)
}
erv := reflect.New(it).Elem()
prvs = append(prvs, gno2GoValue(ptv, erv))
}
// call and get results.
rrvs := []reflect.Value(nil)
if isVarg {
rrvs = fv.Value.CallSlice(prvs)
} else {
rrvs = fv.Value.Call(prvs)
}
// convert and push results.
for _, rvs := range rrvs {
// TODO instead of this shallow conversion,
// look at expected Gno type and convert appropriately.
rtv := go2GnoValue(m.Alloc, rvs)
m.PushValue(rtv)
}
// carry writes to params if needed.
for i := 0; i < fr.NumArgs; i++ {
ptv := &ptvs[i]
prv := prvs[i]
if !ptv.IsUndefined() {
go2GnoValueUpdate(m.Alloc, m.Realm, 0, ptv, prv)
}
}
// cleanup
m.NumResults = fv.Value.Type().NumOut()
m.PopFrame()
}*/

// ----------------------------------------
// misc

Expand Down
4 changes: 0 additions & 4 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,10 +1398,6 @@ func (m *Machine) Run() {
case OpConvert:
m.incrCPU(OpCPUConvert)
m.doOpConvert()
/* GoNative Operators */
//case OpCallGoNative:
// m.incrCPU(OpCPUCallGoNative)
// m.doOpCallGoNative()
/* Type operators */
case OpFieldType:
m.incrCPU(OpCPUFieldType)
Expand Down
14 changes: 0 additions & 14 deletions gnovm/pkg/gnolang/op_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,6 @@ func (m *Machine) doOpReturnCallDefers() {
}
}
copy(b.Values, dfr.Args)
/*} else if dfr.GoFunc != nil {
fv := dfr.GoFunc
ptvs := dfr.Args
prvs := make([]reflect.Value, len(ptvs))
for i := 0; i < len(prvs); i++ {
// TODO consider when declared types can be
// converted, e.g. fmt.Println. See GoValue.
prvs[i] = gno2GoValue(&ptvs[i], reflect.Value{})
}
// Call and ignore results.
fv.Value.Call(prvs)
// Cleanup.
m.NumResults = 0
*/
} else {
panic("should not happen")
}
Expand Down
4 changes: 1 addition & 3 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ func ConvertTo(alloc *Allocator, store Store, tv *TypedValue, t Type, isConst bo
// special case for interface target
if t.Kind() == InterfaceKind {
if tv.IsUndefined() && tv.T == nil {
if _, ok := t.(*NativeType); !ok { // no support for native now
tv.T = t
}
tv.T = t
}
return
}
Expand Down
15 changes: 8 additions & 7 deletions gnovm/stdlibs/testing/testing.gno
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,17 @@ type Report struct {
Failed bool
Skipped bool
}
func (r *Report) marshal() string{
failed:="false"

func (r *Report) marshal() string {
failed := "false"
skipped := "false"
if r.Failed{
failed="true"
if r.Failed {
failed = "true"
}
if r.Skipped{
skipped="true"
if r.Skipped {
skipped = "true"
}
return `{"Failed":`+failed+`,"Skipped":`+skipped+`}`
return `{"Failed":` + failed + `,"Skipped":` + skipped + `}`
}

func (t *T) report() Report {
Expand Down
29 changes: 14 additions & 15 deletions gnovm/tests/stdlibs/fmt/fmt.gno
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package fmt



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

func Printf(format string, 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 Print(a ...interface{}) (int, error) {
return 0, nil
}

func Sprint(a ...interface{}) string {
Expand All @@ -31,28 +29,29 @@ func Sscanf(str string, format string, a ...interface{}) (n int, err error) {
}

func Errorf(format string, a ...interface{}) error {
return &errorFmt{err:format}
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{
type errorFmt struct {
err string
}
func (e *errorFmt) Error()string{

func (e *errorFmt) Error() string {
return e.err
}

type Writer interface {
Write(p []byte) (n int, err error)
}
}
Loading

0 comments on commit ebbe286

Please sign in to comment.