Forum archive
Evaldraw-executable code
- Ken, how do you convert in/generate executable code like in evaldraw, or in other compilers/scripting systems? Do you know some good links to information about this topic?
Re: Evaldraw-executable code
If you intend to write your own compiler from scratch, you will need to deal with machine code. A good site for machine code is: http://sandpile.org/. Also, an Intel Programmer's Reference may be helpful. (I would suggest using an older manual that isn't bloated with all of the latest SSE instructions). You should also know the calling conventions of your compiler. The calling conventions tell you which registers is it ok to overwrite, which must be preserved, what order parameters are passed, how the stack is set up for function entry/exit, etc.. Agner Fog has written a nice manual about calling conventions: http://www.agner.org/optimize/
I did not study other compilers or scripting systems while writing Evaldraw.- For starting...because of the incompatibility and lack of knowledge and experience I would want to develop a virtual compiler/interpretor/scripting system: a compiler inside another compiler, with a virtual machine,virtual assembly code converted in virtual machine code, where I define my own instructions. My inspiration comes from this article on flipcode http://www.flipcode.com/articles/scripting_issue01.shtml. But I do not have ideas on how to link this kind of compiler with an external compiler...or even with data of the same compiler. Can you give me some hits on that, if it's possible?
- A simple scripting system might work like this:
Most of the work is figuring out how the compiler would generate the opcodes and associated data. That's for you to figure out.
#define MAXVARS 1000
double buf[MAXVARS];
#define MAXOPS 1000
long opcode[MAXOPS], dest[MAXOPS], src0[MAXOPS], src1[MAXOPS];
void runscript ()
{
int ip = 0; //Instruction Pointer
while (opcode[ip] != RETURN)
{
switch(opcode[ip]))
{
case GOTO: ip = src0[ip]; break;
case MOV: buf[dest[ip]] = buf[src0[ip]]; break;
case ADD: buf[dest[ip]] = buf[src0[ip]] + buf[src1[ip]]; break;
...
}
}
}