Introduce true and false conditions #21

Manually merged
MightyPork merged 2 commits from User_4574/crsn:master into master 4 years ago

I learned just enough Rust to do something simple and possibly (maybe) just a little bit useful.

I added True and False conditions that are always true and false.

The most useful thing is that it allows you to have an (else? ...) final branch that is always taken.

I did my best in terms of responsible PR, feel free to send it back for changes if you don't like something (or don't outright reject it, which is also fine :p)

I learned just enough Rust to do something simple and possibly (maybe) just a little bit useful. I added True and False conditions that are always true and false. The most useful thing is that it allows you to have an `(else? ...)` final branch that is always taken. I did my best in terms of responsible PR, feel free to send it back for changes if you don't like something (or don't outright reject it, which is also fine :p)
Owner

Cool, else is useful. The compiler could emit a warning if else is not the last branch, since in that case it won't work (or will - depends how you look at it).

No problem with never, but I also see no use for it...

Idk about always, it's not very useful, and seems to evoke something like "finally" - to run always. Which it obviously does not, since there is no fall-through between the branches.

What I don't like is true and false - because there are instructions that write a truthy value as 0 or 1 to the output register (e.g. sc-mbtn, sc-key, maybe others). Logically true should be an alias of "not zero" and false of "zero"?

Cool, `else` is useful. The compiler could emit a warning if else is not the last branch, since in that case it won't work (or will - depends how you look at it). No problem with `never`, but I also see no use for it... Idk about `always`, it's not very useful, and seems to evoke something like "finally" - to run always. Which it obviously does not, since there is no fall-through between the branches. What I don't like is `true` and `false` - because there are instructions that write a truthy value as 0 or 1 to the output register (e.g. `sc-mbtn`, `sc-key`, maybe others). Logically true should be an alias of "not zero" and false of "zero"?
Poster

Okay, that all makes sense. I started out wanting else, but when I saw how the others were implemented it made more sense to me to do it like this because it needs an opposite for not.

Is there a more sensible way to do this rather than it being a cond?

Okay, that all makes sense. I started out wanting `else`, but when I saw how the others were implemented it made more sense to me to do it like this because it needs an opposite for not. Is there a more sensible way to do this rather than it being a cond?
Owner

Oh, you're right.

I'd do it like this then:

  • Cond::True ... parsed from "else", and only documented as "else"
  • Cond::False ... not parsed and not documented (or called "never"), only to satisfy Not

the negation is used only in this one spot, I think: https://git.ondrovo.com/MightyPork/crsn/src/branch/master/crsn/src/asm/instr/flatten.rs#L70

This is also the place where you can add a warning about else not being the final branch, if you want to do that. It's fine either way with me

Oh, you're right. I'd do it like this then: - `Cond::True` ... parsed from "else", and only documented as "else" - `Cond::False` ... not parsed and not documented (or called "never"), only to satisfy Not the negation is used only in this one spot, I think: https://git.ondrovo.com/MightyPork/crsn/src/branch/master/crsn/src/asm/instr/flatten.rs#L70 This is also the place where you can add a warning about else not being the final branch, if you want to do that. It's fine either way with me
Poster

Okay, I've made those changes. This does feel much cleaner.

Okay, I've made those changes. This does feel much cleaner.
MightyPork closed this pull request 4 years ago
Owner

Thanks, it's merged!

Thanks, it's merged!
The pull request has been manually merged as 54ff5fbce9.
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: MightyPork/crsn#21
Loading…
There is no content yet.