Skip to content

Commit 999b529

Browse files
committed
prep for C/C++ cokapi backend merge
1 parent bb24594 commit 999b529

7 files changed

Lines changed: 97 additions & 1 deletion

File tree

‎v3/css/pytutor.css‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,61 @@ div.ExecutionVisualizer table.listTbl td.listElt {
290290
border-left: 1px solid #555555; /* must match td.listHeader border */
291291
}
292292

293+
294+
/* for C and C++ visualizations */
295+
296+
/* make this slightly more compact than listTbl since arrays can be
297+
rendered on the stack so we want to kinda conserve space */
298+
div.ExecutionVisualizer table.cArrayTbl {
299+
background-color: #ffffc6;
300+
padding-left: 0px;
301+
padding-top: 0px;
302+
padding-bottom: 0px;
303+
font-size: 8pt;
304+
color: #777;
305+
text-align: left;
306+
border: 0px solid black;
307+
border-spacing: 0px;
308+
}
309+
310+
div.ExecutionVisualizer table.cArrayTbl td.cArrayHeader {
311+
padding-left: 5px;
312+
padding-top: 0px;
313+
padding-bottom: 2px;
314+
font-size: 6pt;
315+
color: #777;
316+
text-align: left;
317+
border-bottom: 0px solid black; /* override whatever we're nested in */
318+
}
319+
320+
div.ExecutionVisualizer table.cArrayTbl td.cArrayElt {
321+
border-bottom: 1px solid #888;
322+
border-left: 1px solid #888;
323+
border-top: 0px solid black;
324+
color: black;
325+
326+
padding-top: 2px;
327+
padding-bottom: 4px;
328+
padding-left: 5px;
329+
padding-right: 4px;
330+
vertical-align: bottom;
331+
}
332+
333+
div.ExecutionVisualizer .cdataHeader {
334+
font-size: 6pt;
335+
color: #555;
336+
padding-bottom: 2px;
337+
}
338+
339+
div.ExecutionVisualizer .cdataElt {
340+
font-size: 10pt;
341+
}
342+
343+
div.ExecutionVisualizer .cdataUninit {
344+
color: #888;
345+
}
346+
347+
293348
div.ExecutionVisualizer table.tupleTbl td.tupleElt {
294349
border-left: 1px solid #555555; /* must match td.tupleHeader border */
295350
}

‎v3/js/ace/src-min-noconflict/mode-c_cpp.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎v3/js/opt-frontend-common.js‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var js_backend_script = 'web_exec_js.py';
5858
var ts_backend_script = 'web_exec_ts.py';
5959
var java_backend_script = 'web_exec_java.py';
6060
var ruby_backend_script = 'web_exec_ruby.py';
61+
var c_backend_script = 'web_exec_c.py';
62+
var cpp_backend_script = 'web_exec_cpp.py';
6163

6264
// this is customized to my own Linode server:
6365
// these are the REAL endpoints, accessed via jsonp. code is in ../../v4-cokapi/
@@ -67,11 +69,15 @@ if (window.location.protocol === 'https:') {
6769
var TS_JSONP_ENDPOINT = 'https://cokapi.com:8001/exec_ts_jsonp';
6870
var JAVA_JSONP_ENDPOINT = 'https://cokapi.com:8001/exec_java_jsonp';
6971
var RUBY_JSONP_ENDPOINT = 'https://cokapi.com:8001/exec_ruby_jsonp';
72+
var C_JSONP_ENDPOINT = 'https://cokapi.com:8001/exec_c_jsonp';
73+
var CPP_JSONP_ENDPOINT = 'https://cokapi.com:8001/exec_cpp_jsonp';
7074
} else {
7175
var JS_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_js_jsonp'; // for deployment
7276
var TS_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_ts_jsonp'; // for deployment
7377
var JAVA_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_java_jsonp'; // for deployment
7478
var RUBY_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_ruby_jsonp'; // for deployment
79+
var C_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_c_jsonp'; // for deployment
80+
var CPP_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_cpp_jsonp'; // for deployment
7581
}
7682

7783

@@ -91,6 +97,10 @@ function langToBackendScript(lang) {
9197
backend_script = ruby_backend_script;
9298
} else if (lang == 'java') {
9399
backend_script = java_backend_script;
100+
} else if (lang == 'c') {
101+
backend_script = c_backend_script;
102+
} else if (lang == 'cpp') {
103+
backend_script = cpp_backend_script;
94104
}
95105
assert(backend_script);
96106
return backend_script;
@@ -235,6 +245,12 @@ function setAceMode() {
235245
if (pyInputGetValue() === JAVA_BLANK_TEMPLATE) {
236246
pyInputSetValue('');
237247
}
248+
} else if (selectorVal === 'c' || selectorVal == 'cpp') {
249+
mod = 'c_cpp';
250+
// if it's just a Java skeleton, then reset to blank:
251+
if (pyInputGetValue() === JAVA_BLANK_TEMPLATE) {
252+
pyInputSetValue('');
253+
}
238254
} else {
239255
mod = 'python';
240256
tabSize = 4; // PEP8
@@ -1592,12 +1608,20 @@ function executeCodeAndCreateViz(codeToExec,
15921608
frontendOptionsObj.lang = 'java';
15931609
frontendOptionsObj.disableHeapNesting = true; // never nest Java objects, seems like a good default
15941610
jsonp_endpoint = JAVA_JSONP_ENDPOINT;
1611+
} else if (backendScript === c_backend_script) {
1612+
frontendOptionsObj.lang = 'c';
1613+
jsonp_endpoint = C_JSONP_ENDPOINT;
1614+
} else if (backendScript === cpp_backend_script) {
1615+
frontendOptionsObj.lang = 'cpp';
1616+
jsonp_endpoint = CPP_JSONP_ENDPOINT;
15951617
}
15961618

15971619
if (backendScript === js_backend_script ||
15981620
backendScript === ts_backend_script ||
15991621
backendScript === java_backend_script ||
1600-
backendScript === ruby_backend_script) {
1622+
backendScript === ruby_backend_script ||
1623+
backendScript === c_backend_script ||
1624+
backendScript === cpp_backend_script) {
16011625
// hack! should just be a dummy script for logging only
16021626
$.get(backendScript,
16031627
{user_script : codeToExec,

‎v3/js/opt-frontend.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ function experimentalPopUpSyntaxErrorSurvey() {
421421
mod = 'typescript';
422422
} else if (lang === 'ruby') {
423423
mod = 'ruby';
424+
} else if (lang === 'c' || lang === 'cpp') {
425+
mod = 'c_cpp';
424426
}
425427
s.setMode("ace/mode/" + mod);
426428

‎v3/visualize.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
<option value="js">JavaScript ES6</option>
206206
<option value="ts">TypeScript 1.4</option>
207207
<option value="ruby">Ruby 2.2</option>
208+
<option value="c">C (gcc 4.8, experimental)</option>
209+
<option value="cpp">C++ (g++ 4.8, experimental)</option>
208210
</select>
209211

210212
</div>

‎v3/web_exec_c.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/local/bin/python
2+
3+
# dummy NOP script just so Apache can log the request on the server
4+
5+
print("Content-type: text/plain; charset=iso-8859-1\n")
6+
print("OK");

‎v3/web_exec_cpp.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/local/bin/python
2+
3+
# dummy NOP script just so Apache can log the request on the server
4+
5+
print("Content-type: text/plain; charset=iso-8859-1\n")
6+
print("OK");

0 commit comments

Comments
 (0)