From 5722b0f9988afbb53cd58d70b2ffb56ff015952d Mon Sep 17 00:00:00 2001 From: Raghav Khanna Date: Fri, 13 Mar 2020 17:24:17 +0000 Subject: [PATCH] Implement a basic line by line executor --- src/App.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/App.js b/src/App.js index bd8e531..d982b5f 100644 --- a/src/App.js +++ b/src/App.js @@ -24,7 +24,37 @@ class App extends React.Component { js: {code: "", markers: [],}, arm: {code: "", markers: [],}, graphData: [{}], - consoleReset: 0 + consoleReset: 0, + mainStatements: [{}], + statementIndex: 0, + currentNode: { + name: "", + attributes: {value: ""}, + highlighting: { + wacc: [{ + startRow: 0, + startCol: 0, + endRow: 0, + endCol: 0, + className: "", + type: ""}], + js: [{ + startRow: 0, + startCol: 0, + endRow: 0, + endCol: 0, + className: "", + type: ""}], + arm: [{ + startRow: 0, + startCol: 0, + endRow: 0, + endCol: 0, + className: "", + type: ""}] + }, + children: [{}] + } } } @@ -75,7 +105,34 @@ class App extends React.Component { } - } + }; + proccesLine = () => { + 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);; + let newIndex = this.state.statementIndex + 1; + this.setState({ + currentNode: this.state.mainStatements[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}) + }; render() { return ( @@ -87,14 +144,16 @@ class App extends React.Component { { - this.processWaccCode(this.state.wacc.code) + this.processWaccCode(this.state.wacc.code).then(() => { this.clearConsole() + this.getStatements()}) }} - onStepJsClick={(e) => { - this.setState({js: {code: "Hello World!"}}) + onStepWaccClick={(e) => { + this.proccesLine() }} - onStepOverAstClick={(e) => { - this.readInputCallBack(e) + onExecuteClick={(e) => { + + // this.readInputCallBack(e) }} /> -- GitLab