Support serpent lang

pull/150/head
obscuren 11 years ago
parent 931ae0f116
commit 299b50a0d4
  1. 32
      ethutil/script.go

@ -3,23 +3,35 @@ package ethutil
import ( import (
"fmt" "fmt"
"github.com/obscuren/mutan" "github.com/obscuren/mutan"
"github.com/obscuren/serpent-go"
"strings" "strings"
) )
// General compile function // General compile function
func Compile(script string) ([]byte, error) { func Compile(script string) (ret []byte, err error) {
byteCode, errors := mutan.Compile(strings.NewReader(script), false) c := strings.Split(script, "\n")[0]
if len(errors) > 0 {
var errs string if c == "#!serpent" {
for _, er := range errors { byteCode, err := serpent.Compile(script)
if er != nil { if err != nil {
errs += er.Error() return nil, err
}
return byteCode, nil
} else {
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)
} }
return nil, fmt.Errorf("%v", errs)
}
return byteCode, nil return byteCode, nil
}
} }
func CompileScript(script string) ([]byte, []byte, error) { func CompileScript(script string) ([]byte, []byte, error) {

Loading…
Cancel
Save