system.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. procedure DebugWriteHexWord(w: Word);
  46. procedure DebugWriteHexLongWord(lw: Word);
  47. implementation
  48. type
  49. P__wasi_size_t = ^__wasi_size_t;
  50. __wasi_size_t = longint;
  51. __wasi_fd_t = longint;
  52. size_t = longint;
  53. __wasi_errno_t = longint;
  54. P__wasi_ciovec_t = ^__wasi_ciovec_t;
  55. __wasi_ciovec_t = record
  56. buf: pointer;
  57. buf_len: __wasi_size_t;
  58. end;
  59. {$ifdef FULL_RTL}
  60. {$I system.inc}
  61. function GetProcessID: SizeUInt;
  62. begin
  63. end;
  64. Procedure Randomize;
  65. Begin
  66. End;
  67. procedure System_exit;
  68. begin
  69. DebugWriteLn('System_exit');
  70. repeat
  71. until false;
  72. End;
  73. Function ParamCount: Longint;
  74. Begin
  75. End;
  76. function paramstr(l: longint) : string;
  77. begin
  78. end;
  79. procedure SysInitStdIO;
  80. begin
  81. OpenStdIO(Input,fmInput,StdInputHandle);
  82. OpenStdIO(Output,fmOutput,StdOutputHandle);
  83. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  84. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  85. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  86. end;
  87. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  88. begin
  89. end;
  90. {$else FULL_RTL}
  91. procedure fpc_lib_exit; compilerproc;
  92. begin
  93. end;
  94. function StrLen(P: PChar): size_t;
  95. var
  96. i: size_t;
  97. begin
  98. i := 0;
  99. while p[i]<>#0 do
  100. Inc(i);
  101. StrLen := i;
  102. end;
  103. {$endif FULL_RTL}
  104. function fd_write(fd: __wasi_fd_t;
  105. iovs: P__wasi_ciovec_t;
  106. iovs_len: size_t;
  107. nwritten: P__wasi_size_t): __wasi_errno_t; external 'wasi_unstable';
  108. procedure DebugWrite(const P: PChar);
  109. var
  110. our_iov: __wasi_ciovec_t;
  111. our_nwritten: longint;
  112. begin
  113. our_iov.buf := P;
  114. our_iov.buf_len := StrLen(P);
  115. fd_write(1, @our_iov, 1, @our_nwritten);
  116. end;
  117. procedure DebugWriteLn(const P: PChar);
  118. begin
  119. DebugWrite(P);
  120. DebugWriteChar(#10);
  121. end;
  122. procedure DebugWriteChar(Ch: Char);
  123. var
  124. CharArr: array [0..1] of Char;
  125. begin
  126. CharArr[0] := Ch;
  127. CharArr[1] := #0;
  128. DebugWrite(@CharArr);
  129. end;
  130. procedure DebugWriteHexDigit(d: Byte);
  131. const
  132. HexDigits: array [0..15] of Char = '0123456789ABCDEF';
  133. begin
  134. DebugWriteChar(HexDigits[d]);
  135. end;
  136. procedure DebugWriteHexByte(b: Byte);
  137. begin
  138. DebugWriteHexDigit(b shr 4);
  139. DebugWriteHexDigit(b and 15);
  140. end;
  141. procedure DebugWriteHexWord(w: Word);
  142. begin
  143. DebugWriteHexByte(w shr 8);
  144. DebugWriteHexByte(Byte(w));
  145. end;
  146. procedure DebugWriteHexLongWord(lw: Word);
  147. begin
  148. DebugWriteHexWord(lw shr 16);
  149. DebugWriteHexWord(Word(lw));
  150. end;
  151. begin
  152. DebugWriteLn('System unit initialization start');
  153. { To be set if this is a GUI or console application }
  154. IsConsole := TRUE;
  155. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  156. { If dynlibs feature is disabled,
  157. IsLibrary is a constant, which can thus not be set to a value }
  158. { To be set if this is a library and not a program }
  159. IsLibrary := FALSE;
  160. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  161. { Setup heap }
  162. InitHeap;
  163. SysInitExceptions;
  164. initunicodestringmanager;
  165. { Setup stdin, stdout and stderr }
  166. SysInitStdIO;
  167. { Reset IO Error }
  168. InOutRes:=0;
  169. DebugWriteLn('System unit initialization end');
  170. end.