From a47a2669926eb9543ac846a3da99f64cb268bce2 Mon Sep 17 00:00:00 2001
From: charguer <arthur@chargueraud.org>
Date: Tue, 22 Mar 2016 17:12:13 +0100
Subject: [PATCH] step-interpreter

---
 driver.html                    |  6 +++---
 esprima-to-ast.js              |  7 ++++---
 generator/Makefile             |  2 +-
 generator/displayed_sources.ml |  9 ++++----
 generator/js_of_ast.ml         |  2 +-
 generator/lineof.ml            |  8 +++----
 navig-driver.js                | 38 ++++++++++++++++++++++++++++------
 navig.js                       |  1 -
 tools.js                       |  4 ++--
 9 files changed, 52 insertions(+), 25 deletions(-)

diff --git a/driver.html b/driver.html
index 1f8e49d..94ef79c 100644
--- a/driver.html
+++ b/driver.html
@@ -74,7 +74,7 @@
 .scroll-pane
 {
 	width: 100%;
-	height: 200px;
+	height: 300px;
 	overflow: auto;
 }
 </style>
@@ -125,14 +125,14 @@ Reach condition:
 <table id='main_table'><tr>
 <td>
    <div id='file_list'></div>
-   <textarea id='interpreter_code' class='source' rows='20' cols='60'></textarea>
+   <textarea id='interpreter_code' class='source' rows='30' cols='60'></textarea>
 </td>
 <td width='600'>
-   <div id='disp_infos'></div>
    <div id='disp_ctx'>ctx here</div>
 </td>
 </tr></table>
 </div>
+<div id='disp_infos'></div>
 
 <script src="tools.js"></script> 
 <script src="generator/tests/jsref/displayed_sources.js"></script> 
diff --git a/esprima-to-ast.js b/esprima-to-ast.js
index 44ade73..4bece2b 100644
--- a/esprima-to-ast.js
+++ b/esprima-to-ast.js
@@ -17,8 +17,9 @@ function esprimaToAST(prog, sourceText) {
   var toLoc = function (pos) {
     if (pos === null) {throw "null position in esprima AST";};
     return {file: "input.js",
-            start: {line: pos.start.line, col: pos.start.column},
-            stop:  {line: pos.end.line, col: pos.end.column}};
+            start: {line: pos.start.line, column: pos.start.column},
+            end:  {line: pos.end.line, column: pos.end.column}};
+    // TODO : could reuse the start and end object
   };
 
   var toOption = function (funcTr, node) {
@@ -429,7 +430,7 @@ function esprimaToAST(prog, sourceText) {
           loc: {
             file: previousValue.loc.file,
             start: previousValue.loc.start,
-            stop: currentValue.loc.stop
+            end: currentValue.loc.end
           }
         };
       });
diff --git a/generator/Makefile b/generator/Makefile
index 58de204..49ef6e1 100644
--- a/generator/Makefile
+++ b/generator/Makefile
@@ -162,7 +162,7 @@ tests/jsref/%.log.js: tests/jsref/%.ml
 #####################################################################
 # Short targets
 
-everything: gen assembly lineof
+everything: gen assembly lineof display
 
 main: main.byte
 
diff --git a/generator/displayed_sources.ml b/generator/displayed_sources.ml
index cb84bb1..ba5f512 100644
--- a/generator/displayed_sources.ml
+++ b/generator/displayed_sources.ml
@@ -147,10 +147,11 @@ let _ =
    put "var tracer_files = [";
 
    ~~ List.iter !files (fun filename ->
+      let basename = Filename.chop_suffix (Filename.basename filename) ".unlog.js" in
+      let showed_filename = basename ^ ".js" in
+      put (Printf.sprintf "\n/* --------------------- %s --------------------- */" showed_filename);
+      put_no_endline (Printf.sprintf "  { file: '%s', contents: '" showed_filename);
       let lines = XFile.get_lines filename in
-      let short_filename = Filename.chop_suffix (Filename.basename filename) ".unlog.js" in
-      put (Printf.sprintf "\n/* --------------------- %s --------------------- */" short_filename);
-      put_no_endline (Printf.sprintf "  { file: '%s', contents: '" short_filename);
       ~~ List.iter lines (fun line ->
          let line = Str.global_replace (Str.regexp "'") "\\'" line in
          put_no_endline line;
@@ -159,7 +160,7 @@ let _ =
       put "'},";
       );
 
-   put "];";
+   put "];"; 
 
    (*---------------------------------------------------*)
    (* generating output file *)
diff --git a/generator/js_of_ast.ml b/generator/js_of_ast.ml
index dc802d5..943ba8b 100644
--- a/generator/js_of_ast.ml
+++ b/generator/js_of_ast.ml
@@ -439,7 +439,7 @@ let generate_logged_enter arg_ids ctx newctx sbody =
     | Mode_unlogged -> ("", "", "")
   in
   let args = String.concat ", " arg_ids in
-  Printf.sprintf "%sfunction (%s)%s {@;<1 2>@[<v 0>%s%s@]@,}" shead1 args shead2 sintro sbody
+  Printf.sprintf "%sfunction (%s)%s {@\n@;<1 2>@[<v 0>%s%s@]@,}" shead1 args shead2 sintro sbody
 
 (*
 
diff --git a/generator/lineof.ml b/generator/lineof.ml
index 2c9fb3d..1834e57 100644
--- a/generator/lineof.ml
+++ b/generator/lineof.ml
@@ -77,7 +77,7 @@ let hashtbl_keys t =
    The tokens are placed in a list, with entries of the form
    ( filename , tokens_start , tokens_stop )  where
    tokens_start is a hashmap that gives for each token id its
-   opening positions (line and col), and tokens_stop similarly
+   opening positions (line and column), and tokens_stop similarly
    gives the closing positions. *)
 
 type pos = { pos_line: int; pos_col: int }
@@ -134,8 +134,8 @@ let gather_tokens basename input_lines =
      function lineof(filename, token) {
         var d = lineof_data[filename][token];
         return { file: filename,
-                 start: {line: d[0], col: d[1]}, 
-                 stop: {line: d[2], col: d[3]} };
+                 start: {line: d[0], column: d[1]}, 
+                 end: {line: d[2], column: d[3]} };
      }
 
 *)
