<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi there.<br>
<br>
This is a cross-post (cross-mail ?) to
<a class="moz-txt-link-freetext" href="http://www.lazarus.freepascal.org/index.php/topic,17978.0.html">http://www.lazarus.freepascal.org/index.php/topic,17978.0.html</a> as I
got the hint there that it might be better to ask on the list
instead of in the forum, at least concerning the calling conventions
- but I'll ask the whole lot, anyway; I hope that's ok.<br>
<br>
Has anyone successfully used PascalScript with Lazarus Classes (e.g.
TForm, TButton) on Win x64?<br>
<br>
I can compile the downloadable latest stable version from
RemObject's website (the one with the EXE-Installer) as well as the
latest development version from <a
href="https://github.com/remobjects/pascalscript" class="bbc_link"
target="_blank">https://github.com/remobjects/pascalscript</a> OR
(that's not in the Forum) the PascalScript-version included in
Lazarus' SVN, no Problem there, after two small changes in x64.inc
(see below).<br>
Running the script works, adding user defined functions (and calling
them!) is OK, too.<br>
<br>
But as soon as I try to Create forms and objects, like the following
script, the Program crashes with a SIGSEGV.<br>
<br>
<pre style="margin: 0; padding: 0;"><code class="bbc_code">program Script;
var
f:TForm;
b:TButton;
begin
f:=TForm.CreateNew(nil); //<- Works
b:=TButton.Create(f); //<- crash
b.Parent:=f;
f.Show;
end.</code></pre>
<br>
Crash in the Program is here:<br>
<br>
<pre style="margin: 0; padding: 0;"><code class="bbc_code">CLASSES_TCOMPONENT_$__INSERTCOMPONENT$TCOMPONENT
000000000044F900 4883ec38 sub $0x38,%rsp
000000000044F904 48895c2420 mov %rbx,0x20(%rsp)
000000000044F909 4889742428 mov %rsi,0x28(%rsp)
000000000044F90E 4889cb mov %rcx,%rbx
000000000044F911 4889d6 mov %rdx,%rsi
000000000044F914 4889da mov %rbx,%rdx
000000000044F917 4889f1 mov %rsi,%rcx
000000000044F91A 4889f0 mov %rsi,%rax
000000000044F91D 488b00 mov (%rax),%rax
000000000044F920 ff9068010000 callq *0x168(%rax) <-- crash</code><tt> </tt>
</pre>
<br>
Am I doing anything wrong? The same Script runs fine when the
Application was compiled with x86 Lazarus 1.0.<br>
By the way: creating a TObject with e.g. o:=TObject.Create doesn't
break at al.<br>
<br>
Interestingly, when I start debugging
<SomeClass>.Create(aOwner:TComponent)-Type of Constructors,
there is some difference in the Register values, depending on
whether the Constructor was called from "pure" FPC-Code or the
Script (at least so it seems):<br>
o Called from FPC: rcx: 0 (nil), rdx: Class Reference, r8: Value of
aOwner<br>
o Called from Script: rcx: Class Reference, rdx: 1 (!?), r8: Value
of aOwner (at least so it seems)<br>
<br>
Is there any difference in the calling convention on x64-Systems
between Delphi and Lazarus? I could only find the "standard"
information on Windows x64 calling conventions, without special care
of constructors, if there is any...<br>
<br>
Did anybody else stumble about that problem before? Thanks for your
help!<br>
<br>
<br>
<tt>Index: x64.inc</tt><tt><br>
</tt><tt>===================================================================</tt><tt><br>
</tt><tt>--- x64.inc (revision 38441)</tt><tt><br>
</tt><tt>+++ x64.inc (working copy)</tt><tt><br>
</tt><tt>@@ -14,7 +14,7 @@</tt><tt><br>
</tt><tt> _RCX, _RDX, _R8, _R9: IPointer;</tt><tt><br>
</tt><tt> var _XMM0: Double;</tt><tt><br>
</tt><tt> _XMM1, _XMM2, _XMM3: Double;</tt><tt><br>
</tt><tt>- aStack: Pointer; aItems: IntPtr); assembler; {$IFDEF
FPC}nostackframe;{$ENDIF}</tt><tt><br>
</tt><tt>+ aStack: Pointer; aItems: PtrUInt); assembler; {$IFDEF
FPC}nostackframe;{$ENDIF}</tt><tt><br>
</tt><tt> asm</tt><tt><br>
</tt><tt> (* Registers:</tt><tt><br>
</tt><tt> RCX: Address</tt><tt><br>
</tt><tt>@@ -37,7 +37,7 @@</tt><tt><br>
</tt><tt> mov rdx, aStack</tt><tt><br>
</tt><tt> jmp @compareitems</tt><tt><br>
</tt><tt> @work:</tt><tt><br>
</tt><tt>- push [rdx]</tt><tt><br>
</tt><tt>+ push qword ptr [rdx]</tt><tt><br>
</tt><tt> dec rcx</tt><tt><br>
</tt><tt> sub rdx,8</tt><tt><br>
</tt><tt> @compareitems:</tt><br>
<br>
</body>
</html>