Building an FFI for a Virtual Machine: Problems with the ffcall library

Hello, forum.

As the title says, I'm building a virtual machine. I've read the EOPL, Lisp in Small Pieces in Game Scripting Mastery (The latter goes through VM's, parsing, assembly, compiler theory...), and decided to start off with an FFI instead of bolting it later. My approach is based on having a lookup table -- Basically a void function that gets passed a function ID and an arbitrary number of arguments or arbitrary type (Using templates). A switch statement finds the function and then passes the arguments directly (Another argument determines whether the result it to be stored or not, this is irrelevant). To speed up the process, there are many lookup tables (Called tablen_findLookupFunction, where n is their ID number), and a higher-level function called findLookupTable which takes the table ID, function ID, the store-or-not integer (It would've been a boolean, but that breaks everything), and switches the table ID until it finds the proper table, passing down everything else.

To connect this to the virtual machine, the function findLookupTable is called using the avcall module of the libffcall library, building the argument list incrementally before passing. In the main function you can see the comments and some IF's that show how it'd be done, in general.

Code: http://pastebin.com/wDm3k7cn

Command to compile: g++ sample.cpp -I/usr/include -lavcall -std=gnu++0x

The problem arises when actually trying to compile:

1
2
3
$ g++ sample.cpp -I/usr/include -lavcall -std=gnu++0x
sample.cpp: In function ‘int main()’:
sample.cpp:86:5: error: address of overloaded function with no contextual type information


The real line 85 is:

av_start_void(L,&findLookupTable);

Changing this to:

av_start_void(L,(void(*)(int,int,int,&Args...))(&findLookupTable));

Causes:

1
2
3
4
5
6
$ g++ sample.cpp -I/usr/include -lavcall -std=gnu++0x
sample.cpp: In function ‘int main()’:
sample.cpp:85:5: error: expected primary-expression before ‘void’
sample.cpp:85:5: error: expected ‘)’ before ‘void’
sample.cpp:85:71: error: expected ‘)’ before ‘;’ token
sample.cpp:85:71: error: expected ‘)’ before ‘;’ token


This is probably a problem with libffcall being intended for C and not handling templates well. I would use C's variable arguments <cstdarg>, but that would just add extra complexity. Can anyone help out here?
Topic archived. No new replies allowed.