-
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
Implement short circuit evaluation for AND, OR #22
Comments
I already thought about this some time ago, but for some reason (that I don't remember ATM), it wasn't that easy to implement in this context. So I decided against it. When I find the time, I might take a look at it again... |
Thinking about it, I remember my actual problem with it. This logic applies to AND and OR when they are boolean operators. But in BASIC V2, what they actually are, are bitwise AND and OR operators. That means, that
can easily be optimized to
(which is the same as you've suggested, but in BASIC source code) but something like
can't. Or more complex:
can't either. Right now, I'm lacking a clever idea how to separate these cases correctly without going overboard with it...hmm... |
thinking about it... when evaluating the AST, your expression nodes might also include a
then you can check the root node of your |
If
cond1
is false there is no need to evaluatecond2
, it will be always false. Similarly ifcond3
is true no need to evaluatecond4
as it will be always true.That could provide some speed increase. The only caution is that
cond2
andcond4
should not contain call to impure functions (functions that have side effects) but to my knowledge almost all BASIC V2 functions are pure (exceptRND
andFN
?).The text was updated successfully, but these errors were encountered: