🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Epoch/C interface is functional!

Published July 31, 2008
Advertisement
I set aside a few minutes this evening and worked up further integration between Epoch programs and external DLLs. The result is that a new class of program is possible:

external "user32.dll" MessageBoxW : (integer windowhandle, string message, string caption, integer typeflags) -> (integer)entrypoint : () -> (){	MessageBoxW(0, "Test message", "Epoch", 67)}


At the moment, function calling is a bit crippled - only literal values can be passed to a function. Eventually we'll obviously need support for passing variables (by value, at least for now) and nested function calls (i.e. where one function's return value is passed along as a parameter to another function).

It's rudimentary, but it's beautifully simple. Epoch uses the declaration of the function to determine what parameters to push onto the stack, then retrieves the function address and makes a call into it via inline assembly. The return value is handled various ways; at the moment only integral return values in EAX are really supported, but it should be easy enough to expand that once richer type support is implemented in the language.

The approach was inspired by old Visual Basic Declare statements. Combined with a header/include type facility, we can make a comprehensive list of function interfaces from a given DLL, potentially indexing all of the Win32 APIs that would be needed for developing a particular program.

Epoch currently assumes that all external calls are made using the __stdcall calling convention. I don't see any particular necessity to change this, at least not for the near future, since __stdcall will be sufficient for any Win32 API access, and that's really the main goal of this integration exercise.


As an interesting side effect of how I chose to implement parameter passing in the VM, it will be trivial to implement named parameter passing; the only trick will be coming up with a good syntax for it that fits within the "pure" syntax model.


And now my brain is threatening to climb out my left ear, so I will go to bed.
Previous Entry Egotism
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement