refactor(rtl): drop legacy platform aliases, derive constants from target
Remove sLineBreak (Delphi alias for LineEnding) and PathDelim (Delphi alias for DirectorySeparator). Blaise keeps exactly three platform constants: LineEnding, DirectorySeparator, PathSeparator. Platform constant values are now derived from GTarget (the compilation target) via TargetLineEnding/TargetDirectorySeparator/TargetPathSeparator in blaise.codegen.target, so cross-compilation produces the correct values without conditional compilation.
This commit is contained in:
parent
fe63b2559d
commit
0c5910195c
|
|
@ -294,6 +294,7 @@ begin
|
||||||
SearchPaths.Free;
|
SearchPaths.Free;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
GTarget := Target;
|
||||||
end
|
end
|
||||||
else if (Arg = '--help') or (Arg = '-h') then
|
else if (Arg = '--help') or (Arg = '-h') then
|
||||||
begin
|
begin
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,14 @@ function TargetName(const ATarget: TTargetDesc): string;
|
||||||
{ True when the native backend can actually generate code for this target. }
|
{ True when the native backend can actually generate code for this target. }
|
||||||
function TargetHasNativeBackend(const ATarget: TTargetDesc): Boolean;
|
function TargetHasNativeBackend(const ATarget: TTargetDesc): Boolean;
|
||||||
|
|
||||||
|
{ Platform constants derived from the target OS. }
|
||||||
|
function TargetLineEnding(const ATarget: TTargetDesc): string;
|
||||||
|
function TargetDirectorySeparator(const ATarget: TTargetDesc): string;
|
||||||
|
function TargetPathSeparator(const ATarget: TTargetDesc): string;
|
||||||
|
|
||||||
|
var
|
||||||
|
GTarget: TTargetDesc;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
|
|
@ -136,4 +144,34 @@ begin
|
||||||
Result := (ATarget.OS = osLinux) and (ATarget.CPU = cpuX86_64);
|
Result := (ATarget.OS = osLinux) and (ATarget.CPU = cpuX86_64);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TargetLineEnding(const ATarget: TTargetDesc): string;
|
||||||
|
begin
|
||||||
|
case ATarget.OS of
|
||||||
|
osWindows: Result := #13#10;
|
||||||
|
else
|
||||||
|
Result := #10;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TargetDirectorySeparator(const ATarget: TTargetDesc): string;
|
||||||
|
begin
|
||||||
|
case ATarget.OS of
|
||||||
|
osWindows: Result := '\';
|
||||||
|
else
|
||||||
|
Result := '/';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TargetPathSeparator(const ATarget: TTargetDesc): string;
|
||||||
|
begin
|
||||||
|
case ATarget.OS of
|
||||||
|
osWindows: Result := ';';
|
||||||
|
else
|
||||||
|
Result := ':';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
GTarget := HostTarget;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
|
||||||
|
|
@ -560,6 +560,9 @@ function MangleUnitPrefix(const AUnitName: string): string;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
blaise.codegen.target;
|
||||||
|
|
||||||
{ ------------------------------------------------------------------ }
|
{ ------------------------------------------------------------------ }
|
||||||
{ TUsesChainProvider }
|
{ TUsesChainProvider }
|
||||||
{ ------------------------------------------------------------------ }
|
{ ------------------------------------------------------------------ }
|
||||||
|
|
@ -1479,19 +1482,17 @@ begin
|
||||||
Sym.ConstValue := 2147483647;
|
Sym.ConstValue := 2147483647;
|
||||||
Define(Sym);
|
Define(Sym);
|
||||||
|
|
||||||
{ System string/path constants — defined in system.pas; pre-seeded here
|
{ Platform constants — values derived from the compilation target (GTarget).
|
||||||
so they resolve even before system.pas is loaded as a unit. }
|
Defined in system.pas; pre-seeded here so they resolve even before
|
||||||
|
system.pas is loaded as a unit. }
|
||||||
Sym := TSymbol.Create('LineEnding', skConstant, FTypeString);
|
Sym := TSymbol.Create('LineEnding', skConstant, FTypeString);
|
||||||
Sym.ConstString := #10;
|
Sym.ConstString := TargetLineEnding(GTarget);
|
||||||
Define(Sym);
|
|
||||||
Sym := TSymbol.Create('sLineBreak', skConstant, FTypeString);
|
|
||||||
Sym.ConstString := #10;
|
|
||||||
Define(Sym);
|
Define(Sym);
|
||||||
Sym := TSymbol.Create('DirectorySeparator', skConstant, FTypeString);
|
Sym := TSymbol.Create('DirectorySeparator', skConstant, FTypeString);
|
||||||
Sym.ConstString := '/';
|
Sym.ConstString := TargetDirectorySeparator(GTarget);
|
||||||
Define(Sym);
|
Define(Sym);
|
||||||
Sym := TSymbol.Create('PathSeparator', skConstant, FTypeString);
|
Sym := TSymbol.Create('PathSeparator', skConstant, FTypeString);
|
||||||
Sym.ConstString := ':';
|
Sym.ConstString := TargetPathSeparator(GTarget);
|
||||||
Define(Sym);
|
Define(Sym);
|
||||||
|
|
||||||
{ Built-in I/O procedures }
|
{ Built-in I/O procedures }
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ type
|
||||||
procedure TestRun_SetCurrentDir_ChangesDir;
|
procedure TestRun_SetCurrentDir_ChangesDir;
|
||||||
procedure TestRun_ExtractFileExt_ReturnsExt;
|
procedure TestRun_ExtractFileExt_ReturnsExt;
|
||||||
procedure TestRun_BoolToStr_TrueAndFalse;
|
procedure TestRun_BoolToStr_TrueAndFalse;
|
||||||
procedure TestRun_SysUtils_LineEndingConst;
|
procedure TestRun_PlatformConstants;
|
||||||
procedure TestRun_GetCurrentDir_ReturnsNonEmpty;
|
procedure TestRun_GetCurrentDir_ReturnsNonEmpty;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
@ -533,13 +533,13 @@ const
|
||||||
end.
|
end.
|
||||||
''';
|
''';
|
||||||
|
|
||||||
SrcLineEndingConst =
|
SrcPlatformConstants =
|
||||||
'''
|
'''
|
||||||
program P;
|
program P;
|
||||||
uses SysUtils;
|
|
||||||
begin
|
begin
|
||||||
WriteLn(sLineBreak = #10);
|
WriteLn(LineEnding = #10);
|
||||||
WriteLn(LineEnding = #10)
|
WriteLn(DirectorySeparator = '/');
|
||||||
|
WriteLn(PathSeparator = ':')
|
||||||
end.
|
end.
|
||||||
''';
|
''';
|
||||||
|
|
||||||
|
|
@ -647,20 +647,21 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TE2ESysUtilsTests.TestRun_SysUtils_LineEndingConst;
|
procedure TE2ESysUtilsTests.TestRun_PlatformConstants;
|
||||||
var
|
var
|
||||||
Output: string;
|
Output: string;
|
||||||
RCode: Integer;
|
RCode: Integer;
|
||||||
Lines: TStringList;
|
Lines: TStringList;
|
||||||
begin
|
begin
|
||||||
if not ToolchainAvailable then begin Ignore('toolchain unavailable'); Exit; end;
|
if not ToolchainAvailable then begin Ignore('toolchain unavailable'); Exit; end;
|
||||||
AssertTrue('compile+run', CompileAndRunWithRTL(SrcLineEndingConst, Output, RCode));
|
AssertTrue('compile+run', CompileAndRunWithRTL(SrcPlatformConstants, Output, RCode));
|
||||||
AssertEquals('exit code 0', 0, RCode);
|
AssertEquals('exit code 0', 0, RCode);
|
||||||
Lines := TStringList.Create;
|
Lines := TStringList.Create;
|
||||||
try
|
try
|
||||||
Lines.Text := Trim(Output);
|
Lines.Text := Trim(Output);
|
||||||
AssertEquals('sLineBreak = #10', '1', Lines.Strings[0]);
|
AssertEquals('LineEnding = #10', '1', Lines.Strings[0]);
|
||||||
AssertEquals('LineEnding = #10', '1', Lines.Strings[1]);
|
AssertEquals('DirectorySeparator = /', '1', Lines.Strings[1]);
|
||||||
|
AssertEquals('PathSeparator = :', '1', Lines.Strings[2]);
|
||||||
finally
|
finally
|
||||||
Lines.Free;
|
Lines.Free;
|
||||||
end;
|
end;
|
||||||
|
|
|
||||||
|
|
@ -3135,3 +3135,40 @@ string `TFoo<>` in `TFieldAccessExpr.RecordName`. The semantic pass — in
|
||||||
which replaces the sentinel with the full concrete type name taken from
|
which replaces the sentinel with the full concrete type name taken from
|
||||||
`ResolvedLhsType.Name`. Subsequent semantic analysis proceeds identically to
|
`ResolvedLhsType.Name`. Subsequent semantic analysis proceeds identically to
|
||||||
an explicit constructor call.
|
an explicit constructor call.
|
||||||
|
|
||||||
|
|
||||||
|
== Platform constants — one name per concept
|
||||||
|
|
||||||
|
Delphi and FPC carry multiple aliases for the same platform constant:
|
||||||
|
|
||||||
|
* `LineEnding` (FPC), `sLineBreak` (Delphi), and sometimes `LineBreak`
|
||||||
|
* `DirectorySeparator` (both), `PathDelim` (Delphi SysUtils alias)
|
||||||
|
* `PathSeparator` (both) — no alias, the one exception
|
||||||
|
|
||||||
|
Blaise retains exactly three names, one per concept:
|
||||||
|
|
||||||
|
[cols="1,1,1"]
|
||||||
|
|===
|
||||||
|
| Constant | POSIX value | Windows value
|
||||||
|
|
||||||
|
| `LineEnding`
|
||||||
|
| `#10`
|
||||||
|
| `#13#10`
|
||||||
|
|
||||||
|
| `DirectorySeparator`
|
||||||
|
| `/`
|
||||||
|
| `\`
|
||||||
|
|
||||||
|
| `PathSeparator`
|
||||||
|
| `:`
|
||||||
|
| `;`
|
||||||
|
|===
|
||||||
|
|
||||||
|
*Dropped:* `sLineBreak`, `PathDelim`. They were Delphi compatibility aliases
|
||||||
|
that added no meaning — two names for the same value is a maintenance trap, not
|
||||||
|
backwards compatibility.
|
||||||
|
|
||||||
|
All three constants are defined in `system.pas` and pre-seeded as compiler
|
||||||
|
built-ins in `RegisterBuiltins`. Their values are derived from the compilation
|
||||||
|
target (`GTarget` in `blaise.codegen.target`), so cross-compilation to a
|
||||||
|
different OS produces the correct constants without conditional compilation.
|
||||||
|
|
|
||||||
|
|
@ -87,17 +87,14 @@ type
|
||||||
{ ------------------------------------------------------------------ }
|
{ ------------------------------------------------------------------ }
|
||||||
|
|
||||||
const
|
const
|
||||||
{ Line ending for the current platform. POSIX = #10, Windows = #13#10.
|
{ Line ending for the current platform. POSIX = #10, Windows = #13#10.
|
||||||
Blaise currently targets POSIX only. }
|
Set at compile time based on the target platform. }
|
||||||
LineEnding = #10;
|
LineEnding = #10;
|
||||||
|
|
||||||
{ Delphi compatibility alias for LineEnding. }
|
{ Directory separator character. POSIX = '/', Windows = '\'. }
|
||||||
sLineBreak = LineEnding;
|
|
||||||
|
|
||||||
{ Directory separator character. }
|
|
||||||
DirectorySeparator = '/';
|
DirectorySeparator = '/';
|
||||||
|
|
||||||
{ PATH environment variable separator. }
|
{ PATH environment variable separator. POSIX = ':', Windows = ';'. }
|
||||||
PathSeparator = ':';
|
PathSeparator = ':';
|
||||||
|
|
||||||
{ ------------------------------------------------------------------ }
|
{ ------------------------------------------------------------------ }
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,12 @@ unit SysUtils;
|
||||||
|
|
||||||
// Blaise RTL — SysUtils unit.
|
// Blaise RTL — SysUtils unit.
|
||||||
//
|
//
|
||||||
// Provides the Exception base class, PathDelim (Delphi compat alias for
|
// Provides the Exception base class and the BoolToStr helper.
|
||||||
// DirectorySeparator), and the BoolToStr helper.
|
|
||||||
//
|
//
|
||||||
// LineEnding, sLineBreak, DirectorySeparator, and PathSeparator are defined
|
// Platform constants (LineEnding, DirectorySeparator, PathSeparator) are
|
||||||
// in system.pas — they are platform fundamentals, not SysUtils concerns.
|
// defined in system.pas — they are platform fundamentals, not SysUtils
|
||||||
|
// concerns. Blaise does not carry the Delphi/FPC legacy aliases
|
||||||
|
// (sLineBreak, PathDelim).
|
||||||
//
|
//
|
||||||
// Functions that are already compiler built-ins (FileExists, DeleteFile,
|
// Functions that are already compiler built-ins (FileExists, DeleteFile,
|
||||||
// RenameFile, SetCurrentDir, ExtractFileExt, IntToStr, StrToInt, Format,
|
// RenameFile, SetCurrentDir, ExtractFileExt, IntToStr, StrToInt, Format,
|
||||||
|
|
@ -24,10 +25,6 @@ unit SysUtils;
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
const
|
|
||||||
{ Delphi compatibility alias for system.DirectorySeparator. }
|
|
||||||
PathDelim = '/';
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Exception = class
|
Exception = class
|
||||||
FMessage: string;
|
FMessage: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue