Skip to content

Commit

Permalink
Refactored dynamic arrays + initial JIT x86-64 support
Browse files Browse the repository at this point in the history
Array indices upgraded from Integer to NativeInt
  • Loading branch information
EricGrange committed Mar 8, 2021
1 parent dbaeaf3 commit 69b5c13
Show file tree
Hide file tree
Showing 21 changed files with 1,875 additions and 1,079 deletions.
8 changes: 4 additions & 4 deletions Source/SourceUtils/dwsCaseNormalizer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ TSymbolLocation = class (TRefCountedObject)
end;

TSymbolLocations = class(TObjectList<TSymbolLocation>)
function CompareLocations(a, b : Integer) : Integer;
procedure Swap(a, b : Integer);
function CompareLocations(a, b : NativeInt) : Integer;
procedure Swap(a, b : NativeInt);
end;

// CompareLocations
//
function TSymbolLocations.CompareLocations(a, b : Integer) : Integer;
function TSymbolLocations.CompareLocations(a, b : NativeInt) : Integer;
var
locA, locB : TSymbolLocation;
begin
Expand All @@ -71,7 +71,7 @@ function TSymbolLocations.CompareLocations(a, b : Integer) : Integer;

// Swap
//
procedure TSymbolLocations.Swap(a, b : Integer);
procedure TSymbolLocations.Swap(a, b : NativeInt);
var
tmp : TSymbolLocation;
begin
Expand Down
124 changes: 62 additions & 62 deletions Source/dwsArrayElementContext.pas
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,54 @@ interface
TArrayElementDataContext = class (TInterfacedObject, IDataContext)
private
FArray : IScriptDynArray;
FIndex : Integer;
FIndex : NativeInt;
FElementSize : Integer;
FBase : Integer;
FBase : NativeInt;

protected
function GetSelf : TObject;

function ComputeAddr(addr : Integer) : Integer; inline;
function ComputeAddr(addr : NativeInt) : NativeInt; inline;

function GetAsVariant(addr : Integer) : Variant;
procedure SetAsVariant(addr : Integer; const value : Variant);
function GetAsInteger(addr : Integer) : Int64;
procedure SetAsInteger(addr : Integer; const value : Int64);
function GetAsFloat(addr : Integer) : Double;
procedure SetAsFloat(addr : Integer; const value : Double);
function GetAsBoolean(addr : Integer) : Boolean;
procedure SetAsBoolean(addr : Integer; const value : Boolean);
function GetAsString(addr : Integer) : String;
procedure SetAsString(addr : Integer; const value : String);
function GetAsInterface(addr : Integer) : IUnknown;
procedure SetAsInterface(addr : Integer; const value : IUnknown);
function GetAsVariant(addr : NativeInt) : Variant;
procedure SetAsVariant(addr : NativeInt; const value : Variant);
function GetAsInteger(addr : NativeInt) : Int64;
procedure SetAsInteger(addr : NativeInt; const value : Int64);
function GetAsFloat(addr : NativeInt) : Double;
procedure SetAsFloat(addr : NativeInt; const value : Double);
function GetAsBoolean(addr : NativeInt) : Boolean;
procedure SetAsBoolean(addr : NativeInt; const value : Boolean);
function GetAsString(addr : NativeInt) : String;
procedure SetAsString(addr : NativeInt; const value : String);
function GetAsInterface(addr : NativeInt) : IUnknown;
procedure SetAsInterface(addr : NativeInt; const value : IUnknown);

function Addr : Integer;
function DataLength : Integer;
function Addr : NativeInt;
function DataLength : NativeInt;

function AsPData : PData;

procedure CreateOffset(offset : Integer; var result : IDataContext);
procedure CreateOffset(offset : NativeInt; var result : IDataContext);

procedure EvalAsVariant(addr : Integer; var result : Variant);
procedure EvalAsString(addr : Integer; var result : String);
procedure EvalAsInterface(addr : Integer; var result : IUnknown);
procedure EvalAsVariant(addr : NativeInt; var result : Variant);
procedure EvalAsString(addr : NativeInt; var result : String);
procedure EvalAsInterface(addr : NativeInt; var result : IUnknown);

function IsEmpty(addr : Integer) : Boolean;
function VarType(addr : Integer) : TVarType;
function IsEmpty(addr : NativeInt) : Boolean;
function VarType(addr : NativeInt) : TVarType;

procedure CopyData(const destData : TData; destAddr, size : Integer);
procedure WriteData(const src : IDataContext; size : Integer); overload;
procedure WriteData(destAddr : Integer; const src : IDataContext; size : Integer); overload;
procedure WriteData(const srcData : TData; srcAddr, size : Integer); overload;
function SameData(addr : Integer; const otherData : TData; otherAddr, size : Integer) : Boolean;
procedure CopyData(const destData : TData; destAddr, size : NativeInt);
procedure WriteData(const src : IDataContext; size : NativeInt); overload;
procedure WriteData(destAddr : NativeInt; const src : IDataContext; size : NativeInt); overload;
procedure WriteData(const srcData : TData; srcAddr, size : NativeInt); overload;
function SameData(addr : NativeInt; const otherData : TData; otherAddr, size : NativeInt) : Boolean;

