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
9a9e252c
Commit
9a9e252c
authored
Mar 21, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes 'compiler' to work with any type
parent
2ea4c632
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
27 deletions
+49
-27
vm_test.go
ethchain/vm_test.go
+14
-16
parsing.go
ethutil/parsing.go
+35
-11
No files found.
ethchain/vm_test.go
View file @
9a9e252c
...
...
@@ -2,7 +2,6 @@ package ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"math/big"
...
...
@@ -130,27 +129,26 @@ func TestRun3(t *testing.T) {
})
tx
:=
NewTransaction
(
ContractAddr
,
ethutil
.
Big
(
"100000000000000000000000000000000000000000000000000"
),
script
)
addr
:=
tx
.
Hash
()[
12
:
]
fmt
.
Printf
(
"addr contract %x
\n
"
,
addr
)
contract
:=
MakeContract
(
tx
,
state
)
state
.
UpdateContract
(
contract
)
callerScript
:=
Compile
([]
string
{
"PUSH"
,
"1337"
,
// Argument
"PUSH"
,
"65"
,
// argument mem offset
callerScript
:=
ethutil
.
Compile
(
"PUSH"
,
1337
,
// Argument
"PUSH"
,
65
,
// argument mem offset
"MSTORE"
,
"PUSH"
,
"64"
,
// ret size
"PUSH"
,
"0"
,
// ret offset
"PUSH"
,
"32"
,
// arg size
"PUSH"
,
"65"
,
// arg offset
"PUSH"
,
"1000"
,
/// Gas
"PUSH"
,
"0"
,
/// value
"PUSH"
,
string
(
addr
)
,
// Sender
"PUSH"
,
64
,
// ret size
"PUSH"
,
0
,
// ret offset
"PUSH"
,
32
,
// arg size
"PUSH"
,
65
,
// arg offset
"PUSH"
,
1000
,
/// Gas
"PUSH"
,
0
,
/// value
"PUSH"
,
addr
,
// Sender
"CALL"
,
"PUSH"
,
"64"
,
"PUSH"
,
"0"
,
"PUSH"
,
64
,
"PUSH"
,
0
,
"RETURN"
,
}
)
)
callerTx
:=
NewTransaction
(
ContractAddr
,
ethutil
.
Big
(
"100000000000000000000000000000000000000000000000000"
),
callerScript
)
// Contract addr as test address
...
...
ethutil/parsing.go
View file @
9a9e252c
...
...
@@ -84,20 +84,30 @@ func IsOpCode(s string) bool {
return
false
}
func
CompileInstr
(
s
string
)
([]
byte
,
error
)
{
isOp
:=
IsOpCode
(
s
)
if
isOp
{
return
[]
byte
{
OpCodes
[
s
]},
nil
}
func
CompileInstr
(
s
interface
{})
([]
byte
,
error
)
{
switch
s
.
(
type
)
{
case
string
:
str
:=
s
.
(
string
)
isOp
:=
IsOpCode
(
str
)
if
isOp
{
return
[]
byte
{
OpCodes
[
str
]},
nil
}
num
:=
new
(
big
.
Int
)
_
,
success
:=
num
.
SetString
(
str
,
0
)
// Assume regular bytes during compilation
if
!
success
{
num
.
SetBytes
([]
byte
(
str
))
}
num
:=
new
(
big
.
Int
)
_
,
success
:=
num
.
SetString
(
s
,
0
)
// Assume regular bytes during compilation
if
!
success
{
num
.
SetBytes
([]
byte
(
s
))
return
num
.
Bytes
(),
nil
case
int
:
return
big
.
NewInt
(
int64
(
s
.
(
int
)))
.
Bytes
(),
nil
case
[]
byte
:
return
BigD
(
s
.
([]
byte
))
.
Bytes
(),
nil
}
return
n
um
.
Bytes
()
,
nil
return
n
il
,
nil
}
func
Instr
(
instr
string
)
(
int
,
[]
string
,
error
)
{
...
...
@@ -118,3 +128,17 @@ func Instr(instr string) (int, []string, error) {
return
op
,
args
[
1
:
7
],
nil
}
// Script compilation functions
// Compiles strings to machine code
func
Compile
(
instructions
...
interface
{})
(
script
[]
string
)
{
script
=
make
([]
string
,
len
(
instructions
))
for
i
,
val
:=
range
instructions
{
instr
,
_
:=
CompileInstr
(
val
)
script
[
i
]
=
string
(
instr
)
}
return
}
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