首页 > 编程语言 >go-ethereum-master/core/vm/stack.go 源码阅读

go-ethereum-master/core/vm/stack.go 源码阅读

时间:2023-10-23 17:46:59浏览次数:31  
标签:core len st 源码 func go data Stack

// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package vm

import (
	"sync"

	"github.com/holiman/uint256"
) //使用256版本的整数.

// 一个函数把 interface{}作为参数,那么他可以接受任意类型的值作为参数,如果一个函数 返回 interface{},那么也就可以返回任意类型的值。是不是很有用啊!
var stackPool = sync.Pool{ // pool里面设置好new函数就行.
	New: func() interface{} {
		return &Stack{data: make([]uint256.Int, 0, 16)} // 池子里有16个stack,返回类型*stack
	},
}

// Stack is an object for basic stack operations. Items popped to the stack are
// expected to be changed and modified. stack does not take care of adding newly
// initialised objects.
type Stack struct {
	data []uint256.Int
}

func newstack() *Stack {
	return stackPool.Get().(*Stack) //.(*Stack) 是接口转换, 强制转成*Stack指针. //get底层调用stackpool.New.所以返回的是stack的指针. 28行.
}

func returnStack(s *Stack) { //把s放回pool中.
	s.data = s.data[:0] //清空data里面数据.
	stackPool.Put(s)    //放回去.
}

// Data returns the underlying uint256.Int array.
func (st *Stack) Data() []uint256.Int {
	return st.data
}

func (st *Stack) push(d *uint256.Int) {
	// NOTE push limit (1024) is checked in baseCheck
	st.data = append(st.data, *d)
}

func (st *Stack) pop() (ret uint256.Int) {
	ret = st.data[len(st.data)-1]
	st.data = st.data[:len(st.data)-1]
	return
}

func (st *Stack) len() int {
	return len(st.data)
}

func (st *Stack) swap(n int) { //栈顶元素跟距离栈顶n的元素交换.
	st.data[st.len()-n], st.data[st.len()-1] = st.data[st.len()-1], st.data[st.len()-n]
}

func (st *Stack) dup(n int) {
	st.push(&st.data[st.len()-n])
}

func (st *Stack) peek() *uint256.Int {
	return &st.data[st.len()-1]
}

// Back returns the n'th item in stack
func (st *Stack) Back(n int) *uint256.Int {
	return &st.data[st.len()-n-1]
}

  

标签:core,len,st,源码,func,go,data,Stack
From: https://www.cnblogs.com/zhangbo2008/p/17783047.html

相关文章

  • Oracle10gOCP042题库121166题共168题
    121.Youwanttocreateanewoptimizeddatabaseforyourtransactionalproductionenvironmenttobeusedbyafinancialapplication.Whilecreatingthedatabase,youwanttheOraclesoftwaretotakecareofallbasicsettingstooptimizethedatabasep......
  • Oracle10gOCP042题库130题共168题
    声明:对于答案的相关的说明,是个人对Oracle的理解。1.Becauseofapoweroutage,instancefailurehasoccurred.Fromwhatpointintheredologdoesrecoverybeginandwheredoesitend?A.CurrentredologandinactiveredologB.Checkpointpositiontoendofr......
  • Oracle10gOCP042题库3170题共168题
    31.WhichtwostatementsaretrueregardingthedatabaseinARCHIVELOGmode?(Choosetwo.) A)Youhavetoshutdownthedatabasetoperformthebackups. B)Archivinginformationiswrittentothedatafilesandredologfiles. C)Youcanperformcomp......
  • Oracle10gOCP042题库71120题共168题
    71.Yourdatabaseinstanceisstartedusingtheserverparameterfile(SPFILE).Controlfilesaremultiplexedandstoredondifferentdisks.Becauseofadiskfailure,youlostoneofthesecontrolfiles.Youreplacedthedamageddisk.Whatisthecorre......
  • net core 在windows 下部署服务
    参考来源https://www.jb51.net/article/265865.htm首先要指定配置文件,否则运行的时候找不到appsettings.json,在使用sccreate创建Windows服务时,确实存在一个问题,即服务的默认工作目录是C:\Windows\System32,而不是服务的可执行文件所在的目录。这就是为什么你的服务找不......
  • Go语言代码断行规则详解
    本文深入探讨了Go语言中代码断行的各个方面,从基础概念到实际应用实践。关注【TechLeadCloud】,分享互联网架构、云服务技术的全维度知识。作者拥有10+年互联网服务架构、AI产品研发经验、团队管理经验,同济本复旦硕,复旦机器人智能实验室成员,阿里云认证的资深架构师,项目管理专业......
  • ubuntu20.04下源码编译python 3.12
    需要注意的地方 1.安装依赖:https://devguide.python.org/getting-started/setup-building/#build-dependenciessudoapt-getinstallbuild-essentialgdblcovpkg-config\libbz2-devlibffi-devlibgdbm-devlibgdbm-compat-devliblzma-dev\libnc......
  • 视频直播系统源码,在Laravel中自定义模板函数 并在模板中调用
    视频直播系统源码,在Laravel中自定义模板函数并在模板中调用第一步:在app/bootstrap下定义一个php文件 diy_helpers.php​内容如下: <?phpfunctioncssVersion($data){  $version="1.01";  return$data."?v=".$version;}functionjsVersion($data){  $ver......
  • 图书推荐与管理系统Python+协同过滤推荐算法+Django网页界面
    一、介绍图书管理与推荐系统。使用Python作为主要开发语言。前端采用HTML、CSS、BootStrap等技术搭建界面结构,后端采用Django作为逻辑处理,通过Ajax等技术实现数据交互通信。在图书推荐方面使用经典的协同过滤算法作为推荐算法模块。主要功能有:角色分为普通用户和管理员普通用户可注......
  • NetCore windowsService 看门狗应用程序
    publicclassDogService:BackgroundService{publicoverrideTaskStartAsync(CancellationTokencancellationToken){returnbase.StartAsync(cancellationToken);}///<summary>///每一秒执行一次......