From f652431d44a1fecf2ba778cf2d59f8ec650fcd68 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 1 Apr 2015 21:48:49 -0700 Subject: 1001 --- cpp/.traces/array_length | 35 +++++++++++++++++++++++++++++++++++ cpp/030length | 25 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 cpp/.traces/array_length create mode 100644 cpp/030length 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 result; + result.push_back(Memory[x.value]); + write_memory(instructions[pc].products[0], result); + break; +} -- cgit 1.4.1-2-gfad0