• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 16901331054

12 Aug 2025 06:52AM UTC coverage: 59.795% (+0.02%) from 59.775%
16901331054

push

github

web-flow
further optimize shortcircuits (#800)

* further optimize shortcircuits
combine jumps if possible
dont emit logicalconvert instructions if the next instruction is another shortcircuit jump

* docs

45 of 46 new or added lines in 6 files covered. (97.83%)

43646 of 72993 relevant lines covered (59.79%)

418781.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/pol-core/bscript/compiler/optimizer/ShortCircuitCombiner.cpp
1
#include "ShortCircuitCombiner.h"
2

3
#include "bscript/compiler/Report.h"
4
#include "bscript/compiler/ast/BinaryOperatorShortCircuit.h"
5

6

7
namespace Pol::Bscript::Compiler
8
{
9
class ShortCircuitCombinerChildVisitor : public NodeVisitor
10
{
11
public:
12
  ShortCircuitCombinerChildVisitor( BinaryOperatorShortCircuit& parent, bool rhs )
114✔
13
      : parent( parent ), rhs( rhs ){};
114✔
14
  void visit_children( Node& ) override{};
35✔
15
  void visit_binary_operator_short_circuit( BinaryOperatorShortCircuit& child ) override
12✔
16
  {
17
    // create a new jmplink or use the existing
18
    auto parent_endjmp = parent.linked_jmp_label
12✔
19
                             ? parent.linked_jmp_label
12✔
20
                             : std::make_shared<JmpLocationLink>( parent.end_label, parent.oper );
12✔
21
    // its a child so no need to add convert instruction
22
    child.generate_logical_convert = false;
12✔
23
    // on the left side dont jump if the operand is different (would skip the rhs)
24
    if ( !rhs && child.oper != parent_endjmp->oper )
12✔
25
      return;
2✔
26
    // update the jmp, so that it will propagate
27
    if ( child.linked_jmp_label )
20✔
28
      child.linked_jmp_label->update( *parent_endjmp );
1✔
29
    else
30
      child.linked_jmp_label = parent_endjmp;
9✔
31
    // set the parent also, thus if its a child it would propagate to its children
32
    if ( !parent.linked_jmp_label )
20✔
33
      parent.linked_jmp_label = parent_endjmp;
10✔
34
  };
12✔
35

36
private:
37
  BinaryOperatorShortCircuit& parent;
38
  bool rhs;
39
};
40

41

42
ShortCircuitCombiner::ShortCircuitCombiner( Report& ) {}
57✔
43

NEW
44
void ShortCircuitCombiner::visit_children( Node& ) {}
×
45

46
void ShortCircuitCombiner::visit_binary_operator_short_circuit( BinaryOperatorShortCircuit& op )
57✔
47
{
48
  // dont visit recursivly just direct both sides
49
  ShortCircuitCombinerChildVisitor lhs_child{ op, false };
57✔
50
  op.lhs().accept( lhs_child );
57✔
51
  ShortCircuitCombinerChildVisitor rhs_child{ op, true };
57✔
52
  op.rhs().accept( rhs_child );
57✔
53
}
57✔
54

55
}  // namespace Pol::Bscript::Compiler
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc