From 686ef65fd7628fe0aa3d351bacfe2c8aec5df91a Mon Sep 17 00:00:00 2001 From: Softonik Date: Sun, 11 Dec 2022 01:04:59 +0300 Subject: [PATCH] =?UTF-8?q?Python:=20=D1=81=D0=B5=D0=BB=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=20(=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D1=83=20.)=20=D0=B2=D1=8B=D0=B4=D0=B0=D1=8E?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B9=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile_python/service.go | 10 ++++++-- transpile_python/service_test.go | 41 ++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/transpile_python/service.go b/transpile_python/service.go index b2e96c0..1f3d828 100644 --- a/transpile_python/service.go +++ b/transpile_python/service.go @@ -48,7 +48,6 @@ func (s *defaultService) Start() error { if s.out == nil { return fmt.Errorf("Error: %s", ErrorWorkerWriterIsNil) } - ind = 0 main_func_declared = false // Read tokens from file by using Go's parser. fset := token.NewFileSet() @@ -71,6 +70,7 @@ func (s *defaultService) Start() error { // Start a transpile with an individual channel for each declaration in the source file. go func() { for i, decl := range file.Decls { + ind = 0 handleDecl(i, decl, dst[i], done) } }() @@ -112,6 +112,11 @@ func indSpaces() string { } return res } +func indSpacesPlus() string { + increaseInd() + defer decreaseInd() + return indSpaces() +} func handleAssignStmt(as *ast.AssignStmt) string { code := handleAssignStmtExpr(as.Lhs) @@ -488,7 +493,8 @@ func handleSelectorExpr(expr ast.Expr) string { spew.Dump(s) code += "unknown handleSelectorExpr" } - code += "." + code += ".\\\n" + code += indSpacesPlus() code += handleIdent(s.Sel) if val, ok := mapping[code]; ok { code = val diff --git a/transpile_python/service_test.go b/transpile_python/service_test.go index 7b0fe96..d1f82d4 100644 --- a/transpile_python/service_test.go +++ b/transpile_python/service_test.go @@ -179,13 +179,23 @@ main() import . "skidl" func main() { - a.b.c = 1 + a.b.c.d.e = 1 + x = a.b.c.d.e } ` expected := `from skidl import * def main(): - a.b.c = 1 + a.\ + b.\ + c.\ + d.\ + e = 1 + x = a.\ + b.\ + c.\ + d.\ + e main() ` Compare(source, expected) @@ -248,7 +258,11 @@ main() expected := `from skidl import * def main(): - a.b().c(1).d(2).e(3) + a.\ + b().\ + c(1).\ + d(2).\ + e(3) main() ` Compare(source, expected) @@ -476,10 +490,14 @@ main() expected := `from skidl import * def main(): - vkl_iface.value = "k vkl" - vkl_iface.value = 19 - vkl_iface.value = 19 / 3 - vkl_iface.value = 19 * 2 + vkl_iface.\ + value = "k vkl" + vkl_iface.\ + value = 19 + vkl_iface.\ + value = 19 / 3 + vkl_iface.\ + value = 19 * 2 main() ` Compare(source, expected) @@ -701,9 +719,12 @@ main() @subcircuit def mem_module(intfc): ram = Part("Memory_RAM","AS6C1616") - ram["A[0:19]"] += intfc.addr - ram["DQ[0:15]"] += intfc.data - ram["WE#"] += intfc.wr + ram["A[0:19]"] += intfc.\ + addr + ram["DQ[0:15]"] += intfc.\ + data + ram["WE#"] += intfc.\ + wr ram["OE#"] += intfc["rd"] def main(): rd = Net("MEM_RD#")