boolop.mli 1.3 KB

12345678910111213141516171819202122232425262728293031
  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 thiese are still
  11. expressions. A transformation into actual if-else statements would retuire
  12. adding additional statements, which creates other problems which we will not
  13. discuss here.
  14. The applied transformations are as follows:
  15. {v b1 == b2 ==> (int)b1 == (int)b2
  16. b1 != b2 ==> (int)b1 != (int)b2
  17. b1 && b2 ==> b1 ? b2 : false
  18. b1 || b2 ==> b1 ? true : b2
  19. b1 + b2 ==> (bool)((int)b1 + (int)b2)
  20. b1 * b2 ==> (bool)((int)b1 * (int)b2)
  21. (bool)i ==> i != 0
  22. (bool)f ==> f != 0.0
  23. (int)b1 ==> b1 ? 1 : 0
  24. (float)b1 ==> b1 ? 1.0 : 0.0 v}
  25. *)
  26. (** Main phase function, called by {!Main}. *)
  27. val phase : Main.phase_func