Removed defer/panic. #503

This commit is contained in:
obscuren
2015-03-27 16:09:57 +01:00
parent 00f8319faf
commit 8a22cd5e6c
4 changed files with 181 additions and 121 deletions

View File

@ -17,10 +17,7 @@ type stack struct {
}
func (st *stack) push(d *big.Int) {
if len(st.data) == maxStack {
panic(fmt.Sprintf("stack limit reached (%d)", maxStack))
}
// NOTE push limit (1024) is checked in baseCheck
stackItem := new(big.Int).Set(d)
if len(st.data) > st.ptr {
st.data[st.ptr] = stackItem
@ -52,10 +49,11 @@ func (st *stack) peek() *big.Int {
return st.data[st.len()-1]
}
func (st *stack) require(n int) {
func (st *stack) require(n int) error {
if st.len() < n {
panic(fmt.Sprintf("stack underflow (%d <=> %d)", len(st.data), n))
return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n)
}
return nil
}
func (st *stack) Print() {