diff --git a/driver.html b/driver.html index 9b3e906494a0cc7a2eeddd9bd4e446835adb50b4..a55c0f81f2a0c69ff7609d05842f9bdea3588018 100644 --- a/driver.html +++ b/driver.html @@ -111,7 +111,7 @@ <div class='source_div' style=""> Load example: - <select id='select_source_code'><option disabled selected>Examples</option></select> + <select id='select_source_code'></select> Load file: <input type='file' accept='.js' id='select_file' /> <table id='main_table'><tr> <td> diff --git a/generator/tests/jsref/Translate_syntax.js b/generator/tests/jsref/Translate_syntax.js index 550d195883eeb2d7c5787a8e4db8896da752f5f4..df83e1b2fafb4a9f16b3d2cc69cfadf1a52a6f78 100644 --- a/generator/tests/jsref/Translate_syntax.js +++ b/generator/tests/jsref/Translate_syntax.js @@ -2,8 +2,9 @@ var Translate_syntax = { eval_counter: 0, parse_esprima: function (strictness, src) { try { - // TODO Fixup line numbers for eval context - return Some(parseSource(src, "_eval_" + Translate_syntax.eval_counter++, true)); + // EVAL: Uncomment line below to enable multiple eval tabs + //return Some(parseSource(src, "_eval_" + Translate_syntax.eval_counter++, true)); + return Some(parseSource(src, "_eval_", true)); } catch (e) { return None(); } diff --git a/navig-driver.js b/navig-driver.js index e43beb1264712e228b2670d0ddbdb864ea692c66..3bc73554743c0979af359939a5ca997d2f286267 100644 --- a/navig-driver.js +++ b/navig-driver.js @@ -70,6 +70,7 @@ var source = null; var interpreter = null; var source_docs = {}; +var initialSourceName = ""; // Initial source code @@ -118,24 +119,40 @@ function newSourceDoc(name, text, readOnly) { .text(name) .click(e => selectSourceDoc(e.target.textContent)) .appendTo('#source_tabs'); + if (name === '_eval_') { tab.hide(); } + source_docs[name].doc_name = name; source_docs[name].tab = tab; source_docs[name].readOnly = Boolean(readOnly); } return source_docs[name]; } +function selectSourceDocFromLoc(loc) { + var name = loc.file; + if (name === '_eval_') { + source_docs['_eval_'].tab.show(); + source_docs['_eval_'].setValue(loc.sourceText); + } + var old_doc = selectSourceDoc(loc.file); + if (old_doc.doc_name === "_eval_" && name !== "_eval_") { + source_docs['_eval_'].tab.hide(); + } +} + // Switches current source doc function selectSourceDoc(name) { var old_doc = source.swapDoc(source_docs[name]); if (old_doc.tab) old_doc.tab.removeClass('file_item_current'); source_docs[name].tab.addClass('file_item_current'); source.setOption('readOnly', source_docs[name].readOnly); + return old_doc; } // Sets the initial source doc function setInitialSourceCode(name, text) { initSourceDocs(); var doc = newSourceDoc(name, text); + initialSourceName = name; $("#source_code").val(text); @@ -145,7 +162,9 @@ function setInitialSourceCode(name, text) { } } -$('#select_source_code').change(e => { setInitialSourceCode("_toplevel_", e.target.value)}); +$('#select_source_code').change(e => { + setInitialSourceCode("example" + e.target.selectedOptions[0].index + ".js", e.target.value) +}); $('#select_file').change(e => { var f = e.target.files[0]; var fr = new FileReader(); @@ -153,12 +172,11 @@ $('#select_file').change(e => { fr.readAsText(f); }); -// --------------- Initialization ---------------- - -// WARNING: do not move this initialization further down in the file -// source code displayed initially +function setExample(idx) { + $('#select_source_code option')[idx].selected = true; + $('#select_source_code').change(); +} -setInitialSourceCode("_toplevel_", source_files[0]); // --------------- Predicate search ---------------- @@ -1145,9 +1163,7 @@ function updateSelection() { // source panel source_loc_selected = item.source_loc; - newSourceDoc(item.source_loc.file, item.source_loc.sourceText); - selectSourceDoc(item.source_loc.file); - + selectSourceDocFromLoc(source_loc_selected); updateSelectionInCodeMirror(source, source_loc_selected); // console.log(source_loc_selected); @@ -1340,7 +1356,7 @@ function readSourceParseAndRun() { // TODO handle parsing error // TODO handle out of scope errors try { - program = parseSource(code, "_toplevel_"); + program = parseSource(code, initialSourceName); } catch (e) { return "Parse error"; } @@ -1387,8 +1403,8 @@ readSourceParseAndRun(); // $("#reach_condition").val("I_line()"); // button_test_handler(); -// setSourceCode(source_files[3]); -// stepTo(5873); +//setExample(3); +//stepTo(5873); function showCurrent() { console.log(tracer_items[tracer_pos]); @@ -1404,4 +1420,4 @@ function findToken(token) { return -1; }; -//S_line() == 4 && S("j") == 2 \ No newline at end of file +//S_line() == 4 && S("j") == 2