aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/ethereum/serpent-go/serpent.go
blob: 39b60eed74e1a8987d1f444353e463e4c1059071 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package serpent

// #cgo CXXFLAGS: -I. -Ilangs/ -std=c++0x -Wall -fno-strict-aliasing
// #cgo LDFLAGS: -lstdc++
//
// #include "cpp/api.h"
//
import "C"

import (
    "encoding/hex"
    "errors"
    "unsafe"
)

func Compile(str string) ([]byte, error) {
    var err C.int
    out := C.GoString(C.compileGo(C.CString(str), (*C.int)(unsafe.Pointer(&err))))

    if err == C.int(1) {
        return nil, errors.New(out)
    }

    bytes, _ := hex.DecodeString(out)

    return bytes, nil
}