Skip to content
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

Assert expression for goto-math/line-labels #108

Closed
Wolvereness opened this issue Sep 8, 2021 · 3 comments
Closed

Assert expression for goto-math/line-labels #108

Wolvereness opened this issue Sep 8, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@Wolvereness
Copy link

Is your feature request related to a problem? Please describe.
Working with goto-math is dangerous

Describe the solution you'd like
An assert expression applied at compile-time, and will raise an error if the expression is false. This expression is only functionally useful for Line-Labels.

For example:

t = 0
f = 1

mode_check>
	:flight = f and :mode
	:turret = t and :mode
	GOTO mode_check+(not :mode)
	ASSERT mode_swap = mode_check + 1 // Compiles successfully

mode_swap> 
	f = not f
	t = not t
	:FcuRotationalPitch = 0
	:FcuRotationalYaw = 0
	:FcuRotationalRoll = 0
	:ModeColor = t + 3 * f
	:Mode = 1
	goto mode_check
t = 0
f = 1

mode_check>
	:flight = f and :mode
	:turret = t and :mode
	GOTO mode_check+(not :mode)
	ASSERT mode_swap = mode_check + 1 // Fails
$
mode_swap> 
	f = not f
	t = not t
	:FcuRotationalPitch = 0
	:FcuRotationalYaw = 0
	:FcuRotationalRoll = 0
	:ModeColor = t + 3 * f
	:Mode = 1
	goto mode_check

Describe alternatives you've considered
Using names multiplied by truthiness is always correct, but more verbose

Additional context
#107

@Wolvereness Wolvereness added the enhancement New feature or request label Sep 8, 2021
@Wolvereness
Copy link
Author

Addendum suggestions:

  • Add a warning-output for any label used in conjunction with goto-math that doesn't have an assert for the included label.
  • Add a warning-output for any goto-math that doesn't have a label.

@dbaumgarten
Copy link
Owner

Using gotos is always an excellent way to shoot yourself in the foot. These things are error-prone, unreadable and bad style in general.

Instead of improving goto-math I would rather like to completely get rid of user-crafted goto-math.
I am thinking of if-statements beeing automatically compiled to goto-math wen reasonable, or just a justom syntax-feature for jump-tables ( for example #102 ).

That would prevent stupid mistakes from the start, make code readable and help people that are not even aware of how goto-math can be used as an alternative to ifs.

@dbaumgarten
Copy link
Owner

So, I had some time to think about this.
There will be no such assertions.
Goto-math is dangerous and if the user insists on using it, he will have to accept the risk.

#102 would make implementing jump-tables reasonably safe, which is the main use-case for goto-stuff like this. I think thats good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants