4.28.2011

Libs

Think I got it, atleast for Linux. So far, it seems possible for Linux to load, access and free libraries with only 4 functions to call! It's exactly like how I know it from my old Purebasic experiences. However, this isn't portable and specific. There exist libraries out there delivering all functionality to do this crossplatform, but I'm rather looking for a small and specialized library exactly made for loading and iterating through library functions. The bad thing about it is, that if you wan't to also get the parameter types, you won't have any luck. It's rather on assembly/machine level, so all parameter operations are done using their own calling convention. In the case of C, it's crucial cause I'll probably only using C libraries. It's interesting to finally find some informations about calling convention cause so often you read stuff like "_stdcall" or "cdecl" in source codes and you don't know that these actually flags so say the compiler what calling convetion to use here. So my language ones again adds a more compiler-specific element to it: calling conventions. I know I can simulate these using inline ASM. And I guess it's also quite portable when using only push and pop or so. But there almost always registers involved - I can't get around using architecture-specific commands there. But there more I try, the better and cleaner it gets. So we have a way to load and get library functions by name, their addresses and a fixed format for calling them. So our only command, namely "input > module > output" (output < module < input, respectively) is required to do things there. Quite interesting, a programming language only able to handle sequences, types, symbols, addresses and call functions! I bet this is the most horrible joke for a dozen of people out there. I still like coding C or C++, so combining the scripting language and libraries written in these two languages should make a fine combination (not only for bytecode execution, but also for the export-to-C thing as I don't need to rewrite my codes in for the other language). Quite a useless base without beeing able to decide what calling convention to use. It's usually all static in C, so dynamic access isn't possible as far as I know. Hm, this makes things more difficult. Not to say impossible without assembler or libraries/macros for special function calls. I read some articles about it and it seems that GCC doesn't do well with supporting different calling conventions. A wicked situation, indeed. Maybe I'll get an idea later. So far, dynamically loading libraries this ways marks a very, very cool idea. If I ever get this done, I'm the new king of the lab.

On a sidenode, I did some more investigations about how and where stacks are implemented nowadays and discovered that the language FORTH does a quite interesting job of handling parameters and stacks. The way it excludes all kinds of registers for normal use is really something remarkable and exceptionally unique. I always disliked the fact that I don't always know where my variables go in C code (yes I know, show the assembler code blabla), so Forth does it quite nice by always saying they go to the stack. I'm sure that performance, in the case of Forth's stack handling and C's usual register chaos for comparison, bases entirely on how the underlying machine handles them. But with some optimization for specific cases, I bet both concepts are equal and Forth will probably win the simplicity prize. So all in all I like the idea of it enough to keep in my head for later use. It's too bad that there's no really portable assembler nowadays. It should be something really simple, like only giving commands available for all commong machines while giving the option to use specific ones. Oh well, that race never ends. However, I still hope that I'll be able to improve the world of programming languages in this case by representing a more diverse set of calculation concepts.

No comments: