Re: I have been working so hard for over a 2 Weeks but
Focus on one thing at a time. Don't write all of the functions and then see if they pass the tests -- that leaves you with a lot of code without anyway of knowing where to start looking (that's not quite true, but close).
Implement the label command and write a couple of simple VM code fragments that use a few labels and then run your translator on it and look at the resulting assembly code file. Does it do it right?
Then implement the goto command and do the same thing.
Then implement the if-goto command and do the same thing.
Then run test these using the authors' supplied programs.
Don't even worry about the function, call, and return commands until you pass these tests.
If it doesn't pass the tests, don't just go banging away at your code hoping that if you make some changes it will happen to pass the next time. Look at the translated code and figure out what it did that it shouldn't have (or didn't do that it should have) and THEN look at your code and be sure you understand why your code generated the wrong thing. That way you know what needs to be fixed.
Ok Great stuff, SO i tested the Program flow tests (WIthout write init) and it works fine.
DO you think introducing writeinit fails the Program flow tests?
or is there a problem in my Call code?
Yes, as the book describes, the tests BasicLoop, Fibonacci and SimpleFunction expect that the Sys.init code is not implemented yet, so the tests do the initialization. On the other hand FibonacciElement and StaticTest expect that Sys.init is already implemented.
There is a newer test, NestedCall, that is not described in the book. You should implement it after SimpleFunction, but before FibonacciElement. Read NestedCall.html for more info.
It's a good idea to add a switch to your compiler whether to generate the bootstrap code or not. It's only useful during these tests, but it's still makes life easier to have it. Just make sure the default is to generate it.
I'm still on project 7 after six weeks (I am self employed, which is really wrecking my coding time) so don't feel bad. The advice is good about breaking things down into smaller problems and not trying to do it all in one go.
I'm also learning C, malloc and "string" handling has been driving me bonkers on this particular project.
You've got this far, am sure you'll succeed !
Another good tip, (well it's worked for me) if it's late and you're not getting anywhere, do something else, non computer related or even go to sleep if you have the time, sometimes this helps to: "move a mental block" or " helps with an insight".
All the best and good luck (sometimes a lucky break does help, despite all the sensible analysis)