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

[bug]: Testing StringTest with custom String.jack fails #542

Open
1 of 2 tasks
HofmT opened this issue Dec 24, 2024 · 1 comment
Open
1 of 2 tasks

[bug]: Testing StringTest with custom String.jack fails #542

HofmT opened this issue Dec 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@HofmT
Copy link

HofmT commented Dec 24, 2024

Tool

Jack Compiler

Interface

Website (https://nand2tetris.github.io/web-ide)

Contact Details

No response

What happened?

I was testing my implementation of String.jack inside the folder StringTest which I uploaded to the Web IDE JackCompiler. The folder only consisted of the jack files: String.jack and Main.jack.

I noticed that whenever I printed a string, it would start with two whitespaces before printing any characters in the string., e.g. abc would become abc.

I did some debugging and I think the error is related to the following:
Since my folder did not include the Output.jack file, it retrieves the code from the built-in files. When printing a string (Output.printString()) there is a dependency to the function charAt inside String.jack. I assume the compiler does not reference my provided String.jack but instead the built-in String.jack which has a different implementation of the String object.
As a result, the behavior of how the string is getting printed is not deterministic and results into arbitrary characters being printed.

I then tested my custom String.jack with my custom Output.jack in the same StringTest directory and then my code would behave correctly.
I'm wondering now if it is possible to test the String.jack in isolation without providing your custom Output.jack file.

Additional Comments

No response

Do you want to try to fix this bug?

  • I want to try to add this feature!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@HofmT HofmT added the bug Something isn't working label Dec 24, 2024
elp2 added a commit to elp2/nand2tetris that referenced this issue Jan 12, 2025
TESTED=Passes StringTest with Output.jack in this dir (Workaround for nand2tetris/web-ide#542).
@elp2
Copy link

elp2 commented Jan 14, 2025

This also affects MemoryTest even worse since it calls Array.new, which if there's no Array.hack in MemoryTest, will fall back to the built-in memory.ts functions, completely ignoring the memory code you were trying to test!

My PR re-writes the string and os functions to use pointers and heap like a real hack program would.
To fix the MemoryTest, the project files could use Memory.alloc instead of Array.new.

A more cohesive fix would probably be to have compiled golden VMs for each OS function instead of bespoke JS functions (although it might be slower)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants