script.go 911 B

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