1414 - traces now robust to new recipes/types

This commit is contained in:
Kartik K. Agaram 2015-05-21 12:36:59 -07:00
parent 5af8334699
commit d7494165ec
23 changed files with 137 additions and 325 deletions

View File

@ -107,8 +107,7 @@ struct trace_stream {
void newline() {
if (!curr_stream) return;
string curr_contents = curr_stream->str();
curr_contents.erase(curr_contents.find_last_not_of("\r\n")+1);
past_lines.push_back(pair<string, string>(curr_layer, curr_contents));
past_lines.push_back(pair<string, string>(trim(curr_layer), curr_contents)); // preserve indent in contents
if (curr_layer == dump_layer || curr_layer == "dump" || dump_layer == "all" ||
(!Hide_warnings && curr_layer == "warn"))
//? if (dump_layer == "all" && (Current_routine->id == 3 || curr_layer == "schedule")) //? 1
@ -197,12 +196,15 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte
string layer, contents;
split_layer_contents(expected_lines.at(curr_expected_line), &layer, &contents);
for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
//? cerr << "AAA " << layer << ' ' << p->first << '\n'; //? 1
if (layer != p->first)
continue;
if (contents != p->second)
//? cerr << "BBB ^" << contents << "$ ^" << p->second << "$\n"; //? 1
if (contents != trim(p->second))
continue;
//? cerr << "CCC\n"; //? 1
++curr_expected_line;
while (curr_expected_line < SIZE(expected_lines) && expected_lines.at(curr_expected_line).empty())
++curr_expected_line;
@ -213,6 +215,7 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte
++Num_failures;
cerr << "\nF - " << FUNCTION << "(" << FILE << ":" << LINE << "): missing [" << contents << "] in trace:\n";
DUMP(layer);
//? exit(0); //? 1
Passed = false;
return false;
}
@ -222,11 +225,11 @@ void split_layer_contents(const string& s, string* layer, string* contents) {
size_t pos = s.find(delim);
if (pos == string::npos) {
*layer = "";
*contents = s;
*contents = trim(s);
}
else {
*layer = s.substr(0, pos);
*contents = s.substr(pos+SIZE(delim));
*layer = trim(s.substr(0, pos));
*contents = trim(s.substr(pos+SIZE(delim)));
}
}
@ -308,6 +311,19 @@ bool headmatch(const string& s, const string& pat) {
return std::mismatch(pat.begin(), pat.end(), s.begin()).first == pat.end();
}
string trim(const string& s) {
string::const_iterator first = s.begin();
while (first != s.end() && isspace(*first))
++first;
if (first == s.end()) return "";
string::const_iterator last = --s.end();
while (last != s.begin() && isspace(*last))
--last;
++last;
return string(first, last);
}
:(before "End Includes")
#include<vector>
using std::vector;

View File

@ -27,6 +27,11 @@ void test_trace_ignores_trailing_whitespace() {
CHECK_TRACE_CONTENTS("test layer 1: foo");
}
void test_trace_ignores_trailing_whitespace2() {
trace("test layer 1") << "foo ";
CHECK_TRACE_CONTENTS("test layer 1: foo");
}
void test_trace_orders_across_layers() {
trace("test layer 1") << "foo";
trace("test layer 2") << "bar";
@ -93,3 +98,19 @@ void test_split_handles_multichar_delim() {
CHECK_EQ(result.at(1), "def");
CHECK_EQ(result.at(2), "ghi");
}
void test_trim() {
CHECK_EQ(trim(""), "");
CHECK_EQ(trim(" "), "");
CHECK_EQ(trim(" "), "");
CHECK_EQ(trim("a"), "a");
CHECK_EQ(trim(" a"), "a");
CHECK_EQ(trim(" a"), "a");
CHECK_EQ(trim(" ab"), "ab");
CHECK_EQ(trim("a "), "a");
CHECK_EQ(trim("a "), "a");
CHECK_EQ(trim("ab "), "ab");
CHECK_EQ(trim(" a "), "a");
CHECK_EQ(trim(" a "), "a");
CHECK_EQ(trim(" ab "), "ab");
}

View File

@ -39,6 +39,7 @@ struct instruction {
// us how to interpret them. They also can contain arbitrary other lists of
// properties besides types, but we're getting ahead of ourselves.
struct reagent {
string original_string;
vector<pair<string, vector<string> > > properties;
string name;
double value;
@ -167,7 +168,7 @@ instruction::instruction() :is_label(false), operation(IDLE) {}
void instruction::clear() { is_label=false; label.clear(); operation=IDLE; ingredients.clear(); products.clear(); }
// Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...
reagent::reagent(string s) :value(0), initialized(false) {
reagent::reagent(string s) :original_string(s), value(0), initialized(false) {
istringstream in(s);
in >> std::noskipws;
// properties
@ -203,11 +204,7 @@ reagent::reagent() :value(0), initialized(false) {
}
string reagent::to_string() const {
ostringstream out;
out << "{name: \"" << name << "\", value: " << value << ", type: ";
for (long long int i = 0; i < SIZE(types); ++i) {
if (i > 0) out << '-';
out << types.at(i);
}
out << "{name: \"" << name << "\"";
if (!properties.empty()) {
out << ", properties: [";
for (long long int i = 0; i < SIZE(properties); ++i) {
@ -229,13 +226,13 @@ string instruction::to_string() const {
ostringstream out;
for (long long int i = 0; i < SIZE(products); ++i) {
if (i > 0) out << ", ";
out << products.at(i).to_string();
out << products.at(i).original_string;
}
if (!products.empty()) out << " <- ";
out << name << '/' << operation << ' ';
out << name << ' ';
for (long long int i = 0; i < SIZE(ingredients); ++i) {
if (i > 0) out << ", ";
out << ingredients.at(i).to_string();
out << ingredients.at(i).original_string;
}
return out.str();
}

View File

@ -6,8 +6,8 @@ recipe main [
1:number <- copy 23:literal
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(code)
vector<recipe_number> load(string form) {
@ -220,8 +220,8 @@ recipe main [
1:number <- copy 23:literal
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(scenario parse_comment_amongst_instruction)
recipe main [
@ -229,8 +229,8 @@ recipe main [
1:number <- copy 23:literal
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(scenario parse_comment_amongst_instruction2)
recipe main [
@ -239,8 +239,8 @@ recipe main [
# comment
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(scenario parse_comment_amongst_instruction3)
recipe main [
@ -249,19 +249,19 @@ recipe main [
2:number <- copy 23:literal
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "2", properties: ["2": "number"]}
:(scenario parse_comment_after_instruction)
recipe main [
1:number <- copy 23:literal # comment
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(scenario parse_label)
recipe main [
@ -280,40 +280,40 @@ recipe main [
1:number <- copy 23:literal/foo:bar:baz
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal", "foo": "bar":"baz"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal", "foo": "bar":"baz"]}
+parse: product: {name: "1", properties: ["1": "number"]}
:(scenario parse_multiple_products)
recipe main [
1:number, 2:number <- copy 23:literal
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: product: {name: "1", properties: ["1": "number"]}
+parse: product: {name: "2", properties: ["2": "number"]}
:(scenario parse_multiple_ingredients)
recipe main [
1:number, 2:number <- copy 23:literal, 4:number
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "number"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: product: {name: "2", value: 0, type: 1, properties: ["2": "number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: ingredient: {name: "4", properties: ["4": "number"]}
+parse: product: {name: "1", properties: ["1": "number"]}
+parse: product: {name: "2", properties: ["2": "number"]}
:(scenario parse_multiple_types)
recipe main [
1:number, 2:address:number <- copy 23:literal, 4:number
]
+parse: instruction: copy
+parse: ingredient: {name: "23", value: 0, type: 0, properties: ["23": "literal"]}
+parse: ingredient: {name: "4", value: 0, type: 1, properties: ["4": "number"]}
+parse: product: {name: "1", value: 0, type: 1, properties: ["1": "number"]}
+parse: product: {name: "2", value: 0, type: 2-1, properties: ["2": "address":"number"]}
+parse: ingredient: {name: "23", properties: ["23": "literal"]}
+parse: ingredient: {name: "4", properties: ["4": "number"]}
+parse: product: {name: "1", properties: ["1": "number"]}
+parse: product: {name: "2", properties: ["2": "address":"number"]}
:(scenario parse_properties)
recipe main [
1:number:address/deref <- copy 23:literal
]
+parse: product: {name: "1", value: 0, type: 1-2, properties: ["1": "number":"address", "deref": ]}
+parse: product: {name: "1", properties: ["1": "number":"address", "deref": ]}

View File

@ -10,13 +10,13 @@
recipe main [
1:address:array:character <- copy [abc def] # copy can't really take a string
]
+parse: ingredient: {name: "abc def", value: 0, type: 0, properties: ["abc def": "literal-string"]}
+parse: ingredient: {name: "abc def", properties: ["abc def": "literal-string"]}
:(scenario string_literal_with_colons)
recipe main [
1:address:array:character <- copy [abc:def/ghi]
]
+parse: ingredient: {name: "abc:def/ghi", value: 0, type: 0, properties: ["abc:def/ghi": "literal-string"]}
+parse: ingredient: {name: "abc:def/ghi", properties: ["abc:def/ghi": "literal-string"]}
:(before "End Mu Types Initialization")
Type_number["literal-string"] = 0;
@ -65,14 +65,14 @@ string slurp_quoted(istream& in) {
recipe main [
1:address:array:character <- copy [abc [def]]
]
+parse: ingredient: {name: "abc [def]", value: 0, type: 0, properties: ["abc [def]": "literal-string"]}
+parse: ingredient: {name: "abc [def]", properties: ["abc [def]": "literal-string"]}
:(scenario string_literal_and_comment)
recipe main [
1:address:array:character <- copy [abc] # comment
]
+parse: instruction: copy
+parse: ingredient: {name: "abc", value: 0, type: 0, properties: ["abc": "literal-string"]}
+parse: product: {name: "1", value: 0, type: 2-5-4, properties: ["1": "address":"array":"character"]}
+parse: ingredient: {name: "abc", properties: ["abc": "literal-string"]}
+parse: product: {name: "1", properties: ["1": "address":"array":"character"]}
# no other ingredients
$parse: 3

View File

@ -6,7 +6,7 @@
recipe main [
1:number <- copy 3.14159
]
+parse: ingredient: {name: "3.14159", value: 3.14159, type: 0, properties: ["3.14159": "literal-number"]}
+parse: ingredient: {name: "3.14159", properties: ["3.14159": "literal-number"]}
:(after "reagent::reagent(string s)")
if (is_noninteger(s)) {

View File

@ -13,8 +13,7 @@
recipe main [
1:number <- copy 23:literal
]
+run: instruction main/0
+run: ingredient 0 is 23
+run: 1:number <- copy 23:literal
+mem: storing 23 in location 1
:(scenario copy)
@ -22,8 +21,7 @@ recipe main [
1:number <- copy 23:literal
2:number <- copy 1:number
]
+run: instruction main/1
+run: ingredient 0 is 1
+run: 2:number <- copy 1:number
+mem: location 1 is 23
+mem: storing 23 in location 2
@ -31,8 +29,6 @@ recipe main [
recipe main [
1:number, 2:number <- copy 23:literal, 24:literal
]
+run: ingredient 0 is 23
+run: ingredient 1 is 24
+mem: storing 23 in location 1
+mem: storing 24 in location 2
@ -62,7 +58,7 @@ void run_current_routine()
{
// Running One Instruction.
if (current_instruction().is_label) { ++current_step_index(); continue; }
trace("run") << "instruction " << current_recipe_name() << '/' << current_step_index();
//? trace("run") << "instruction " << current_recipe_name() << '/' << current_step_index();
trace("run") << current_instruction().to_string();
assert(Memory[0] == 0);
// Read all ingredients from memory.
@ -70,7 +66,7 @@ void run_current_routine()
// permits operating on reagents spanning multiple locations.
vector<vector<double> > ingredients;
for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
trace("run") << "ingredient " << i << " is " << current_instruction().ingredients.at(i).name;
//? trace("run") << "ingredient " << i << " is " << current_instruction().ingredients.at(i).name;
ingredients.push_back(read_memory(current_instruction().ingredients.at(i)));
}
// Instructions below will write to 'products' or to 'instruction_counter'.
@ -93,7 +89,7 @@ void run_current_routine()
raise << "failed to write to all products! " << current_instruction().to_string();
//? cout << "CCC: " << current_instruction().to_string() << '\n'; //? 1
for (long long int i = 0; i < SIZE(current_instruction().products); ++i) {
trace("run") << "product " << i << " is " << current_instruction().products.at(i).name;
//? trace("run") << "product " << i << " is " << current_instruction().products.at(i).name;
write_memory(current_instruction().products.at(i), products.at(i));
}
//? cout << "DDD: " << current_instruction().to_string() << '\n'; //? 1
@ -230,12 +226,12 @@ recipe main [
1:number <- copy 23:literal
2:number <- copy 1:number
]
+run: instruction main/1
+run: instruction main/2
-run: instruction main/0
+run: 1:number <- copy 23:literal
+run: 2:number <- copy 1:number
-run: +foo
:(scenario run_dummy)
recipe main [
_ <- copy 0:literal
]
+run: instruction main/0
+run: _ <- copy 0:literal

View File

@ -20,10 +20,6 @@ case ADD: {
recipe main [
1:number <- add 23:literal, 34:literal
]
+run: instruction main/0
+run: ingredient 0 is 23
+run: ingredient 1 is 34
+run: product 0 is 1
+mem: storing 57 in location 1
:(scenario add)
@ -32,12 +28,6 @@ recipe main [
2:number <- copy 34:literal
3:number <- add 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 23
+run: ingredient 1 is 2
+mem: location 2 is 34
+run: product 0 is 3
+mem: storing 57 in location 3
:(scenario add_multiple)
@ -67,10 +57,6 @@ case SUBTRACT: {
recipe main [
1:number <- subtract 5:literal, 2:literal
]
+run: instruction main/0
+run: ingredient 0 is 5
+run: ingredient 1 is 2
+run: product 0 is 1
+mem: storing 3 in location 1
:(scenario subtract)
@ -79,12 +65,6 @@ recipe main [
2:number <- copy 34:literal
3:number <- subtract 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 23
+run: ingredient 1 is 2
+mem: location 2 is 34
+run: product 0 is 3
+mem: storing -11 in location 3
:(scenario subtract_multiple)
@ -113,10 +93,6 @@ case MULTIPLY: {
recipe main [
1:number <- multiply 2:literal, 3:literal
]
+run: instruction main/0
+run: ingredient 0 is 2
+run: ingredient 1 is 3
+run: product 0 is 1
+mem: storing 6 in location 1
:(scenario multiply)
@ -125,12 +101,6 @@ recipe main [
2:number <- copy 6:literal
3:number <- multiply 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 4
+run: ingredient 1 is 2
+mem: location 2 is 6
+run: product 0 is 3
+mem: storing 24 in location 3
:(scenario multiply_multiple)
@ -160,10 +130,6 @@ case DIVIDE: {
recipe main [
1:number <- divide 8:literal, 2:literal
]
+run: instruction main/0
+run: ingredient 0 is 8
+run: ingredient 1 is 2
+run: product 0 is 1
+mem: storing 4 in location 1
:(scenario divide)
@ -172,12 +138,6 @@ recipe main [
2:number <- copy 3:literal
3:number <- divide 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 27
+run: ingredient 1 is 2
+mem: location 2 is 3
+run: product 0 is 3
+mem: storing 9 in location 3
:(scenario divide_multiple)
@ -207,12 +167,7 @@ case DIVIDE_WITH_REMAINDER: {
recipe main [
1:number, 2:number <- divide-with-remainder 9:literal, 2:literal
]
+run: instruction main/0
+run: ingredient 0 is 9
+run: ingredient 1 is 2
+run: product 0 is 1
+mem: storing 4 in location 1
+run: product 1 is 2
+mem: storing 1 in location 2
:(scenario divide_with_remainder)
@ -221,14 +176,7 @@ recipe main [
2:number <- copy 11:literal
3:number, 4:number <- divide-with-remainder 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 27
+run: ingredient 1 is 2
+mem: location 2 is 11
+run: product 0 is 3
+mem: storing 2 in location 3
+run: product 1 is 4
+mem: storing 5 in location 4
:(scenario divide_with_decimal_point)

View File

@ -22,12 +22,6 @@ recipe main [
2:boolean <- copy 0:literal
3:boolean <- and 1:boolean, 2:boolean
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 1
+run: ingredient 1 is 2
+mem: location 2 is 0
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario and2)
@ -70,12 +64,6 @@ recipe main [
2:boolean <- copy 0:literal
3:boolean <- or 1:boolean, 2:boolean
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 1
+run: ingredient 1 is 2
+mem: location 2 is 0
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario or2)
@ -115,10 +103,6 @@ recipe main [
1:boolean <- copy 1:literal
2:boolean <- not 1:boolean
]
+run: instruction main/1
+run: ingredient 0 is 1
+mem: location 1 is 1
+run: product 0 is 2
+mem: storing 0 in location 2
:(scenario not_multiple)

View File

@ -5,9 +5,8 @@ recipe main [
jump 1:offset
1:number <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 0 is 1
-run: instruction main/1
+run: jump 1:offset
-run: 1:number <- copy 1:literal
-mem: storing 1 in location 1
:(before "End Primitive Recipe Declarations")
@ -31,13 +30,13 @@ Type_number["offset"] = 0;
:(scenario jump_backward)
recipe main [
jump 1:offset # 0 -+
jump 1:offset # | +-+ 1
jump 3:offset # | +-+ 1
# \/ /\ |
jump -2:offset # 2 +-->+ |
] # \/ 3
+run: instruction main/0
+run: instruction main/2
+run: instruction main/1
+run: jump 1:offset
+run: jump -2:offset
+run: jump 3:offset
:(before "End Primitive Recipe Declarations")
JUMP_IF,
@ -61,22 +60,21 @@ case JUMP_IF: {
:(scenario jump_if)
recipe main [
jump-if 999:literal, 1:offset
1:number <- copy 1:literal
123:number <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 1 is 1
+run: jump-if 999:literal, 1:offset
+run: jumping to instruction 2
-run: instruction main/1
-mem: storing 1 in location 1
-run: 1:number <- copy 1:literal
-mem: storing 1 in location 123
:(scenario jump_if_fallthrough)
recipe main [
jump-if 0:literal, 1:offset
123:number <- copy 1:literal
]
+run: instruction main/0
+run: jump-if 0:literal, 1:offset
+run: jump-if fell through
+run: instruction main/1
+run: 123:number <- copy 1:literal
+mem: storing 1 in location 123
:(before "End Primitive Recipe Declarations")
@ -101,21 +99,19 @@ case JUMP_UNLESS: {
:(scenario jump_unless)
recipe main [
jump-unless 0:literal, 1:offset
1:number <- copy 1:literal
123:number <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 1 is 1
+run: jump-unless 0:literal, 1:offset
+run: jumping to instruction 2
-run: instruction main/1
-mem: storing 1 in location 1
-run: 123:number <- copy 1:literal
-mem: storing 1 in location 123
:(scenario jump_unless_fallthrough)
recipe main [
jump-unless 999:literal, 1:offset
123:number <- copy 1:literal
]
+run: instruction main/0
+run: ingredient 0 is 999
+run: jump-unless 999:literal, 1:offset
+run: jump-unless fell through
+run: instruction main/1
+run: 123:number <- copy 1:literal
+mem: storing 1 in location 123

View File

@ -25,12 +25,8 @@ recipe main [
2:number <- copy 33:literal
3:number <- equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario equal2)
@ -39,12 +35,8 @@ recipe main [
2:number <- copy 34:literal
3:number <- equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 34
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario equal_multiple)
@ -85,12 +77,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- greater-than 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario greater_than2)
@ -99,12 +85,6 @@ recipe main [
2:number <- copy 34:literal
3:boolean <- greater-than 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 34
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario greater_than_multiple)
@ -145,12 +125,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- lesser-than 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 32
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario lesser_than2)
@ -159,12 +133,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- lesser-than 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario lesser_than_multiple)
@ -205,12 +173,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- greater-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario greater_or_equal2)
@ -219,12 +181,6 @@ recipe main [
2:number <- copy 34:literal
3:boolean <- greater-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 34
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario greater_or_equal3)
@ -233,12 +189,6 @@ recipe main [
2:number <- copy 35:literal
3:boolean <- greater-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 35
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario greater_or_equal_multiple)
@ -279,12 +229,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- lesser-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 32
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario lesser_or_equal2)
@ -293,12 +237,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- lesser-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 33
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 1 in location 3
:(scenario lesser_or_equal3)
@ -307,12 +245,6 @@ recipe main [
2:number <- copy 33:literal
3:boolean <- lesser-or-equal 1:number, 2:number
]
+run: instruction main/2
+run: ingredient 0 is 1
+mem: location 1 is 34
+run: ingredient 1 is 2
+mem: location 2 is 33
+run: product 0 is 3
+mem: storing 0 in location 3
:(scenario lesser_or_equal_multiple)

View File

@ -20,9 +20,6 @@ recipe main [
2:number <- copy 35:literal
3:point <- copy 1:point
]
+run: ingredient 0 is 1
+mem: location 1 is 34
+mem: location 2 is 35
+mem: storing 34 in location 3
+mem: storing 35 in location 4
@ -96,13 +93,6 @@ recipe main [
13:number <- copy 35:literal
15:number <- get 12:point, 1:offset
]
+run: instruction main/2
+run: ingredient 0 is 12
+run: ingredient 1 is 1
+run: address to copy is 13
+run: its type is 1
+mem: location 13 is 35
+run: product 0 is 15
+mem: storing 35 in location 15
:(before "End Primitive Recipe Declarations")
@ -141,13 +131,6 @@ recipe main [
14:number <- copy 36:literal
15:number <- get 12:point-number, 1:offset
]
+run: instruction main/2
+run: ingredient 0 is 12
+run: ingredient 1 is 1
+run: address to copy is 14
+run: its type is 1
+mem: location 14 is 36
+run: product 0 is 15
+mem: storing 36 in location 15
//:: To write to elements of containers, you need their address.
@ -158,10 +141,6 @@ recipe main [
13:number <- copy 35:literal
15:address:number <- get-address 12:point, 1:offset
]
+run: instruction main/2
+run: ingredient 0 is 12
+run: ingredient 1 is 1
+run: address to copy is 13
+mem: storing 13 in location 15
:(before "End Primitive Recipe Declarations")

View File

@ -8,9 +8,6 @@ recipe main [
# This loads location 1 as an address and looks up *that* location.
3:number <- copy 1:address:number/deref
]
+run: instruction main/2
+mem: location 1 is 2
+mem: location 2 is 34
+mem: storing 34 in location 3
:(before "long long int base = x.value" following "vector<double> read_memory(reagent x)")
@ -23,8 +20,6 @@ recipe main [
1:address:number <- copy 2:literal
1:address:number/deref <- copy 34:literal
]
+run: instruction main/1
+mem: location 1 is 2
+mem: storing 34 in location 2
:(before "long long int base = x.value" following "void write_memory(reagent x, vector<double> data)")
@ -76,9 +71,6 @@ recipe main [
3:number <- copy 35:literal
4:number <- get 1:address:point/deref, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4
+mem: storing 34 in location 4
:(scenario include_nonderef_properties)
@ -88,9 +80,6 @@ recipe main [
3:number <- copy 35:literal
4:number <- get 1:address:point/deref/foo, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4
+mem: storing 34 in location 4
:(after "reagent base = " following "case GET:")
@ -104,9 +93,7 @@ recipe main [
3:number <- copy 35:literal
4:number <- get-address 1:address:point/deref, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4
+mem: storing 2 in location 4
:(after "reagent base = " following "case GET_ADDRESS:")
base = canonize(base);

View File

@ -15,12 +15,6 @@ recipe main [
4:number <- copy 16:literal
5:array:number <- copy 1:array:number
]
+run: instruction main/4
+run: ingredient 0 is 1
+mem: location 1 is 3
+mem: location 2 is 14
+mem: location 3 is 15
+mem: location 4 is 16
+mem: storing 3 in location 5
+mem: storing 14 in location 6
+mem: storing 15 in location 7
@ -35,12 +29,6 @@ recipe main [
5:address:array:number <- copy 1:literal
6:array:number <- copy 5:address:array:number/deref
]
+run: instruction main/5
+run: ingredient 0 is 5
+mem: location 1 is 3
+mem: location 2 is 14
+mem: location 3 is 15
+mem: location 4 is 16
+mem: storing 3 in location 6
+mem: storing 14 in location 7
+mem: storing 15 in location 8
@ -66,11 +54,6 @@ recipe main [
4:number <- copy 16:literal
5:number <- index 1:array:number, 0:literal
]
+run: instruction main/4
+run: address to copy is 2
+run: its type is 1
+mem: location 2 is 14
+run: product 0 is 5
+mem: storing 14 in location 5
:(scenario index_direct_offset)
@ -82,11 +65,6 @@ recipe main [
5:number <- copy 0:literal
6:number <- index 1:array:number, 5:number
]
+run: instruction main/5
+run: address to copy is 2
+run: its type is 1
+mem: location 2 is 14
+run: product 0 is 6
+mem: storing 14 in location 6
:(before "End Primitive Recipe Declarations")
@ -129,7 +107,6 @@ recipe main [
4:number <- copy 16:literal
5:number <- index-address 1:array:number, 0:literal
]
+run: instruction main/4
+mem: storing 2 in location 5
//:: To write to elements of containers, you need their address.
@ -143,7 +120,6 @@ recipe main [
5:address:array:number <- copy 1:literal
6:number <- index 5:address:array:number/deref, 1:literal
]
+run: instruction main/5
+mem: storing 15 in location 6
:(before "End Primitive Recipe Declarations")

View File

@ -8,7 +8,6 @@ recipe main [
4:number <- copy 16:literal
5:number <- length 1:array:number
]
+run: instruction main/4
+mem: storing 3 in location 5
:(before "End Primitive Recipe Declarations")

View File

@ -12,20 +12,22 @@ recipe f [
:(scenario return_on_fallthrough)
recipe main [
f
1:number <- copy 34:literal
2:number <- copy 34:literal
3:number <- copy 34:literal
1:number <- copy 0:literal
2:number <- copy 0:literal
3:number <- copy 0:literal
]
recipe f [
4:number <- copy 34:literal
5:number <- copy 34:literal
4:number <- copy 0:literal
5:number <- copy 0:literal
]
+run: instruction main/0
+run: instruction f/0
+run: instruction f/1
+run: instruction main/1
+run: instruction main/2
+run: instruction main/3
+run: f
# running f
+run: 4:number <- copy 0:literal
+run: 5:number <- copy 0:literal
# back out to main
+run: 1:number <- copy 0:literal
+run: 2:number <- copy 0:literal
+run: 3:number <- copy 0:literal
:(before "struct routine {")
// Everytime a recipe runs another, we interrupt it and start running the new

View File

@ -9,8 +9,6 @@ recipe f [
12:number <- next-ingredient
13:number <- add 1:literal, 12:number
]
+run: instruction f/1
+mem: location 12 is 2
+mem: storing 3 in location 13
:(scenario next_ingredient_missing)

View File

@ -9,7 +9,6 @@ recipe f [
13:number <- add 1:literal, 12:number
reply 12:number, 13:number
]
+run: instruction main/0
+mem: storing 34 in location 1
+mem: storing 35 in location 2
@ -53,7 +52,6 @@ recipe f [
13:number <- copy 35:literal
reply 12:point
]
+run: instruction main/0
+run: result 0 is [2, 35]
+mem: storing 2 in location 3
+mem: storing 35 in location 4

View File

@ -161,9 +161,9 @@ recipe f1 [
2:number <- copy 0:literal
]
+schedule: f1
+run: instruction f1/0
+run: 1:number <- copy 0:literal
+schedule: f1
+run: instruction f1/1
+run: 2:number <- copy 0:literal
:(scenario scheduler_interleaves_routines)
% Scheduling_interval = 1;
@ -173,19 +173,19 @@ recipe f1 [
2:number <- copy 0:literal
]
recipe f2 [
3:number <- copy 4:literal
4:number <- copy 4:literal
3:number <- copy 0:literal
4:number <- copy 0:literal
]
+schedule: f1
+run: instruction f1/0
+run: start-running f2:recipe
+schedule: f2
+run: instruction f2/0
+run: 3:number <- copy 0:literal
+schedule: f1
+run: instruction f1/1
+run: 1:number <- copy 0:literal
+schedule: f2
+run: instruction f2/1
+run: 4:number <- copy 0:literal
+schedule: f1
+run: instruction f1/2
+run: 2:number <- copy 0:literal
:(scenario start_running_takes_args)
recipe f1 [

View File

@ -7,7 +7,6 @@ recipe main [
x:number <- copy 0:literal
]
+name: assign x 1
+run: instruction main/0
+mem: storing 0 in location 1
:(scenario convert_names_warns)

View File

@ -119,10 +119,8 @@ recipe main [
2:address:number/raw <- new number:type
3:number/raw <- subtract 2:address:number/raw, 1:address:array:number/raw
]
+run: instruction main/0
+run: 1:address:array:number/raw <- new number:type, 5:literal
+mem: array size is 5
+run: instruction main/1
+run: instruction main/2
# don't forget the extra location for array size
+mem: storing 6 in location 3

View File

@ -14,11 +14,11 @@ recipe main [
1:number <- copy 32:literal
1:number/space:1 <- copy 33:literal
]
+run: instruction main/3
# chain space
+mem: storing 20 in location 11
+run: instruction main/4
# store to default-space
+mem: storing 32 in location 12
+run: instruction main/5
# store to chained space
+mem: storing 33 in location 22
//: If you think of a space as a collection of variables with a common

View File

@ -482,17 +482,3 @@ void slurp_until_matching_bracket(istream& in, ostream& out) {
out << c;
}
}
// see tests for this function in tangle/030tangle.test.cc
string trim(const string& s) {
string::const_iterator first = s.begin();
while (first != s.end() && isspace(*first))
++first;
if (first == s.end()) return "";
string::const_iterator last = --s.end();
while (last != s.begin() && isspace(*last))
--last;
++last;
return string(first, last);
}