good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
78d18b13
Commit
78d18b13
authored
Jan 3, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Pop, push, load for vm
parent
7cd41ac4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
vm.go
+28
-10
28 additions, 10 deletions
vm.go
vm_test.go
+13
-7
13 additions, 7 deletions
vm_test.go
with
41 additions
and
17 deletions
vm.go
+
28
−
10
View file @
78d18b13
...
...
@@ -6,12 +6,15 @@ import (
"fmt"
_
"strconv"
_
"encoding/hex"
"strconv"
)
// Op codes
const
(
oSTOP
int
=
0x00
oPSH
int
=
0x30
oPUSH
int
=
0x30
oPOP
int
=
0x31
oLOAD
int
=
0x36
/*
oADD int = 0x10
oSUB int = 0x11
...
...
@@ -70,7 +73,7 @@ func NewStack() *Stack {
func
(
st
*
Stack
)
Pop
()
string
{
s
:=
len
(
st
.
data
)
str
:=
st
.
data
[
s
]
str
:=
st
.
data
[
s
-
1
]
st
.
data
=
st
.
data
[
:
s
-
1
]
return
str
...
...
@@ -91,30 +94,45 @@ func NewVm() *Vm {
}
}
func
(
vm
*
Vm
)
RunTransaction
(
tx
*
Transaction
,
block
*
Block
,
cb
TxCallback
)
{
func
(
vm
*
Vm
)
ProcContract
(
tx
*
Transaction
,
block
*
Block
,
cb
TxCallback
)
{
// Instruction pointer
iptr
:=
0
// Index pointer for the memory
memIndex
:=
0
contract
:=
block
.
GetContract
(
tx
.
Hash
())
if
contract
==
nil
{
fmt
.
Println
(
"Contract not found"
)
return
}
fmt
.
Printf
(
"# op arg
\n
"
)
for
iptr
<
len
(
tx
.
data
)
{
memIndex
++
out
:
for
{
// The base big int for all calculations. Use this for any results.
base
:=
new
(
big
.
Int
)
base
.
SetString
(
"0"
,
0
)
// so it doesn't whine about it
// XXX Should Instr return big int slice instead of string slice?
op
,
args
,
_
:=
Instr
(
tx
.
data
[
iptr
])
// Get the next instruction from the contract
op
,
args
,
_
:=
Instr
(
contract
.
state
.
Get
(
string
(
Encode
(
uint32
(
iptr
)))))
if
Debug
{
fmt
.
Printf
(
"%-3d %-4d %v
\n
"
,
iptr
,
op
,
args
)
}
switch
op
{
case
oPSH
:
case
oPUSH
:
// Get the next entry and pushes the value on the stack
iptr
++
vm
.
stack
.
Push
(
contract
.
state
.
Get
(
string
(
Encode
(
uint32
(
iptr
)))))
case
oPOP
:
// Pop current value of the stack
vm
.
stack
.
Pop
()
case
oLOAD
:
// Load instruction X on the stack
i
,
_
:=
strconv
.
Atoi
(
vm
.
stack
.
Pop
())
vm
.
stack
.
Push
(
contract
.
state
.
Get
(
string
(
Encode
(
uint32
(
i
)))))
case
oSTOP
:
break
out
}
// Increment instruction pointer
iptr
++
}
}
...
...
This diff is collapsed.
Click to expand it.
vm_test.go
+
13
−
7
View file @
78d18b13
package
main
import
(
"fmt"
_
"fmt"
"testing"
)
...
...
@@ -10,17 +10,23 @@ func TestVm(t *testing.T) {
db
,
_
:=
NewMemDatabase
()
Db
=
db
tx
:=
NewTransaction
(
""
,
20
,
[]
string
{
"PSH 10"
,
ctrct
:=
NewTransaction
(
""
,
20
,
[]
string
{
"PUSH"
,
"1a2f2e"
,
"PUSH"
,
"hallo"
,
"POP"
,
// POP hallo
"PUSH"
,
"3"
,
"LOAD"
,
// Load hallo back on the stack
"STOP"
,
})
tx
:=
NewTransaction
(
"1e8a42ea8cce13"
,
100
,
[]
string
{})
block
:=
CreateBlock
(
""
,
0
,
""
,
""
,
0
,
0
,
""
,
[]
*
Transaction
{
tx
})
block
:=
CreateBlock
(
""
,
0
,
""
,
""
,
0
,
0
,
""
,
[]
*
Transaction
{
ctrct
,
tx
})
db
.
Put
(
block
.
Hash
(),
block
.
MarshalRlp
())
bm
:=
NewBlockManager
()
bm
.
ProcessBlock
(
block
)
contract
:=
block
.
GetContract
(
tx
.
Hash
())
fmt
.
Println
(
contract
)
fmt
.
Println
(
"it is"
,
contract
.
state
.
Get
(
string
(
Encode
(
0
))))
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment