Git Product home page Git Product logo

Comments (3)

EgonOlsen71 avatar EgonOlsen71 commented on August 11, 2024

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...

from basicv2.

EgonOlsen71 avatar EgonOlsen71 commented on August 11, 2024

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

if x=5 and y=12 then...

can easily be optimized to

if x=5 then if y=12 then...

(which is the same as you've suggested, but in BASIC source code)

but something like

if a and 8 then...

can't. Or more complex:

if (b>2)*-8 and 2*b then ...

can't either. Right now, I'm lacking a clever idea how to separate these cases correctly without going overboard with it...hmm...

from basicv2.

nippur72 avatar nippur72 commented on August 11, 2024

thinking about it... when evaluating the AST, your expression nodes might also include a isBoolean property that bubbles up to the root, e.g.

b<2 => return { ..., isBoolean: true }
b * 4  => return { ..., isBoolean: false }
expr1 AND expr2 => return { ..., isBoolean: expr1.isBoolean AND expr2.isBoolean }
expr1 OR expr2 => return { ..., isBoolean: expr1.isBoolean AND expr2.isBoolean }

then you can check the root node of your IF expression and if it's isBoolean you can apply short circuit optimization. Something like this.

from basicv2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.