just spend some time finishing the plugin system, i will begin exposing some functionality tomorrow most likely.. a sample ziron assembler plugin written in ziron
program WIN32DLL 'Sample';
#include 'ziron32.zir';
const strLoaded = 'Test plugin has been loaded';
//////////////////////////////
function* GetFunction(char* strName): DWord; stdcall;
function InitPlugin(pointer pGetF) {
GetFunction = pGetF;
//do something
//GetFunction(.... coming soon
return strLoaded;
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin;
of course this does nothing much apart from output the message the plugin has been loaded, but it gives an example of the simplicity of the plugin system.
Ziron's parser does not work on a line by line basis, so passing line by line to a plugin is not possible, however I have added a function to allow access to each file's code as it is included before compilation of the file begins.
Basically a pointer is passed to the code in memory, allowing for changes in code, however this is a problem since the size of memory needs also to be expanded, so i'm thinking about adding a grow function, allowing plugins to call Ziron_GrowMem(32)
which of course will realloc the memory with the additional size of 32 kb of ram.. it may be difficult for plugin writers to know exactly how much more ram their plugin would require, meaning they would need to often call the grow function as it becomes necessary.
Reallocating is not fast of course, however... plugins can resize by lets say 32kb, and keep track of the size, and if it plans to go over 32kb, to call to realloc again, 32kb i believe is more than enough space for any changes anyways. infact, in most cases, they may not even need to reallocate more than for 10000 character changes, 10kb would usually be more than enough.
Optionally, it could be made that the plugin writer allocates the space they need, write the entire file into a buffer, pass it to the plugin and the compiler can replace the internal buffer by copying the contents of the new buffer.
first: we can pass the filename of source code that will compiled by Ziron to the pluging
then the plugin will load the file and changes it then save it again the Ziron will take the
control.
second: and i prefer it , Ziron will load the file then pass each line to a plugin and after
the plugin changes the code , Ziron save that to file and load it again to compile it as usual.
note will , there will be more than one plugins form the users and each one will change the code as wanted. so the plugins must be ordered and the second solution will do it.