Line | |
---|

1 | (* Pasted from Pottier's PP compiler *) |
---|

2 | |
---|

3 | let (+) = |
---|

4 | Int32.add |
---|

5 | |
---|

6 | let (-) = |
---|

7 | Int32.sub |
---|

8 | |
---|

9 | let ( * ) = |
---|

10 | Int32.mul |
---|

11 | |
---|

12 | let (/) = |
---|

13 | Int32.div |
---|

14 | |
---|

15 | let (mod) = |
---|

16 | Int32.rem |
---|

17 | |
---|

18 | let max_int = |
---|

19 | Int32.max_int |
---|

20 | |
---|

21 | let min_int = |
---|

22 | Int32.min_int |
---|

23 | |
---|

24 | let (land) = |
---|

25 | Int32.logand |
---|

26 | |
---|

27 | let (lor) = |
---|

28 | Int32.logor |
---|

29 | |
---|

30 | let (lxor) = |
---|

31 | Int32.logxor |
---|

32 | |
---|

33 | let (lsl) = |
---|

34 | Int32.shift_left |
---|

35 | |
---|

36 | let (asr) = |
---|

37 | Int32.shift_right |
---|

38 | |
---|

39 | let (lsr) = |
---|

40 | Int32.shift_right_logical |
---|

41 | |
---|

42 | let (~-) = |
---|

43 | Int32.neg |
---|

44 | |
---|

45 | let negative c = |
---|

46 | c < 0 |
---|

47 | |
---|

48 | let nonpositive c = |
---|

49 | c <= 0 |
---|

50 | |
---|

51 | let (<=) i1 i2 = |
---|

52 | nonpositive (Int32.compare i1 i2) |
---|

53 | |
---|

54 | let (<) i1 i2 = |
---|

55 | negative (Int32.compare i1 i2) |
---|

56 | |
---|

57 | let (>=) i1 i2 = |
---|

58 | i2 <= i1 |
---|

59 | |
---|

60 | let (>) i1 i2 = |
---|

61 | i2 < i1 |
---|

62 | |
---|

63 | let fits16 i = |
---|

64 | let two15 = 1l lsl 15 in |
---|

65 | i >= -two15 && i < two15 |
---|

66 | |
---|

67 | let rec is_power_of_two i = |
---|

68 | if i <= 0l then |
---|

69 | false |
---|

70 | else |
---|

71 | match i with |
---|

72 | | 1l -> |
---|

73 | true |
---|

74 | | _ -> |
---|

75 | i mod 2l = 0l && is_power_of_two (i / 2l) |
---|

76 | |
---|

77 | let rec log2 i = |
---|

78 | assert (i > 0l); |
---|

79 | match i with |
---|

80 | | 1l -> |
---|

81 | 0l |
---|

82 | | _ -> |
---|

83 | 1l + log2 (i / 2l) |
---|

84 | |
---|

85 | let rec exp2 i = |
---|

86 | if i = 0l then |
---|

87 | 1l |
---|

88 | else |
---|

89 | let p = exp2 (i / 2l) in |
---|

90 | let p = p * p in |
---|

91 | if i mod 2l = 0l then |
---|

92 | p |
---|

93 | else |
---|

94 | p * 2l |
---|

95 | |
---|

96 | let max i1 i2 = |
---|

97 | if i1 < i2 then i2 else i1 |
---|

98 | |
---|

99 | module Array = struct |
---|

100 | |
---|

101 | let make i v = |
---|

102 | Array.make (Int32.to_int i) v |
---|

103 | |
---|

104 | let init i f = |
---|

105 | Array.init (Int32.to_int i) (fun j -> f (Int32.of_int j)) |
---|

106 | |
---|

107 | let get a i = |
---|

108 | Array.get a (Int32.to_int i) |
---|

109 | |
---|

110 | let set a i v = |
---|

111 | Array.set a (Int32.to_int i) v |
---|

112 | |
---|

113 | let length a = |
---|

114 | Int32.of_int (Array.length a) |
---|

115 | |
---|

116 | end |
---|

**Note:** See

TracBrowser
for help on using the repository browser.