Okay, this is going to be quite long ...
Code:
procedure CallFunction(var n:valrec; fi:integer; needResult:boolean); var arity:integer;
var descriptors:string;
var args:TArgs;
var flag:integer;
var needBraces:boolean;
var i:integer;
var missing:boolean;
var stack:array [0..30 { TUNE: }] of integer;
var sp:integer;
var _eax,_edx,_ecx:integer;
var regcount:integer;
var ltr:boolean;
var stkusage:integer;
var stkadr:integer;
var regcall:boolean;
var adr:pointer;
var resadr:pointer;
var resvalue:integer;
var needsExtraParam:boolean;
var isMethod:boolean;
var obj:TObject;
asm
push esi // esi, edi, ebp and ebx must be kept
push edi // (we use only esi and edi here).
sub esp, StkUsage // make room on stack
mov edi, esp // set destination of mem copy, it is the stack
mov esi, StkAdr // set source of mem copy, it is Addr(ExtStk)
mov ecx, StkUsage // prepare ecx to copy StkUsage bytes
shr ecx, 2 // divide by 4 to perform DWORD-copy (is faster)
//add edi, StkUsage;
//sub edi,4
//add esi, StkUsage;
//sub esi,4
cld // choose copy direction
rep movsd // do DWORD-copy
cmp RegCall, true
jnz @@EXEC
mov EAX, _EAX
mov EDX, _EDX
mov ECX, _ECX
@@EXEC:
call Adr // execute the external function
// esp is restored by the external function
// (except for cdecl-convention)
pop edi // restore edi...
pop esi // ...and esi
mov _EAX,eax
end; // asm
// TODO: convert references back
I hope this is the correct code since there are a lot of nested procedures and functions ...
Bookmarks