solang icon indicating copy to clipboard operation
solang copied to clipboard

Create switch instruction

Open LucasSte opened this issue 3 years ago • 3 comments

We aim at moving the dispatch code to codegen. It means we'll need new instructions and builtin structs there, like the switch instruction, utilized in this line.

This PR wires up the switch instruction for that and enables the code generation for switch statements in Yul, using the newly added instruction.

LucasSte avatar Sep 22 '22 04:09 LucasSte

LGTM, although it could use some more tests (e.g. no cases and no default at all, multiple default cases, duplicate cases, etc...)

  1. no cases and no default at all, The parser does not allow that. You can have only no cases and a default block and cases without a default. There is a test missing for the former. I'm going to add that.
  2. multiple default cases The parser does not accept that.
  3. duplicate cases. This is missing. Good point

I'll add those tests!

LucasSte avatar Sep 22 '22 10:09 LucasSte

LGTM, although it could use some more tests (e.g. no cases and no default at all, multiple default cases, duplicate cases, etc...)

  1. no cases and no default at all, The parser does not allow that. You can have only no cases and a default block and cases without a default. There is a test missing for the former. I'm going to add that.
  2. multiple default cases The parser does not accept that.
  3. duplicate cases. This is missing. Good point

I'll add those tests!

For the #3, that is a semantic error that I was not detecting.

LucasSte avatar Sep 22 '22 10:09 LucasSte

@seanyoung and @xermicus I am requesting your review again as I implemented Cyrill's suggestions.

LucasSte avatar Sep 23 '22 06:09 LucasSte