From 6b7e8cf27e8573cd57d69144922e168e2c9b0c56 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
Date: Mon, 29 Feb 2016 13:42:49 +0100
Subject: [PATCH] debugging

---
 generator/js_of_ast.ml                 | 16 ++++--
 generator/tests/jsref/JsInterpreter.ml | 80 ++++++++------------------
 2 files changed, 36 insertions(+), 60 deletions(-)

diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml
index 5bf5344..4b7d9e2 100644
--- a/generator/js_of_ast.ml
+++ b/generator/js_of_ast.ml
@@ -62,6 +62,10 @@ let string_fold_righti f s acc =
 
 let is_sbool x = List.mem x ["true" ; "false"]
 
+let is_unit x = x = "()"
+
+let unit_repr = "{}"
+
 (* Given an expression, check whether it is a primitive type or a constructed type *)
 let exp_type_is_constant exp =
   List.exists (Ctype.matches exp.exp_env exp.exp_type)
@@ -635,10 +639,12 @@ and js_of_expression ctx dest e =
     let cstr_name = cd.cstr_name in
     (*let styp = string_of_type_exp e.exp_type in*)
     let sexp =
-      if is_sbool cstr_name then cstr_name else begin
-        let expr_strs = List.map (fun exp -> inline_of_wrap exp) el in
-        ppf_cstrs_fct cstr_fullname expr_strs
-      end in
+      if is_sbool cstr_name then cstr_name else
+      if is_unit cstr_name then unit_repr else
+        begin
+          let expr_strs = List.map (fun exp -> inline_of_wrap exp) el in
+          ppf_cstrs_fct cstr_fullname expr_strs
+        end in
     apply_dest ctx dest sexp
 
   | Texp_array      (exp_l)           -> ppf_array @@ show_list_f (fun exp -> inline_of_wrap exp) ", " exp_l
@@ -717,7 +723,7 @@ and js_of_constant = function
 
 and js_of_longident loc =
   match String.concat "." @@ Longident.flatten loc.txt with
-  | "()"  -> "undefined"
+  | "()"  -> unit_repr
   | "+."  -> "+"
   | "*."  -> "*"
   | "-."  -> "-"
diff --git a/generator/tests/jsref/JsInterpreter.ml b/generator/tests/jsref/JsInterpreter.ml
index 45000c0..ec59781 100644
--- a/generator/tests/jsref/JsInterpreter.ml
+++ b/generator/tests/jsref/JsInterpreter.ml
@@ -6141,58 +6141,28 @@ let run_javascript runs0 p =
 
 (** val runs : int -> runs_type **)
 
