Fix in RTL-Core
This commit is contained in:
@@ -216,6 +216,7 @@ begin
|
||||
+ '### 2. Constraints & Rules'
|
||||
+ sLineBreak
|
||||
+ GenerateGenerationRules;
|
||||
//TODO add 3. RTL
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -7,92 +7,145 @@ uses
|
||||
Myc.Utils,
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Value,
|
||||
Myc.Ast.RTL;
|
||||
Myc.Ast.RTL,
|
||||
Myc.Ast.Attributes;
|
||||
|
||||
type
|
||||
// Contains the "pure" native implementations.
|
||||
TRtlFunctions = record
|
||||
public
|
||||
// (* --- Dynamic Fallbacks (Interpreter) --- *)
|
||||
|
||||
// Arithmetic
|
||||
[TRtlExport('+', Pure)]
|
||||
[AstDoc('Adds two numbers or concatenates two strings.')]
|
||||
class function Add(const Args: TArray<TDataValue>): TDataValue; overload; static;
|
||||
|
||||
[TRtlExport('-', Pure)]
|
||||
[AstDoc('Subtracts B from A, or negates A if called with one argument.')]
|
||||
class function Subtract(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
[TRtlExport('*', Pure)]
|
||||
[AstDoc('Multiplies two numbers.')]
|
||||
class function Multiply(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
[TRtlExport('/', Pure)]
|
||||
[AstDoc('Divides A by B. Returns a Float.')]
|
||||
class function Divide(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
[TRtlExport('div', Pure)]
|
||||
[AstDoc('Integer division.')]
|
||||
class function IntDivide(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
[TRtlExport('mod', Pure)]
|
||||
[AstDoc('Remainder of integer division.')]
|
||||
class function Modulus(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// Comparison
|
||||
[TRtlExport('=', Impure)]
|
||||
[TRtlExport('=', Pure)]
|
||||
[AstDoc('Returns true if A equals B.')]
|
||||
class function Equal(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('<>', Impure)]
|
||||
|
||||
[TRtlExport('<>', Pure)]
|
||||
[AstDoc('Returns true if A is not equal to B.')]
|
||||
class function NotEqual(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('<', Impure)]
|
||||
|
||||
[TRtlExport('<', Pure)]
|
||||
[AstDoc('Returns true if A is less than B.')]
|
||||
class function LessThan(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('<=', Impure)]
|
||||
|
||||
[TRtlExport('<=', Pure)]
|
||||
[AstDoc('Returns true if A is less than or equal to B.')]
|
||||
class function LessThanOrEqual(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('>', Impure)]
|
||||
|
||||
[TRtlExport('>', Pure)]
|
||||
[AstDoc('Returns true if A is greater than B.')]
|
||||
class function GreaterThan(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('>=', Impure)]
|
||||
|
||||
[TRtlExport('>=', Pure)]
|
||||
[AstDoc('Returns true if A is greater than or equal to B.')]
|
||||
class function GreaterThanOrEqual(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// Logic / Bitwise
|
||||
[TRtlExport('not', Impure)]
|
||||
[TRtlExport('not', Pure)]
|
||||
[AstDoc('Logical or bitwise NOT.')]
|
||||
class function LogicalNot(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('and', Impure)]
|
||||
|
||||
[TRtlExport('and', Pure)]
|
||||
[AstDoc('Logical or bitwise AND.')]
|
||||
class function BitwiseAnd(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('or', Impure)]
|
||||
|
||||
[TRtlExport('or', Pure)]
|
||||
[AstDoc('Logical or bitwise OR.')]
|
||||
class function BitwiseOr(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('xor', Impure)]
|
||||
|
||||
[TRtlExport('xor', Pure)]
|
||||
[AstDoc('Logical or bitwise XOR.')]
|
||||
class function BitwiseXor(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('shl', Impure)]
|
||||
|
||||
[TRtlExport('shl', Pure)]
|
||||
[AstDoc('Bitwise shift left.')]
|
||||
class function LeftShift(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('shr', Impure)]
|
||||
|
||||
[TRtlExport('shr', Pure)]
|
||||
[AstDoc('Bitwise shift right.')]
|
||||
class function RightShift(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// (* Dynamic fallbacks for TScalar input *)
|
||||
[TRtlExport('Abs', Impure)]
|
||||
// Math Functions
|
||||
[TRtlExport('Abs', Pure)]
|
||||
[AstDoc('Returns the absolute value.')]
|
||||
class function Abs(const Arg: TScalar): TScalar; static;
|
||||
[TRtlExport('Round', Impure)]
|
||||
|
||||
[TRtlExport('Round', Pure)]
|
||||
[AstDoc('Rounds a float to the nearest integer.')]
|
||||
class function Round(const Arg: TScalar): TScalar; static;
|
||||
[TRtlExport('Trunc', Impure)]
|
||||
|
||||
[TRtlExport('Trunc', Pure)]
|
||||
[AstDoc('Truncates a float to an integer.')]
|
||||
class function Trunc(const Arg: TScalar): TScalar; static;
|
||||
[TRtlExport('Ceil', Impure)]
|
||||
|
||||
[TRtlExport('Ceil', Pure)]
|
||||
[AstDoc('Returns the smallest integer greater than or equal to the argument.')]
|
||||
class function Ceil(const Arg: TScalar): TScalar; static;
|
||||
[TRtlExport('Floor', Impure)]
|
||||
|
||||
[TRtlExport('Floor', Pure)]
|
||||
[AstDoc('Returns the largest integer less than or equal to the argument.')]
|
||||
class function Floor(const Arg: TScalar): TScalar; static;
|
||||
[TRtlExport('Sign', Impure)]
|
||||
|
||||
[TRtlExport('Sign', Pure)]
|
||||
[AstDoc('Returns -1 for negative numbers, 1 for positive numbers, and 0 for zero.')]
|
||||
class function Sign(const Arg: TScalar): TScalar; static;
|
||||
|
||||
// (* DateTime Constructors *)
|
||||
// DateTime
|
||||
[TRtlExport('Now', Impure)]
|
||||
[AstDoc('Returns the current system date and time.')]
|
||||
class function Now(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
[TRtlExport('Date', Impure)]
|
||||
[AstDoc('Returns the current date or constructs a date from (Year, Month, Day).')]
|
||||
class function Date(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// (* Other dynamic functions *)
|
||||
[TRtlExport('Memoize', Impure)]
|
||||
// High-Order / Series
|
||||
[TRtlExport('Memoize', Pure)]
|
||||
[AstDoc('Returns a memoized version of the provided function.')]
|
||||
class function Memoize(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('Map', Impure)]
|
||||
|
||||
[TRtlExport('Map', Pure)]
|
||||
[AstDoc('Maps a function over a series.')]
|
||||
class function Map(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('Reduce', Impure)]
|
||||
|
||||
[TRtlExport('Reduce', Pure)]
|
||||
[AstDoc('Reduces a series using a combining function and an accumulator.')]
|
||||
class function Reduce(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('Where', Impure)]
|
||||
|
||||
[TRtlExport('Where', Pure)]
|
||||
[AstDoc('Filters a series using a predicate function.')]
|
||||
class function Where(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
[TRtlExport('Any', Impure)]
|
||||
|
||||
[TRtlExport('Any', Pure)]
|
||||
[AstDoc('Returns true if any element in the series satisfies the predicate.')]
|
||||
class function Any(const Args: TArray<TDataValue>): TDataValue; static;
|
||||
|
||||
// (* --- Static Specializations (Monomorphization Targets) --- *)
|
||||
// --- Static Specializations (Picked up by TRtlRegistry via attributes) ---
|
||||
|
||||
// Add
|
||||
[TRtlExport('+', Pure)]
|
||||
class function Add_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('+', Pure)]
|
||||
@@ -104,7 +157,6 @@ type
|
||||
[TRtlExport('+', Pure)]
|
||||
class function Add_Text_Text_Text(const A: String; const B: String): String; static;
|
||||
|
||||
// Subtract
|
||||
[TRtlExport('-', Pure)]
|
||||
class function Subtract_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('-', Pure)]
|
||||
@@ -114,7 +166,6 @@ type
|
||||
[TRtlExport('-', Pure)]
|
||||
class function Subtract_Float_Ordinal_Float(A: Double; B: Int64): Double; static;
|
||||
|
||||
// Multiply
|
||||
[TRtlExport('*', Pure)]
|
||||
class function Multiply_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('*', Pure)]
|
||||
@@ -124,23 +175,20 @@ type
|
||||
[TRtlExport('*', Pure)]
|
||||
class function Multiply_Float_Ordinal_Float(A: Double; B: Int64): Double; static;
|
||||
|
||||
// Divide (Impure due to EDivByZero potential)
|
||||
[TRtlExport('/', Impure)]
|
||||
[TRtlExport('/', Pure)]
|
||||
class function Divide_Ordinal_Ordinal_Float(A, B: Int64): Double; static;
|
||||
[TRtlExport('/', Impure)]
|
||||
[TRtlExport('/', Pure)]
|
||||
class function Divide_Float_Float_Float(A, B: Double): Double; static;
|
||||
[TRtlExport('/', Impure)]
|
||||
[TRtlExport('/', Pure)]
|
||||
class function Divide_Ordinal_Float_Float(A: Int64; B: Double): Double; static;
|
||||
[TRtlExport('/', Impure)]
|
||||
[TRtlExport('/', Pure)]
|
||||
class function Divide_Float_Ordinal_Float(A: Double; B: Int64): Double; static;
|
||||
|
||||
// Integer Math (Impure due to EDivByZero)
|
||||
[TRtlExport('div', Impure)]
|
||||
[TRtlExport('div', Pure)]
|
||||
class function Div_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('mod', Impure)]
|
||||
[TRtlExport('mod', Pure)]
|
||||
class function Mod_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
|
||||
// Comparisons
|
||||
[TRtlExport('=', Pure)]
|
||||
class function Equal_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('=', Pure)]
|
||||
@@ -199,7 +247,6 @@ type
|
||||
[TRtlExport('>=', Pure)]
|
||||
class function GreaterOrEqual_Float_Ordinal_Ordinal(A: Double; B: Int64): Int64; static;
|
||||
|
||||
// Bitwise Static
|
||||
[TRtlExport('and', Pure)]
|
||||
class function And_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
[TRtlExport('or', Pure)]
|
||||
@@ -211,26 +258,21 @@ type
|
||||
[TRtlExport('shr', Pure)]
|
||||
class function Shr_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64; static;
|
||||
|
||||
// Unary
|
||||
[TRtlExport('-', Pure)]
|
||||
class function Negate_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
[TRtlExport('-', Pure)]
|
||||
class function Negate_Float_Float(A: Double): Double; static;
|
||||
|
||||
[TRtlExport('not', Pure)]
|
||||
class function Not_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
|
||||
// Standard functions
|
||||
[TRtlExport('Abs', Pure)]
|
||||
class function Abs_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
[TRtlExport('Abs', Pure)]
|
||||
class function Abs_Float_Float(A: Double): Double; static;
|
||||
|
||||
[TRtlExport('Round', Pure)]
|
||||
class function Round_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
[TRtlExport('Round', Pure)]
|
||||
class function Round_Float_Ordinal(A: Double): Int64; static;
|
||||
|
||||
[TRtlExport('Trunc', Pure)]
|
||||
class function Trunc_Ordinal_Ordinal(A: Int64): Int64; static;
|
||||
[TRtlExport('Trunc', Pure)]
|
||||
@@ -278,7 +320,6 @@ class function TRtlFunctions.Divide(const Args: TArray<TDataValue>): TDataValue;
|
||||
begin
|
||||
if Length(Args) <> 2 then
|
||||
raise EArgumentException.Create('Operator / requires 2 arguments.');
|
||||
// Explicit check is handled in TScalar.Divide
|
||||
Result := Args[0].AsScalar / Args[1].AsScalar;
|
||||
end;
|
||||
|
||||
@@ -609,7 +650,6 @@ begin
|
||||
item := sourceSeries.Items[i];
|
||||
predicateResult := predicateFunc([TDataValue(item)]);
|
||||
|
||||
// Use the implicit Boolean operator of TScalar
|
||||
if (predicateResult.Kind = vkScalar) and (Boolean(predicateResult.AsScalar)) then
|
||||
matchingIndices.Add(i);
|
||||
end;
|
||||
@@ -754,7 +794,7 @@ end;
|
||||
class function TRtlFunctions.Div_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64;
|
||||
begin
|
||||
Result := A div B;
|
||||
end; // Delphi runtime handles EDivByZero for integers
|
||||
end;
|
||||
class function TRtlFunctions.Mod_Ordinal_Ordinal_Ordinal(A, B: Int64): Int64;
|
||||
begin
|
||||
Result := A mod B;
|
||||
@@ -906,7 +946,7 @@ end;
|
||||
class function TRtlFunctions.Not_Ordinal_Ordinal(A: Int64): Int64;
|
||||
begin
|
||||
Result := Ord(A = 0);
|
||||
end; // Logical NOT for Int64
|
||||
end;
|
||||
|
||||
// Standard
|
||||
class function TRtlFunctions.Abs_Ordinal_Ordinal(A: Int64): Int64;
|
||||
|
||||
Reference in New Issue
Block a user