script_unix.go 931 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // +build !windows
  2. package ethutil
  3. import (
  4. "fmt"
  5. "strings"
  6. "github.com/ethereum/serpent-go"
  7. "github.com/obscuren/mutan"
  8. "github.com/obscuren/mutan/backends"
  9. )
  10. // General compile function
  11. func Compile(script string, silent bool) (ret []byte, err error) {
  12. if len(script) > 2 {
  13. line := strings.Split(script, "\n")[0]
  14. if len(line) > 1 && line[0:2] == "#!" {
  15. switch line {
  16. case "#!serpent":
  17. byteCode, err := serpent.Compile(script)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return byteCode, nil
  22. }
  23. } else {
  24. compiler := mutan.NewCompiler(backend.NewEthereumBackend())
  25. compiler.Silent = silent
  26. byteCode, errors := compiler.Compile(strings.NewReader(script))
  27. if len(errors) > 0 {
  28. var errs string
  29. for _, er := range errors {
  30. if er != nil {
  31. errs += er.Error()
  32. }
  33. }
  34. return nil, fmt.Errorf("%v", errs)
  35. }
  36. return byteCode, nil
  37. }
  38. }
  39. return nil, nil
  40. }