-
Notifications
You must be signed in to change notification settings - Fork 4
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
Question/proposal: LibC in Ada #1
Comments
Er no. I said you can implement it in Ada, there's no need for that much C, I said I implemented memcpy, although I think I told you memset . Only things you cannot really handle easily are macros and ellipsis/varargs, the latter can be handled in Ada 202x, when GNAT gets support. Everything else can be aspects and Interfaces.C, but you might have to strip out some functions from that package depending on what you have available in your runtime. I also have a small secondary stack in mine. |
Hi Fer. I think @Lucretia is right. For example, the varargs problem is not easily solved in Ada, because that breaks the fundamental strong typing. Macros was marked absolutely evil from day 0 of Ada inception. The reason behind the C nanolibrary is to ease a porting of small C programs in SweetAda. Obviously the library is very limited. To be honest, I drag into SweetAda this C library that I rewrote from other implementations just to have other pieces of software to test, and also to experiment the level of goodness of my project. But, as a matter of fact, it is already based on underneath Ada subprograms (malloc()-related and memcpy()-related are wrappers around the Ada counterparts). Just the string/stdio functions are unrolled in C, and, anyway, the printf() family of functions is actually calling Ada console subprograms. That being said, step by step I will try to delete as much of C code as I can, and expand the functionalities, whenever that will seem ok, in the near future. Best regards. |
If that's the case then why not just export them from Ada as C functions and create a C header for the clib? |
This is already the case, more or less. But you can't exploit exporting blindly. There is one level of indirection because problems arise when you try to export a subprogram with two different identifiers. Unfortunately, e.g., I had to export Ada "Malloc" to both "__gnat_malloc" (compiler calls for the new operator) and "malloc" proper (libgcc calls to the stack unwinder). When I will have more time I will think about other ways (renaming, linker quirks, etc). |
Thank you for your explanation Gabriele. Feel free to close the issue then. One last comment. If you open issues for the things that you are trying to do, we (the community) could take a look at what needs to be done/changed/fixed and may be able to chime in or comment on it. If you want, of course. |
You're welcome. Still I have to understand github properly. And still I am full of things to do in SweetAda, to the point that Ada writing is almost a negligible activity. But slowly I'll try to setup everything. That issue of a libc on top of Ada will find perhaps a good end, current SweetAda status doesn't mean it's not possible to make something better later. In the meantime, feel free to ask/request/propose. |
Can't you use the weak attribute to create a new symbol which points to the same malloc? |
Yes, I tried, but other errors showed up. But this happened with an old toolchain, which led me to a naive solution in order to speed up things. Maybe it is unrelated. Haven't yet tried with a recent one, I will do ASAP. |
Hi Gabriele,
I was taking a deeper look into the project. I found that the C library is implemented in C. That is no surprise. But I was wondering whether you would consider/allow a PR (pull request) for it to be changed into Ada.
As far as I know, @Lucretia already implemented one in Ada (or part of it). I am pinging him to see if he has more insight into the matter. Maybe there is an already MIT compatible C library implemented in Ada out there.
I think SweetAda could be a wonderful showcase/base for Ada projects, and having the C library written in Ada would be the cherry on top.
Regards,
Fer
The text was updated successfully, but these errors were encountered: