boolop.mli 1.3 KB

123456789101112131415161718192021222324252627282930
  1. (** Convert boolean operations to equivalent operations on different CiviC data
  2. types. *)
  3. (** This phase transforms operations on boolean values to equivalent operations
  4. on different data types. This transformation is necessary, because the CiviC
  5. VM does not define some operations for boolean arguments.
  6. This phase also handles the first step of short-circuit evaluation, by
  7. transforming conjunction and disjunction operators into conditional
  8. operations of the form [a ? b : c]. This operation is supported by the
  9. assembly phase, which handles them similarly to if-else statements. The
  10. benefit of using conditional operations, is that they are still expressions.
  11. A transformation into actual if-else statements would require adding
  12. additional statements, which is not only more difficult to implement, but
  13. also changes the evaluation order, which (however in agreement with the C
  14. standard) may lead to confusing behaviour.
  15. The applied transformations are as follows:
  16. {v b1 == b2 ==> (int)b1 == (int)b2
  17. b1 != b2 ==> (int)b1 != (int)b2
  18. b1 && b2 ==> b1 ? b2 : false
  19. b1 || b2 ==> b1 ? true : b2
  20. (bool)i ==> i != 0
  21. (bool)f ==> f != 0.0
  22. (int)b ==> b ? 1 : 0
  23. (float)b ==> b ? 1.0 : 0.0 v}
  24. *)
  25. (** Main phase function, called by {!Main}. *)
  26. val phase : Main.phase_func