1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
vector<void*> externalFP;
[...]
case 'I':
{
string funcName=s.popCString();
string lib=s.popCString();
auto f=getExternalFunction(lib,funcName);
if (f)
{
externalFP.push_back(f);
s.push(externalFP.size());
}
else s.push(0);
break;
}
case 'C':
{
uint fhandle=s.pop()-1;
string params=s.popCString();
if (params.empty())params="V";
#ifdef __x86_64__
typedef uint64_t P;
#else
#error "Architecture currently not supported"
#endif
vector<P> p;
if (fhandle>=externalFP.size())
{
cout << "Invalid external function called." << endl;
return 2;
}
void* func=externalFP[fhandle];
for (uint i=1;i<params.length();i++)
{
switch (params[i])
{
case 'I': p.push_back(s.pop()); break;
case 'L':
{
uint l=s.pop();
uint h=s.pop();
p.push_back((uint64_t(h)<<32)|l);
break;
}
case 'P':
{
int y=s.pop();
int x=s.pop();
void* ptr=&grid(x,y);
p.push_back((P)ptr);
break;
}
case 'C':
{
//todo
break;
}
}
}
P ret=0;
switch(p.size())
{
case 0: ret=reinterpret_cast<P(*)()>(func)(); break;
case 1: ret=reinterpret_cast<P(*)(P)>(func)(p[0]); break;
case 2: ret=reinterpret_cast<P(*)(P,P)>(func)(p[0],p[1]); break;
case 3: ret=reinterpret_cast<P(*)(P,P,P)>(func)(p[0],p[1],p[2]); break;
case 4: ret=reinterpret_cast<P(*)(P,P,P,P)>(func)(p[0],p[1],p[2],p[3]); break;
case 5: ret=reinterpret_cast<P(*)(P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4]); break;
case 6: ret=reinterpret_cast<P(*)(P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5]); break;
case 7: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6]); break;
case 8: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]); break;
case 9: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]); break;
case 10: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9]); break;
case 11: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10]); break;
case 12: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11]); break;
case 13: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12]); break;
case 14: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13]); break;
case 15: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14]); break;
case 16: ret=reinterpret_cast<P(*)(P,P,P,P,P,P,P,P,P,P,P,P,P,P,P,P)>(func)(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); break;
default: cout << "External function calls with more than 16 parameters are not supported." << endl; return 1;
}
switch (params[0])
{
case 'V': break;
case 'I': s.push(ret); break;
case 'L': s.push(ret>>32); s.push(ret); break;
}
break;
}
|