sunjay / brain

A high level programming language that compiles into the brainfuck esoteric programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean && and || operators do not short-circuit

sunjay opened this issue · comments

Short-circuit evaluation

This is less of a problem now because we don't have functions yet (#16), but this is a very important property of booleans that should be properly implemented sooner rather than later.

The problem is that boolean operators are implemented as regular functions (like stdout.print, etc.). They just have "internal-only" names which are only callable from inside the compiler. This solution works quite well, except it doesn't work here because we want to actually delay the evaluation of the expression of the operators until we deem it necessary to evaluate them.

Two ideas:

  1. Some kind of lazy operators table in the scope which takes expressions instead of the direct scope items
  2. Special BooleanOr and BooleanAnd ast::Expression enum variants which have to be handled everywhere using a special intrinsics::boolean_or or intrinsics::boolean_and function

Either way, the solution to this needs to be thought about more before it is implemented.