-
Notifications
You must be signed in to change notification settings - Fork 66
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
Extract the variable stack to a separate file and test it #157
Conversation
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 think this is close; it just needs a decision about how js-specific stack.js should be.
* @return {string} Assignment code | ||
*/ | ||
push(exprCode) { | ||
const code = this.name(++this.sp) + " = " + exprCode + ";"; |
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.
Even though this is only used from generate-js at the moment, I was surprised to find JS code here. a) it makes it harder to see all of the JS code in one place b) it makes it harder to use this class for other languages later.
If you decide to do something about this, then this.type
may or may not still be needed in the class.
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.
Actually, this class can be used by almost any C-like code generator: C/C++/C#/JS/Java. I'm not consider it as a public API right now, although
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.
OK, that makes sense. Later, if we want to be able to generate languages like Python, we can deal with type
and semicolon being optional without breaking any code that relies on this interface.
"use strict"; | ||
|
||
class Stack { | ||
constructor(ruleName, varName, type) { |
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.
constructor docs. for example, it wasn't clear that "type" could be "let".
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.
Added
); | ||
}); | ||
}); | ||
}); |
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.
Nice tests!
Also this change add additional safety checks to the code generator and improves errors if they was violated
I've added missing documentation for |
Also this change add additional safety checks to the code generator and improves errors if they was violated