Skip to content

Commit

Permalink
Tifa improvements, properties=>variables, engine only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Jan 10, 2018
1 parent 37e5895 commit 813eff9
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 57 deletions.
190 changes: 190 additions & 0 deletions engine_test.html
@@ -0,0 +1,190 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Blockpy/Kennel/Silicon</title>

<link rel="stylesheet" href="libs/bootstrap.min.css">
<link rel="stylesheet" href="libs/codemirror/codemirror.css">
<link rel="stylesheet" href="libs/font-awesome.min.css">
<link rel="stylesheet" href="libs/summernote/summernote.css">
<link rel="stylesheet" href="libs/multi-select.css">
<link rel="stylesheet" href="src/blockpy.css">
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">-->

<!-- JQuery, D3, Math.js, Bootstrap -->
<script type="text/javascript" src="libs/jquery.js"></script>
<script type="text/javascript" src="libs/jquery-ui.min.js"></script>
<script type="text/javascript" src="libs/jquery.hotkeys.js"></script>
<script type="text/javascript" src="libs/jquery.multi-select.js"></script>
<script type="text/javascript" src="libs/d3.min.js"></script>
<script type="text/javascript" src="libs/math.0.19.0.min.js"></script>
<script type="text/javascript" src="libs/bootstrap.min.js"></script>
<script type="text/javascript" src="libs/bootstrap-wysiwyg.js"></script>
<script type="text/javascript" src="libs/mindmup-editabletable.js"></script>
<script type="text/javascript" src="libs/codemirror/codemirror.js"></script>
<script type="text/javascript" src="libs/codemirror/python.js"></script>
<script type="text/javascript" src="libs/codemirror/htmlmixed.js"></script>
<script type="text/javascript" src="libs/codemirror/xml.js"></script>
<script type="text/javascript" src="libs/knockout-3.4.0.js"></script>
<script type="text/javascript" src="libs/stringify.js"></script>

<!-- Summernote, a rich text editor -->
<script type="text/javascript" src="libs/summernote/summernote.min.js"></script>
<script type="text/javascript" src="libs/summernote/summernote-ext-hint.js"></script>
<script type="text/javascript" src="libs/summernote/summernote-ext-video.js"></script>

<!-- Skulpt -->
<script type="text/javascript" src="skulpt/dist/skulpt.min.js"></script>
<script type="text/javascript" src="skulpt/dist/skulpt-stdlib.js"></script>

<!-- Source Code -->
<script type="text/javascript" src="src/utilities.js"></script>
<script type="text/javascript" src="src/python_errors.js"></script>
<script type="text/javascript" src="src/ast_node_visitor.js"></script>
<script type="text/javascript" src="src/abstract_interpreter.js"></script>
<script type="text/javascript" src="src/pytifa.js"></script>
<script type="text/javascript" src="src/abstract_interpreter_definitions.js"></script>
<script type="text/javascript" src="src/abstract_interpreter_tests.js"></script>
<script type="text/javascript" src="src/dialog.js"></script>
<script type="text/javascript" src="src/storage.js"></script>
<script type="text/javascript" src="src/printer.js"></script>
<script type="text/javascript" src="src/server.js"></script>
<script type="text/javascript" src="src/corgis.js"></script>
<script type="text/javascript" src="src/feedback.js"></script>
<script type="text/javascript" src="src/sk_mod_instructor_extended.js"></script>
<script type="text/javascript" src="src/sk_mod_instructor.js"></script>
<script type="text/javascript" src="src/engine.js"></script>

<!-- CORGIS -->
<!--<script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_dataset.js"></script>
<script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_blockly.js"></script>
<script type="text/javascript" src="test_corgis/blockpy/school_scores/school_scores_skulpt.js"></script>-->

<!--<script type="text/javascript" src="test_corgis/blockpy/tate/tate_blockly.js"></script>
<script type="text/javascript" src="test_corgis/blockpy/tate/tate_skulpt.js"></script>
<script type="text/javascript" src="test_corgis/blockpy/tate/tate_dataset.js"></script>-->

<style>

</style>

