mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
yield op code for yielding coroutine computation
This commit is contained in:
parent
e959d6cee1
commit
9fa627cd54
4 changed files with 29 additions and 1 deletions
|
|
@ -817,6 +817,26 @@ func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func opYield(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
// Save current Environment as coroutine
|
||||
coroutine := NewCoroutine(*pc + 1, *scope.Stack)
|
||||
|
||||
// Push coroutine to the stack
|
||||
scope.PushCoroutine(coroutine)
|
||||
|
||||
log.Printf("Coroutine %d yielded with %v", coroutine.PC, coroutine.Stack)
|
||||
|
||||
// Call the next coroutine
|
||||
nextCoroutine, err := scope.PopCoroutine()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret, err := nextCoroutine.ExecuteCoroutine(interpreter, scope)
|
||||
log.Printf("Coroutine %d returned with %v", nextCoroutine.PC, ret)
|
||||
|
||||
return nil, errStopToken
|
||||
}
|
||||
|
||||
func opReturn(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
||||
ret := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))
|
||||
|
|
|
|||
|
|
@ -275,7 +275,6 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
|
|||
err = nil // clear stop token error
|
||||
}
|
||||
|
||||
log2.Println("returning from run with", res, err)
|
||||
// Res is array of bytes located in scope.Memory
|
||||
return res, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1044,6 +1044,12 @@ func newFrontierInstructionSet() JumpTable {
|
|||
maxStack: maxStack(7, 1),
|
||||
memorySize: memoryCall,
|
||||
},
|
||||
YIELD: {
|
||||
execute: opYield,
|
||||
constantGas: 1, //TODO: set this to something reasonable
|
||||
minStack: minStack(0, 0),
|
||||
maxStack: maxStack(0, 0),
|
||||
},
|
||||
RETURN: {
|
||||
execute: opReturn,
|
||||
dynamicGas: gasReturn,
|
||||
|
|
|
|||
|
|
@ -219,6 +219,7 @@ const (
|
|||
|
||||
STATICCALL OpCode = 0xfa
|
||||
SPAWN OpCode = 0xfb
|
||||
YIELD OpCode = 0xfc
|
||||
REVERT OpCode = 0xfd
|
||||
INVALID OpCode = 0xfe
|
||||
SELFDESTRUCT OpCode = 0xff
|
||||
|
|
@ -393,6 +394,7 @@ var opCodeToString = map[OpCode]string{
|
|||
DELEGATECALL: "DELEGATECALL",
|
||||
CREATE2: "CREATE2",
|
||||
STATICCALL: "STATICCALL",
|
||||
YIELD: "YIELD",
|
||||
REVERT: "REVERT",
|
||||
INVALID: "INVALID",
|
||||
SELFDESTRUCT: "SELFDESTRUCT",
|
||||
|
|
@ -448,6 +450,7 @@ var stringToOp = map[string]OpCode{
|
|||
"BLOBHASH": BLOBHASH,
|
||||
"DELEGATECALL": DELEGATECALL,
|
||||
"STATICCALL": STATICCALL,
|
||||
"YIELD": YIELD,
|
||||
"CODESIZE": CODESIZE,
|
||||
"CODECOPY": CODECOPY,
|
||||
"GASPRICE": GASPRICE,
|
||||
|
|
|
|||
Loading…
Reference in a new issue