system.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. {$ifdef FULL_RTL}
  5. {$I systemh.inc}
  6. const
  7. maxExitCode = 65535;
  8. {$else FULL_RTL}
  9. type
  10. integer = longint;
  11. hresult = integer;
  12. ttypekind = integer;
  13. filerec = integer;
  14. textrec = integer;
  15. pbyte = ^byte;
  16. pchar = ^Char;
  17. procedure fpc_lib_exit; compilerproc;
  18. {$endif FULL_RTL}
  19. procedure DebugWrite(const P: PChar);
  20. procedure DebugWriteLn(const P: PChar);
  21. procedure DebugWriteChar(Ch: Char);
  22. procedure DebugWriteHexDigit(d: Byte);
  23. procedure DebugWriteHexByte(b: Byte);
  24. implementation
  25. type
  26. P__wasi_size_t = ^__wasi_size_t;
  27. __wasi_size_t = longint;
  28. __wasi_fd_t = longint;
  29. size_t = longint;
  30. __wasi_errno_t = longint;
  31. P__wasi_ciovec_t = ^__wasi_ciovec_t;
  32. __wasi_ciovec_t = record
  33. buf: pointer;
  34. buf_len: __wasi_size_t;
  35. end;
  36. {$ifdef FULL_RTL}
  37. {$I system.inc}
  38. {$else FULL_RTL}
  39. procedure fpc_lib_exit; compilerproc;
  40. begin
  41. end;
  42. function StrLen(P: PChar): size_t;
  43. var
  44. i: size_t;
  45. begin
  46. i := 0;
  47. while p[i]<>#0 do
  48. Inc(i);
  49. StrLen := i;
  50. end;
  51. {$endif FULL_RTL}
  52. function fd_write(fd: __wasi_fd_t;
  53. iovs: P__wasi_ciovec_t;
  54. iovs_len: size_t;
  55. nwritten: P__wasi_size_t): __wasi_errno_t; external 'wasi_unstable';
  56. procedure DebugWrite(const P: PChar);
  57. var
  58. our_iov: __wasi_ciovec_t;
  59. our_nwritten: longint;
  60. begin
  61. our_iov.buf := P;
  62. our_iov.buf_len := StrLen(P);
  63. fd_write(1, @our_iov, 1, @our_nwritten);
  64. end;
  65. procedure DebugWriteLn(const P: PChar);
  66. begin
  67. DebugWrite(P);
  68. DebugWriteChar(#10);
  69. end;
  70. procedure DebugWriteChar(Ch: Char);
  71. var
  72. CharArr: array [0..1] of Char;
  73. begin
  74. CharArr[0] := Ch;
  75. CharArr[1] := #0;
  76. DebugWrite(@CharArr);
  77. end;
  78. procedure DebugWriteHexDigit(d: Byte);
  79. const
  80. HexDigits: array [0..15] of Char = '0123456789ABCDEF';
  81. begin
  82. DebugWriteChar(HexDigits[d]);
  83. end;
  84. procedure DebugWriteHexByte(b: Byte);
  85. begin
  86. DebugWriteHexDigit(b shr 4);
  87. DebugWriteHexDigit(b and 15);
  88. end;
  89. end.