nand2tetris / web-ide

A web-based IDE for https://nand2tetris.org
https://nand2tetris.github.io/web-ide
Other
84 stars 22 forks source link

Feat/compiler #483

Open happytomatoe opened 1 month ago

happytomatoe commented 1 month ago

Improved Jack compiler. Underneath the covers it uses ANTLR List of improvements:

Cons:

Don't get scared because it says 13k LOC. Most of it are tests and test files. The src changes is around 1k LOC. This doesn't include the generated files.

You can check it out on https://happytomatoe.github.io/web-ide/compiler

TODO:

happytomatoe commented 1 month ago

@DavidSouther @netalondon Could you please take a look?

happytomatoe commented 1 month ago

Upd: I've added validate method to the compiler. Now after each keystroke time of execution is under 100ms for many big files.

happytomatoe commented 1 month ago

qq - why do we write VM files on disk?

happytomatoe commented 1 month ago

@DavidSouther @netalondon just FYI - I've created new repo for jack language server protocol, I would gladly contribute this to nand2tetris repo. About this PR - I would rather have extract compiler into its' own package because of the new repo

DavidSouther commented 1 month ago

Great work in here, I've been following your WIP as it goes.

We're happy to have the LSP in this repo, we just need to spend a bit thinking through where it will go, how to extend it to the other languages, and how to integrate it with the web, cli, and ide extensions.

Again, your use case as a "Jack developer" is relatively niche in the NAND2Tetris community. The vast bulk of work happens at the Hack level, and a little bit at the VM and assembly levels. Improvements to those will have the most impact for NAND2Tetris students.

So finding a migration path from the current state to your ANTLR based approach is a good project for quarter, if someone wanted to pick that up.

Are you ready for me to review this PR?

happytomatoe commented 1 month ago

@DavidSouther Please go ahead. There is a possibility that I can find some small bugs. I can create another PR, if you would like, to fix them.

happytomatoe commented 1 month ago

So finding a migration path from the current state to your ANTLR based approach is a good project for quarter, if someone wanted to pick that up.

@DavidSouther Can you create a new repo? I would provide the scaffolding along with the jack lsp implementation

DavidSouther commented 1 month ago

As you can see that 1 key stroke calls compiler 2 times on screenshot.

In dev, yes; in production, it should still only be called once. That said, we can probably make better use of effects to ensure it happens only once either way.

happytomatoe commented 1 month ago

So finding a migration path from the current state to your ANTLR based approach is a good project for quarter, if someone wanted to pick that up.

@DavidSouther Can you create a new repo? I would provide the scaffolding along with the jack lsp implementation

Nvm. I don't want to spend my time on that.

DavidSouther commented 1 month ago

So finding a migration path from the current state to your ANTLR based approach is a good project for quarter, if someone wanted to pick that up.

@DavidSouther Can you create a new repo? I would provide the scaffolding along with the jack lsp implementation

Nvm. I don't want to spend my time on that.

After we get this compiler in, I think we can look at putting the LSP server in a new folder, server. I prefer monorepo development for contained projects like this that are highly reliant on one another.

DavidSouther commented 1 month ago

@happytomatoe I hope you're able to keep making progress on this, but I wanted to let you know that I'm unavailable for the coming week. I'll be back October 20th to review any changes.

happytomatoe commented 1 month ago

@happytomatoe I hope you're able to keep making progress on this, but I wanted to let you know that I'm unavailable for the coming week. I'll be back October 20th to review any changes.

Have a nice holiday if it's a holiday)

happytomatoe commented 1 month ago

Small update - I was fed up working with official antlr4 typescript target. Migrated to antlr4ng

DavidSouther commented 1 month ago

Small update - I was fed up working with official antlr4 typescript target. Migrated to antlr4ng

Have you looked at Treesitter at all? (question, not a suggestion, but I hear great things about it and might be where I'd start if I was going from scratch today).

happytomatoe commented 1 month ago

Small update - I was fed up working with official antlr4 typescript target. Migrated to antlr4ng

Have you looked at Treesitter at all? (question, not a suggestion, but I hear great things about it and might be where I'd start if I was going from scratch today).

What do you hear specifically? It's a pure C library with language bindings. I didn't work with such combination. Probably it has it's own pain points. I don't know. I've seen this tool when I was building prettier plugin for Jack as it can build syntax tree(Tree with whitespaces and comments.)

If you would build this from scratch, based on my experience, the most go to options are

happytomatoe commented 1 month ago

Testing is done from my subjective point of view.