diff options
author | stefan <stefan@s00.xyz> | 2023-05-24 08:32:08 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-05-24 08:32:08 -0400 |
commit | ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (patch) | |
tree | 9b49307112b0f489189cf65c1b50dd281f8e430f /vm/stack.go | |
parent | c30e7f5f99f9ad4d9552b645d7b89d7385972f99 (diff) | |
download | evm-ba2b9c8a1bb1876b6eb4c9783fde798b19de4418.tar.gz |
init
Diffstat (limited to 'vm/stack.go')
-rw-r--r-- | vm/stack.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/vm/stack.go b/vm/stack.go new file mode 100644 index 0000000..fc1cbd4 --- /dev/null +++ b/vm/stack.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + + "github.com/holiman/uint256" +) + +const STACK_CAP = (1 << 10) + +type Stack []uint256.Int + +func (s *Stack) Push(x *uint256.Int) { + *s = append(*s, *x) + if len(*s) + 1 > STACK_CAP { + log.Fatal("stack overflow") + } +} + +func (s *Stack) Pop() *uint256.Int { + if len(*s) <= 0 { + log.Fatal("stack underflow") + } + + r := (*s)[len(*s)-1] + *s = (*s)[:len(*s)-1] + return &r +} + +func (s *Stack) Peek() *uint256.Int { + return &(*s)[len(*s)-1] +} |