[fpc-pascal] assign code to a method
Angel Montesinos
montesin at uv.es
Fri Feb 18 09:14:10 CET 2011
While waiting for a 64 bits Delphi, I am doing experimentation with
fpc-Lazarus 64 bits. And this is my problem:
In most of my programs I use my own library for parsing and evaluating
floating point functions like
'x sin(y z)'
passed by the user as strings. The basic organization is as follows:
{---------------simplified code------------}
TFunctionEvaluator= class(TObject)
...
code: AnsiString;
...
public
{call the parser}
function ParseAFunctText(t, vars: AnsiString): AnsiString;
{call the evaluator}
V: function(X: array of Double): Double;
end;
{----------end code------------------------}
Suppose that "theF" is an already created instance of
TFunctionEvaluator and suppose that a program calls
msg:= theF.ParseAFunctText('pi', 'xyz');
Here, 'pi' is the text of the constant funcion that must give 3.14...
as result, 'xyz' contains the chars in the function text that the
parser should take as independent variables if they appear in t. The
result will be an error message "msg" if something fails. Then
ParseAFunctText builds "code" and puts
@V:= PChar(code);
Suppose that a program calls for example
r:= theF.V([1, 2, 3]);
Then Lazarus (fpc 2.2.4, lazarus 0.9.28.2 beta, target windows 64
bits, mode Delphi) compiles, but it raises an
'External:SIGSEGV' error.
In the debugger the exception is raised before the effective call of
the function code. If then I press F7, then the debugger jumps to the
following assemblies
push %rbp
mov %esp,%ebp
fldpi {loads pi to the fpu}
ftspl -0x18(%rbp) {copy pi to stack}
movsd -0x18(%rbp),%xmm0 {copies pi to XMM0, so caller
{may find also there the result}
leaveq
retq
I have tried all possible combinations like V:= PChar(code), V:=
@code[1], etc. to no avail. Thus I think something is wrong in my
understanding of the whole business in 64 bits or in fpc-Lazarus,
because this is not a problem in Delphi nor it was in an old version
of fpc-Lazarus 32 bits. Please give me a tip.
Many thanks in advance.
--
montesin at uv dot es
More information about the fpc-pascal
mailing list