Reputation: 694
I'm developing custom language, and everything works good, but I stopped at adding support of standard functions, like getchar(), fopen(), etc. One of my ideas is to parse visual .lib files, but it's massive task (e.g. because of lacks in specification). Do you have other ideas? How it's made in language like D?
EDIT: What I want to achieve, is to be able to use system features (e.g. opening files, using sockets), but without need to write it from the scratch. I need some way to access libs/dlls already written.
The simplest solution would be to load e.g. C standard library and make calls to these functions (setting up stack before), but I need to have some way to get this code (assembled).
Upvotes: 0
Views: 332
Reputation: 3164
Normally, you would make your own standard library that makes sense for your language, rather than using the C standard library. Why are you writing your own language, and shouldn't that feed into the design of your standard library?
For compatibility with C libraries in general, I find the most common approach is to re-express the interface to the library in a different language. Python provides the ctypes module for this. In .NET, you would use P/Invokes. This brings in some manual work and opportunity for error as you translate the interface, but it's much simpler and more powerful than an automated process would be.
Also, .NET is designed so that .NET libraries can be accessed from any language implementation in .NET, as long as the library and language are designed correctly. Specific languages may have their own needs that are filled by their own standard libraries, but things like console i/o are in one place and don't need to be reinvented by each language.
Upvotes: 1