diff options
author | obscuren <geffobscura@gmail.com> | 2014-06-27 01:55:14 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-06-27 01:55:14 +0800 |
commit | 9d5a3f013121c319f9cf679d9afc4e40661a0284 (patch) | |
tree | f57ecbea40ca0354bb050d70a10851669412a581 /ethutil/script.go | |
parent | 3f1f8438ed8bf7b63ea5172090a5c7025cb093f0 (diff) | |
parent | a98e6a262a21ff08c28495bab5180a1c15826d40 (diff) | |
download | go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar.gz go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar.bz2 go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar.lz go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar.xz go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.tar.zst go-tangerine-9d5a3f013121c319f9cf679d9afc4e40661a0284.zip |
Merge branch 'release/0.5.15'
Diffstat (limited to 'ethutil/script.go')
-rw-r--r-- | ethutil/script.go | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/ethutil/script.go b/ethutil/script.go index 94e401406..af4ca6a38 100644 --- a/ethutil/script.go +++ b/ethutil/script.go @@ -3,39 +3,35 @@ package ethutil import ( "fmt" "github.com/obscuren/mutan" + "github.com/obscuren/mutan/backends" + "github.com/obscuren/serpent-go" "strings" ) // General compile function -func Compile(script string) ([]byte, error) { - byteCode, 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) - } +func Compile(script string) (ret []byte, err error) { + c := strings.Split(script, "\n")[0] - return byteCode, nil -} + if c == "#!serpent" { + byteCode, err := serpent.Compile(script) + if err != nil { + return nil, err + } -func CompileScript(script string) ([]byte, []byte, error) { - // Preprocess - mainInput, initInput := mutan.PreParse(script) - // Compile main script - mainScript, err := Compile(mainInput) - if err != nil { - return nil, nil, err - } + return byteCode, nil + } else { + compiler := mutan.NewCompiler(backend.NewEthereumBackend()) + byteCode, errors := compiler.Compile(strings.NewReader(script)) + if len(errors) > 0 { + var errs string + for _, er := range errors { + if er != nil { + errs += er.Error() + } + } + return nil, fmt.Errorf("%v", errs) + } - // Compile init script - initScript, err := Compile(initInput) - if err != nil { - return nil, nil, err + return byteCode, nil } - - return mainScript, initScript, nil } |