Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
c7dc92e1
Commit
c7dc92e1
authored
Dec 28, 2013
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset stack pointer on run
parent
0f656652
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
vm.go
vm.go
+13
-10
No files found.
vm.go
View file @
c7dc92e1
...
...
@@ -60,8 +60,6 @@ type TxCallback func(opType OpType) bool
type
Vm
struct
{
// Memory stack
stack
map
[
string
]
string
// Index ptr
iptr
int
memory
map
[
string
]
map
[
string
]
string
}
...
...
@@ -71,7 +69,10 @@ func NewVm() *Vm {
stackSize
:=
uint
(
256
)
fmt
.
Println
(
"stack size ="
,
stackSize
)
return
&
Vm
{
make
(
map
[
string
]
string
),
0
,
make
(
map
[
string
]
map
[
string
]
string
)}
return
&
Vm
{
stack
:
make
(
map
[
string
]
string
),
memory
:
make
(
map
[
string
]
map
[
string
]
string
),
}
}
func
(
vm
*
Vm
)
RunTransaction
(
tx
*
Transaction
,
cb
TxCallback
)
{
...
...
@@ -84,6 +85,8 @@ func (vm *Vm) RunTransaction(tx *Transaction, cb TxCallback) {
vm
.
stack
[
"0"
]
=
tx
.
sender
vm
.
stack
[
"1"
]
=
"100"
//int(tx.value)
vm
.
stack
[
"1"
]
=
"1000"
//int(tx.fee)
// Stack pointer
stPtr
:=
0
//vm.memory[tx.addr] = make([]int, 256)
vm
.
memory
[
tx
.
addr
]
=
make
(
map
[
string
]
string
)
...
...
@@ -93,13 +96,13 @@ func (vm *Vm) RunTransaction(tx *Transaction, cb TxCallback) {
// Instructions are shorthanded as Ix/y/z
x
:=
0
;
y
:=
1
;
z
:=
2
;
//a := 3; b := 4; c := 5
out
:
for
vm
.
ip
tr
<
len
(
tx
.
data
)
{
for
stP
tr
<
len
(
tx
.
data
)
{
// The base big int for all calculations. Use this for any results.
base
:=
new
(
big
.
Int
)
// XXX Should Instr return big int slice instead of string slice?
op
,
args
,
_
:=
Instr
(
tx
.
data
[
vm
.
ip
tr
])
op
,
args
,
_
:=
Instr
(
tx
.
data
[
stP
tr
])
fmt
.
Printf
(
"%-3d %d %v
\n
"
,
vm
.
ip
tr
,
op
,
args
)
fmt
.
Printf
(
"%-3d %d %v
\n
"
,
stP
tr
,
op
,
args
)
opType
:=
OpType
(
tNorm
)
// Determine the op type (used for calculating fees by the block manager)
...
...
@@ -113,7 +116,7 @@ out:
// If the callback yielded a negative result abort execution
if
!
cb
(
opType
)
{
break
out
}
nptr
:=
vm
.
ip
tr
nptr
:=
stP
tr
switch
op
{
case
oSTOP
:
fmt
.
Println
(
"exiting (oSTOP), idx ="
,
nptr
)
...
...
@@ -171,10 +174,10 @@ out:
break
}
if
vm
.
ip
tr
==
nptr
{
vm
.
ip
tr
++
if
stP
tr
==
nptr
{
stP
tr
++
}
else
{
vm
.
ip
tr
=
nptr
stP
tr
=
nptr
fmt
.
Println
(
"... JMP"
,
nptr
,
"..."
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment