From 56fe6574c94465f40c8ebbae8c50031cfc017f4f Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Tue, 2 Mar 2021 14:43:58 +0300 Subject: [PATCH] compiler: simplify `convert.To*` processing With inlining there is no need for special logic in compiler. --- pkg/compiler/analysis.go | 3 +-- pkg/compiler/codegen.go | 9 --------- pkg/interop/convert/convert.go | 6 +++--- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index c90a49c0f..2aacbbfff 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -327,6 +327,5 @@ func canInline(s string) bool { return false } return !strings.HasPrefix(s[len(interopPrefix):], "/neogointernal") && - !strings.HasPrefix(s[len(interopPrefix):], "/util") && - !strings.HasPrefix(s[len(interopPrefix):], "/convert") + !strings.HasPrefix(s[len(interopPrefix):], "/util") } diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 730256e9d..d5eea6b74 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1708,15 +1708,6 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) { c.emitStoreByIndex(varGlobal, c.exceptionIndex) case "delete": emit.Opcodes(c.prog.BinWriter, opcode.REMOVE) - case "ToInteger", "ToByteArray", "ToBool": - typ := stackitem.IntegerT - switch name { - case "ToByteArray": - typ = stackitem.ByteArrayT - case "ToBool": - typ = stackitem.BooleanT - } - c.emitConvert(typ) case "Remove": if !isCompoundSlice(c.typeOf(expr.Args[0])) { c.prog.Err = errors.New("`Remove` supports only non-byte slices") diff --git a/pkg/interop/convert/convert.go b/pkg/interop/convert/convert.go index 9cba7ae0f..060f14fbb 100644 --- a/pkg/interop/convert/convert.go +++ b/pkg/interop/convert/convert.go @@ -3,15 +3,15 @@ package convert // ToInteger converts it's argument to an Integer. func ToInteger(v interface{}) int64 { - return 0 + return v.(int64) } // ToByteArray converts it's argument to a ByteArray. func ToByteArray(v interface{}) []byte { - return nil + return v.([]byte) } // ToBool converts it's argument to a Boolean. func ToBool(v interface{}) bool { - return false + return v.(bool) }