NOP0 / rustmatic

PLC programming in Rust!
Apache License 2.0
35 stars 2 forks source link

Start case statement #19

Open NOP0 opened 4 years ago

NOP0 commented 4 years ago

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

No test yet..

NOP0 commented 4 years ago

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?

Michael-F-Bryan commented 4 years ago

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).