Keywords as basic scalar type
This commit is contained in:
@@ -11,20 +11,8 @@ uses
|
||||
Myc.Data.Keyword;
|
||||
|
||||
type
|
||||
TDataValueKind = (
|
||||
vkVoid,
|
||||
vkScalar,
|
||||
vkText,
|
||||
vkKeyword,
|
||||
vkSeries,
|
||||
vkRecordSeries,
|
||||
vkRecord,
|
||||
vkManagedObject,
|
||||
vkMethod,
|
||||
vkInterface,
|
||||
vkPointer,
|
||||
vkGeneric
|
||||
);
|
||||
TDataValueKind =
|
||||
(vkVoid, vkScalar, vkText, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkPointer, vkGeneric);
|
||||
|
||||
TDataValue = record
|
||||
type
|
||||
@@ -60,7 +48,6 @@ type
|
||||
class operator Implicit(const AValue: TScalar): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: TDataValue): TScalar; overload; inline;
|
||||
class operator Implicit(const AValue: String): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: IKeyword): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: TDataValue.TFunc): TDataValue; overload; inline;
|
||||
class operator Implicit(const AValue: TObject): TDataValue; overload; inline;
|
||||
|
||||
@@ -82,12 +69,10 @@ type
|
||||
class function FromRecordSeries(const AValue: IRecordSeries): TDataValue; static; inline;
|
||||
class function FromRecord(const [ref] AValue: TScalarRecord): TDataValue; static; inline;
|
||||
class function FromSeries(const AValue: ISeries): TDataValue; static; inline;
|
||||
class function FromKeyword(const AValue: IKeyword): TDataValue; static; inline;
|
||||
|
||||
function AsScalar: TScalar; inline;
|
||||
function AsMethod: TFunc; inline;
|
||||
function AsText: String; inline;
|
||||
function AsKeyword: IKeyword; inline;
|
||||
function AsRecordSeries: IRecordSeries; inline;
|
||||
function AsRecord: TScalarRecord; inline;
|
||||
function AsSeries: ISeries; inline;
|
||||
@@ -187,13 +172,6 @@ begin
|
||||
Result := Pointer(FScalar.Value.AsInt64);
|
||||
end;
|
||||
|
||||
function TDataValue.AsKeyword: IKeyword;
|
||||
begin
|
||||
if (FKind <> vkKeyword) then
|
||||
raise EInvalidCast.Create('Cannot read value as Keyword.');
|
||||
Result := IKeyword(FInterface);
|
||||
end;
|
||||
|
||||
function TDataValue.AsRecord: TScalarRecord;
|
||||
begin
|
||||
if (FKind <> vkRecord) then
|
||||
@@ -248,7 +226,7 @@ begin
|
||||
case FKind of
|
||||
vkScalar:
|
||||
case FScalar.Kind of
|
||||
TScalar.TKind.Ordinal:
|
||||
TScalar.TKind.Ordinal, TScalar.TKind.Keyword:
|
||||
Result :=
|
||||
TInterlocked
|
||||
.CompareExchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64, Expected.AsScalar.Value.AsInt64)
|
||||
@@ -264,7 +242,7 @@ begin
|
||||
TInterlocked.CompareExchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64, Expected.AsScalar.Value.AsInt64)
|
||||
= Expected.AsScalar.Value.AsInt64;
|
||||
|
||||
vkText, vkKeyword, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
vkText, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
Result := IntfCompareExchange(FInterface, NewValue.FInterface, Expected.FInterface) = Expected.FInterface;
|
||||
end;
|
||||
end;
|
||||
@@ -281,12 +259,6 @@ begin
|
||||
Result.FInterface := TVal<T>.Create(AValue);
|
||||
end;
|
||||
|
||||
class function TDataValue.FromKeyword(const AValue: IKeyword): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkKeyword;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
class function TDataValue.FromPtr(const AValue: Pointer): TDataValue;
|
||||
begin
|
||||
Assert(sizeof(Pointer) <= sizeof(Int64));
|
||||
@@ -325,12 +297,6 @@ begin
|
||||
Result.FInterface := TVal<String>.Create(AValue);
|
||||
end;
|
||||
|
||||
class operator TDataValue.Implicit(const AValue: IKeyword): TDataValue;
|
||||
begin
|
||||
Result.FKind := vkKeyword;
|
||||
Result.FInterface := AValue;
|
||||
end;
|
||||
|
||||
function TDataValue.GetIsVoid: Boolean;
|
||||
begin
|
||||
Result := FKind = vkVoid;
|
||||
@@ -364,12 +330,13 @@ begin
|
||||
case FKind of
|
||||
vkScalar:
|
||||
case FScalar.Kind of
|
||||
TScalar.TKind.Ordinal: Result := TInterlocked.Exchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64);
|
||||
TScalar.TKind.Ordinal, TScalar.TKind.Keyword:
|
||||
Result := TInterlocked.Exchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64);
|
||||
TScalar.TKind.Float: Result := TInterlocked.Exchange(FScalar.Value.AsDouble, NewValue.AsScalar.Value.AsDouble);
|
||||
end;
|
||||
vkPointer: Result := TInterlocked.Exchange(FScalar.Value.AsInt64, NewValue.AsScalar.Value.AsInt64);
|
||||
|
||||
vkText, vkKeyword, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
vkText, vkSeries, vkRecordSeries, vkRecord, vkManagedObject, vkMethod, vkInterface, vkGeneric:
|
||||
begin
|
||||
Result.FKind := FKind;
|
||||
Result.FInterface := IntfExchange(FInterface, NewValue.FInterface);
|
||||
@@ -386,7 +353,6 @@ begin
|
||||
case FKind of
|
||||
vkScalar: Result := FScalar.ToString;
|
||||
vkText: Result := '"' + AsText + '"';
|
||||
vkKeyword: Result := ':' + AsKeyword.Name;
|
||||
vkSeries:
|
||||
begin
|
||||
var series := AsSeries;
|
||||
@@ -490,7 +456,6 @@ begin
|
||||
vkVoid: Result := 'Void';
|
||||
vkScalar: Result := 'Scalar';
|
||||
vkText: Result := 'Text';
|
||||
vkKeyword: Result := 'Keyword';
|
||||
vkSeries: Result := 'Series';
|
||||
vkRecordSeries: Result := 'RecordSeries';
|
||||
vkRecord: Result := 'Record';
|
||||
|
||||
Reference in New Issue
Block a user