summaryrefslogtreecommitdiff
path: root/vm/stack.go
blob: fc1cbd4b532307c19fa0291b8377fd0a491c8434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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]	
}