function IncInteger(addr : Integer; delta : Int64) : Int64;
function IncInteger(addr : NativeInt; delta : Int64) : Int64;

function HashCode(size : Integer) : Cardinal;
function HashCode(size : NativeInt) : Cardinal;

public
constructor Create(const anArray : IScriptDynArray; anIndex : Integer);
constructor Create(const anArray : IScriptDynArray; anIndex : NativeInt);

end;

Expand All @@ -88,7 +88,7 @@ implementation

// Create
//
constructor TArrayElementDataContext.Create(const anArray : IScriptDynArray; anIndex : Integer);
constructor TArrayElementDataContext.Create(const anArray : IScriptDynArray; anIndex : NativeInt);
begin
inherited Create;
if FIndex < 0 then
Expand All @@ -108,7 +108,7 @@ function TArrayElementDataContext.GetSelf : TObject;

// ComputeAddr
//
function TArrayElementDataContext.ComputeAddr(addr : Integer) : Integer;
function TArrayElementDataContext.ComputeAddr(addr : NativeInt) : NativeInt;
begin
Assert(Cardinal(addr) < Cardinal(FElementSize));
if FIndex >= FArray.ArrayLength then
Expand All @@ -118,98 +118,98 @@ function TArrayElementDataContext.ComputeAddr(addr : Integer) : Integer;

// GetAsVariant
//
function TArrayElementDataContext.GetAsVariant(addr : Integer) : Variant;
function TArrayElementDataContext.GetAsVariant(addr : NativeInt) : Variant;
begin
FArray.EvalAsVariant(ComputeAddr(addr), Result);
end;

// SetAsVariant
//
procedure TArrayElementDataContext.SetAsVariant(addr : Integer; const value : Variant);
procedure TArrayElementDataContext.SetAsVariant(addr : NativeInt; const value : Variant);
begin
FArray.SetAsVariant(ComputeAddr(addr), value);
end;

// GetAsInteger
//
function TArrayElementDataContext.GetAsInteger(addr : Integer) : Int64;
function TArrayElementDataContext.GetAsInteger(addr : NativeInt) : Int64;
begin
Result := FArray.AsInteger[ComputeAddr(addr)];
end;

// SetAsInteger
//
procedure TArrayElementDataContext.SetAsInteger(addr : Integer; const value : Int64);
procedure TArrayElementDataContext.SetAsInteger(addr : NativeInt; const value : Int64);
begin
FArray.AsInteger[ComputeAddr(addr)] := value;
end;

// GetAsFloat
//
function TArrayElementDataContext.GetAsFloat(addr : Integer) : Double;
function TArrayElementDataContext.GetAsFloat(addr : NativeInt) : Double;
begin
Result := FArray.AsFloat[ComputeAddr(addr)];
end;

// SetAsFloat
//
procedure TArrayElementDataContext.SetAsFloat(addr : Integer; const value : Double);
procedure TArrayElementDataContext.SetAsFloat(addr : NativeInt; const value : Double);
begin
FArray.AsFloat[ComputeAddr(addr)] := value;
end;

// GetAsBoolean
//
function TArrayElementDataContext.GetAsBoolean(addr : Integer) : Boolean;
function TArrayElementDataContext.GetAsBoolean(addr : NativeInt) : Boolean;
begin
Result := FArray.AsBoolean[FIndex];
end;

// SetAsBoolean
//
procedure TArrayElementDataContext.SetAsBoolean(addr : Integer; const value : Boolean);
procedure TArrayElementDataContext.SetAsBoolean(addr : NativeInt; const value : Boolean);
begin
FArray.AsBoolean[ComputeAddr(addr)] := value;
end;

// GetAsString
//
function TArrayElementDataContext.GetAsString(addr : Integer) : String;
function TArrayElementDataContext.GetAsString(addr : NativeInt) : String;
begin
FArray.EvalAsString(ComputeAddr(addr), Result);
end;

// SetAsString
//
procedure TArrayElementDataContext.SetAsString(addr : Integer; const value : String);
procedure TArrayElementDataContext.SetAsString(addr : NativeInt; const value : String);
begin
FArray.SetAsString(ComputeAddr(addr), value);
end;

// GetAsInterface
//
function TArrayElementDataContext.GetAsInterface(addr : Integer) : IUnknown;
function TArrayElementDataContext.GetAsInterface(addr : NativeInt) : IUnknown;
begin
FArray.EvalAsInterface(ComputeAddr(addr), Result);
end;

// SetAsInterface
//
procedure TArrayElementDataContext.SetAsInterface(addr : Integer; const value : IUnknown);
procedure TArrayElementDataContext.SetAsInterface(addr : NativeInt; const value : IUnknown);
begin
FArray.SetAsInterface(ComputeAddr(addr), value);
end;

