segments.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package vm
  17. import "math/big"
  18. type jumpSeg struct {
  19. pos uint64
  20. err error
  21. gas *big.Int
  22. }
  23. func (j jumpSeg) do(program *Program, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) ([]byte, error) {
  24. if !contract.UseGas(j.gas) {
  25. return nil, OutOfGasError
  26. }
  27. if j.err != nil {
  28. return nil, j.err
  29. }
  30. *pc = j.pos
  31. return nil, nil
  32. }
  33. func (s jumpSeg) halts() bool { return false }
  34. func (s jumpSeg) Op() OpCode { return 0 }
  35. type pushSeg struct {
  36. data []*big.Int
  37. gas *big.Int
  38. }
  39. func (s pushSeg) do(program *Program, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) ([]byte, error) {
  40. // Use the calculated gas. When insufficient gas is present, use all gas and return an
  41. // Out Of Gas error
  42. if !contract.UseGas(s.gas) {
  43. return nil, OutOfGasError
  44. }
  45. for _, d := range s.data {
  46. stack.push(new(big.Int).Set(d))
  47. }
  48. *pc += uint64(len(s.data))
  49. return nil, nil
  50. }
  51. func (s pushSeg) halts() bool { return false }
  52. func (s pushSeg) Op() OpCode { return 0 }