Commits

Paweł Wieczorek committed 596dcd6

Added AstCartesianProducts, etc

  • Participants
  • Parent commits c8de494
  • Branches three_address_code

Comments (0)

Files changed (6)

 CTAGS_CMD=ctags
 
 SRCS= $(shell find source -iname "*.mli" -or -iname "*.ml" -and -not -iname "Autogen.ml")
+TEST_SRCS= $(shell find test -iname "*.mli" -or -iname "*.ml" -and -not -iname "Autogen.ml")
 VERBOSE?=@
 .PHONY: clean ${PROGRAM} runtime test
 .SUFFIXES: .cma
 
 all: ${PROGRAM} ${TAGS_FILE} runtime
 
-${TAGS_FILE}: ${SRCS}
-	${CTAGS_CMD} -f ${TAGS_FILE} -R source 
+${TAGS_FILE}: ${SRCS} ${TEST_SRCS}
+	${CTAGS_CMD} -f ${TAGS_FILE} -R source test
 
 ${PROGRAM}: ${AUTOGEN}
 	${VERBOSE}${OCAMLBUILD_CMD} source/Bin/${PROGRAM}/${PROGRAM}.native source/Bin/Tmp/Tmp.native 
 
-test: ${AUTOGEN}
+test: ${AUTOGEN} ${TAGS_FILE}
 	${VERBOSE}${OCAMLBUILD_CMD}  test/Bin/Test/Test.native
 
 ${AUTOGEN}: Makefile ${SRCS}

source/Lang/TAC/AST.ml

     | _ ->
         false
 
-let eq_arithmetic_expression aexpr1 aexpr2 = 
-    Error.not_yet_implemented "eq_arithmetic_expression"
+let eq_arithmetic_expression aexpr1 aexpr2 = match aexpr1, aexpr2 with
+    | AEXPR_Atom (_, atom1)
+    , AEXPR_Atom (_, atom2) ->
+        eq_atom atom1 atom2
+
+    | AEXPR_BinaryOperator (_, op1, atom1a, atom1b)
+    , AEXPR_BinaryOperator (_, op2, atom2a, atom2b)
+    when op1 = op2 ->
+        eq_atom atom1a atom2a && eq_atom atom1b atom2b
+
+    | _ ->
+        false
 
 let eq_boolean_expression bexpr1 bexpr2 = 
     Error.not_yet_implemented "eq_boolean_expression"

source/Util/Util.ml

 
 let get_filename_with_suffix suffix filename =
     get_filename_base filename ^ suffix
+
+
+let cartesian_product_2 = List.cartesian_product
+
+let cartesian_product_3 xs1 xs2 xs3 =
+    let cart = cartesian_product_2 xs1 xs2 in
+    let fix (a,b) c = (a,b,c) in
+    concat_map (fun p -> List.map (fix p) xs3) cart
+
+let cartesian_product_4 xs1 xs2 xs3 xs4 =
+    let cart = cartesian_product_3 xs1 xs2 xs3 in
+    let fix (a,b,c) d = (a,b,c,d) in
+    concat_map (fun p -> List.map (fix p) xs4) cart

test/TestSet/TestRegister.ml

 let test_suites = ref []
 
 let test_suite () = "TestSet" >:::
-    !test_suites
+    List.rev (!test_suites)
 
 let rec register_at_path test_suite last_node (Table table) = function
     | [] ->
 
 
 let register_test_suite (module_name : string) (test_suite : test) =
+    Printf.printf "Adding %s%!\n" module_name;
     test_suites := test_suite :: !test_suites
 
 let build_top_test_suite () =

test/TestSet/Test_Lang/Test_Common/Test_AST.ml

  *)
 
 open Batteries
-open OUnit
+open TestFramework
 
 (*********************************************************************************************************************
  * Module Under Test
  * Helpers
  ********************************************************************************************************************)
 
+
+(*********************************************************************************************************************
+ * Data
+ ********************************************************************************************************************)
+
+module Data = struct
+    open MUT
+
+    module AstCartesianProduct = struct
+
+
+        let from_1 embed xs =
+            List.map embed xs
+
+        let many_from_1 embed xss =
+            List.map (from_1 embed) xss
+
+        let from_2 embed xs ys =
+            List.map embed (Util.cartesian_product_2 xs ys)
+
+        let from_3 embed xs ys zs =
+            List.map embed (Util.cartesian_product_3 xs ys zs)
+
+        let from_4 embed xs ys zs rs =
+            List.map embed (Util.cartesian_product_4 xs ys zs rs)
+
+    end
+
+    let arithmetic_binary_operators =
+            [ AOP_ADD
+            ; AOP_SUB
+            ; AOP_MUL
+            ; AOP_DIV
+            ; AOP_MOD
+            ]
+
+    let arithmetic_unary_operators =
+        [ AOP_NEG
+        ]
+
+    let boolean_arithmetic_binary_operators =
+        [ BOP_LT
+        ; BOP_LEQ
+        ; BOP_EQ
+        ; BOP_GT
+        ; BOP_GEQ
+        ; BOP_NEQ
+        ]
+
+    let boolean_binary_operators =
+        [ BOP_AND
+        ; BOP_OR
+        ]
+
+    let boolean_unary_operators =
+        [ BOP_NOT
+        ]
+
+end
+
 (*********************************************************************************************************************
  * Tests
  ********************************************************************************************************************)

test/TestSet/Test_Lang/Test_TAC/Test_AST.ml

  ********************************************************************************************************************)
 
 module Data = struct
+    open Test_Common.Test_AST.Data
 
     let atom_v000_constant_5 =
         MUT.ATOM_Constant(new_label (), 5)
         let f atom = MUT.AEXPR_Atom (new_label (), atom) in
         List.map f different_atoms
 
+    let different_aexprs_from_abops =
+        let embed (aop, atom1, atom2) = MUT.AEXPR_BinaryOperator (new_label (), aop, atom1, atom2) in
+        AstCartesianProduct.from_3 embed
+            arithmetic_binary_operators
+            different_atoms
+            different_atoms
+
+    let different_aexprs_from_auops =
+        let embed (aop, atom) = MUT.AEXPR_UnaryOperator (new_label (), aop, atom) in
+        AstCartesianProduct.from_2 embed
+            arithmetic_unary_operators
+            different_atoms
+
     let equal_aexprs_from_atom =
-        let f atom = MUT.AEXPR_Atom (new_label (), atom) in
-        List.map (List.map f) atoms_equals
+        let embed atom = MUT.AEXPR_Atom (new_label (), atom) in
+        AstCartesianProduct.many_from_1 embed atoms_equals
 
     let different_aexprs = List.concat
         [ different_aexprs_from_atoms 
+        ; different_aexprs_from_abops
+        ; different_aexprs_from_auops
         ]
 
     let equal_aexprs = List.concat