diff --git a/transpile_python/service.go b/transpile_python/service.go index c9c23fd..b8433f8 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -136,8 +136,19 @@ func handleBasicLit(bl *ast.BasicLit) string { return bl.Value } -func handleCompositeLit(bl *ast.CompositeLit) string { - return "[]" +func handleCompositeLit(cl *ast.CompositeLit) string { + code := "[" + switch cl.Type.(type) { + case *ast.ArrayType: + args := make([]string, 0) + for _, arg := range cl.Elts { + args = append(args, handleExpr(arg)) + } + code += strings.Join(args, ",") + } + code += "]" + + return code } func handleUnaryExpr(expr *ast.UnaryExpr) string { @@ -210,6 +221,7 @@ func handleDeclStmt(stmt *ast.DeclStmt) string { func handleExpr(expr ast.Expr) string { code := "" + // spew.Dump(expr) switch e := expr.(type) { case *ast.BasicLit: code += handleBasicLit(e) diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index ac21a86..96dbfab 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -98,7 +98,7 @@ main() Compare(source, expected) }) - It("Array assignment", func() { + It("Empty Array assignment", func() { source := `package test import "skidl" @@ -117,6 +117,23 @@ main() Compare(source, expected) }) + It("Inited array assignment", func() { + source := `package test + import "skidl" + + func main() { + a := []any{1, 2, x} + } + ` + expected := `from skidl import * + +def main(): + a = [1,2,x] +main() +` + Compare(source, expected) + }) + It("Array append", func() { source := `package test import "skidl"