Compiler update (#21)
* added seperate folders for cmd packages. * Fix netmodes in test + reverse bigint bytes * glide get deps * add, sub, mul, div * booleans * strings * binary expressions * if statements * function calls * composite literals (slice, array) * Added lots of test cases and update readme.
This commit is contained in:
parent
f7d57e4e49
commit
b257a06f3e
18 changed files with 1253 additions and 494 deletions
|
@ -1,9 +1,14 @@
|
|||
package smartcontract
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/vm"
|
||||
"github.com/CityOfZion/neo-go/pkg/vm/compiler"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -17,6 +22,12 @@ func NewCommand() cli.Command {
|
|||
Name: "compile",
|
||||
Usage: "compile a smart contract to a .avm file",
|
||||
Action: contractCompile,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "out, o",
|
||||
Usage: "Output of the compiled contract",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "opdump",
|
||||
|
@ -28,14 +39,40 @@ func NewCommand() cli.Command {
|
|||
}
|
||||
|
||||
func contractCompile(ctx *cli.Context) error {
|
||||
fmt.Println("compile")
|
||||
return nil
|
||||
if len(ctx.Args()) == 0 {
|
||||
return errors.New("not enough arguments")
|
||||
}
|
||||
|
||||
src := ctx.Args()[0]
|
||||
c := compiler.New()
|
||||
if err := c.CompileSource(src); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
filename := strings.Split(src, ".")[0]
|
||||
filename = filename + ".avm"
|
||||
|
||||
out := ctx.String("out")
|
||||
if len(out) > 0 {
|
||||
filename = out
|
||||
}
|
||||
|
||||
f, err := os.Create(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hx := hex.EncodeToString(c.Buffer().Bytes())
|
||||
fmt.Println(hx)
|
||||
|
||||
_, err = io.Copy(f, c.Buffer())
|
||||
return err
|
||||
}
|
||||
|
||||
func contractDumpOpcode(ctx *cli.Context) error {
|
||||
src := ctx.Args()[0]
|
||||
|
||||
c := vm.NewCompiler()
|
||||
c := compiler.New()
|
||||
if err := c.CompileSource(src); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue