Skip to content
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

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

Mingun
Copy link
Member

@Mingun Mingun commented May 27, 2021

Also this change add additional safety checks to the code generator and improves errors if they was violated

@hildjj hildjj added this to the 1.2 milestone May 28, 2021
@hildjj hildjj mentioned this pull request May 28, 2021
3 tasks
Copy link
Contributor

@hildjj hildjj left a 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 + ";";
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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) {
Copy link
Contributor

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".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

);
});
});
});
Copy link
Contributor

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
@Mingun
Copy link
Member Author

Mingun commented Jun 2, 2021

I've added missing documentation for Stack and fix some spelling errors (and hopefully did not introduce new).

@hildjj hildjj merged commit 5108729 into peggyjs:main Jun 2, 2021
@Mingun Mingun deleted the stack branch June 2, 2021 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants