Skip to content

Commit a0dc7a0

Browse files
committed
started adding additional langs to opt-live
1 parent f97e19f commit a0dc7a0

3 files changed

Lines changed: 102 additions & 5 deletions

File tree

‎v3/bottle_server.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
import urllib
2020
import urllib2
2121

22+
# dummy routes for testing only
23+
@route('/web_exec_<name:re:.+>.py')
24+
def web_exec(name):
25+
return 'OK'
26+
27+
@route('/web_exec_LIVE_<name:re:.+>.py')
28+
def web_exec_live(name):
29+
return 'OK'
30+
2231

2332
@route('/<filepath:path>')
2433
def index(filepath):

‎v3/js/opt-live.js‎

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4242
- make Ace editor resizable width-wise using jQuery resizable
4343
(stackoverflow has some tips for how to do that)
4444
45-
- add toggles for language choices
46-
4745
- support pasting in code via URL, which will be important for
4846
transporting the user from regular OPT to live mode
4947
5048
- make sure server logging works properly, esp. session and user IDs,
5149
and slider interactions
5250
- have separate web_exec_live executor scripts for logging live mode
5351
52+
- add "Generate permanent link" button, but no need for iframe embed btn
53+
5454
- if these Ace enhancements look good, then I can also use them for
5555
Codeopticon as well!
5656
@@ -59,13 +59,44 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5959
6060
*/
6161

62+
6263
// Pre-reqs:
6364
// - pytutor.js
6465
// - jquery.ba-bbq.min.js
6566
// - jquery.ba-dotimeout.min.js // for event debouncing: http://benalman.com/code/projects/jquery-dotimeout/examples/debouncing/
6667
// - opt-frontend-common.js
6768
// should all be imported BEFORE this file
6869

70+
71+
// these scripts override the versions defined in opt-frontend-common.js
72+
73+
// backend scripts to execute (Python 2 and 3 variants, if available)
74+
// make two copies of ../web_exec.py and give them the following names,
75+
// then change the first line (starting with #!) to the proper version
76+
// of the Python interpreter (i.e., Python 2 or Python 3).
77+
// Note that your hosting provider might have stringent rules for what
78+
// kind of scripts are allowed to execute. For instance, my provider
79+
// (Webfaction) seems to let scripts execute only if permissions are
80+
// something like:
81+
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
82+
// (most notably, only the owner of the file should have write
83+
// permissions)
84+
//var python2_backend_script = 'web_exec_LIVE_py2.py';
85+
//var python3_backend_script = 'web_exec_LIVE_py3.py';
86+
87+
// uncomment below if you're running on Google App Engine using the built-in app.yaml
88+
var python2_backend_script = 'exec';
89+
var python3_backend_script = 'exec';
90+
91+
// empty dummy just to do logging on the Apache's server
92+
var js_backend_script = 'web_exec_LIVE_js.py';
93+
var ts_backend_script = 'web_exec_LIVE_ts.py';
94+
var java_backend_script = 'web_exec_LIVE_java.py';
95+
var ruby_backend_script = 'web_exec_LIVE_ruby.py';
96+
var c_backend_script = 'web_exec_LIVE_c.py';
97+
var cpp_backend_script = 'web_exec_LIVE_cpp.py';
98+
99+
69100
var originFrontendJsFile = 'opt-live.js';
70101

71102
var prevVisualizer = null; // the visualizer object from the previous execution
@@ -328,10 +359,32 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
328359
clearFrontendError();
329360
startExecutingCode();
330361

362+
jsonp_endpoint = null;
363+
364+
// hacky!
331365
if (backendScript === python2_backend_script) {
332366
frontendOptionsObj.lang = 'py2';
333367
} else if (backendScript === python3_backend_script) {
334368
frontendOptionsObj.lang = 'py3';
369+
} else if (backendScript === js_backend_script) {
370+
frontendOptionsObj.lang = 'js';
371+
jsonp_endpoint = JS_JSONP_ENDPOINT;
372+
} else if (backendScript === ts_backend_script) {
373+
frontendOptionsObj.lang = 'ts';
374+
jsonp_endpoint = TS_JSONP_ENDPOINT;
375+
} else if (backendScript === ruby_backend_script) {
376+
frontendOptionsObj.lang = 'ruby';
377+
jsonp_endpoint = RUBY_JSONP_ENDPOINT;
378+
} else if (backendScript === java_backend_script) {
379+
frontendOptionsObj.lang = 'java';
380+
frontendOptionsObj.disableHeapNesting = true; // never nest Java objects, seems like a good default
381+
jsonp_endpoint = JAVA_JSONP_ENDPOINT;
382+
} else if (backendScript === c_backend_script) {
383+
frontendOptionsObj.lang = 'c';
384+
jsonp_endpoint = C_JSONP_ENDPOINT;
385+
} else if (backendScript === cpp_backend_script) {
386+
frontendOptionsObj.lang = 'cpp';
387+
jsonp_endpoint = CPP_JSONP_ENDPOINT;
335388
} else {
336389
assert(false);
337390
}
@@ -350,7 +403,7 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
350403
rawInputLst = forceRawInputLst; // UGLY global across modules, FIXME
351404
}
352405

353-
backend_script = python2_backend_script;
406+
var backend_script = langToBackendScript($('#pythonVersionSelector').val());
354407

355408
var backendOptionsObj = {cumulative_mode: false,
356409
heap_primitives: false,
@@ -374,6 +427,12 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
374427
}
375428

376429
$(document).ready(function() {
377-
genericOptFrontendReady(); // initialize at the very end
430+
genericOptFrontendReady();
431+
432+
$('#pythonVersionSelector').change(function() {
433+
// force a recompile on a toggle switch
434+
executeCode();
435+
});
436+
378437
$("#pyOutputPane").show();
379438
});

‎v3/opt-live.html‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,36 @@
6363
<tr>
6464
<td valign="top">
6565
<div id="pyInputPane">
66-
<div id="codeInputWarnings">Write Python code here:</div>
66+
<div id="codeInputWarnings">Write code in
67+
<select id="pythonVersionSelector">
68+
<option value="2">Python 2.7</option>
69+
<option value="3">Python 3.3</option>
70+
<option value="java">Java 7</option>
71+
<option value="js">JavaScript ES6</option>
72+
<option value="ts">TypeScript 1.4</option>
73+
<option value="ruby">Ruby 2.2</option>
74+
<option value="c">C (gcc 4.8, C11) EXPERIMENTAL</option>
75+
<option value="cpp">C++ (gcc 4.8, C++11) EXPERIMENTAL</option>
76+
</select>
77+
</div>
78+
79+
<!-- keep this here but hide so that opt-frontend-common.js stuff works -->
80+
<div id="optionsPane" style="margin-top: 18px; line-height: 150%; display: none;">
81+
<select id="cumulativeModeSelector">
82+
<option value="false">hide exited frames [default]</option>
83+
<option value="true">show exited frames (Python)</option>
84+
<!-- <option value="holistic">holistic mode (experimental)</option> -->
85+
</select>
86+
<select id="heapPrimitivesSelector">
87+
<option value="false">inline primitives &amp; nested objects [default]</option>
88+
<option value="true">render all objects on the heap</option>
89+
</select>
90+
<select id="textualMemoryLabelsSelector">
91+
<option value="false">draw pointers as arrows [default]</option>
92+
<option value="true">use text labels for pointers</option>
93+
</select>
94+
</div>
95+
6796
<div id="codeInputPane"></div>
6897
<div id="executionSlider" style="margin-top: 10px;"></div>
6998
<div id="curInstr"></div>

0 commit comments

Comments
 (0)