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

Pre-parsed stdlib #100

Closed
sbarzowski opened this issue Oct 2, 2017 · 4 comments
Closed

Pre-parsed stdlib #100

sbarzowski opened this issue Oct 2, 2017 · 4 comments

Comments

@sbarzowski
Copy link
Collaborator

@mqliang wrote in #89:

It would be very interesting if we can dump ast as go source files, then we can dump ast of stdlib as go source code, and embed it into vm, thus avoid parsing stdlib every time. Any idea?

I think we should look into it. It sound quite easy.

@sbarzowski sbarzowski mentioned this issue Oct 2, 2017
@mqliang
Copy link
Contributor

mqliang commented Oct 2, 2017

I tried to dump ast using go-spew (https://github.com/davecgh/go-spew), it's practicable: about 7w line source code is generated.

The problem is: we need fork go-spew and modify its source code to make the generated files meet go's syntax.

@sbarzowski
Copy link
Collaborator Author

sbarzowski commented Oct 2, 2017

My feeling is that the easiest and most maintainable way would be to do it by hand (without go-spew), i.e. have a function that does a type switch over ast nodes and formats each of them into a go source code representation. There are just ~30 AST node types IIRC. This will give us full control over the output and let us specially handle location information, aliased nodes and other complex cases. I think that with some helper functions the boilerplate could be minimal.

@mqliang
Copy link
Contributor

mqliang commented Oct 2, 2017

utter(github.com/kortschak/utter) works. See experiment: #101

The only problem is: we need make ALL fields of AST node as public, then the dumped source code can be put in any package. Otherwise, we must put the source code in the "ast" package.

@mqliang
Copy link
Contributor

mqliang commented Oct 3, 2017

#82 will also benefit from this.

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

No branches or pull requests

3 participants