Skip to content

Commit

Permalink
Merge branch 'master' into feat/gnoland-txtar-driver
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton authored Sep 24, 2023
2 parents 28ac3b0 + 5a7d005 commit d47e2f4
Show file tree
Hide file tree
Showing 41 changed files with 3,730 additions and 74 deletions.
19 changes: 14 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ Add to your `.vimrc` file:

```vim
function! GnoFmt()
cexpr system('gofmt -e -w ' . expand('%')) "or replace with gofumpt, see below
edit!
cexpr system('gofmt -e -w ' . expand('%')) " or replace with gofumpt, see below
edit!
set syntax=go
endfunction
command! GnoFmt call GnoFmt()
augroup gno_autocmd
autocmd!
autocmd BufNewFile,BufRead *.gno set filetype=go
autocmd BufWritePost *.gno GnoFmt
autocmd!
autocmd BufNewFile,BufRead *.gno set syntax=go
autocmd BufWritePost *.gno GnoFmt
augroup END
```

Expand All @@ -96,6 +97,9 @@ To use *gofumpt* instead of *gofmt*, as hinted in the comment, you may either ha
cexpr system('go run -modfile </path/to/gno>/misc/devdeps/go.mod mvdan.cc/gofumpt -w ' . expand('%'))
```

There is an experimental and unofficial [Gno Language Server](https://github.com/jdkato/gnols)
developed by the community, with an installation guide for Neovim.

#### Emacs Support

1. Install [go-mode.el](https://github.com/dominikh/go-mode.el).
Expand All @@ -105,6 +109,11 @@ cexpr system('go run -modfile </path/to/gno>/misc/devdeps/go.mod mvdan.cc/gofump
(add-to-list 'auto-mode-alist '("\\.gno\\'" . go-mode))
```

#### Sublime Text

There is an experimental and unofficial [Gno Language Server](https://github.com/jdkato/gnols)
developed by the community, with an installation guide for Sublime Text.

### Local Setup

To get started with Gno development, the process is relatively straightforward.
Expand Down
8 changes: 4 additions & 4 deletions examples/gno.land/p/demo/grc/grc721/basic_nft.gno
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *basicNFT) Approve(to std.Address, tid TokenID) error {
return ErrApprovalToCurrentOwner
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if caller != owner && !s.IsApprovedForAll(owner, caller) {
return ErrCallerIsNotOwnerOrApproved
}
Expand Down Expand Up @@ -123,15 +123,15 @@ func (s *basicNFT) SetApprovalForAll(operator std.Address, approved bool) error
return ErrInvalidAddress
}

caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
return s.setApprovalForAll(caller, operator, approved)
}

// Safely transfers `tokenId` token from `from` to `to`, checking that
// contract recipients are aware of the GRC721 protocol to prevent
// tokens from being forever locked.
func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if !s.isApprovedOrOwner(caller, tid) {
return ErrCallerIsNotOwnerOrApproved
}
Expand All @@ -150,7 +150,7 @@ func (s *basicNFT) SafeTransferFrom(from, to std.Address, tid TokenID) error {

// Transfers `tokenId` token from `from` to `to`.
func (s *basicNFT) TransferFrom(from, to std.Address, tid TokenID) error {
caller := std.GetOrigCaller()
caller := std.PrevRealm().Addr()
if !s.isApprovedOrOwner(caller, tid) {
return ErrCallerIsNotOwnerOrApproved
}
Expand Down
2 changes: 1 addition & 1 deletion gnovm/docs/go-gno-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Additional native types:
| net/rpc/jsonrpc | TBD |
| net/smtp | TBD |
| net/textproto | TBD |
| net/url | TBD |
| net/url | full |
| os | TBD |
| os/exec | TBD |
| os/signal | TBD |
Expand Down
42 changes: 18 additions & 24 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type MachineOptions struct {
var machinePool = sync.Pool{
New: func() interface{} {
return &Machine{
Ops: make([]Op, OpSize),
Values: make([]TypedValue, ValueSize),
Ops: make([]Op, VMSliceSize),
Values: make([]TypedValue, VMSliceSize),
}
},
}
Expand Down Expand Up @@ -117,20 +117,14 @@ func NewMachineWithOptions(opts MachineOptions) *Machine {
}
context := opts.Context
mm := machinePool.Get().(*Machine)
*mm = Machine{
Ops: mm.Ops,
NumOps: 0,
Values: mm.Values,
NumValues: 0,
Package: pv,
Alloc: alloc,
CheckTypes: checkTypes,
ReadOnly: readOnly,
MaxCycles: maxCycles,
Output: output,
Store: store,
Context: context,
}
mm.Package = pv
mm.Alloc = alloc
mm.CheckTypes = checkTypes
mm.ReadOnly = readOnly
mm.MaxCycles = maxCycles
mm.Output = output
mm.Store = store
mm.Context = context

if pv != nil {
mm.SetActivePackage(pv)
Expand All @@ -139,13 +133,12 @@ func NewMachineWithOptions(opts MachineOptions) *Machine {
}

const (
OpSize = 1024
ValueSize = 1024
VMSliceSize = 1024
)

var (
opZeroed [OpSize]Op
valueZeroed [ValueSize]TypedValue
opZeroed [VMSliceSize]Op
valueZeroed [VMSliceSize]TypedValue
)

// m should not be used after this call
Expand All @@ -154,13 +147,14 @@ var (
// and prevent objects that were not taken from
// the pool, to call Release
func (m *Machine) Release() {
// copy()
// here we zero in the values for the next user
m.NumOps = 0
m.NumValues = 0
// this is the fastest way to zero-in a slice in Go
copy(m.Ops, opZeroed[:])
copy(m.Values, valueZeroed[:])

ops, values := m.Ops[:VMSliceSize:VMSliceSize], m.Values[:VMSliceSize:VMSliceSize]
copy(ops, opZeroed[:])
copy(values, valueZeroed[:])
*m = Machine{Ops: ops, Values: values}

machinePool.Put(m)
}
Expand Down
10 changes: 10 additions & 0 deletions gnovm/pkg/gnolang/machine_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gnolang

import "testing"

func BenchmarkCreateNewMachine(b *testing.B) {
for i := 0; i < b.N; i++ {
m := NewMachineWithOptions(MachineOptions{})
m.Release()
}
}
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/values_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func (tv *TypedValue) Sprint(m *Machine) string {
res := m.Eval(Call(Sel(&ConstExpr{TypedValue: *tv}, "Error")))
return res[0].GetString()
}
// print declared type
if _, ok := tv.T.(*DeclaredType); ok {
return tv.String()
}
// otherwise, default behavior.
switch bt := baseOf(tv.T).(type) {
case PrimitiveType:
Expand Down
Loading

0 comments on commit d47e2f4

Please sign in to comment.