about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/.traces/array_length35
-rw-r--r--cpp/030length25
2 files changed, 60 insertions, 0 deletions
diff --git a/cpp/.traces/array_length b/cpp/.traces/array_length
new file mode 100644
index 00000000..45e8181d
--- /dev/null
+++ b/cpp/.traces/array_length
@@ -0,0 +1,35 @@
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "3", value: 0, type: 0, properties: ["3": "literal"]}
+parse/0:   product: {name: "1", value: 0, type: 1, properties: ["1": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "14", value: 0, type: 0, properties: ["14": "literal"]}
+parse/0:   product: {name: "2", value: 0, type: 1, properties: ["2": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "15", value: 0, type: 0, properties: ["15": "literal"]}
+parse/0:   product: {name: "3", value: 0, type: 1, properties: ["3": "integer"]}
+parse/0: instruction: 1
+parse/0:   ingredient: {name: "16", value: 0, type: 0, properties: ["16": "literal"]}
+parse/0:   product: {name: "4", value: 0, type: 1, properties: ["4": "integer"]}
+parse/0: instruction: 25
+parse/0:   ingredient: {name: "1", value: 0, type: 4-1, properties: ["1": "array":"integer"]}
+parse/0:   product: {name: "5", value: 0, type: 1, properties: ["5": "integer"]}
+after-brace/0: recipe main
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: copy ...
+after-brace/0: length ...
+run/0: instruction main/0
+run/0: ingredient 0 is 3
+mem/0: storing 3 in location 1
+run/0: instruction main/1
+run/0: ingredient 0 is 14
+mem/0: storing 14 in location 2
+run/0: instruction main/2
+run/0: ingredient 0 is 15
+mem/0: storing 15 in location 3
+run/0: instruction main/3
+run/0: ingredient 0 is 16
+mem/0: storing 16 in location 4
+run/0: instruction main/4
+mem/0: storing 3 in location 5
diff --git a/cpp/030length b/cpp/030length
new file mode 100644
index 00000000..6a297dd3
--- /dev/null
+++ b/cpp/030length
@@ -0,0 +1,25 @@
+:(scenario "array_length")
+recipe main [
+  1:integer <- copy 3:literal
+  2:integer <- copy 14:literal
+  3:integer <- copy 15:literal
+  4:integer <- copy 16:literal
+  5:integer <- length 1:array:integer
+]
++run: instruction main/4
++mem: storing 3 in location 5
+
+:(before "End Globals")
+const int LENGTH = 25;
+:(before "End Primitive Recipe Numbers")
+Recipe_number["length"] = LENGTH;
+assert(Next_recipe_number == LENGTH);
+Next_recipe_number++;
+:(before "End Primitive Recipe Implementations")
+case LENGTH: {
+  reagent x = canonize(instructions[pc].ingredients[0]);
+  vector<int> result;
+  result.push_back(Memory[x.value]);
+  write_memory(instructions[pc].products[0], result);
+  break;
+}
' href='#n201'>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