Skip to content

Commit

Permalink
feat: Implement Scheme tree debug + autodraw functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularya50 committed Jul 3, 2019
1 parent 236abbf commit 07cd3e8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/languages/python/utils/debugPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default `# these lines stub out the debugging functions you have available
def draw(something): pass
def autodraw(): pass
def disableAutodraw(): pass
def visualize(): pass
def editor(): pass
# your code is below
`;
1 change: 1 addition & 0 deletions src/languages/scheme/utils/debugPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "";
22 changes: 15 additions & 7 deletions src/languages/scheme/web/brython_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
_launchtext = """CS61A Scheme Web Interpreter
--------------------------------------------------------------------------------
Welcome to the 61A Scheme web interpreter!
Source for this interpreter is restricted.
The source for this interpreter is restricted, but you'll build it yourself as your Scheme Project!
[in the future] To visualize a list, call (draw <list>).
[in the future] To draw list visualizations automatically, call (autodraw).
[in the future] To view an environment diagram of your entire program, call (visualize).
To visualize a list, call (draw <list>).
To draw list visualizations automatically, call (autodraw).
To view an environment diagram of your entire program, call (visualize).
To launch an editor associated with your console, call (editor).
"""

Expand Down Expand Up @@ -44,9 +44,15 @@ def exit(data):
firstLine = True


@builtin("editor")
def editor():
print("EDITOR: ")
def record_exec(code, wrap):
if wrap:
out = "(ignore-error\n"
for line in code.split("\n"):
out += " " + line + "\n"
out += ")\n"
record_exec(out, False)
else:
print("EXEC: " + code)


frame = create_global_frame()
Expand Down Expand Up @@ -94,8 +100,10 @@ def run_expr(expr):
ret = scheme_eval(expr, frame)
if ret is not None:
print(ret)
record_exec(str(expr), False)
except Exception as err:
handle_error(frame)
record_exec(str(expr), True)
if isinstance(err, RuntimeError):
print('Error: maximum recursion depth exceeded')
else:
Expand Down
8 changes: 4 additions & 4 deletions src/languages/scheme/web/communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { err, exit, sendAndExit } from "../../../web/webBackend.js";
import { interactProcess } from "../../../main/processes.js";

// import webConsole from "./web_console.py";
import interpreter from "./IGNORE_needed.py";
// import transpiledInterpreter from "!!raw-loader!./IGNORE_scheme_transpiled.js";
// import interpreter from "./IGNORE_needed.py";
import transpiledInterpreter from "!!raw-loader!./IGNORE_scheme_transpiled.js";
import runPyScript from "../../../web/runPython.js";

export default async function receive(arg) {
Expand All @@ -29,7 +29,7 @@ export default async function receive(arg) {
}

async function runScmCode(key, code) {
await runPyScript(key, interpreter, []);
// await runPyScript(key, transpiledInterpreter, { transpiled: true });
// await runPyScript(key, interpreter, []);
await runPyScript(key, transpiledInterpreter, { transpiled: true });
interactProcess(key, code);
}
12 changes: 2 additions & 10 deletions src/renderer/components/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { send, sendNoInteract } from "../utils/communication.js";
import { SAVE_FILE, SHOW_ERROR_DIALOG, SHOW_SAVE_DIALOG } from "../../common/communicationEnums.js";
import { PYTHON, SCHEME, SQL } from "../../common/languages.js";
import {
Debugger,
Debugger, debugPrefix,
format, generateDebugTrace, runCode, runFile,
} from "../utils/dispatch.js";

Expand Down Expand Up @@ -125,16 +125,8 @@ export default class File extends React.Component {
}
};

// TODO: Make language agnostic! Probably move to lang/web folder at some point
debugExecutedCode = async () => {
// language=Python
const TEMPLATE_CODE = "# these lines stub out the debugging functions you have available\n"
+ "def draw(something): pass\n"
+ "def autodraw(): pass\n"
+ "def disableAutodraw(): pass\n"
+ "def visualize(): pass\n"
+ "def editor(): pass\n\n"
+ "# your code is below\n";
const TEMPLATE_CODE = debugPrefix(this.identifyLanguage());
const code = TEMPLATE_CODE + this.state.executedCode.join("\n");
const debugData = await generateDebugTrace(this.identifyLanguage())(code);
if (debugData.success) {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/utils/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { runPyCode, runPyFile } from "../../languages/python/utils/run.js";
import { runScmCode, runScmFile } from "../../languages/scheme/utils/run.js";
import SchemeDebugger from "../../languages/scheme/components/SchemeDebugger.js";
import PythonTutorDebug from "../../languages/python/components/PythonTutorDebug.js";
import pyDebugPrefix from "../../languages/python/utils/debugPrefix.js";
import scmDebugPrefix from "../../languages/scheme/utils/debugPrefix.js";

export function format(language) {
const options = {
Expand Down Expand Up @@ -47,3 +49,11 @@ export function Debugger(language) {
};
return options[language];
}

export function debugPrefix(language) {
const options = {
[PYTHON]: pyDebugPrefix,
[SCHEME]: scmDebugPrefix,
};
return options[language];
}

0 comments on commit 07cd3e8

Please sign in to comment.