Browse Source

Documented Boolop phase

Taddeus Kroes 12 năm trước cách đây
mục cha
commit
714565b5d0
2 tập tin đã thay đổi với 35 bổ sung5 xóa
  1. 5 5
      phases/boolop.ml
  2. 30 0
      phases/boolop.mli

+ 5 - 5
phases/boolop.ml

@@ -9,11 +9,11 @@
  * > b1 != b2   ==>   (int)b1 != (int)b2
  * > b1 && b2   ==>   b1 ? b2 : false
  * > b1 || b2   ==>   b1 ? true : b2
- * > b1 + b2  ==>   (bool)((int)b1 + (int)b2)
- * > b1 * b2  ==>   (bool)((int)b1 * (int)b2)
- * > (bool)i  ==>   i != 0
- * > (bool)f  ==>   f != 0.0
- * > (int)b1  ==>   b1 ? 1 : 0
+ * > b1 + b2    ==>   (bool)((int)b1 + (int)b2)
+ * > b1 * b2    ==>   (bool)((int)b1 * (int)b2)
+ * > (bool)i    ==>   i != 0
+ * > (bool)f    ==>   f != 0.0
+ * > (int)b1    ==>   b1 ? 1 : 0
  * > (float)b1  ==>   b1 ? 1.0 : 0.0
  *)
 open Types

+ 30 - 0
phases/boolop.mli

@@ -1 +1,31 @@
+(** Convert boolean operations to equivalent operations on different CiviC data
+    types. *)
+
+(** This phase transforms operations on boolean values to equivalent operations
+    no different data types. This transformation is necessary, because the CiviC
+    VM does not define some operations for boolean arguments.
+
+    This phase also handles the first step of short-circuit evaluation, by
+    transforming conjunction and disjunction operators into conditional
+    operations of the form [a ? b : c]. This operation is supported by the
+    assembly phase, which handles them similarly to if-else statements. The
+    benefit of using conditional operations, is that thiese are still
+    expressions. A transformation into actual if-else statements would retuire
+    adding additional statements, which creates other problems which we will not
+    discuss here.
+
+    The applied transformations are as follows:
+{v b1 == b2    ==>   (int)b1 == (int)b2
+b1 != b2    ==>   (int)b1 != (int)b2
+b1 && b2    ==>   b1 ? b2 : false
+b1 || b2    ==>   b1 ? true : b2
+b1 + b2     ==>   (bool)((int)b1 + (int)b2)
+b1 * b2     ==>   (bool)((int)b1 * (int)b2)
+(bool)i     ==>   i != 0
+(bool)f     ==>   f != 0.0
+(int)b1     ==>   b1 ? 1 : 0
+(float)b1   ==>   b1 ? 1.0 : 0.0 v}
+    *)
+
+(** Main phase function, called by {!Main}. *)
 val phase : Main.phase_func