Commit fb9b2300 fb9b2300d7d135986c60e0de26dcdbfb4630ecf5 by Sergey Poznyakoff

Documented boolean shortcuts

1 parent 5c0e78e8
1 1
2 1. Overview 2 * Overview
3 3
4 A compiled sieve program consists of a sequence of cells. Each cell 4 A compiled sieve program consists of a sequence of cells. Each cell
5 is a pointer to sieve_op_t data, i.e. it points to an instruction handler 5 is a pointer to sieve_op_t data, i.e. it points to an instruction handler
...@@ -13,55 +13,67 @@ the cell contents, interprets it as address of an instruction handler, ...@@ -13,55 +13,67 @@ the cell contents, interprets it as address of an instruction handler,
13 increments the program counter and executes the handler. The evaluator 13 increments the program counter and executes the handler. The evaluator
14 stops executing the program when it encounters a NULL pointer. 14 stops executing the program when it encounters a NULL pointer.
15 15
16 When invoked, an instruction handler receives a single argument: a pointer 16 When invoked, the instruction handler receives a single argument: a pointer
17 to the sieve_machine_t structure, describing current runtime environment. 17 to the sieve_machine_t structure, describing current runtime environment.
18 If the handler needs any surplus arguments, it is its responsibility 18 If the handler needs any surplus arguments, it is its responsibility
19 to retrieve them from the program cells immediately following the 19 to retrieve them from the program cells immediately following the
20 handler address and increment the pc value accordingly. 20 handler address and increment the pc value accordingly.
21 21
22 2. Existing handlers 22 * Existing handlers
23 23
24 2.1. Push 24 ** Nop
25
26 Name: instr_nop
27 Arguments: None
28
29 Does nothing
30
31 ** Push
25 32
26 Name: instr_push 33 Name: instr_push
27 Arguments: None 34 Arguments: None
28 35
29 Pushes current numeric register on stack. 36 Pushes current numeric register on stack.
30 37
31 2.2. Pop 38 ** Pop
32 39
33 Name: instr_pop 40 Name: instr_pop
34 Arguments: None 41 Arguments: None
35 42
36 Pops the top of stack value into the numeric register. 43 Pops the top of stack value into the numeric register.
37 44
38 2.3. Unconditional branch 45 ** Unconditional branch
39 46
40 Name: instr_branch 47 Name: instr_branch
41 Arguments: [pc ] (number) Offset of the new cell. 48 Arguments: [pc ] (number) Offset of the new cell.
42 49
43 2.4. Branch if zero 50 ** Branch if zero
44 51
45 Name: instr_brz 52 Name: instr_brz
46 Arguments: [pc ] (number) Offset of the new cell. 53 Arguments: [pc ] (number) Offset of the new cell.
47 54
48 2.5. Logical NOT 55 ** Branch if not zero
56
57 Name: instr_brnz
58 Arguments: [pc ] (number) Offset of the new cell.
59
60 ** Logical NOT
49 61
50 Name: instr_not 62 Name: instr_not
51 Arguments: none 63 Arguments: none
52 64
53 2.6. Logical AND 65 ** Logical AND
54 66
55 Name: instr_allof 67 Name: instr_allof
56 Arguments: [pc ] (number) Number of items to be popped from stack 68 Arguments: [pc ] (number) Number of items to be popped from stack
57 69
58 70
59 2.7. Logical OR 71 ** Logical OR
60 72
61 Name: instr_anyof 73 Name: instr_anyof
62 Arguments: [pc ] (number) Number of items to be popped from stack 74 Arguments: [pc ] (number) Number of items to be popped from stack
63 75
64 2.8. Action handler 76 ** Action handler
65 77
66 Name: instr_action 78 Name: instr_action
67 Arguments: [pc ] (sieve_handler_t*) Pointer to the action handling function. 79 Arguments: [pc ] (sieve_handler_t*) Pointer to the action handling function.
...@@ -69,7 +81,7 @@ Arguments: [pc ] (sieve_handler_t*) Pointer to the action handling function. ...@@ -69,7 +81,7 @@ Arguments: [pc ] (sieve_handler_t*) Pointer to the action handling function.
69 [pc+2] (list_t of sieve_runtime_tag_t) A list of tags. 81 [pc+2] (list_t of sieve_runtime_tag_t) A list of tags.
70 [pc+3] (string) Name of the action (for debugging purposes). 82 [pc+3] (string) Name of the action (for debugging purposes).
71 83
72 2.9. Test handler 84 ** Test handler
73 85
74 Name: instr_test 86 Name: instr_test
75 Arguments: [pc ] (sieve_handler_t*) Pointer to the test handling function. 87 Arguments: [pc ] (sieve_handler_t*) Pointer to the test handling function.
...@@ -77,7 +89,7 @@ Arguments: [pc ] (sieve_handler_t*) Pointer to the test handling function. ...@@ -77,7 +89,7 @@ Arguments: [pc ] (sieve_handler_t*) Pointer to the test handling function.
77 [pc+2] (list_t of sieve_runtime_tag_t) A list of tags. 89 [pc+2] (list_t of sieve_runtime_tag_t) A list of tags.
78 [pc+3] (string) Name of the test (for debugging purposes). 90 [pc+3] (string) Name of the test (for debugging purposes).
79 91
80 3. Conditional statement branching 92 * Conditional statement branching
81 93
82 A simple statement 94 A simple statement
83 95
...@@ -138,3 +150,64 @@ L_END: ...@@ -138,3 +150,64 @@ L_END:
138 150
139 Generally speaking, each ELSIF branch generates a code, similar to usual 151 Generally speaking, each ELSIF branch generates a code, similar to usual
140 IF ... ELSE sequence. 152 IF ... ELSE sequence.
153
154 * Boolean shortcuts
155
156 Boolean shortcuts are implemented for coding ALLOF and ANYOF conditions.
157 The code these produce is shown in the next two subsections. Notice the
158 insertion of the two Nop statement after the last condition. These replace
159 the two slots used by the Brz or Brnz instruction, which would be useless,
160 since the next statement after ALLOF or ANYOF is guaranteed to be a branch
161 statement. This replacement speeds up the execution a little.
162
163 ** ALLOF
164
165 ALLOF(cond1,cond2,cond3)
166
167 # Evaluate cond1
168 .
169 .
170 .
171 brz L_end
172 # Evaluate cond2
173 .
174 .
175 .
176 brz L_end
177 # Evaluate cond3
178 .
179 .
180 .
181 nop
182 nop
183 L_end:
184 .
185
186 ** ANYOF
187
188 ALLOF(cond1,cond2,cond3)
189
190 # Evaluate cond1
191 .
192 .
193 .
194 brnz L_end
195 # Evaluate cond2
196 .
197 .
198 .
199 brnz L_end
200 # Evaluate cond3
201 .
202 .
203 .
204 nop
205 nop
206 L_end:
207 .
208
209
210 Local variables:
211 mode: outline
212 paragraph-separate: "[ ]*$"
213 end:
......