<script>
$(document).ready(function() {
var trace = function() {

};
trace.removeAll = x => x;
mockFeedback = {
'isFeedbackVisible': x => true,
'clear': x => x,
//'presentFeedback': x => blockpy.BlockPyFeedback.prototype.presentFeedback.bind(mockFeedback)(x),
'presentFeedback': x => x, //console.log(Sk.executionReports.instructor.complaint),
'presentAnalyzerFeedback': x => BlockPyFeedback.prototype.presentAnalyzerFeedback.bind(mockFeedback)(x),
'instructorFeedback': (name, message, line) => name, //console.log(name, message, line),
}
main = {
'components': {
'printer': {
'print': e => this.printed.push(e.slice(0, -1)), //console.log("PRINTED", e),
'printHtml': e => this.printed.push(e),
'resetPrinter': e => this.printed = [], //console.log("PRINTER RESET"),
'getConfiguration': BlockPyPrinter.getDisabledConfiguration,
},
'editor': {
'triggerOnChange': 0
},
'server': {
'logEvent': x => x,
'markSuccess': x => x,
},
'feedback': mockFeedback,
'toolbar': {

}
},
'model': {
'execution': {
'reports': {},
'suppressions': {},
'status': v => this['status'] = v,
'trace': trace,
'step': x => x,
'last_step': x => x,
'line_number': x => x,
'show_trace': x => x,
'output': v => this.printed
},
'programs': {
'__main__': v => 'a = "Words"\nprint(a)',
'give_feedback': v => 'from instructor import *\ngently("You have failed.")\ngently("Not bad!")',
},
'settings': {
'disable_timeout': x => false,
'mute_printer': x => this['mute_printer'] = x,
}
}
};
main.components.feedback.main = main;
engine = new BlockPyEngine(main);
Sk.afterSingleExecution = engine.step.bind(engine);


function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if (inIframe()) {
$("#blockpy-container").width("100%");
}
});
</script>

</head>
<body>
<div style="width:900px; margin:0 auto;" id='blockpy-container'> <!-- 900px -->
<div id="blockpy-div" style='height:100%'></div>
</div>
<div id="blockpy-div2" style='height:100%'></div>
<script>

function getQueryParams(){
try{
url = window.location.href;
query_str = url.substr(url.indexOf('?')+1, url.length-1);
r_params = query_str.split('&');
params = {}
for( i in r_params){
param = r_params[i].split('=');
params[ param[0] ] = param[1];
}
return params;
}
catch(e){
return {};
}
}
</script>


<!-- Google Analytics -->
<script>
switch(window.location.protocol) {
case 'file:':
break;
default:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-38802329-2', 'auto');
ga('send', 'pageview');
}
</script>

