🎉 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!

An Epoch weekend

Published February 08, 2009
Advertisement
Had another few spare hours today, so I sat down and made some improvements and did some bugfixing in the Fugue VM code.

I honestly don't remember everything I did - I'm deliberately not doing changelists for the first few releases of Epoch, because things are moving so fast and stuff is still subject to change a lot.

Aside from all the minor stuff, I changed the way that libraries work. Previously, in order to build a library of functions, you had to write the code inside the Fugue VM DLL, and package it together. This is obviously stupid and would prevent people from just including the packages they need. Even worse, if someone needs a random package, they have to link it as part of the VM DLL just to get it to work. Eurgh.

So my new model is to have a simple DLL interface that conforming libraries must expose. Basically, the library DLL gets loaded, then a "link to the VM" function is called. This link function receives a pointer to a second function, and some context data.

The second function is essentially a "register a function with the VM" sort of thing. The library DLL invokes this function for each function implemented in the library. On the other side, the VM records each function signature, and creates a dummy function that invokes the library DLL.


This means I can write a DLL with a function like, say, GetRandomNumber(integer(maximum)) and then link it into the Epoch VM using any name I want (how about random?). From then on, random is treated as though it were an actual Epoch function, but in reality it's just a shim that pops out and invokes the library DLL.


This approach gives me several advantages. First and most obvious, it means we can implement libraries without touching the VM code. Secondly, it means any language that can output a simple DLL can be used to extend Epoch's functionality. Finally, it provides a way for programmers to avoid a lot of painful and redundant external DLL function references.

The library functions actually go through the same marshalling process as standard DLL calls, so as long as the DLL speaks C, everything works great.

My first test library is a simple random number generator, which just delegates to the standard library rand(). All I have to do is add one line of code someplace in my file, at global scope:

library("random")

And then I magically get a new function random which I can call as if it were written directly in Epoch.


One final advantage to this - anyone can now expand the Epoch standard library, CPAN-style, with libraries of their own. This means that (theoretically at least) I don't have to be the only one developing library code for Epoch distributions. Woohoo!


[Afterthought] I also will eventually get around to letting libraries register their own structures, tuples, and other data types. This will mean that we can build libraries for common things like Win32 programming, and save out a lot of typing and manual copying of function signatures and structure layouts.
Previous Entry More Epoch shtuffs
Next Entry Epoch Success!
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