From 9cf77cdbadd8249498d62542502def6ecb2fb6b8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 16 Apr 2014 04:08:37 +0200 Subject: Moved compiling related object to utils package --- utils/compile.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 utils/compile.go (limited to 'utils/compile.go') diff --git a/utils/compile.go b/utils/compile.go new file mode 100644 index 000000000..e5ea50ad4 --- /dev/null +++ b/utils/compile.go @@ -0,0 +1,24 @@ +package utils + +import ( + "fmt" + "github.com/ethereum/eth-go/ethutil" + "github.com/obscuren/mutan" + "strings" +) + +// General compile function +func Compile(script string) ([]byte, error) { + asm, errors := mutan.Compile(strings.NewReader(script), false) + if len(errors) > 0 { + var errs string + for _, er := range errors { + if er != nil { + errs += er.Error() + } + } + return nil, fmt.Errorf("%v", errs) + } + + return ethutil.Assemble(asm...), nil +} -- cgit v1.2.3 From 43f1214f97e52863b1f1ef7913991bef3d00c58e Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 23 Apr 2014 15:54:34 +0200 Subject: Refactored code --- utils/compile.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils/compile.go') diff --git a/utils/compile.go b/utils/compile.go index e5ea50ad4..894fc2d09 100644 --- a/utils/compile.go +++ b/utils/compile.go @@ -22,3 +22,21 @@ func Compile(script string) ([]byte, error) { return ethutil.Assemble(asm...), nil } + +func CompileScript(script string) ([]byte, []byte, error) { + // Preprocess + mainInput, initInput := ethutil.PreProcess(script) + // Compile main script + mainScript, err := Compile(mainInput) + if err != nil { + return nil, nil, err + } + + // Compile init script + initScript, err := Compile(initInput) + if err != nil { + return nil, nil, err + } + + return mainScript, initScript, nil +} -- cgit v1.2.3 From 883810b53328b302aa765ccf9d228bd73c046cac Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 18:05:48 +0200 Subject: Using mutan assembler stage --- utils/compile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'utils/compile.go') diff --git a/utils/compile.go b/utils/compile.go index 894fc2d09..12e3a60c3 100644 --- a/utils/compile.go +++ b/utils/compile.go @@ -9,7 +9,7 @@ import ( // General compile function func Compile(script string) ([]byte, error) { - asm, errors := mutan.Compile(strings.NewReader(script), false) + byteCode, errors := mutan.Compile(strings.NewReader(script), false) if len(errors) > 0 { var errs string for _, er := range errors { @@ -20,7 +20,7 @@ func Compile(script string) ([]byte, error) { return nil, fmt.Errorf("%v", errs) } - return ethutil.Assemble(asm...), nil + return byteCode, nil } func CompileScript(script string) ([]byte, []byte, error) { -- cgit v1.2.3 From a0f35d324822fc66951f8a33526ff3d15b0de09d Mon Sep 17 00:00:00 2001 From: Casey Kuhlman Date: Mon, 28 Apr 2014 11:37:44 +0200 Subject: PreProcess moved to Mutan package --- utils/compile.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'utils/compile.go') diff --git a/utils/compile.go b/utils/compile.go index 12e3a60c3..6d75f73d1 100644 --- a/utils/compile.go +++ b/utils/compile.go @@ -2,7 +2,6 @@ package utils import ( "fmt" - "github.com/ethereum/eth-go/ethutil" "github.com/obscuren/mutan" "strings" ) @@ -25,7 +24,7 @@ func Compile(script string) ([]byte, error) { func CompileScript(script string) ([]byte, []byte, error) { // Preprocess - mainInput, initInput := ethutil.PreProcess(script) + mainInput, initInput := mutan.PreProcess(script) // Compile main script mainScript, err := Compile(mainInput) if err != nil { -- cgit v1.2.3