lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wednesday 22 February 2006 10:16, Lisa Parratt wrote:
> All of this can be achieved in a much more compact manner by using a
> compiler to extract a decorated syntax tree and by maintaining the
> symbol table. In addition to this, all you require is a short routine
> that prepares translates a Lua stack frame into a Native stack frame,
> performs the call, and then converts it back.

This is a rather big 'all': it's *not* something that can be done portably on 
any system. On some platforms, you may be able to get away with naive 
approaches, but on others, you're going to have to abuse the internal 
structure of jmp_buf, ucontext_t or resort to writing machine code. Not hard, 
but extremely fiddly, annoying, and highly platform-specific.


void func1(int a, void* b);
void func2(int a, int b);
typeof(func2)* p = (typeof(func2)*) func1;
p(1, 2);

On some platforms, including ia32, func1 will be called with a=1 and b=(void*)
2. On others, such as the 68k, you'll get a=1 and b=garbage, because the 68k 
uses different registers to pass integers and pointers.

We're rather spoilt with ia32 because it's basically such an appalling 
architecture that parameters have to be passed the hard way, i.e. on the 
stack. Other architectures don't work like that. (See the -mrtd and -mregparm 
options for gcc's ia32 backend.)

+- David Given --McQ-+ "I must have spent at least ten minutes out of my
|    | life talking to this joker like he was a sane
| ( | person. I want a refund." --- Louann Miller, on
+- --+ rasfw

Attachment: pgpYGJrpv_Drr.pgp
Description: PGP signature