-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some JSInterpreter code cleanup #15744
Conversation
pcardune
commented
Jun 9, 2017
- Moved JSInterpreter to lib/tools/jsinterpreter/JSInterpreter.js where it belongs
- Switch everything to es6 class syntax
- Removed use of unnecessary bind calls in favor of arrow functions
- Remove direct access to interpreter stack, putting everything behind accessor functions instead
- Replace var with const and let throughout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, much cleaner! I caught a couple of lint issues and one possible refactoring error.
@@ -92,8 +93,11 @@ export function evalWithEvents(apis, events, evalCode = '') { | |||
// to call, and any arguments. | |||
const eventLoop = ';while(true){var event=wait();setReturnValue(this[event.name].apply(null,event.args));}'; | |||
|
|||
interpreter = new Interpreter( | |||
// TODO (pcardune): remove circular dependency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When will this TODO be addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to move codegen
to lib/tools/jsinterpreter
. At that point, I will probably move a number of these functions onto CustomMarshalingInterpreter and kill off the circular deps.
apps/src/turtle/turtle.js
Outdated
this.level[prop] === undefined || | ||
this.level[prop] === group.defaultValues[prop]))) { | ||
this.level[prop] === undefined || | ||
this.level[prop] === group.defaultValues[prop]))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whitespace change looks like a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. I blame my editor which does auto-indenting.
* @return {boolean} true if program is complete (or an error has occurred). | ||
*/ | ||
isProgramDone() { | ||
const topStackFrame = this.interpreter.peekStackFrame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible null reference: Should probably pull the this.interpreter
null check in the expression below up into this assignment.
this.yield(); | ||
} | ||
return retVal; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
"slider to its maximum value)"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting. eslint doesn't seem to catch this.
|
||
if (this.paused) { | ||
// Store the first call expression stack depth seen while in this step operation: | ||
if (inUserCode && this.interpreter.peekStackFrame().node.type === "CallExpression") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think extracting inUserCallExpression
(here and eight lines above) makes sense.
bd16816
to
60acb47
Compare
Ok, pushed a new version without the unintentional indentation changes. |
} | ||
const topStackFrame = this.interpreter.peekStackFrame(); | ||
return this.executionError || | ||
!this.interpreter || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This guard is now redundant.