Commit c7a5d217 authored by Raghav Khanna's avatar Raghav Khanna
Browse files

Check for error before proccessing graph

parent c8a32334
...@@ -37,21 +37,24 @@ class App extends React.Component { ...@@ -37,21 +37,24 @@ class App extends React.Component {
endRow: 0, endRow: 0,
endCol: 0, endCol: 0,
className: "", className: "",
type: ""}], type: ""
}],
js: [{ js: [{
startRow: 0, startRow: 0,
startCol: 0, startCol: 0,
endRow: 0, endRow: 0,
endCol: 0, endCol: 0,
className: "", className: "",
type: ""}], type: ""
}],
arm: [{ arm: [{
startRow: 0, startRow: 0,
startCol: 0, startCol: 0,
endRow: 0, endRow: 0,
endCol: 0, endCol: 0,
className: "", className: "",
type: ""}] type: ""
}]
}, },
children: [{}] children: [{}]
} }
...@@ -84,7 +87,9 @@ class App extends React.Component { ...@@ -84,7 +87,9 @@ class App extends React.Component {
readInputCallBack = (codeToEval) => { readInputCallBack = (codeToEval) => {
eval(codeToEval); eval(codeToEval);
window.EMULATOR_CONSOLE_READ = () => { return window.prompt()}; window.EMULATOR_CONSOLE_READ = () => {
return window.prompt()
};
}; };
clearConsole = () => { clearConsole = () => {
...@@ -110,31 +115,37 @@ class App extends React.Component { ...@@ -110,31 +115,37 @@ class App extends React.Component {
}; };
proccesLine = () => { proccesLine = () => {
if(this.state.statementIndex < this.state.mainStatements.length){ if (this.state.statementIndex < this.state.mainStatements.length) {
let current = this.state.currentNode; let current = this.state.currentNode;
let jsLines = this.state.js.code.split(/;\n(?!})/); let jsLines = this.state.js.code.split(/;\n(?!})/);
// console.log(jsLines) // console.log(jsLines)
// console.log(current) // console.log(current)
let codeLine = jsLines[current.highlighting.js[0].startRow]; let codeLine = jsLines[current.highlighting.js[0].startRow];
codeLine = codeLine.replace("var ", "window."); codeLine = codeLine.replace("var ", "window.");
eval(codeLine);; eval(codeLine);
;
let newIndex = this.state.statementIndex + 1; let newIndex = this.state.statementIndex + 1;
this.setState({ this.setState({
currentNode: this.state.mainStatements[newIndex], currentNode: this.state.mainStatements[newIndex],
statementIndex: newIndex}) statementIndex: newIndex
})
} else { } else {
console.log("Finished executing code") console.log("Finished executing code")
} }
}; };
getStatements = () => { getStatements = () => {
if (typeof this.state.graphData.children !== "undefined") {
let rootChildren = this.state.graphData.children; let rootChildren = this.state.graphData.children;
let funcMain = rootChildren[rootChildren.length - 1]; let funcMain = rootChildren[rootChildren.length - 1];
let mainFuncStatementsNode = funcMain.children[0]; let mainFuncStatementsNode = funcMain.children[0];
let mainFuncStatements = mainFuncStatementsNode.children; let mainFuncStatements = mainFuncStatementsNode.children;
this.setState({mainStatements: mainFuncStatements, this.setState({
mainStatements: mainFuncStatements,
currentNode: mainFuncStatements[0], currentNode: mainFuncStatements[0],
statementIndex: 0}) statementIndex: 0
})
}
}; };
render() { render() {
...@@ -148,16 +159,21 @@ class App extends React.Component { ...@@ -148,16 +159,21 @@ class App extends React.Component {
<ButtonStrip <ButtonStrip
onCompileClick={(e) => { onCompileClick={(e) => {
this.processWaccCode(this.state.wacc.code).then(() => { this.processWaccCode(this.state.wacc.code).then(() => {
if (typeof this.state.graphData.children !== "undefined") {
this.clearConsole() this.clearConsole()
this.getStatements()}) this.getStatements()
}
}
)
}} }}
onExecuteClick={(e) => { onExecuteClick={(e) => {
eval(this.state.js.code) eval(this.state.js.code)
eval("waccPrintFinished()") eval("waccPrintFinished()")
}} }}
onStepWaccClick={(e) => { onStepWaccClick={(e) => {
this.readInputCallBack(e) this.proccesLine()
}} }}
/> />
</CardBody> </CardBody>
</Card> </Card>
...@@ -235,6 +251,6 @@ class App extends React.Component { ...@@ -235,6 +251,6 @@ class App extends React.Component {
</div> </div>
) )
} }
} }
export default App; export default App;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment