-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch case like feature #102
Comments
I am not completely sure if I understand what you are trying to say. The hard part here seems to be to create an expression that evaluates to the correct jump-line for every case. The naive implementation Also I am wondering if it would be better to simply re-use the multiline-ifs for this. |
Exactly
This is why I proposed fixed line count per expression and assuming argument is integers only
Yes automatic syntax identification requires knowledge of argument's type. IMO for early implementation it should be able to
|
I think the thingy with "case 0" is a little un-intuitve. Maybe it would be batter to name it differently to make clear what is going on?
Would make things more obvious. The question is, is it that much better than doing the table manually that it justifies adding a new sytnax-feature to the language? |
I understand that my idea for case 0 is intuitive. I included it as a way of having a script get looped back to the line so response time can be minimized. I intended cases to be fixed size of n lines for simplicity's sake as figuring a way to get a jump with nonlinear length is significantly more complicated.
or
Perosnally I like second option a bit more but I am open to other placement of the init statement. generating the folowing code
|
I think somehow integrating the "setup" into the head of the block is a good idea. I thas similarities to how a for-loop is written in many languages. Maybe something like:
(with the init-statement being optional)? I am not sure if allowing cases to be missing is a good idea. It adds additional complexity. |
The problrm is that in this case user would have to place "line n:" at a specific point to optimize line fill, this point could end up inside a macro or move easily due to for example variable name change which places a burden of chosing and updating its placement every time code changes. I think compilation could go as follows, after variable substitution and optimization compile each block of code separated by a label ("line n:") checking if it fits within lines that are free so if there are line 1, 3 6, 7 labels then block 1 has to fit within 2 lines othervise it is an error, block 3 can be three lines, block 6 can be only one line and block 7 can fill the rest of the chip. |
You're correct, allowing lines to be missing reduces the need for manual line-management. Good point. I guess the only thing missing now is the time (and motivation) to actually implement this. |
Is your feature request related to a problem? Please describe.
I am working on a device that has an interface, this interface works on a variable that can be set to specific integer values that initiate certain actions. In order for an interface to be responsive I would like to use switch case like structure.
Describe the solution you'd like
I would like to be able to tell compiler that these groups of statements are to be organized in a way that places each group on an individual line and each group is placed on a fixed number of lines.
cases can be placed in three ways
Break cause execution to jump to first line after switch has ended
Continue causes execution to jump to the line switch begins (one containing goto with var).
Describe alternatives you've considered
I could implement such structures manually in a way that is similar to what is shown in documentation here (second example). but for more complex cases such as multiline statements this would provide more readable and automated way of implementing switch case.
The text was updated successfully, but these errors were encountered: