Skip to content

Commit

Permalink
fix(irgen): all examples now compiles to valid go
Browse files Browse the repository at this point in the history
  • Loading branch information
emil14 committed Feb 22, 2024
1 parent 860a2db commit c19ff5b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c19ff5b

Please sign in to comment.