File: def.ref

package info (click to toggle)
cppo 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 588 kB
  • sloc: ml: 2,133; makefile: 54; sh: 11
file content (152 lines) | stat: -rw-r--r-- 3,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 1 "def.cppo"
(* This macro application combinator provides call-by-value
   semantics: the actual argument is evaluated up front and
   its value is bound to a variable, which is passed as an
   argument to the macro [F]. *)

# 10 "def.cppo"
(* Some trivial tests. *)
# 13 "def.cppo"
let forty_one = 
# 13 "def.cppo"
                
  (let __x = ( 41) in  __x )
    (* Multiple lines permitted; no backslash required. *)
 
# 14 "def.cppo"
let forty_two = 
# 14 "def.cppo"
                
  (let __x = (      42  ) in  __x )
    (* Multiple lines permitted; no backslash required. *)
 

# 16 "def.cppo"
(* A [for]-loop macro. *)

# 25 "def.cppo"
(* A [for]-loop macro that performs unrolling. *)

# 47 "def.cppo"
(* In the examples that follow, #scope ... #endscope is used to
   avoid the need to #undefine local macros such as BODY and F. *)

(* Iteration over an array, with a normal loop. *)
let iter f a =

  
# 54 "def.cppo"
  
(
  for __index = 0 to  Array.length a-1 do
     (f a.(__index)) 
  done
)
 

# 57 "def.cppo"
(* Iteration over an array, with an unrolled loop. *)
let unrolled_iter f a =

  
# 61 "def.cppo"
   (
  (* #define can be nested inside #def. *)
  (* #def can be nested inside #def. *)
  let __finish = ( Array.length a) in
  let __index = ref (0) in
  while !__index + 2 <= __finish do
     
  (let __x = ( !__index) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
     
  (let __x = ( !__index + 1) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
    
    __index := !__index +  2
 
  done;
  while !__index < __finish do
     
  (let __x = ( !__index) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
    
    __index := !__index +  1
 
  done
)
 

# 64 "def.cppo"
(* Printing an array, with a normal loop. *)
let print_int_array a =

  
# 68 "def.cppo"
  
(
  for __index = 0 to  Array.length a-1 do
     Printf.printf "%d" a.(__index) 
  done
)
 

# 71 "def.cppo"
(* A higher-order macro that produces a definition of [iter],
   and accepts an arbitrary definition of the macro [LOOP]. *)

# 81 "def.cppo"
(* Some noise, which does not affect the above definitions. *)

# 84 "def.cppo"


  let iter f a =
    
(
  for __index = 0 to  Array.length a-1 do
     (f a.(__index)) 
  done
)
 
 
# 85 "def.cppo"


  let unrolled_iter f a =
     (
  (* #define can be nested inside #def. *)
  (* #def can be nested inside #def. *)
  let __finish = ( Array.length a) in
  let __index = ref (0) in
  while !__index + 2 <= __finish do
     
  (let __x = ( !__index) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
     
  (let __x = ( !__index + 1) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
    
    __index := !__index +  2
 
  done;
  while !__index < __finish do
     
  (let __x = ( !__index) in  (f a.(__x)) )
    (* Multiple lines permitted; no backslash required. *)
  ;
    
    __index := !__index +  1
 
  done
)
 
 

# 87 "def.cppo"
(* Just because we can, undefine BODY. *)