-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add std.CreatePackage #715
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -891,6 +891,21 @@ func (pv *PackageValue) GetPkgAddr() crypto.Address { | |
return DerivePkgAddr(pv.PkgPath) | ||
} | ||
|
||
func (pv *PackageValue) GetExportedFunctions(store Store) []*FuncDecl { | ||
res := []*FuncDecl{} | ||
for _, file := range pv.GetPackageNode(store).FileSet.Files { | ||
for _, decl := range file.Decls { | ||
if fdecl, ok := decl.(*FuncDecl); ok { | ||
if !fdecl.NameExpr.Name.IsExportedName() { | ||
continue | ||
} | ||
res = append(res, fdecl) | ||
} | ||
} | ||
} | ||
return res | ||
} | ||
|
||
// ---------------------------------------- | ||
// NativeValue | ||
|
||
|
@@ -1521,6 +1536,37 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey { | |
return MapKey(bz) | ||
} | ||
|
||
// - PrimitiveValue is moveable across realm boundary. | ||
// - Array and Struct are moveable across realm only if they are composed of moveable types(recursively applied). The value will be copied to the callee realm. | ||
// - Slice are moveable across realm only if they are referring to moveable types(recursively applied)(not implemented yet). | ||
// - Any other cases require some complex inter-realm object management scheme, low priority. | ||
func (tv *TypedValue) IsMoveableAcrossRealm() bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a misnomer because there is already a notion of what is passable between realms as already implemented... that is, one can already call a realm function from another realm, passing in objects, as long as objects aren't sharing persistence. What is implemented here conflicts with that. I think what you maybe want is IsMoveableAcrossChains or IsIBCArgument, and for that for now I think it should be limited to a list of stringified primitives only, no structs; and then we need to have a whole series of conversations to evolve that into something that either supports the EVM ABI, or some other interop standard. |
||
switch tv.T.Kind() { | ||
case | ||
BoolKind, StringKind, | ||
IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, | ||
UintKind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, | ||
BigintKind, BigdecKind: | ||
return true | ||
case StructKind: | ||
for _, field := range tv.V.(*StructValue).Fields { | ||
if !field.IsMoveableAcrossRealm() { | ||
return false | ||
} | ||
} | ||
return true | ||
case ArrayKind: | ||
for _, field := range tv.V.(*ArrayValue).List { | ||
if !field.IsMoveableAcrossRealm() { | ||
return false | ||
} | ||
} | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// ---------------------------------------- | ||
// Value utility/manipulation functions. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"bytes" | ||
|
||
gno "github.com/gnolang/gno/gnovm/pkg/gnolang" | ||
) | ||
|
||
func TestCreatePackage(t *testing.T) { | ||
stdin := new(bytes.Buffer) | ||
stdout := os.Stdout | ||
stderr := new(bytes.Buffer) | ||
store := TestStore("..", "", stdin) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.