From c19ff5b78b92d681f28bcd740c623b2f96587773 Mon Sep 17 00:00:00 2001 From: Emil Valeev Date: Thu, 22 Feb 2024 17:42:40 +0600 Subject: [PATCH] fix(irgen): all examples now compiles to valid go --- .vscode/launch.json | 2 +- .../backend/golang/{golang.go => backend.go} | 0 .../backend/golang/{funcs.go => funcmap.go} | 15 ++++++++++----- .../golang/native/{native.go => backend.go} | 0 4 files changed, 11 insertions(+), 6 deletions(-) rename internal/compiler/backend/golang/{golang.go => backend.go} (100%) rename internal/compiler/backend/golang/{funcs.go => funcmap.go} (92%) rename internal/compiler/backend/golang/native/{native.go => backend.go} (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index bfbfd273..9c242299 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "mode": "auto", "program": "${workspaceFolder}/cmd/neva", "cwd": "${workspaceFolder}/examples", - "args": ["build", "1_echo"] + "args": ["build", "7_struct_selector/with_sugar"] }, // === Vscode-neva extension debug tasks === // extension itself diff --git a/internal/compiler/backend/golang/golang.go b/internal/compiler/backend/golang/backend.go similarity index 100% rename from internal/compiler/backend/golang/golang.go rename to internal/compiler/backend/golang/backend.go diff --git a/internal/compiler/backend/golang/funcs.go b/internal/compiler/backend/golang/funcmap.go similarity index 92% rename from internal/compiler/backend/golang/funcs.go rename to internal/compiler/backend/golang/funcmap.go index 5ae2b371..5181c4ec 100644 --- a/internal/compiler/backend/golang/funcs.go +++ b/internal/compiler/backend/golang/funcmap.go @@ -24,25 +24,30 @@ func getMsg(msg *ir.Msg) (string, error) { case ir.MsgTypeString: return fmt.Sprintf(`runtime.NewStrMsg("%v")`, msg.Str), nil case ir.MsgTypeList: - s := "runtime.NewListMsg(\n\t" + s := `runtime.NewListMsg( + ` for _, v := range msg.List { el, err := getMsg(compiler.Pointer(v)) if err != nil { return "", err } - s += fmt.Sprintf("\t%v,\n", el) + s += fmt.Sprintf(` %v, +`, el) } return s + ")", nil case ir.MsgTypeMap: - s := "runtime.NewMapMsg(map[string]runtime.Msg{\n\t" + s := `runtime.NewMapMsg(map[string]runtime.Msg{ + ` for k, v := range msg.Map { el, err := getMsg(compiler.Pointer(v)) if err != nil { return "", err } - s += fmt.Sprintf(`\t"%v": %v,\n`, k, el) + s += fmt.Sprintf(` "%v": %v, +`, k, el) } - return s + "},\n)", nil + return s + `}, +)`, nil } return "", fmt.Errorf("%w: %v", ErrUnknownMsgType, msg.Type) diff --git a/internal/compiler/backend/golang/native/native.go b/internal/compiler/backend/golang/native/backend.go similarity index 100% rename from internal/compiler/backend/golang/native/native.go rename to internal/compiler/backend/golang/native/backend.go