Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 44 additions & 37 deletions BenchmarkRunner.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ var
GMode: TGocciaEngineBackend = ebTreeWalk;

procedure PopulateFileResult(const AFileResult: TBenchmarkFileResult;
const AScriptResult: TGocciaObjectValue; const AReporter: TBenchmarkReporter;
out AResultObj: TGocciaObjectValue);
const AScriptResult: TGocciaObjectValue; const AReporter: TBenchmarkReporter);
var
ResultsArray: TGocciaArrayValue;
SingleResult: TGocciaObjectValue;
Expand Down Expand Up @@ -105,23 +104,18 @@ begin
end;

AReporter.AddFileResult(MutableFileResult);
AResultObj := AScriptResult;
end
else
begin
MutableFileResult.TotalBenchmarks := 0;
MutableFileResult.DurationNanoseconds := 0;
SetLength(MutableFileResult.Entries, 0);
AReporter.AddFileResult(MutableFileResult);

AResultObj := TGocciaObjectValue.Create;
AResultObj.AssignProperty('totalBenchmarks', TGocciaNumberLiteralValue.ZeroValue);
AResultObj.AssignProperty('duration', TGocciaNumberLiteralValue.ZeroValue);
end;
end;

function MakeErrorFileResult(const AFileName, AMessage: string;
const AReporter: TBenchmarkReporter): TGocciaObjectValue;
procedure MakeErrorFileResult(const AFileName, AMessage: string;
const AReporter: TBenchmarkReporter);
var
FileResult: TBenchmarkFileResult;
begin
Expand All @@ -137,17 +131,14 @@ begin
FileResult.Entries[0].Name := '(fatal)';
FileResult.Entries[0].Error := AMessage;
AReporter.AddFileResult(FileResult);

Result := TGocciaObjectValue.Create;
Result.AssignProperty('totalBenchmarks', TGocciaNumberLiteralValue.ZeroValue);
Result.AssignProperty('duration', TGocciaNumberLiteralValue.ZeroValue);
end;

function CollectBenchmarkFileInterpreted(const AFileName: string;
const AReporter: TBenchmarkReporter): TGocciaObjectValue;
procedure CollectBenchmarkFileInterpreted(const AFileName: string;
const AReporter: TBenchmarkReporter);
var
Source: TStringList;
Engine: TGocciaEngine;
GC: TGarbageCollector;
BenchGlobals: TGocciaGlobalBuiltins;
EngineResult: TGocciaScriptResult;
ScriptResult: TGocciaObjectValue;
Expand All @@ -167,24 +158,31 @@ begin
Engine.BuiltinBenchmark.OnProgress := TBenchmarkProgress.OnProgress;

EngineResult := Engine.Execute;
FileResult.FileName := AFileName;
FileResult.LexTimeNanoseconds := EngineResult.LexTimeNanoseconds;
FileResult.ParseTimeNanoseconds := EngineResult.ParseTimeNanoseconds;
FileResult.CompileTimeNanoseconds := 0;
FileResult.ExecuteTimeNanoseconds := EngineResult.ExecuteTimeNanoseconds;

GC := TGarbageCollector.Instance;
ScriptResult := nil;
if EngineResult.Result is TGocciaObjectValue then
ScriptResult := TGocciaObjectValue(EngineResult.Result);

if Assigned(ScriptResult) and Assigned(GC) then
GC.AddTempRoot(ScriptResult);
try
PopulateFileResult(FileResult, ScriptResult, AReporter);
finally
if Assigned(ScriptResult) and Assigned(GC) then
GC.RemoveTempRoot(ScriptResult);
end;
finally
Engine.Free;
end;

FileResult.FileName := AFileName;
FileResult.LexTimeNanoseconds := EngineResult.LexTimeNanoseconds;
FileResult.ParseTimeNanoseconds := EngineResult.ParseTimeNanoseconds;
FileResult.CompileTimeNanoseconds := 0;
FileResult.ExecuteTimeNanoseconds := EngineResult.ExecuteTimeNanoseconds;

ScriptResult := nil;
if EngineResult.Result is TGocciaObjectValue then
ScriptResult := TGocciaObjectValue(EngineResult.Result);

PopulateFileResult(FileResult, ScriptResult, AReporter, Result);
except
on E: Exception do
Result := MakeErrorFileResult(AFileName, E.Message, AReporter);
MakeErrorFileResult(AFileName, E.Message, AReporter);
end;
finally
if Assigned(TGarbageCollector.Instance) then
Expand All @@ -193,8 +191,8 @@ begin
end;
end;

