Canot call functions defined in script in Lazarus 1.8.0 FPC 3.0.4
I try to execute Test\Algorithms\dot_product.pas script and got error in Lazarus. Script defines function and then calls it. It looks like to me that result variable could not be placed correctly in stack. I got error because FStackAddr variable which is used as Index in stack array is -3. I think free pascal do not support negative indexes. Is it same in Delphi?
Debuger shows that error is here in dwsCoreExprs.pas:
// AssignValueAsFloat
//
procedure TFloatVarExpr.AssignValueAsFloat(exec : TdwsExecution; const value: Double);
begin
exec.Stack.WriteFloatValue_BaseRelative(FStackAddr, value);
end;
dot_product.pas content:
function DotProduct(a, b : array of Float) : Float;
require
a.Length = b.Length;
var
i : Integer;
begin
Result := 0;
for i := 0 to a.High do
Result += a[i]*b[i];
end;
PrintLn(DotProduct([1,3,-5], [4,-2,-1]));
Code which execute script is:
Script := TDelphiWebScript.Create(Self);
try
f := TFileStream.Create('C:\dwscript\Test\Algorithms\dot_product.pas', fmOpenRead);
Source := TStringStream.Create('');
Source.CopyFrom(F, 0);
F.Free;
Source.Position := 0;
prog := Script.Compile(Source .DataString);
Source.Free;
if prog.Msgs.Count=0 then
begin
exec:=prog.Execute;
DbgOut(exec.Result.ToString);
end
else
DbgOut(prog.Msgs.AsInfo)
finally
exec := nil;
prog := nil;
Script.Free
end
Comments (6)
-
-
I think I understood how to create pull requests
-
repo owner Does the following work in Lazarus/FPC ?
If yes this could avoid the need for an ifdef as it compiles similarly to existing code in Delphi.
function TStackMixIn.GetBaseData(index : Integer) : PVarData; begin Result := PVarData(NativeUInt(FBaseData) + NativeUInt(Index * SizeOf(Variant))); end;
-
It looks like that this is working in Lazarus/FPC. I updated my pool request.
-
repo owner Don't worry to much on the pull request, I cannot use it directly (this repo is synched from an SVN repo...)
I committed changes with your fixes, let me know if that's ok
-
It is OK. I will delete my pull request then. I thin you can resolve this issue. At leas I do not see how I can do it.
- Log in to comment
I created fix for this problem is it possible to somehow share it with you