AMD64.Builtins.Mod 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. MODULE Builtins; (** AUTHOR "fof"; PURPOSE "Built-in functions for the Active Oberon Compiler"; *)
  2. IMPORT SYSTEM;
  3. VAR
  4. kernelModule-: ARRAY 32 OF ADDRESS;
  5. modules-: LONGINT;
  6. PROCEDURE InsertModule*(a: ADDRESS): BOOLEAN;
  7. BEGIN
  8. kernelModule[modules] := a;
  9. INC(modules);
  10. RETURN TRUE
  11. END InsertModule;
  12. (* compare strings,
  13. returns 0 if strings are equal,
  14. returns +1 if left is lexicographic greater than right,
  15. returns -1 if left is lexicographics smaller than right
  16. traps if src or destination is not 0X terminated and comparison is not finished
  17. *)
  18. PROCEDURE CompareString*(CONST left,right: ARRAY OF CHAR): SHORTINT;
  19. VAR i: LONGINT; res: SHORTINT; l,r: CHAR;
  20. BEGIN
  21. i := 0; res := 0;
  22. LOOP
  23. l := left[i]; (* index check included *)
  24. r := right[i]; (* index check included *)
  25. IF (res = 0) THEN
  26. IF (l > r) THEN
  27. res := 1; EXIT
  28. ELSIF (l<r) THEN
  29. res := -1; EXIT
  30. ELSIF l=0X THEN
  31. EXIT
  32. END;
  33. END;
  34. INC(i);
  35. END;
  36. RETURN res
  37. END CompareString;
  38. (* copy string from src to dest, emits trap if not 0X terminated or destination too short *)
  39. PROCEDURE CopyString*(VAR dest: ARRAY OF CHAR; CONST src: ARRAY OF CHAR);
  40. VAR i: LONGINT; ch :CHAR; l1,l2: LONGINT;
  41. BEGIN
  42. (*
  43. i := 0;
  44. REPEAT
  45. ch := src[i]; (* index check included *)
  46. dest[i] := ch; (* index check included *)
  47. INC(i);
  48. UNTIL ch=0X;
  49. *)
  50. (*! currently implemented: old PACO semantics *)
  51. l1 := LEN(dest);
  52. l2 := LEN(src);
  53. IF l2 < l1 THEN l1 := l2 END;
  54. SYSTEM.MOVE(ADDRESSOF(src[0]),ADDRESSOF(dest[0]),l1);
  55. dest[l1-1] := 0X;
  56. END CopyString;
  57. BEGIN
  58. (*! assumed that modules = 0, implicit call of InsertModule *)
  59. END Builtins.