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

Recursion in ShyvyC #119

Open
rolex20 opened this issue May 6, 2023 · 2 comments
Open

Recursion in ShyvyC #119

rolex20 opened this issue May 6, 2023 · 2 comments

Comments

@rolex20
Copy link

rolex20 commented May 6, 2023

does ShyvyC was designed to support recursion? I couldn't find test cases for it

@ShivamSarodia
Copy link
Owner

Hi @rolex20 , it does support recursive function calls although it appears you’re right there’s currently no test for that. Feel free to add one in the general tests directory.

@rolex20
Copy link
Author

rolex20 commented May 10, 2023

Thank you, I will and thank you very much for writing this compiler, I think Its great. As a hobby project, I am trying to adapt it to produce assember code for a CASIO PB-1000 from the 80's. I know there was no C compiler for it. There was a Pascal compiler that almost no one was able to buy and my goal is to beat this Pascal compiler although after my initial experiments it looks like the Pascal compiler had common subexpression elimination and that is where it beats me.

Initially I wrote a C compiler on my own using Java but without AST, cyclic register allocation, and lots of peephole optimizations but it doesn't support recursion. My compiler written java generated code that took 11 seconds for a sieve program. The pascal compiler takes 7 seconds for the same program. A hand written translation from the Intel assembler generated by ShyvyC takes 10 seconds but I have hopes that it should be possible doing the subexpression elimination in ShyvyC but not in my compiler that has no AST.

If I do the subexpression elimination by hand, my compiler written in java generates code that takes 6 seconds (beating Pascal) and ShyvyC would take 5 seconds or maybe less. So I am pretty sure this is what is missing.

For example, this code extract:

for(j=2; j<=n/i; j++)
    is_prime[i*j] = 0;

would need to be "rewritten by the compiler" as

d = n/i;
for(j=2; j<=d; j++)
    is_prime[i*j] = 0;

Any pointers you could offer would be greatly appreciated or even better if you decide to add those common expression elimination improvement :) and also regarding where to add the modifications to generate code for a different architecture, right now I think I would have to change a lot of code in a lot of places so perhaps it would be easier just to write a translator after ShyvyC has produced the assembler, which is what I am preparing to do but it sounds ugly but it would make it easier to integrate against any improvements you decide to make in the future. Another point where I would really appreciate your help is if you can tell me how can I force ShyvyC to flush the registers to memory because I need to call an internal ROM routine that will completely overwrite pretty much all registers (for example the Internal putch() ROM routine uses all registers, the internal IMUL and IDIV overwrites about 6 of the 16 available 16-bit registers)

And if you are curious about the PB-1000, people loved it so much, there are open source emulators for it, and almost all their secrets and architecture have been documented (I still have the real thing and it works as new).

Please let my know if you are interested in any of this, kind regards

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

2 participants