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 33 commits
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.gno linguist-language=Go
*.pb.go linguist-generated merge=ours -diff
go.sum linguist-generated text
gnovm/stdlibs/native.go linguist-generated
gnovm/tests/stdlibs/native.go linguist-generated
4 changes: 4 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ flags:
paths:
- gno.land
after_n_builds: 3
misc:
paths:
- misc
after_n_builds: 1
97 changes: 97 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: lint
thehowl marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches: [ "master" ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
# sync with misc/devdeps/go.mod
version: v1.53
args:
--config=./.github/golangci.yml
fmt:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Install make
run: sudo apt-get install -y make

- name: Checkout code
uses: actions/checkout@v3

# prefill dependencies so that mod messages don't show up in make output
- name: Fetch dependencies
run: go mod download -modfile ./misc/devdeps/go.mod -x

# inspired by:
# https://github.com/Jerome1337/gofmt-action/blob/d5eabd189843f1d568286a54578159978b7c0fb1/entrypoint.sh
- name: Check gofumpt
thehowl marked this conversation as resolved.
Show resolved Hide resolved
run: |
output="$(GOFMT_FLAGS=-l make -s fmt)"
if [ ! -z "$output" ]; then
echo "The following files are not properly formatted; run 'make fmt' to format them."
echo "$output"
exit 1
else
echo 'Succeeded.'
fi
modtidy:
thehowl marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3

- name: Check go.mods
run: |
sums="$(sha256sum go.mod misc/devdeps/go.mod)"
for path in . ./misc/devdeps; do
env -C $path go mod tidy -v || exit 1
done
echo "$sums" | sha256sum -c
generated:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3

- name: Check generated files are up to date
run: |
go generate -x ./...
if [ "$(git status -s)" != "" ]; then
echo "command 'go generate' creates file that differ from git tree, please run 'go generate' and commit:"
git status -s
exit 1
fi
104 changes: 46 additions & 58 deletions .github/workflows/misc.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,66 @@
# tests the "misc" directory & tools
# (not meant for miscellaneous workflows)
name: misc

on:
pull_request:
paths:
- "misc/genstd/**.go"
- "misc/Makefile"
- ".github/workflows/misc.yml"
push:
branches: [ "master" ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
build:
strategy:
fail-fast: false
matrix:
go-version: # two latest versions
- "1.19.x"
- "1.20.x"
thehowl marked this conversation as resolved.
Show resolved Hide resolved
program:
- "genstd"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Install Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: go install
working-directory: misc
run: go install ./${{ matrix.program }}

- name: Checkout code
uses: actions/checkout@v3

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
# sync with misc/devdeps/go.mod
version: v1.53
args:
--config=./.github/golangci.yml
fmt:
test:
strategy:
fail-fast: false
matrix:
go-version: [ "1.19.x", "1.20.x" ]
args:
- _test.genstd
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Install Go
uses: actions/setup-go@v4
- uses: actions/setup-go@v4
with:
go-version: 1.20.x

- name: Install make
run: sudo apt-get install -y make

- name: Checkout code
uses: actions/checkout@v3

# prefill dependencies so that mod messages don't show up in make output
- name: Fetch dependencies
run: go mod download -modfile ./misc/devdeps/go.mod -x

# inspired by:
# https://github.com/Jerome1337/gofmt-action/blob/d5eabd189843f1d568286a54578159978b7c0fb1/entrypoint.sh
- name: Check gofumpt
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: test
working-directory: misc
run: |
output="$(GOFMT_FLAGS=-l make -s fmt)"
if [ ! -z "$output" ]; then
echo "The following files are not properly formatted; run 'make fmt' to format them."
echo "$output"
exit 1
else
echo 'Succeeded.'
fi
modtidy:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
export GOPATH=$HOME/go
export GOTEST_FLAGS="-v -p 1 -timeout=30m -coverprofile=coverage.out -covermode=atomic"
make ${{ matrix.args }}
- if: runner.os == 'Linux'
uses: codecov/codecov-action@v3
with:
go-version: 1.20.x

- name: Checkout code
uses: actions/checkout@v3

- name: Check go.mods
run: |
sums="$(sha256sum go.mod misc/devdeps/go.mod)"
for path in . ./misc/devdeps; do
env -C $path go mod tidy -v || exit 1
done
echo "$sums" | sha256sum -c
token: ${{ secrets.CODECOV_TOKEN }}
name: misc
flags: misc,misc-${{matrix.args}},go-${{ matrix.go-version }}
files: ./misc/coverage.out
fail_ci_if_error: false # temporarily
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test.components:
$(MAKE) --no-print-directory -C gnovm test
$(MAKE) --no-print-directory -C gno.land test
$(MAKE) --no-print-directory -C examples test
$(MAKE) --no-print-directory -C misc test

.PHONY: test.docker
test.docker:
Expand Down
4 changes: 4 additions & 0 deletions examples/gno.land/p/demo/avl/z_0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "init.0",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/test",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down Expand Up @@ -301,6 +303,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/test",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down
4 changes: 4 additions & 0 deletions examples/gno.land/p/demo/avl/z_1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "init.0",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/test",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down Expand Up @@ -325,6 +327,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/test",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down
8 changes: 4 additions & 4 deletions examples/gno.land/r/demo/boards/z_4_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func main() {
// "Escaped": true,
// "ObjectID": "336074805fc853987abe6f7fe3ad97a6a6f3077a:2"
// },
// "Index": "188",
// "Index": "189",
// "TV": null
// }
// }
Expand Down Expand Up @@ -541,7 +541,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "8164abed5231309c88497013f7da72a1b5d427b0",
// "Hash": "25ffc45509708ca0ae17271cb4c3a1dfb367b965",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:115"
// }
// },
Expand Down Expand Up @@ -847,7 +847,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "5b4b593f1d4b37cb99166247ea28174f91087fdd",
// "Hash": "a8e67b9881af89ca2ec2f05778bf7528a54a5833",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:82"
// }
// },
Expand All @@ -865,7 +865,7 @@ func main() {
// },
// "V": {
// "@type": "/gno.RefValue",
// "Hash": "7e9fd9bb5e90a06c7751585cd80f23aedddde25b",
// "Hash": "d8ae14a4620e3c6dedabd76cd0c5d7e3c205d647",
// "ObjectID": "f6dbf411da22e67d74cd7ddba6a76cd7e14a4822:83"
// }
// },
Expand Down
9 changes: 9 additions & 0 deletions gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ _test.gnolang.stdlibs.sync:; go test $(GOTEST_FLAGS) tests/*.go -test.short -run

########################################
# Code gen
# TODO: move _dev.stringer to go:generate instructions, simplify generate
# to just go generate.
.PHONY: generate
generate: _dev.stringer _dev.generate

stringer_cmd=$(rundep) golang.org/x/tools/cmd/stringer
.PHONY: _dev.stringer
_dev.stringer:
Expand All @@ -68,5 +73,9 @@ _dev.stringer:
$(stringer_cmd) -type=VPType ./pkg/gnolang
$(stringer_cmd) -type=Word ./pkg/gnolang

.PHONY: _dev.generate
_dev.generate:
go generate -x ./...

# genproto:
# see top-level Makefile.
2 changes: 2 additions & 0 deletions gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/x",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/gno_test/realm_incorrect.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stderr '=== RUN file/x_filetest.gno'
stderr 'panic: fail on x_filetest.gno: diff:'
stderr '--- Expected'
stderr '\+\+\+ Actual'
stderr '@@ -1 \+1,64 @@'
stderr '@@ -1 \+1,66 @@'
stderr '-xxx'
stderr '\+switchrealm\["gno.land/r/x"\]'

Expand Down
2 changes: 2 additions & 0 deletions gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func main() {
// "FileName": "main.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
// "NativePkg": "",
// "PkgPath": "gno.land/r/x",
// "Source": {
// "@type": "/gno.RefNode",
Expand Down
4 changes: 3 additions & 1 deletion gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
// run empty main().
func TestRunEmptyMain(t *testing.T) {
m := NewMachine("test", nil)
main := FuncD("main", nil, nil, nil)
// []Stmt{} != nil, as nil means that in the source code not even the
// brackets are present and is reserved for external (ie. native) functions.
thehowl marked this conversation as resolved.
Show resolved Hide resolved
main := FuncD("main", nil, nil, []Stmt{})
m.RunDeclaration(main)
m.RunMain()
}
Expand Down
Loading
Loading