Skip to content

Commit 3c14a68

Browse files
committed
refactored some option-handling code
1 parent 78234d9 commit 3c14a68

5 files changed

Lines changed: 31 additions & 25 deletions

File tree

v3/js/opt-frontend.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,15 @@ $(document).ready(function() {
153153
$("#embedLinkDiv").hide();
154154

155155

156+
// set up all options in a JS object
157+
var options = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
158+
heap_primitives: ($('#heapPrimitivesSelector').val() == 'true'),
159+
show_only_outputs: ($('#showOnlyOutputsSelector').val() == 'true')};
160+
156161
$.get(backend_script,
157162
{user_script : pyInputCodeMirror.getValue(),
158163
raw_input_json: rawInputLst.length > 0 ? JSON.stringify(rawInputLst) : '',
159-
cumulative_mode: $('#cumulativeModeSelector').val(),
160-
heap_primitives: $('#heapPrimitivesSelector').val()},
164+
options_json: JSON.stringify(options)},
161165
function(dataFromBackend) {
162166
var trace = dataFromBackend.trace;
163167

@@ -214,6 +218,7 @@ $(document).ready(function() {
214218
disableHeapNesting: ($('#heapPrimitivesSelector').val() == 'true'),
215219
drawParentPointers: ($('#drawParentPointerSelector').val() == 'true'),
216220
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
221+
showOnlyOutputs: ($('#showOnlyOutputsSelector').val() == 'true'),
217222
executeCodeWithRawInputFunc: executeCodeWithRawInput,
218223
//allowEditAnnotations: true,
219224
});
@@ -526,6 +531,11 @@ $(document).ready(function() {
526531
if (textRefsState !== undefined) {
527532
$('#textualMemoryLabelsSelector').val(textRefsState);
528533
}
534+
var showOnlyOutputsState = $.bbq.getState('showOnlyOutputs');
535+
if (showOnlyOutputsState !== undefined) {
536+
$('#showOnlyOutputsSelector').val(showOnlyOutputsState);
537+
}
538+
529539
var pyState = $.bbq.getState('py');
530540
if (pyState !== undefined) {
531541
$('#pythonVersionSelector').val(pyState);
@@ -572,6 +582,7 @@ $(document).ready(function() {
572582
heapPrimitives: $('#heapPrimitivesSelector').val(),
573583
drawParentPointers: $('#drawParentPointerSelector').val(),
574584
textReferences: $('#textualMemoryLabelsSelector').val(),
585+
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
575586
py: $('#pythonVersionSelector').val()};
576587

577588
if (appMode == 'display') {
@@ -590,6 +601,7 @@ $(document).ready(function() {
590601
heapPrimitives: $('#heapPrimitivesSelector').val(),
591602
drawParentPointers: $('#drawParentPointerSelector').val(),
592603
textReferences: $('#textualMemoryLabelsSelector').val(),
604+
showOnlyOutputs: $('#showOnlyOutputsSelector').val(),
593605
py: $('#pythonVersionSelector').val(),
594606
curInstr: myVisualizer.curInstr,
595607
};

v3/pg_logger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,10 @@ def finalize(self):
10391039
import json
10401040

10411041
# the MAIN meaty function!!!
1042-
def exec_script_str(script_str, raw_input_lst_json, cumulative_mode, heap_primitives, finalizer_func):
1043-
logger = PGLogger(cumulative_mode, heap_primitives, finalizer_func)
1042+
def exec_script_str(script_str, raw_input_lst_json, options_json, finalizer_func):
1043+
options = json.loads(options_json)
1044+
1045+
logger = PGLogger(options['cumulative_mode'], options['heap_primitives'], finalizer_func)
10441046

10451047
# TODO: refactor these NOT to be globals
10461048
global input_string_queue

v3/pythontutor.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,9 @@ def get(self):
7474
self.response.headers['Content-Type'] = 'application/json'
7575
self.response.headers['Cache-Control'] = 'no-cache'
7676

77-
# convert from string to a Python boolean ...
78-
cumulative_mode = (self.request.get('cumulative_mode') == 'true')
79-
heap_primitives = (self.request.get('heap_primitives') == 'true')
80-
8177
pg_logger.exec_script_str(self.request.get('user_script'),
8278
self.request.get('raw_input_json'),
83-
cumulative_mode,
84-
heap_primitives,
79+
self.request.get('options_json'),
8580
self.json_finalizer)
8681

8782

v3/visualize.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070

7171
<div id="codeInputPane"></div> <!-- populate with a CodeMirror instance -->
7272

73-
<p style="margin-top: 10px;">
73+
<p style="margin-top: 10px; line-height: 200%;">
7474
Execute code using
7575
<select id="pythonVersionSelector">
7676
<option value="2">Python 2.7</option>
@@ -87,10 +87,14 @@
8787
<select id="drawParentPointerSelector">
8888
<option value="false">hide environment parent pointers</option>
8989
<option value="true">show environment parent pointers</option>
90-
</select>, and
90+
</select>,
9191
<select id="textualMemoryLabelsSelector">
9292
<option value="false">draw references using arrows</option>
9393
<option value="true">use text labels for references</option>
94+
</select>, and
95+
<select id="showOnlyOutputsSelector">
96+
<option value="false">show everything</option>
97+
<option value="true">show only outputs</option>
9498
</select>.
9599
</p>
96100

v3/web_exec.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ def cgi_finalizer(input_code, output_trace):
5656
print("Content-type: text/plain; charset=iso-8859-1\n")
5757
print(json_output)
5858

59-
60-
cumulative_mode = False
61-
heap_primitives = False
59+
raw_input_json = None
60+
options_json = None
6261

6362
# If you pass in a filename as an argument, then process script from that file ...
6463
if len(sys.argv) > 1:
@@ -67,19 +66,13 @@ def cgi_finalizer(input_code, output_trace):
6766
# Otherwise act like a CGI script with parameters:
6867
# user_script
6968
# raw_input_json
70-
# cumulative_mode
71-
# heap_primitives
69+
# options_json
7270
else:
7371
form = cgi.FieldStorage()
7472
user_script = form['user_script'].value
75-
raw_input_json = ''
7673
if 'raw_input_json' in form:
7774
raw_input_json = form['raw_input_json'].value
78-
if 'cumulative_mode' in form:
79-
# convert from string to a Python boolean ...
80-
cumulative_mode = (form['cumulative_mode'].value == 'true')
81-
if 'heap_primitives' in form:
82-
heap_primitives = (form['heap_primitives'].value == 'true')
83-
75+
if 'options_json' in form:
76+
options_json = form['options_json'].value
8477

85-
pg_logger.exec_script_str(user_script, raw_input_json, cumulative_mode, heap_primitives, cgi_finalizer)
78+
pg_logger.exec_script_str(user_script, raw_input_json, options_json, cgi_finalizer)

0 commit comments

Comments
 (0)