-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# test recursion | ||
|
||
## start a new node | ||
gnoland start | ||
|
||
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/panic -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/demo/panic --func Trigger --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast -chainid=tendermint_test test1 | ||
|
||
stderr 'panic\(i\<VPBlock\(1\,0\)\>\)' | ||
stderr 'gno.land/r/demo/panic:5' | ||
stderr 'p\<VPBlock\(3\,0\)\>\(\)' | ||
stderr 'gno.land/r/demo/panic:9' | ||
|
||
-- panic.gno -- | ||
package main | ||
|
||
func p() { | ||
i := "here" | ||
panic(i) | ||
} | ||
|
||
func Trigger() { | ||
p() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# test panic recursion | ||
## start a new node | ||
gnoland start | ||
|
||
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/panic -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/demo/panic --func Trigger --gas-fee 1000000ugnot --gas-wanted 2000000 --broadcast -chainid=tendermint_test test1 | ||
|
||
|
||
stderr 'panic\(\(const \(\"here\" \<untyped\> string\)\)\)' | ||
stderr 'gno.land/r/demo/panic:5' | ||
stderr 'p\<VPBlock\(3\,0\)\>\(i\<VPBlock\(1\,0\)\> \+ \(const \(1 int\)\)\)' | ||
stderr 'gno.land/r/demo/panic:7' | ||
stderr 'p\<VPBlock\(3\,0\)\>\(i\<VPBlock\(1\,0\)\> \+ \(const \(1 int\)\)\)' | ||
stderr 'gno.land/r/demo/panic:7' | ||
stderr 'p\<VPBlock\(3\,0\)\>\(i\<VPBlock\(1\,0\)\> \+ \(const \(1 int\)\)\)' | ||
stderr 'gno.land/r/demo/panic:7' | ||
stderr 'p\<VPBlock\(3\,0\)\>\(\(const \(0 int\)\)\)' | ||
stderr 'gno.land/r/demo/panic:11' | ||
|
||
-- panic.gno -- | ||
package main | ||
|
||
func p(i int) { | ||
if i == 3 { | ||
panic("here") | ||
} | ||
p(i+1) | ||
} | ||
|
||
func Trigger() { | ||
p(0) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package gnolang | ||
|
||
type execution struct { | ||
Stmt Stmt | ||
Fun *FuncValue | ||
} | ||
type Stack struct { | ||
Execs []execution | ||
} | ||
|
||
func NewStack() *Stack { | ||
return &Stack{ | ||
Execs: make([]execution, 0), | ||
} | ||
} | ||
|
||
func (s *Stack) onStmtPopped(stmt Stmt) { | ||
if len(s.Execs) > 0 { | ||
s.Execs[len(s.Execs)-1].Stmt = stmt | ||
} | ||
} | ||
|
||
func (s *Stack) OnFramePushed(frame *Frame) { | ||
if frame.Func != nil { | ||
s.Execs = append(s.Execs, execution{Fun: frame.Func}) | ||
} | ||
} | ||
|
||
func (s *Stack) OnFramePopped(frame *Frame) { | ||
if frame.Func != nil { | ||
s.Execs = s.Execs[:len(s.Execs)-1] | ||
} | ||
} | ||
|
||
func (s *Stack) Copy() *Stack { | ||
cpy := NewStack() | ||
cpy.Execs = make([]execution, len(s.Execs)) | ||
copy(cpy.Execs, s.Execs) | ||
return cpy | ||
} |