// Addr
//
function TArrayElementDataContext.Addr : Integer;
function TArrayElementDataContext.Addr : NativeInt;
begin
Result := 0;
end;

// DataLength
//
function TArrayElementDataContext.DataLength : Integer;
function TArrayElementDataContext.DataLength : NativeInt;
begin
Result := FElementSize;
end;
Expand All @@ -223,7 +223,7 @@ function TArrayElementDataContext.AsPData : PData;

// CreateOffset
//
procedure TArrayElementDataContext.CreateOffset(offset : Integer; var result : IDataContext);
procedure TArrayElementDataContext.CreateOffset(offset : NativeInt; var result : IDataContext);
var
dc : TArrayElementDataContext;
begin
Expand All @@ -237,54 +237,54 @@ procedure TArrayElementDataContext.CreateOffset(offset : Integer; var result : I

// EvalAsVariant
//
procedure TArrayElementDataContext.EvalAsVariant(addr : Integer; var result : Variant);
procedure TArrayElementDataContext.EvalAsVariant(addr : NativeInt; var result : Variant);
begin
FArray.EvalAsVariant(ComputeAddr(addr), result);
end;

// EvalAsString
//
procedure TArrayElementDataContext.EvalAsString(addr : Integer; var result : String);
procedure TArrayElementDataContext.EvalAsString(addr : NativeInt; var result : String);
begin
FArray.EvalAsString(ComputeAddr(addr), result);
end;

// EvalAsInterface
//
procedure TArrayElementDataContext.EvalAsInterface(addr : Integer; var result : IUnknown);
procedure TArrayElementDataContext.EvalAsInterface(addr : NativeInt; var result : IUnknown);
begin
FArray.EvalAsInterface(ComputeAddr(addr), result);
end;

// IsEmpty
//
function TArrayElementDataContext.IsEmpty(addr : Integer) : Boolean;
function TArrayElementDataContext.IsEmpty(addr : NativeInt) : Boolean;
begin
Result := FArray.IsEmpty(ComputeAddr(addr));
end;

// VarType
//
function TArrayElementDataContext.VarType(addr : Integer) : TVarType;
function TArrayElementDataContext.VarType(addr : NativeInt) : TVarType;
begin
Result := FArray.VarType(ComputeAddr(addr));
end;

// CopyData
//
procedure TArrayElementDataContext.CopyData(const destData : TData; destAddr, size : Integer);
procedure TArrayElementDataContext.CopyData(const destData : TData; destAddr, size : NativeInt);
var
i : Integer;
i : NativeInt;
begin
for i := 0 to size-1 do
FArray.EvalAsVariant(ComputeAddr(i), destData[destAddr+i]);
end;

// WriteData
//
procedure TArrayElementDataContext.WriteData(const src : IDataContext; size : Integer);
procedure TArrayElementDataContext.WriteData(const src : IDataContext; size : NativeInt);
var
p, i : Integer;
p, i : NativeInt;
v : Variant;
begin
p := ComputeAddr(0);
Expand All @@ -296,28 +296,28 @@ procedure TArrayElementDataContext.WriteData(const src : IDataContext; size : In

// WriteData
//
procedure TArrayElementDataContext.WriteData(destAddr : Integer; const src : IDataContext; size : Integer);
procedure TArrayElementDataContext.WriteData(destAddr : NativeInt; const src : IDataContext; size : NativeInt);
begin
raise Exception.Create('TArrayElementDataContext.WriteData(2) not implemented');
end;

// WriteData
//
procedure TArrayElementDataContext.WriteData(const srcData : TData; srcAddr, size : Integer);
procedure TArrayElementDataContext.WriteData(const srcData : TData; srcAddr, size : NativeInt);
begin
raise Exception.Create('TArrayElementDataContext.WriteData(3) not implemented');
end;

// SameData
//
function TArrayElementDataContext.SameData(addr : Integer; const otherData : TData; otherAddr, size : Integer) : Boolean;
function TArrayElementDataContext.SameData(addr : NativeInt; const otherData : TData; otherAddr, size : NativeInt) : Boolean;
begin
raise Exception.Create('TArrayElementDataContext.SameData not implemented');
end;

// IncInteger
//
function TArrayElementDataContext.IncInteger(addr : Integer; delta : Int64) : Int64;
function TArrayElementDataContext.IncInteger(addr : NativeInt; delta : Int64) : Int64;
begin
addr := ComputeAddr(addr);
Result := FArray.AsInteger[addr] + delta;
Expand All @@ -326,7 +326,7 @@ function TArrayElementDataContext.IncInteger(addr : Integer; delta : Int64) : In

// HashCode
//
function TArrayElementDataContext.HashCode(size : Integer) : Cardinal;
function TArrayElementDataContext.HashCode(size : NativeInt) : Cardinal;
begin
Result := FArray.HashCode(ComputeAddr(0), size);
end;
Expand Down
Loading

0 comments on commit 69b5c13

Please sign in to comment.