diff --git a/src/App.js b/src/App.js index 3c2b4b95f683ac49c4e13dcf36dc79e55949ca47..42b53e261c27f2860648e6c4b60348e3da75ab79 100644 --- a/src/App.js +++ b/src/App.js @@ -31,27 +31,30 @@ class App extends React.Component { name: "", attributes: {value: ""}, highlighting: { - wacc: [{ + wacc: [{ startRow: 0, startCol: 0, endRow: 0, endCol: 0, className: "", - type: ""}], - js: [{ + type: "" + }], + js: [{ startRow: 0, startCol: 0, endRow: 0, endCol: 0, className: "", - type: ""}], - arm: [{ + type: "" + }], + arm: [{ startRow: 0, startCol: 0, endRow: 0, endCol: 0, className: "", - type: ""}] + type: "" + }] }, children: [{}] } @@ -68,15 +71,15 @@ class App extends React.Component { } onNodeOver = (nodeData, evt) => { - let hl = nodeData.highlighting; + let hl = nodeData.highlighting; - this.setState((state, props) => { - state.wacc.markers = hl.wacc; - state.js.markers = hl.js; - state.arm.markers = hl.arm; + this.setState((state, props) => { + state.wacc.markers = hl.wacc; + state.js.markers = hl.js; + state.arm.markers = hl.arm; - return state - }) + return state + }) } onNodeOut = (nodeData, evt) => { @@ -84,7 +87,9 @@ class App extends React.Component { readInputCallBack = (codeToEval) => { eval(codeToEval); - window.EMULATOR_CONSOLE_READ = () => { return window.prompt()}; + window.EMULATOR_CONSOLE_READ = () => { + return window.prompt() + }; }; clearConsole = () => { @@ -110,31 +115,37 @@ class App extends React.Component { }; proccesLine = () => { - if(this.state.statementIndex < this.state.mainStatements.length){ + if (this.state.statementIndex < this.state.mainStatements.length) { let current = this.state.currentNode; let jsLines = this.state.js.code.split(/;\n(?!})/); // console.log(jsLines) // console.log(current) let codeLine = jsLines[current.highlighting.js[0].startRow]; codeLine = codeLine.replace("var ", "window."); - eval(codeLine);; + eval(codeLine); + ; let newIndex = this.state.statementIndex + 1; this.setState({ currentNode: this.state.mainStatements[newIndex], - statementIndex: newIndex}) + statementIndex: newIndex + }) } else { console.log("Finished executing code") } }; getStatements = () => { - let rootChildren = this.state.graphData.children; - let funcMain = rootChildren[rootChildren.length - 1]; - let mainFuncStatementsNode = funcMain.children[0]; - let mainFuncStatements = mainFuncStatementsNode.children; - this.setState({mainStatements: mainFuncStatements, - currentNode: mainFuncStatements[0], - statementIndex: 0}) + if (typeof this.state.graphData.children !== "undefined") { + let rootChildren = this.state.graphData.children; + let funcMain = rootChildren[rootChildren.length - 1]; + let mainFuncStatementsNode = funcMain.children[0]; + let mainFuncStatements = mainFuncStatementsNode.children; + this.setState({ + mainStatements: mainFuncStatements, + currentNode: mainFuncStatements[0], + statementIndex: 0 + }) + } }; render() { @@ -148,93 +159,98 @@ class App extends React.Component { { this.processWaccCode(this.state.wacc.code).then(() => { - this.clearConsole() - this.getStatements()}) + if (typeof this.state.graphData.children !== "undefined") { + this.clearConsole() + this.getStatements() + } + } + ) }} onExecuteClick={(e) => { eval(this.state.js.code) eval("waccPrintFinished()") }} onStepWaccClick={(e) => { - this.readInputCallBack(e) + this.proccesLine() }} - /> - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ -
-
-
-
- - - -
+ + + + + + +
- { + }} + > + { window.EMULATOR_CONSOLE_READ = () => {return cmd[0]}; window.EMULATOR_IS_INPUT = true; - }} watchConsoleLogging hideTopBar allowTabs={false} key={this.state.consoleReset}/> -
-
-
-
- - -
-
- ) - } -} + }} watchConsoleLogging hideTopBar allowTabs={false} key={this.state.consoleReset}/> + +
+
+
+ + + + + ) + } + } -export default App; + export default App;