-let rec runs max_step =
-  (fun fO fS n -> if int_eq n 0 then fO () else fS (n-1))
-    (fun _ -> { runs_type_expr = (fun s x x0 -> Coq_result_bottom s);
-    runs_type_stat = (fun s x x0 -> Coq_result_bottom s); runs_type_prog =
-    (fun s x x0 -> Coq_result_bottom s); runs_type_call =
-    (fun s x x0 x1 x2 -> Coq_result_bottom s); runs_type_call_prealloc =
-    (fun s x x0 x1 x2 -> Coq_result_bottom s); runs_type_construct =
-    (fun s x x0 x1 x2 -> Coq_result_bottom s);
-    runs_type_function_has_instance = (fun s x x0 -> Coq_result_bottom s);
-    runs_type_object_has_instance = (fun s x x0 x1 x2 -> Coq_result_bottom
-    s); runs_type_get_args_for_apply = (fun s x x0 x1 x2 -> Coq_result_bottom
-    s); runs_type_stat_while = (fun s x x0 x1 x2 x3 -> Coq_result_bottom s);
-    runs_type_stat_do_while = (fun s x x0 x1 x2 x3 -> Coq_result_bottom s);
-    runs_type_stat_for_loop = (fun s x x0 x1 x2 x3 x4 -> Coq_result_bottom
-    s); runs_type_object_delete = (fun s x x0 x1 x2 -> Coq_result_bottom s);
-    runs_type_object_get_own_prop = (fun s x x0 x1 -> Coq_result_bottom s);
-    runs_type_object_get_prop = (fun s x x0 x1 -> Coq_result_bottom s);
-    runs_type_object_get = (fun s x x0 x1 -> Coq_result_bottom s);
-    runs_type_object_proto_is_prototype_of = (fun s x x0 -> Coq_result_bottom
-    s); runs_type_object_put = (fun s x x0 x1 x2 x3 -> Coq_result_bottom s);
-    runs_type_equal = (fun s x x0 x1 -> Coq_result_bottom s);
-    runs_type_to_integer = (fun s x x0 -> Coq_result_bottom s);
-    runs_type_to_string = (fun s x x0 -> Coq_result_bottom s);
-    runs_type_array_join_elements = (fun s x x0 x1 x2 x3 x4 ->
-    Coq_result_bottom s); runs_type_array_element_list = (fun s x x0 x1 x2 ->
-    Coq_result_bottom s); runs_type_object_define_own_prop_array_loop =
-    (fun s x x0 x1 x2 x3 x4 x5 x6 -> Coq_result_bottom
-    s) })
-    (fun max_step' ->
-    let wrap = fun _ f s -> let runs' = runs max_step' in f runs' s in
-    { runs_type_expr = (wrap __ run_expr); runs_type_stat =
-    (wrap __ run_stat); runs_type_prog = (wrap __ run_prog); runs_type_call =
-    (wrap __ run_call); runs_type_call_prealloc =
-    (wrap __ run_call_prealloc); runs_type_construct =
-    (wrap __ run_construct); runs_type_function_has_instance =
-    (wrap __ run_function_has_instance); runs_type_object_has_instance =
-    (wrap __ run_object_has_instance); runs_type_get_args_for_apply =
-    (wrap __ run_get_args_for_apply); runs_type_stat_while =
-    (wrap __ run_stat_while); runs_type_stat_do_while =
-    (wrap __ run_stat_do_while); runs_type_stat_for_loop =
-    (wrap __ run_stat_for_loop); runs_type_object_delete =
-    (wrap __ object_delete); runs_type_object_get_own_prop =
-    (wrap __ run_object_get_own_prop); runs_type_object_get_prop =
-    (wrap __ run_object_get_prop); runs_type_object_get =
-    (wrap __ run_object_get); runs_type_object_proto_is_prototype_of =
-    (wrap __ object_proto_is_prototype_of); runs_type_object_put =
-    (wrap __ object_put); runs_type_equal = (wrap __ run_equal);
-    runs_type_to_integer = (wrap __ to_integer); runs_type_to_string =
-    (wrap __ to_string); runs_type_array_join_elements =
-    (wrap __ run_array_join_elements); runs_type_array_element_list =
-    (wrap __ run_array_element_list);
-    runs_type_object_define_own_prop_array_loop =
-    (wrap __ run_object_define_own_prop_array_loop) })
-    max_step
-
+let rec runs =
+  { runs_type_expr = (fun x y z -> run_expr runs x y z);
+    runs_type_stat = (fun x y z -> run_stat runs x y z);
+    runs_type_prog = (fun x y z -> run_prog runs x y z);
+    runs_type_call = (fun x y z r t -> run_call runs x y z r t);
+    runs_type_call_prealloc = (fun x y z r t -> run_call_prealloc runs x y z r t);
+    runs_type_construct = (fun x y z r t -> run_construct runs x y z r t);
+    runs_type_function_has_instance = (fun x y z -> run_function_has_instance runs x y z);
+    runs_type_object_has_instance = (fun x y z r t -> run_object_has_instance runs x y z r t);
+    runs_type_get_args_for_apply = (fun x y z r t -> run_get_args_for_apply runs x y z r t);
+    runs_type_stat_while = (fun x y z r t s -> run_stat_while runs x y z r t s);
+    runs_type_stat_do_while = (fun x y z r t s -> run_stat_do_while runs x y z r t s);
+    runs_type_stat_for_loop = (fun x y z r t s v -> run_stat_for_loop runs x y z r t s v);
+    runs_type_object_delete = (fun x y z r t -> object_delete runs x y z r t);
+    runs_type_object_get_own_prop = (fun x y z r -> run_object_get_own_prop runs x y z r);
+    runs_type_object_get_prop = (fun x y z r -> run_object_get_prop runs x y z r);
+    runs_type_object_get = (fun x y z r -> run_object_get runs x y z r);
+    runs_type_object_proto_is_prototype_of = (fun x y z -> object_proto_is_prototype_of runs x y z);
+    runs_type_object_put = (fun x y z r s t -> object_put runs x y z r s t);
+    runs_type_equal = (fun x y z r -> run_equal runs x y z r);
+    runs_type_to_integer = (fun x y z -> to_integer runs x y z);
+    runs_type_to_string = (fun x y z -> to_string runs x y z);
+    runs_type_array_join_elements = (fun x y z r s t v -> run_array_join_elements runs x y z r s t v);
+    runs_type_array_element_list = (fun x y z r s -> run_array_element_list runs x y z r s);
+    runs_type_object_define_own_prop_array_loop = (fun x y z r s t u v w -> run_object_define_own_prop_array_loop runs x y z r s t u v w) }
-- 
GitLab