about summary refs log tree commit diff stats
path: root/024compare.cc
blob: 619caa03e8d60be7763f59379f25af57d46101e5 (plain) (blame)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//: Comparison primitives

:(before "End Primitive Recipe Declarations")
EQUAL,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["equal"] = EQUAL;
:(before "End Primitive Recipe Implementations")
case EQUAL: {
  if (SIZE(ingredients) <= 1) {
    raise << current_recipe_name() << ": 'equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
    break;
  }
  vector<double>& exemplar = ingredients.at(0);
  bool result = true;
  for (long long int i = 1; i < SIZE(ingredients); ++i) {
    if (!equal(ingredients.at(i).begin(), ingredients.at(i).end(), exemplar.begin())) {
      result = false;
      break;
    }
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario equal)
recipe main [
  1:number <- copy 34
  2:number <- copy 33
  3:number <- equal 1:number, 2:number
]
+mem: location 1 is 34
+mem: location 2 is 33
+mem: storing 0 in location 3

:(scenario equal_2)
recipe main [
  1:number <- copy 34
  2:number <- copy 34
  3:number <- equal 1:number, 2:number
]
+mem: location 1 is 34
+mem: location 2 is 34
+mem: storing 1 in location 3

:(scenario equal_multiple)
recipe main [
  1:number <- equal 34, 34, 34
]
+mem: storing 1 in location 1

:(scenario equal_multiple_2)
recipe main [
  1:number <- equal 34, 34, 35
]
+mem: storing 0 in location 1

:(before "End Primitive Recipe Declarations")
GREATER_THAN,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["greater-than"] = GREATER_THAN;
:(before "End Primitive Recipe Implementations")
case GREATER_THAN: {
  bool result = true;
  if (SIZE(ingredients) <= 1) {
    raise << current_recipe_name() << ": 'greater-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
    break;
  }
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    if (!scalar(ingredients.at(i))) {
      raise << current_recipe_name() << ": 'greater-than' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end();
      goto finish_greater_than;
    }
  }
  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
    if (ingredients.at(i-1).at(0) <= ingredients.at(i).at(0)) {
      result = false;
    }
  }
  finish_greater_than:
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario greater_than)
recipe main [
  1:number <- copy 34
  2:number <- copy 33
  3:boolean <- greater-than 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario greater_than_2)
recipe main [
  1:number <- copy 34
  2:number <- copy 34
  3:boolean <- greater-than 1:number, 2:number
]
+mem: storing 0 in location 3

:(scenario greater_than_multiple)
recipe main [
  1:boolean <- greater-than 36, 35, 34
]
+mem: storing 1 in location 1

:(scenario greater_than_multiple_2)
recipe main [
  1:boolean <- greater-than 36, 35, 35
]
+mem: storing 0 in location 1

:(before "End Primitive Recipe Declarations")
LESSER_THAN,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["lesser-than"] = LESSER_THAN;
:(before "End Primitive Recipe Implementations")
case LESSER_THAN: {
  bool result = true;
  if (SIZE(ingredients) <= 1) {
    raise << current_recipe_name() << ": 'lesser-than' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
    break;
  }
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    if (!scalar(ingredients.at(i))) {
      raise << current_recipe_name() << ": 'lesser-than' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end();
      goto finish_lesser_than;
    }
  }
  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
    if (ingredients.at(i-1).at(0) >= ingredients.at(i).at(0)) {
      result = false;
    }
  }
  finish_lesser_than:
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario lesser_than)
recipe main [
  1:number <- copy 32
  2:number <- copy 33
  3:boolean <- lesser-than 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario lesser_than_2)
recipe main [
  1:number <- copy 34
  2:number <- copy 33
  3:boolean <- lesser-than 1:number, 2:number
]
+mem: storing 0 in location 3

:(scenario lesser_than_multiple)
recipe main [
  1:boolean <- lesser-than 34, 35, 36
]
+mem: storing 1 in location 1

:(scenario lesser_than_multiple_2)
recipe main [
  1:boolean <- lesser-than 34, 35, 35
]
+mem: storing 0 in location 1

:(before "End Primitive Recipe Declarations")
GREATER_OR_EQUAL,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["greater-or-equal"] = GREATER_OR_EQUAL;
:(before "End Primitive Recipe Implementations")
case GREATER_OR_EQUAL: {
  bool result = true;
  if (SIZE(ingredients) <= 1) {
    raise << current_recipe_name() << ": 'greater-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
    break;
  }
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    if (!scalar(ingredients.at(i))) {
      raise << current_recipe_name() << ": 'greater-or-equal' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end();
      goto finish_greater_or_equal;
    }
  }
  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
    if (ingredients.at(i-1).at(0) < ingredients.at(i).at(0)) {
      result = false;
    }
  }
  finish_greater_or_equal:
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario greater_or_equal)
recipe main [
  1:number <- copy 34
  2:number <- copy 33
  3:boolean <- greater-or-equal 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario greater_or_equal_2)
recipe main [
  1:number <- copy 34
  2:number <- copy 34
  3:boolean <- greater-or-equal 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario greater_or_equal_3)
recipe main [
  1:number <- copy 34
  2:number <- copy 35
  3:boolean <- greater-or-equal 1:number, 2:number
]
+mem: storing 0 in location 3

:(scenario greater_or_equal_multiple)
recipe main [
  1:boolean <- greater-or-equal 36, 35, 35
]
+mem: storing 1 in location 1

:(scenario greater_or_equal_multiple_2)
recipe main [
  1:boolean <- greater-or-equal 36, 35, 36
]
+mem: storing 0 in location 1

:(before "End Primitive Recipe Declarations")
LESSER_OR_EQUAL,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["lesser-or-equal"] = LESSER_OR_EQUAL;
:(before "End Primitive Recipe Implementations")
case LESSER_OR_EQUAL: {
  bool result = true;
  if (SIZE(ingredients) <= 1) {
    raise << current_recipe_name() << ": 'lesser-or-equal' needs at least two ingredients to compare in '" << current_instruction().to_string() << "'\n" << end();
    break;
  }
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    if (!scalar(ingredients.at(i))) {
      raise << current_recipe_name() << ": 'lesser-or-equal' can only compare numbers; got " << current_instruction().ingredients.at(i).original_string << '\n' << end();
      goto finish_lesser_or_equal;
    }
  }
  for (long long int i = /**/1; i < SIZE(ingredients); ++i) {
    if (ingredients.at(i-1).at(0) > ingredients.at(i).at(0)) {
      result = false;
    }
  }
  finish_lesser_or_equal:
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario lesser_or_equal)
recipe main [
  1:number <- copy 32
  2:number <- copy 33
  3:boolean <- lesser-or-equal 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario lesser_or_equal_2)
recipe main [
  1:number <- copy 33
  2:number <- copy 33
  3:boolean <- lesser-or-equal 1:number, 2:number
]
+mem: storing 1 in location 3

:(scenario lesser_or_equal_3)
recipe main [
  1:number <- copy 34
  2:number <- copy 33
  3:boolean <- lesser-or-equal 1:number, 2:number
]
+mem: storing 0 in location 3

:(scenario lesser_or_equal_multiple)
recipe main [
  1:boolean <- lesser-or-equal 34, 35, 35
]
+mem: storing 1 in location 1

:(scenario lesser_or_equal_multiple_2)
recipe main [
  1:boolean <- lesser-or-equal 34, 35, 34
]
+mem: storing 0 in location 1