</body>
</html>
6 changes: 3 additions & 3 deletions server.js
Expand Up @@ -103,8 +103,8 @@ console.log(AbstractInterpreter.MODULES)
// Actual work
final_result = []
loadJsonFile('data_analysis/f17_ct_solutions.json').then(assignment_solutions => {
loadJsonFile('data_analysis/f17_ct_8-5_run_submission.json').then(data => {
subs = data.submissions;
loadJsonFile('data_analysis/f17_ct_8-5_change_steps.json').then(data => {
subs = data.steps;
var next = function(subi, stui) {
processSub(subs[subi][stui], function() {
stui += 1;
Expand All @@ -115,7 +115,7 @@ loadJsonFile('data_analysis/f17_ct_solutions.json').then(assignment_solutions =>
if (subi < subs.length) {
next(subi, stui);
} else {
fs.writeFile('./data_analysis/f17_ct_processed_new_8-5.json',
fs.writeFile('./data_analysis/f17_ct_stepped_new_8-5.json',
JSON.stringify(final_result),
{'spaces':2},
function (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/abstract_interpreter_tests.js
Expand Up @@ -161,13 +161,13 @@
}
for (var j = 0, len2 = nones.length; j < len2; j=j+1) {
if (analyzer.report.issues[nones[j]].length > 0) {
console.error("AI Tests: Incorrectly detected "+nones[j], "\n"+source);
console.error("AI Tests: Incorrectly detected "+nones[j], "\n"+source, "\n", analyzer.report);
errors += 1;
}
}
for (var k = 0, len2 = somes.length; k < len2; k=k+1) {
if (analyzer.report.issues[somes[k]].length == 0) {
console.error("AI Tests: Failed to detect "+somes[k], "\n"+source);
console.error("AI Tests: Failed to detect "+somes[k], "\n"+source, "\n", analyzer.report);
errors += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine.js
Expand Up @@ -507,7 +507,7 @@ BlockPyEngine.prototype.runInstructorCode = function(filename, after) {
' return None\n'+
instructorCode
);
console.log(lineOffset, instructorCode.split(NEW_LINE_REGEX).length, instructorCode);
//console.log(lineOffset, instructorCode.split(NEW_LINE_REGEX).length, instructorCode);
lineOffset = instructorCode.split(NEW_LINE_REGEX).length - lineOffset;
var engine = this;
report['instructor'] = {
Expand Down
14 changes: 7 additions & 7 deletions src/feedback.js
Expand Up @@ -456,31 +456,31 @@ BlockPyFeedback.prototype.presentAnalyzerFeedback = function() {
return true;
} else if (!suppress['Iteration variable is iteration list'] && report['Iteration variable is iteration list'].length >= 1) {
var variable = report['Iteration variable is iteration list'][0];
this.semanticError("Iteration Problem", "The property <code>"+variable.name+"</code> was iterated on line "+variable.position.line+", but you used the same variable as the iteration variable. You should choose a different variable name for the iteration variable. Usually, the iteration variable is the singular form of the iteration list (e.g., <code>for dog in dogs:</code>).", variable.position.line)
this.semanticError("Iteration Problem", "The variable <code>"+variable.name+"</code> was iterated on line "+variable.position.line+", but you used the same variable as the iteration variable. You should choose a different variable name for the iteration variable. Usually, the iteration variable is the singular form of the iteration list (e.g., <code>for dog in dogs:</code>).", variable.position.line)
return true;
} else if (!suppress["Undefined variables"] && report["Undefined variables"].length >= 1) {
var variable = report["Undefined variables"][0];
this.semanticError("Initialization Problem", "The property <code>"+variable.name+"</code> was used on line "+variable.position.line+", but it was not given a value on a previous line. You cannot use a property until it has been given a value.", variable.position.line)
this.semanticError("Initialization Problem", "The variable <code>"+variable.name+"</code> was used on line "+variable.position.line+", but it was not given a value on a previous line. You cannot use a variable until it has been given a value.", variable.position.line)
return true;
} else if (!suppress["Possibly undefined variables"] && report["Possibly undefined variables"].length >= 1) {
var variable = report["Possibly undefined variables"][0];
this.semanticError("Initialization Problem", "The property <code>"+variable.name+"</code> was used on line "+variable.position.line+", but it was possibly not given a value on a previous line. You cannot use a property until it has been given a value. Check to make sure that this variable was declared in all of the branches of your decision.", variable.position.line);
this.semanticError("Initialization Problem", "The variable <code>"+variable.name+"</code> was used on line "+variable.position.line+", but it was possibly not given a value on a previous line. You cannot use a variable until it has been given a value. Check to make sure that this variable was declared in all of the branches of your decision.", variable.position.line);
return true;
} else if (!suppress["Unread variables"] && report["Unread variables"].length >= 1) {
var variable = report["Unread variables"][0];
this.semanticError("Unused Property", "The property <code>"+variable.name+"</code> was given a value, but was never used after that.", null)
this.semanticError("Unused Variable", "The variable <code>"+variable.name+"</code> was given a value, but was never used after that.", null)
return true;
} else if (!suppress["Overwritten variables"] && report["Overwritten variables"].length >= 1) {
var variable = report["Overwritten variables"][0];
this.semanticError("Overwritten Property", "The property <code>"+variable.name+"</code> was given a value, but <code>"+variable.name+"</code> was changed on line "+variable.position.line+" before it was used. One of the times that you gave <code>"+variable.name+"</code> a value was incorrect.", variable.position.line)
this.semanticError("Overwritten Variable", "The variable <code>"+variable.name+"</code> was given a value, but <code>"+variable.name+"</code> was changed on line "+variable.position.line+" before it was used. One of the times that you gave <code>"+variable.name+"</code> a value was incorrect.", variable.position.line)
return true;
} else if (!suppress["Empty iterations"] && report["Empty iterations"].length >= 1) {
var variable = report["Empty iterations"][0];
this.semanticError("Iterating over empty list", "The property <code>"+variable.name+"</code> was set as an empty list, and then you attempted to use it in an iteration on "+variable.position.line+". You should only iterate over non-empty lists.", variable.position.line)
this.semanticError("Iterating over empty list", "The variable <code>"+variable.name+"</code> was set as an empty list, and then you attempted to use it in an iteration on "+variable.position.line+". You should only iterate over non-empty lists.", variable.position.line)
return true;
} else if (!suppress["Non-list iterations"] && report["Non-list iterations"].length >= 1) {
var variable = report["Non-list iterations"][0];
this.semanticError("Iterating over non-list", "The property <code>"+variable.name+"</code> is not a list, but you used it in the iteration on line "+variable.position.line+". You should only iterate over lists.", variable.position.line)
this.semanticError("Iterating over non-list", "The variable <code>"+variable.name+"</code> is not a list, but you used it in the iteration on line "+variable.position.line+". You should only iterate over lists.", variable.position.line)
return true;
} else if (!suppress["Incompatible types"] && report["Incompatible types"].length >= 1) {
var variable = report["Incompatible types"][0];
Expand Down
4 changes: 2 additions & 2 deletions src/instructor/instructor_printing.py
Expand Up @@ -4,7 +4,7 @@
def ensure_prints(count):
prints = find_function_calls('print')
if not prints:
gently("You are not using the print command!")
gently("You are not using the print function!")
return False
elif len(prints) > count:
gently("You are printing too many times!")
Expand All @@ -15,6 +15,6 @@ def ensure_prints(count):
else:
for a_print in prints:
if not is_top_level(a_print):
gently("You have a print statement that is not at the top level. That is incorrect!")
gently("You have a print function that is not at the top level. That is incorrect for this problem!")
return False
return prints

0 comments on commit 813eff9

Please sign in to comment.