Search code examples
delphipascalscript

Compiling Pascalscript in 64 bit mode, events not working?


I have downloaded and started playing with Pascalscript and its sample programs.

I have come across a problem with interfacing to Forms using the Forms access sample script.

It works in 32 bit mode, in 64 bit mode no events get triggered.

That is, a buttons onpress event never calls the pascalscript onpress code.

I am using Delphi 10 Seattle on windows 7 pro.

Any ideas on how to get scripts working right on the 64 bit platform?


Solution

  • Well seeing as no one had an answer to this I had to do the hard work myself.

    So the problem was empty prolog code for x64 in the conversion from delphi to pascalscript method calling which was written in assembler. The empty method handler was called "MyAllMethodhandler" in the uPSruntime unit and my code solution is as follows

    function MyAllMethodsHandler2(Self:PScriptMethodInfo; const Stack:PPointer; _EDX,_ECX:Pointer):Integer; forward;
    
    {$ifdef CPUX64}
    procedure MyAllMethodsHandler;
    //  On entry:
    //  RCX = Self pointer
    //  RDX, R8, R9 = param1 .. param3
    //  STACK = param4... paramcount
    asm
      PUSH  R9
      MOV   R9,R8     // R9:=_ECX
      MOV   R8,RDX    // R8:=_EDX
      MOV   RDX, RSP  // RDX:=Stack
      SUB   RSP, 20h
      CALL MyAllMethodsHandler2
      ADD   RSP, 20h  //Restore stack
      POP   R9
    end;
    {$else}
    
    procedure MyAllMethodsHandler;   //original x86 code
    //  On entry:
    //  EAX = Self pointer
    //  EDX, ECX = param1 and param2
    //  STACK = param3... paramcount
    asm
      push 0
      push ecx
      push edx
      mov edx, esp
      add edx, 16 // was 12
      pop ecx
      call MyAllMethodsHandler2
      pop ecx
      mov edx, [esp]
      add esp, eax
      mov [esp], edx
      mov eax, ecx
    end;
    {$endif}
    

    Not sure if this will work with everything but seems to work for at least 2 parameters.

    I'll post it as a comment on GitHub, I can't really fix it directly as I have made extensive changes to the whole of Pascal script so it supports complex math.