From ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 24 May 2023 08:32:08 -0400 Subject: init --- vm/stack.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 vm/stack.go (limited to 'vm/stack.go') 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] +} -- cgit v1.2.3