Skip to content
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(gnovm): improved native bindings #859

Merged
merged 73 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a938f69
initial poc
thehowl May 30, 2023
5358970
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Jun 9, 2023
6153b6a
changes
thehowl Jun 20, 2023
0002819
add injector call
thehowl Jun 20, 2023
cd94b0c
log ptrs
thehowl Jun 20, 2023
6248c80
change approach to "NativeStore"
thehowl Jun 23, 2023
b70c124
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Jun 23, 2023
9fc487a
remove old debug call
thehowl Jun 23, 2023
da4f9a8
make AssertOriginCall native gno
thehowl Jul 7, 2023
9edecac
more permanent location and name for stdgen
thehowl Jul 7, 2023
c4094d2
allow overriding std functions in test context
thehowl Jul 10, 2023
bc2d558
implement SkipHeights, add NativeStore elsewhere
thehowl Jul 10, 2023
d27a7ca
fix native bindings in realms
thehowl Jul 12, 2023
c876012
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Jul 12, 2023
0f54a0c
fix low-hanging failing tests
thehowl Jul 12, 2023
3a985fc
remove unused code, add more docs
thehowl Jul 12, 2023
f2d8894
more docs & text fixes
thehowl Jul 12, 2023
daa58c9
Merge branch 'master' into dev/native-bindings-poc
thehowl Jul 24, 2023
50c919d
ci: add workflow to ensure go generate is executed
thehowl Jul 24, 2023
73e411e
add generate to make
thehowl Jul 24, 2023
b1d6a3d
convert all injections to new native bindings
thehowl Aug 23, 2023
3560f42
add native.go files as generated
thehowl Aug 23, 2023
82e113c
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Aug 23, 2023
6452305
add // injected comment on all injected fns
thehowl Aug 23, 2023
ed81331
address PR comments
thehowl Aug 23, 2023
b661430
support returning gno.TypedValue, for specialcasing GetBanker
thehowl Aug 23, 2023
5bda745
fix failing cmd tests
thehowl Aug 23, 2023
e1bf401
refactor genstd field iteration
thehowl Aug 23, 2023
60525e3
typo
thehowl Aug 23, 2023
b6a6c5d
Update gnovm/pkg/gnolang/gonative.go
thehowl Aug 30, 2023
62afd22
add tests
thehowl Aug 31, 2023
0e787fa
update makefiles & workflows
thehowl Aug 31, 2023
9f3f261
add misc to codecov
thehowl Aug 31, 2023
ec9f5da
address TODO in filterDuplicates
thehowl Sep 6, 2023
d7de22f
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Sep 6, 2023
a3b25e5
add stdlibs documentation file;
thehowl Sep 6, 2023
a68cfe4
fix ci
thehowl Sep 6, 2023
a89302f
remove 1.20 from versions for genstd
thehowl Sep 6, 2023
c3200a6
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Sep 16, 2023
c6a4be3
fix: copy native store on Fork()
thehowl Sep 20, 2023
dcf4904
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Oct 11, 2023
42a11cc
Update docs/stdlibs.md
thehowl Oct 20, 2023
c64aaac
allow duplicate definitions in preprocessor/vm; switch to checkDuplic…
thehowl Oct 21, 2023
f874119
add comment on exprstring;
thehowl Oct 21, 2023
237bce9
add godoc to FuncD
thehowl Oct 21, 2023
bef0473
doc changes
thehowl Oct 21, 2023
361667a
base64 change doc
thehowl Oct 21, 2023
5592265
fixes on new method
thehowl Oct 21, 2023
b5b46d6
lint fix
thehowl Oct 21, 2023
c7f0c1a
jae trying new approach
jaekwon Oct 21, 2023
9477f86
Merge branch 'thehowl/dev/native-bindings-poc' of github.com:gnolang/…
thehowl Oct 21, 2023
1475790
also update the FuncValue.Type
jaekwon Oct 21, 2023
5bc3815
Merge branch 'thehowl/dev/native-bindings-poc' of github.com:gnolang/…
thehowl Oct 21, 2023
bb613a7
help for debugging
thehowl Oct 21, 2023
b910ac9
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Oct 21, 2023
ce0185e
gofmt
thehowl Oct 21, 2023
1f647e0
redeclaration tests; better redeclaration handling; still WIP
jaekwon Oct 21, 2023
f6c83ae
do not redeclare methods upon restart // hack
jaekwon Oct 21, 2023
7874fb7
cleanup
jaekwon Oct 23, 2023
5930f1a
recover and revertToOld upon panic in preprocessor
jaekwon Oct 24, 2023
c065637
Merge branch 'thehowl/dev/native-bindings-poc' of github.com:gnolang/…
thehowl Oct 27, 2023
d8d93c8
workflow changes
thehowl Oct 27, 2023
c9deb06
fmt
thehowl Oct 27, 2023
fc858af
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Oct 27, 2023
9439ac3
make error understandable
thehowl Oct 27, 2023
b89bf91
move invalid packages to gnovm/tests/files/extern
thehowl Oct 27, 2023
7ca0167
make gno test . work for math, and other native bindings stdlibs
thehowl Oct 27, 2023
2ff3f63
add test to check for revertToOld
thehowl Oct 28, 2023
6f6a621
prefer comparing locations directly
thehowl Dec 18, 2023
12a837b
Merge branch 'master' of github.com:gnolang/gno into dev/native-bindi…
thehowl Dec 18, 2023
ac66975
fix lint
thehowl Dec 18, 2023
108acc1
cleanup
thehowl Dec 18, 2023
9d13896
remove old stdlib doc
thehowl Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions gnovm/pkg/gnolang/go2gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func ParseFile(filename string, body string) (fn *FileNode, err error) {
defer func() {
if r := recover(); r != nil {
if rerr, ok := r.(error); ok {
err = rerr
err = errors.Wrap(rerr, "parsing file")
} else {
err = errors.New(fmt.Sprintf("%v", r))
err = errors.New(fmt.Sprintf("%v", r)).Stacktrace()
}
return
}
Expand Down Expand Up @@ -431,7 +431,16 @@ func Go2Gno(fs *token.FileSet, gon ast.Node) (n Node) {
}
name := toName(gon.Name)
type_ := Go2Gno(fs, gon.Type).(*FuncTypeExpr)
body := Go2Gno(fs, gon.Body).(*BlockStmt).Body
var body []Stmt
if gon.Body != nil {
body = Go2Gno(fs, gon.Body).(*BlockStmt).Body
} else {
/*bd, err := ParseExpr(`panic("call to bodyless/external function is invalid outside of standard library")`)
if err != nil {
panic(err)
}
body = []Stmt{&ExprStmt{X: bd}}*/
}
return &FuncDecl{
IsMethod: isMethod,
Recv: recv,
Expand Down
9 changes: 8 additions & 1 deletion gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,14 @@ func (x *PackageNode) DefineNative(n Name, ps, rs FieldTypeExprs, native func(*M
if native == nil {
panic("DefineNative expects a function, but got nil")
}

if idx, exists := x.GetLocalIndex(n); exists {
// XXX(morgan): trick to look as a new definition to Define2;
// if we try to redefine an old value it looks like precompile
// is not cooperating well with us...
x.Names[idx] = "#uncallable_" + x.Names[idx]
}

fd := FuncD(n, ps, rs, nil)
fd = Preprocess(nil, x, fd).(*FuncDecl)
ft := evalStaticType(nil, x, &fd.Type).(*FuncType)
Expand Down Expand Up @@ -1648,7 +1656,6 @@ func (sb *StaticBlock) GetStaticTypeOfAt(store Store, path ValuePath) Type {
path.Depth -= 1
}
}
panic("should not happen")
}

// Implements BlockNode.
Expand Down
3 changes: 3 additions & 0 deletions gnovm/stdlibs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ type ExecContext struct {
OrigSendSpent *std.Coins // mutable
Banker Banker
}

func (e ExecContext) GetTimestamp() int64 { return e.Timestamp }
func (e ExecContext) GetTimestampNano() int64 { return e.TimestampNano }
8 changes: 1 addition & 7 deletions gnovm/stdlibs/crypto/sha256/sha256.gno
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package sha256

import (
isha256 "internal/crypto/sha256"
)

const Size = 32

// Sum returns the SHA-256 checksum of the data.
func Sum256(data []byte) [Size]byte {
return isha256.Sum256(data)
}
func Sum256(data []byte) [Size]byte
thehowl marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions gnovm/stdlibs/crypto/sha256/sha256.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package sha256

import "crypto/sha256"

func Sum256(data []byte) [32]byte {
return sha256.Sum256(data)
}
thehowl marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 0 additions & 3 deletions gnovm/stdlibs/internal/crypto/sha256/sha256.gno

This file was deleted.

Loading