From c9d3b90caaba8e1eac386a405e5f089871541286 Mon Sep 17 00:00:00 2001 From: Softonik Date: Thu, 8 Dec 2022 04:43:48 +0300 Subject: [PATCH] =?UTF-8?q?Python:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84-=D1=86=D0=B8=D1=8F=20append?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 29 ++++++++++++++++++++++------- transpile_python/service_test.go | 17 +++++++++++++++++ 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/transpile_python/service.go b/transpile_python/service.go index 6870ae7..c9c23fd 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -160,14 +160,29 @@ func handleBinaryExpr(expr ast.Expr) string { } func handleCallExpr(expr *ast.CallExpr) string { - code := handleExpr(expr.Fun) - code += "(" - args := make([]string, 0) - for _, arg := range expr.Args { - args = append(args, handleExpr(arg)) + func_name := handleExpr(expr.Fun) + code := "" + switch func_name { + case "append": + code = handleExpr(expr.Args[0]) + code += ".append(" + args := make([]string, 0) + for _, arg := range expr.Args[1:] { + args = append(args, handleExpr(arg)) + } + code += strings.Join(args, ",") + code += ")" + return code + default: + code = func_name + code += "(" + args := make([]string, 0) + for _, arg := range expr.Args { + args = append(args, handleExpr(arg)) + } + code += strings.Join(args, ",") + code += ")" } - code += strings.Join(args, ",") - code += ")" return code } diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index 12c231d..ac21a86 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -117,6 +117,23 @@ main() Compare(source, expected) }) + It("Array append", func() { + source := `package test + import "skidl" + + func main() { + append(a, 1) + } + ` + expected := `from skidl import * + +def main(): + a.append(1) +main() +` + Compare(source, expected) + }) + It("Function Declaration", func() { source := `package test import "skidl"