From 2a171babf970e0330e8216abd51be91a008c89e5 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Thu, 23 Jan 2020 14:48:02 -0500 Subject: [PATCH] [cgogen] refs #17 Complete functions callback --- Gopkg.lock | 4 +--- src/cmd/cgogen.go | 40 ++++++++++++++++++++++++++++++---------- vendor/vendor.json | 13 ------------- 3 files changed, 31 insertions(+), 26 deletions(-) mode change 100644 => 100755 src/cmd/cgogen.go delete mode 100644 vendor/vendor.json diff --git a/Gopkg.lock b/Gopkg.lock index f5db56c..2bd4fa4 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,16 +2,14 @@ [[projects]] - digest = "1:76e62cadfb857e4f8e4442799ef04dcc6111d187adac9a4a552a34cdf1862550" name = "github.com/dave/jennifer" packages = ["jen"] - pruneopts = "UT" revision = "724ff9887965e893831e9493011297e6bc01ecb4" version = "v1.4.0" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = ["github.com/dave/jennifer/jen"] + inputs-digest = "32c43d922fa782ed1e847c7403dd671b96fc14b9d811152e65deef6fa658c1b3" solver-name = "gps-cdcl" solver-version = 1 diff --git a/src/cmd/cgogen.go b/src/cmd/cgogen.go old mode 100644 new mode 100755 index e1b633f..cedf0a0 --- a/src/cmd/cgogen.go +++ b/src/cmd/cgogen.go @@ -1,5 +1,6 @@ package main +import "C" import ( "bytes" "flag" @@ -1309,15 +1310,34 @@ var basicTypesMap = map[string]string{ var packageSeparator = "__" -func getCallbackCode(name string, typeName string) []jen.Code { - - c := jen.Func().Params( - jen.Id("a").Id("A"), - ).Id("foo").Params( - jen.Id("b"), - jen.Id("c").String(), - ).String().Block( - jen.Return(jen.Id("b").Op("+").Id("c")), +func getCallbackCode() []jen.Code { + + varfunction := jen.Func().Params( + jen.Id("pTx").Id("*coin.Transaction"), + ).Uint64().Error().Block( + jen.Var().Id("fee").Id("C.GoUint64_"), + jen.Id("handle").Op(":=").Id("registerTransactionHandle").Call().Params(jen.Id("pTx")), + jen.Id("result").Op(":=").Id("C.callFeeCalculator").Call(jen.Id("pFeeCalc"), jen.Id("handle"), jen.Id("&fee")), + jen.Id("closeHandle").Call(jen.Id("Handle").Call(jen.Id("handle"))), + jen.If(jen.Id("result").Op("==").Id("SKY_OK")).Block( + jen.Return(jen.Id("uint64").Call(jen.Id("fee"))), jen.Nil()), + jen.Else().Block( + jen.Return(jen.Lit(0), jen.Id("errors.New").Call(jen.Id("Error calculating fee"))), + ), ) - return jenCodeToArray(c) + + varname := jen.Id("feeCalc").Op(":=").Add(varfunction) + + //feeCalc := func(pTx *coin.Transaction) (uint64, error) { + // var fee C.GoUint64_ + // handle := registerTransactionHandle(pTx) + // result := C.callFeeCalculator(pFeeCalc, handle, &fee) + // closeHandle(Handle(handle)) + // if result == SKY_OK { + // return uint64(fee), nil + // } else { + // return 0, errors.New("Error calculating fee") + // } + //} + return jenCodeToArray(varname) } diff --git a/vendor/vendor.json b/vendor/vendor.json deleted file mode 100644 index aef8800..0000000 --- a/vendor/vendor.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "comment": "", - "ignore": "test", - "package": [ - { - "checksumSHA1": "GtqEEHjKsMGUSCqjPyKLi+DfcEs=", - "path": "github.com/dave/jennifer/jen", - "revision": "724ff9887965e893831e9493011297e6bc01ecb4", - "revisionTime": "2019-11-26T19:34:09Z" - } - ], - "rootPath": "github.com/fibercrypto/cgogen" -}