system.pp 3.8 KB

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