dbaumgarten / yodk

Development Kit for Starbase's ingame programming language YOLOL
MIT License
57 stars 16 forks source link

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

Closed Wolvereness closed 3 years ago

Wolvereness commented 3 years ago

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 commented 3 years ago

Addendum suggestions:

dbaumgarten commented 3 years ago

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 commented 3 years ago

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.