system.pp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. {$ifdef FULL_RTL}
  5. {$I systemh.inc}
  6. const
  7. LineEnding = #10;
  8. LFNSupport = true;
  9. DirectorySeparator = '/';
  10. DriveSeparator = '';
  11. ExtensionSeparator = '.';
  12. PathSeparator = ':';
  13. AllowDirectorySeparators : set of char = ['\','/'];
  14. AllowDriveSeparators : set of char = [];
  15. { FileNameCaseSensitive and FileNameCasePreserving are defined below! }
  16. maxExitCode = 65535;
  17. MaxPathLen = 4096;
  18. AllFilesMask = '*';
  19. const
  20. UnusedHandle = -1;
  21. StdInputHandle = 0;
  22. StdOutputHandle = 1;
  23. StdErrorHandle = 2;
  24. FileNameCaseSensitive : boolean = true;
  25. FileNameCasePreserving: boolean = true;
  26. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  27. sLineBreak = LineEnding;
  28. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  29. {$else FULL_RTL}
  30. type
  31. integer = longint;
  32. hresult = integer;
  33. ttypekind = integer;
  34. filerec = integer;
  35. textrec = integer;
  36. pbyte = ^byte;
  37. pchar = ^Char;
  38. procedure fpc_lib_exit; compilerproc;
  39. {$endif FULL_RTL}
  40. procedure DebugWrite(const P: PChar);
  41. procedure DebugWriteLn(const P: PChar);
  42. procedure DebugWriteChar(Ch: Char);
  43. procedure DebugWriteHexDigit(d: Byte);
  44. procedure DebugWriteHexByte(b: Byte);
  45. implementation
  46. type
  47. P__wasi_size_t = ^__wasi_size_t;
  48. __wasi_size_t = longint;
  49. __wasi_fd_t = longint;
  50. size_t = longint;
  51. __wasi_errno_t = longint;
  52. P__wasi_ciovec_t = ^__wasi_ciovec_t;
  53. __wasi_ciovec_t = record
  54. buf: pointer;
  55. buf_len: __wasi_size_t;
  56. end;
  57. {$ifdef FULL_RTL}
  58. {$I system.inc}
  59. function GetProcessID: SizeUInt;
  60. begin
  61. end;
  62. Procedure Randomize;
  63. Begin
  64. End;
  65. procedure System_exit;
  66. begin
  67. DebugWriteLn('System_exit');
  68. End;
  69. Function ParamCount: Longint;
  70. Begin
  71. End;
  72. function paramstr(l: longint) : string;
  73. begin
  74. end;
  75. procedure SysInitStdIO;
  76. begin
  77. // OpenStdIO(Input,fmInput,StdInputHandle);
  78. // OpenStdIO(Output,fmOutput,StdOutputHandle);
  79. // OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  80. // OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  81. // OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  82. end;
  83. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  84. begin
  85. end;
  86. {$else FULL_RTL}
  87. procedure fpc_lib_exit; compilerproc;
  88. begin
  89. end;
  90. function StrLen(P: PChar): size_t;
  91. var
  92. i: size_t;
  93. begin
  94. i := 0;
  95. while p[i]<>#0 do
  96. Inc(i);
  97. StrLen := i;
  98. end;
  99. {$endif FULL_RTL}
  100. function fd_write(fd: __wasi_fd_t;
  101. iovs: P__wasi_ciovec_t;
  102. iovs_len: size_t;
  103. nwritten: P__wasi_size_t): __wasi_errno_t; external 'wasi_unstable';
  104. procedure DebugWrite(const P: PChar);
  105. var
  106. our_iov: __wasi_ciovec_t;
  107. our_nwritten: longint;
  108. begin
  109. our_iov.buf := P;
  110. our_iov.buf_len := StrLen(P);
  111. fd_write(1, @our_iov, 1, @our_nwritten);
  112. end;
  113. procedure DebugWriteLn(const P: PChar);
  114. begin
  115. DebugWrite(P);
  116. DebugWriteChar(#10);
  117. end;
  118. procedure DebugWriteChar(Ch: Char);
  119. var
  120. CharArr: array [0..1] of Char;
  121. begin
  122. CharArr[0] := Ch;
  123. CharArr[1] := #0;
  124. DebugWrite(@CharArr);
  125. end;
  126. procedure DebugWriteHexDigit(d: Byte);
  127. const
  128. HexDigits: array [0..15] of Char = '0123456789ABCDEF';
  129. begin
  130. DebugWriteChar(HexDigits[d]);
  131. end;
  132. procedure DebugWriteHexByte(b: Byte);
  133. begin
  134. DebugWriteHexDigit(b shr 4);
  135. DebugWriteHexDigit(b and 15);
  136. end;
  137. begin
  138. DebugWriteLn('System unit initialization start');
  139. { To be set if this is a GUI or console application }
  140. IsConsole := TRUE;
  141. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  142. { If dynlibs feature is disabled,
  143. IsLibrary is a constant, which can thus not be set to a value }
  144. { To be set if this is a library and not a program }
  145. IsLibrary := FALSE;
  146. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  147. { Setup heap }
  148. InitHeap;
  149. SysInitExceptions;
  150. initunicodestringmanager;
  151. { Setup stdin, stdout and stderr }
  152. SysInitStdIO;
  153. { Reset IO Error }
  154. InOutRes:=0;
  155. DebugWriteLn('System unit initialization end');
  156. end.