rustmatic icon indicating copy to clipboard operation
rustmatic copied to clipboard

Start case statement

Open NOP0 opened this issue 5 years ago • 2 comments

Should have been a simple --amend. Seriously messed up :slightly_smiling_face:

No test yet..

NOP0 avatar Dec 03 '19 11:12 NOP0

Started thinking about the implementation here. I guess each case branch is sort of a conditional branch where the expression is ("case in branch-list?"). But even though there are similarities, Case should maybe have it's own struct to keep these separate?

NOP0 avatar Dec 13 '19 11:12 NOP0

I would keep them separate. Abstract syntax trees are meant to be a pretty accurate representation of the source code at a syntactic level. A good guideline would be to keep enough information so some hypothetical pretty-printer could walk the AST and generate roughly the same source code.

At later steps in the compilation process (i.e. "MIR" in rustc) you'll make these sorts of simplifications. For example, converting all loops, conditionals, and switch statements into a simpler compare and branch (e.g. if condition == true then goto block_1).

Michael-F-Bryan avatar Dec 13 '19 13:12 Michael-F-Bryan