Skip to content

The code generators should be AST to AST transformations #6

Open
@Araq

Description

@Araq

Currently the JS / C / C++ code generators produce the code directly as strings/ropes so the result cannot be optimized further. This design is a messy legacy and prevents certain bugs from being fixed easily. A much more elegant design is to give the target language an internal representation (AST like) that we convert the Nim AST to. There would be a simple "IR to text" step automating trivialities such as seperating arguments with commas. The IR needs an escape hatch like cEmit so that the .emit statement can continue to work. Also, some parts of the code generation might not map easily to a structured IR such as the code generation for Nim's type information.

It's an open question if the C IR should be based on Nim's PNode structure, but currently I am leaning heavily to new dedicated tree structure that naturally supports goto statements, for example.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions