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

Question/proposal: LibC in Ada #1

Open
Irvise opened this issue Aug 2, 2021 · 8 comments
Open

Question/proposal: LibC in Ada #1

Irvise opened this issue Aug 2, 2021 · 8 comments

Comments

@Irvise
Copy link

Irvise commented Aug 2, 2021

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

@Lucretia
Copy link

Lucretia commented Aug 2, 2021

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.

@gabriele-galeotti
Copy link
Owner

gabriele-galeotti commented Aug 2, 2021

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.
G

@Lucretia
Copy link

Lucretia commented Aug 2, 2021

If that's the case then why not just export them from Ada as C functions and create a C header for the clib?

@gabriele-galeotti
Copy link
Owner

gabriele-galeotti commented Aug 2, 2021

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).

@Irvise
Copy link
Author

Irvise commented Aug 3, 2021

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.

@gabriele-galeotti
Copy link
Owner

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.

@Lucretia
Copy link

Lucretia commented Aug 3, 2021

Can't you use the weak attribute to create a new symbol which points to the same malloc?

@gabriele-galeotti
Copy link
Owner

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.

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

3 participants