function CollectBenchmarkFileBytecode(const AFileName: string;
const AReporter: TBenchmarkReporter): TGocciaObjectValue;
procedure CollectBenchmarkFileBytecode(const AFileName: string;
const AReporter: TBenchmarkReporter);
var
Source: TStringList;
SourceText: string;
Expand All @@ -205,6 +203,7 @@ var
ProgramNode: TGocciaProgram;
Module: TSouffleBytecodeModule;
Backend: TGocciaSouffleBackend;
GC: TGarbageCollector;
ResultValue: TGocciaValue;
FileResult: TBenchmarkFileResult;
ScriptResult: TGocciaObjectValue;
Expand Down Expand Up @@ -263,11 +262,19 @@ begin
FileResult.CompileTimeNanoseconds := CompileEnd - CompileStart;
FileResult.ExecuteTimeNanoseconds := ExecEnd - CompileEnd;

GC := TGarbageCollector.Instance;
if Assigned(ResultValue) and Assigned(GC) then
GC.AddTempRoot(ResultValue);

ScriptResult := nil;
if ResultValue is TGocciaObjectValue then
ScriptResult := TGocciaObjectValue(ResultValue);

PopulateFileResult(FileResult, ScriptResult, AReporter, Result);
try
PopulateFileResult(FileResult, ScriptResult, AReporter);
finally
if Assigned(ResultValue) and Assigned(GC) then
GC.RemoveTempRoot(ResultValue);
end;
finally
Module.Free;
end;
Expand All @@ -276,7 +283,7 @@ begin
end;
except
on E: Exception do
Result := MakeErrorFileResult(AFileName, E.Message, AReporter);
MakeErrorFileResult(AFileName, E.Message, AReporter);
end;
finally
if Assigned(TGarbageCollector.Instance) then
Expand All @@ -285,12 +292,12 @@ begin
end;
end;

function CollectBenchmarkFile(const AFileName: string;
const AReporter: TBenchmarkReporter): TGocciaObjectValue;
procedure CollectBenchmarkFile(const AFileName: string;
const AReporter: TBenchmarkReporter);
begin
case GMode of
ebTreeWalk: Result := CollectBenchmarkFileInterpreted(AFileName, AReporter);
ebSouffleVM: Result := CollectBenchmarkFileBytecode(AFileName, AReporter);
ebTreeWalk: CollectBenchmarkFileInterpreted(AFileName, AReporter);
ebSouffleVM: CollectBenchmarkFileBytecode(AFileName, AReporter);
else
raise Exception.CreateFmt('Unsupported execution backend: %d', [Ord(GMode)]);
end;
Expand Down
11 changes: 0 additions & 11 deletions units/Goccia.Runtime.Operations.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3629,16 +3629,12 @@ function TGocciaRuntimeOperations.GetIterator(
if GocciaVal is TGocciaMapValue then
begin
Iterator := TGocciaMapIteratorValue.Create(GocciaVal, mkEntries);
if Assigned(TGarbageCollector.Instance) then
TGarbageCollector.Instance.AddTempRoot(Iterator);
Result := WrapGocciaValue(Iterator);
Exit;
end;
if GocciaVal is TGocciaSetValue then
begin
Iterator := TGocciaSetIteratorValue.Create(GocciaVal, skValues);
if Assigned(TGarbageCollector.Instance) then
TGarbageCollector.Instance.AddTempRoot(Iterator);
Result := WrapGocciaValue(Iterator);
Exit;
end;
Expand Down Expand Up @@ -3666,8 +3662,6 @@ function TGocciaRuntimeOperations.GetIterator(
end;
if Assigned(IteratorObj) then
begin
if Assigned(TGarbageCollector.Instance) then
TGarbageCollector.Instance.AddTempRoot(IteratorObj);
Result := WrapGocciaValue(IteratorObj);
Exit;
end;
Expand Down Expand Up @@ -3716,8 +3710,6 @@ function TGocciaRuntimeOperations.GetIterator(
Exit;
end;

if Assigned(TGarbageCollector.Instance) then
TGarbageCollector.Instance.AddTempRoot(Iterator);
Result := WrapGocciaValue(Iterator);
except
on E: TGocciaThrowValue do
Expand Down Expand Up @@ -7973,9 +7965,6 @@ function TGocciaRuntimeOperations.FinalizeEnum(const ARecord: TSouffleValue;
EnumObj.PreventExtensions;
InitializeEnumSymbols(EnumObj);

if Assigned(TGarbageCollector.Instance) then
TGarbageCollector.Instance.AddTempRoot(EnumObj);

Result := WrapGocciaValue(EnumObj);
except
on E: TGocciaThrowValue do
Expand Down