@@ -159,7 +159,7 @@ let generate_lineof_function put =
                key pos_start.pos_line pos_start.pos_col  
                    pos_stop.pos_line  pos_stop.pos_col);
      );
-     put (Printf.sprintf "lineof_data[\"%s\"] = lineof_temp;" basename);
+     put (Printf.sprintf "lineof_data[\"%s\"] = lineof_temp;" filename);
   )
  
 
diff --git a/navig-driver.js b/navig-driver.js
index 53ac4c0..74436a9 100644
--- a/navig-driver.js
+++ b/navig-driver.js
@@ -2,7 +2,7 @@
 // ----------- Types ----------------
 
 // type loc
-// e.g.  {file: "foo.js", start: {line: 12, col: 9}, stop: {line: 13, col: 2} };
+// e.g.  {file: "foo.js", start: {line: 12, column: 9}, end: {line: 13, column: 2} };
 //   Locations are generated by the translation from the parser to the AST.
 //   Lines are numbered starting from "1", and columns are numbered starting from "0".
 
@@ -359,14 +359,38 @@ function updateContext(targetid, heap, env) {
  });
 }
 
+// --------------- Debuggin view ----------------
+
+function htmlDiv(s) {
+  return "<div>" + s + "</div>";
+}
+
+function ctxToHtml(ctx) {
+  var s = '';
+  var a = ctx_to_array(ctx);
+  for (var i = 0; i < a.length; i++) {
+    var b = a[i];
+    s += "<div style='white-space: nowrap;'><b>" + b.key + "</b>: " + JSON.stringify(b.val) + "</div>";
+  }
+  return s;
+}
+
+
+function itemToHtml(item) {
+  var s = '';
+  s += htmlDiv("type: " + item.type);
+  s += ctxToHtml(item.ctx);
+  return s;
+}
+
 // --------------- Selection view ----------------
 
 function updateSelectionInCodeMirror(codeMirrorObj, loc) {
  if (loc === undefined) {
    return; 
  }
- var anchor = {line: loc.start.line-1 , ch: loc.start.col };
- var head = {line: loc.stop.line-1, ch: loc.stop.col };
+ var anchor = {line: loc.start.line-1 , ch: loc.start.column };
+ var head = {line: loc.end.line-1, ch: loc.end.column };
  codeMirrorObj.setSelection(anchor, head);
 }
 
@@ -376,7 +400,8 @@ function updateSelection() {
 
  if (item !== undefined) {
    // console.log(item);
-   // $("#disp_infos").html();
+   $("#disp_infos").html("");
+   $("#disp_infos").html(itemToHtml(item));
    if (item.source_loc === undefined) {
      console.log("Error: missing line in log event");
 
@@ -435,7 +460,7 @@ interpreter = CodeMirror.fromTextArea(document.getElementById('interpreter_code'
    'F': function(cm) { finish(); updateSelection(); }
  },
 });
-interpreter.setSize(600,250);
+interpreter.setSize(600,400);
 
 /* ==> try in new version of codemirror*/
 try {
@@ -471,7 +496,8 @@ interpreter.focus();
 // the corresponding location from the piece of AST that corresponds.
 // These locations are used for source highlighting.
 function assignSourceLocInTrace() {
- var last = { start: { line: 1, col: 0}, stop: { line: 1, col: 0 } };
+ var last = parsedTree.loc;
+   // { start: { line: 1, column: 0}, end: { line: 1, column: 1 } };
  for (var k = 0; k < tracer_items.length; k++) {
    var item = tracer_items[k];
    if (item.ctx !== undefined && item.ctx.bindings !== undefined) {
diff --git a/navig.js b/navig.js
index cd78ee7..97e1e47 100644
--- a/navig.js
+++ b/navig.js
@@ -311,7 +311,6 @@ function updateSourceSelection() {
   if (source_select === undefined) {
     return; 
   }
-  // TODO: rename column into col
   var anchor = {line: source_select.start.line-1 , ch: source_select.start.column };
   var head = {line: source_select.end.line-1, ch: source_select.end.column };
   source.setSelection(anchor, head);
diff --git a/tools.js b/tools.js
index c87b9d3..3945784 100644
--- a/tools.js
+++ b/tools.js
@@ -5,8 +5,8 @@
 function lineof(filename, token) {
    var d = lineof_data[filename][token];
    return { file: filename,
-            start: {line: d[0], col: d[1]}, 
-            stop: {line: d[2], col: d[3]} };
+            start: {line: d[0], column: d[1]}, 
+            end: {line: d[2], column: d[3]} };
 };
 
 
-- 
GitLab