Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add none-native calling for class methods/properties. #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

User4martin
Copy link
Contributor

For plain procedures/functions there are
RegisterDelphiFunction which emulates a native call
RegisterFunctionName which avoids "playing" with the stack

For methods this does not exist.
I added
TPSRuntimeClass.RegisterMethodName and TPSRuntimeClass.RegisterPropertyNameHelper

The name RegisterPropertyNameHelper may need to be changed, but RegisterPropertyHelperName was already taken.

Using those functions should be more resistant against changes in the compiler.

According to the fpc mailing list, fpc trunk changes calling convention on i386 linux...

….RegisterMethodName and TPSRuntimeClass.RegisterPropertyNameHelper
@pult
Copy link

pult commented Sep 20, 2019

please provide an example of use

@User4martin
Copy link
Contributor Author

User4martin/lazarus@e30b8c8
This has been tested on 64bit Win (64 and 32 bit compiled) and Linux (64 bit only).
That is the (still existing) self-test in the IDE passes. (And the 64bit build on win, is used daily be me)

Using the InnerfuseCall did IIRC for example not work on arm (raspi) when sets are involved. Though I have not tested the new implementation on arm, as I do not have a test env setup (I am waiting for feedback)

Again not tested, InnerfuseCall might also need work for fpc trunk on linux 32bit, as fpc changed calling convention.

RegisterFunctionName has been available for a long time already. And I had looked at it (in fact I had IFDEF'D code for it) long ago.
But since I needed to relay on InnerfuseCall for properties, I had not used it back then.

Given the fact, that at least on fpc, InnerfuseCall would need careful retesting with every fpc release, I had actually always thought the absence of alternative methods for properties was because no one had found the time to do them.

That is why in the IDE I run a self-test at each startup (since a user could have build it with any version of fpc, including future). This self-test is carefully designed to detected if it crashed on its last run. Because if fpc changes calling convention, building older IDE code (with older PascalScript) with newer fpc, has the very real potential of crashing.

@pult
Copy link

pult commented Sep 20, 2019

Need samples of usage.
? What it is: ExtRead1, ExtRead2, ExtWrite1, ExtWrite2 ?

@pult
Copy link

pult commented Sep 20, 2019

FPC + x64 - InnerfuseCall without asm: https://github.com/pult/pascalscript/blob/fix_20170321_x64call/Source/x64.inc
This will also must work if the fpc call notification changes

@User4martin
Copy link
Contributor Author

Unfortunately I don't recall where the examples are, from which I learned about RegisterFunctionName.

With RegisterFunctionName you specify the @HandlerFunc, and Ext1, Ext2. The latter 2 are passed to HandlerFunc.
That allows you to reuse the same HandlerFunc for different functions.

For properties you have a read and a write method. So you can specify a pair for each of them.

Of course you can also set 2 (read/write) new HandlerFunc for each of property.

In the linked code the HandlerFunc is ExecBasicHandler.


Btw, the last commit 86a057c, seems to change InnerfuseCall to InvokeCall. But that is Delphi only. It does not affect FPC.

@pult
Copy link

pult commented Sep 20, 2019

latest commit not tested and do not work/compilation on previous delphi versions (sample XE3 not compiled). Need fix: #203 (comment)

@User4martin
Copy link
Contributor Author

About your commit / link:
I am not an expert on calling conventions: But your InnerfuseCall must still know what is allowed in a register, and what must be on the stack. And by how many bytes the stack must be aligned, etc.

Those things should be defined per platform. But then (search the recent fpc mail list) fpc changed it for 32bit linux.

@pult
Copy link

pult commented Sep 20, 2019

For x64 platform - simple call notations.
The compiler (FPC or Delphi) can generate calls based on the pas-code.
For 32 bit - much more confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants