Skip to content

Commit

Permalink
2803
Browse files Browse the repository at this point in the history
Show more thorough information about instructions in the trace, but keep
the original form in error messages.
  • Loading branch information
akkartik committed Mar 21, 2016
1 parent dad3bed commit acc4792
Show file tree
Hide file tree
Showing 38 changed files with 264 additions and 249 deletions.
36 changes: 28 additions & 8 deletions 010vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct instruction {
string label; // only if is_label
string name; // only if !is_label
string old_name; // before our automatic rewrite rules
string original_string;
string original_string; // for error messages
recipe_ordinal operation; // get(Recipe_ordinal, name)
vector<reagent> ingredients; // only if !is_label
vector<reagent> products; // only if !is_label
Expand Down Expand Up @@ -451,7 +451,7 @@ string debug_string(const recipe& x) {
return out.str();
}

string to_string(const instruction& inst) {
string to_original_string(const instruction& inst) {
if (inst.is_label) return inst.label;
ostringstream out;
for (int i = 0; i < SIZE(inst.products); ++i) {
Expand All @@ -467,20 +467,40 @@ string to_string(const instruction& inst) {
return out.str();
}

string to_string(const instruction& inst) {
if (inst.is_label) return inst.label;
ostringstream out;
for (int i = 0; i < SIZE(inst.products); ++i) {
if (i > 0) out << ", ";
out << to_string(inst.products.at(i));
}
if (!inst.products.empty()) out << " <- ";
out << inst.name << ' ';
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (i > 0) out << ", ";
out << to_string(inst.ingredients.at(i));
}
return out.str();
}

string to_string(const reagent& r) {
if (is_dummy(r)) return "_";
ostringstream out;
out << "{";
out << r.name << ": " << names_to_string(r.type);
if (!r.properties.empty()) {
out << ", {";
for (int i = 0; i < SIZE(r.properties); ++i) {
if (i > 0) out << ", ";
out << "\"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second);
}
out << "}";
for (int i = 0; i < SIZE(r.properties); ++i)
out << ", \"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second);
}
out << "}";
return out.str();
}

// special name for ignoring some products
inline bool is_dummy(const reagent& x) {
return x.name == "_";
}

string debug_string(const reagent& x) {
ostringstream out;
out << x.name << ": " << x.value << ' ' << to_string(x.type) << " -- " << to_string(x);
Expand Down
56 changes: 28 additions & 28 deletions 011load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def main [
1:number <- copy 23
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}

:(code)
vector<recipe_ordinal> load(string form) {
Expand Down Expand Up @@ -235,17 +235,17 @@ def main [
1:number <- copy 23
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}

:(scenario parse_comment_amongst_instruction)
def main [
# comment
1:number <- copy 23
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}

:(scenario parse_comment_amongst_instruction_2)
def main [
Expand All @@ -254,8 +254,8 @@ def main [
# comment
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}

:(scenario parse_comment_amongst_instruction_3)
def main [
Expand All @@ -264,19 +264,19 @@ def main [
2:number <- copy 23
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 2: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {2: "number"}

:(scenario parse_comment_after_instruction)
def main [
1:number <- copy 23 # comment
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}

:(scenario parse_label)
def main [
Expand All @@ -295,43 +295,43 @@ def main [
1:number <- copy 23/foo:bar:baz
]
+parse: instruction: copy
+parse: ingredient: 23: "literal", {"foo": ("bar" "baz")}
+parse: product: 1: "number"
+parse: ingredient: {23: "literal", "foo": ("bar" "baz")}
+parse: product: {1: "number"}

:(scenario parse_multiple_products)
def main [
1:number, 2:number <- copy 23
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: product: 1: "number"
+parse: product: 2: "number"
+parse: ingredient: {23: "literal"}
+parse: product: {1: "number"}
+parse: product: {2: "number"}

:(scenario parse_multiple_ingredients)
def main [
1:number, 2:number <- copy 23, 4:number
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: ingredient: 4: "number"
+parse: product: 1: "number"
+parse: product: 2: "number"
+parse: ingredient: {23: "literal"}
+parse: ingredient: {4: "number"}
+parse: product: {1: "number"}
+parse: product: {2: "number"}

:(scenario parse_multiple_types)
def main [
1:number, 2:address:number <- copy 23, 4:number
]
+parse: instruction: copy
+parse: ingredient: 23: "literal"
+parse: ingredient: 4: "number"
+parse: product: 1: "number"
+parse: product: 2: ("address" "number")
+parse: ingredient: {23: "literal"}
+parse: ingredient: {4: "number"}
+parse: product: {1: "number"}
+parse: product: {2: ("address" "number")}

:(scenario parse_properties)
def main [
1:address:number/lookup <- copy 23
]
+parse: product: 1: ("address" "number"), {"lookup": ()}
+parse: product: {1: ("address" "number"), "lookup": ()}

//: this test we can't represent with a scenario
:(code)
Expand Down
22 changes: 11 additions & 11 deletions 014literal_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
def main [
1:address:array:character <- copy [abc def] # copy can't really take a string
]
+parse: ingredient: "abc def": "literal-string"
+parse: ingredient: {"abc def": "literal-string"}
:(scenario string_literal_with_colons)
def main [
1:address:array:character <- copy [abc:def/ghi]
]
+parse: ingredient: "abc:def/ghi": "literal-string"
+parse: ingredient: {"abc:def/ghi": "literal-string"}
:(before "End Mu Types Initialization")
put(Type_ordinal, "literal-string", 0);
Expand Down Expand Up @@ -131,7 +131,7 @@ string emit_literal_string(string name) {
size_t pos = 0;
while (pos != string::npos)
pos = replace(name, "\n", "\\n", pos);
return '"'+name+"\": \"literal-string\"";
return "{\""+name+"\": \"literal-string\"}";
}
size_t replace(string& str, const string& from, const string& to, size_t n) {
Expand All @@ -149,20 +149,20 @@ void strip_last(string& s) {
def main [
1:address:array:character <- copy [abc [def]]
]
+parse: ingredient: "abc [def]": "literal-string"
+parse: ingredient: {"abc [def]": "literal-string"}
:(scenario string_literal_escaped)
def main [
1:address:array:character <- copy [abc \[def]
]
+parse: ingredient: "abc [def": "literal-string"
+parse: ingredient: {"abc [def": "literal-string"}
:(scenario string_literal_escaped_comment_aware)
def main [
1:address:array:character <- copy [
abc \\\[def]
]
+parse: ingredient: "\nabc \[def": "literal-string"
+parse: ingredient: {"\nabc \[def": "literal-string"}
:(scenario string_literal_and_comment)
def main [
Expand All @@ -171,15 +171,15 @@ def main [
+parse: --- defining main
+parse: instruction: copy
+parse: number of ingredients: 1
+parse: ingredient: "abc": "literal-string"
+parse: product: 1: ("address" "array" "character")
+parse: ingredient: {"abc": "literal-string"}
+parse: product: {1: ("address" "array" "character")}
:(scenario string_literal_escapes_newlines_in_trace)
def main [
copy [abc
def]
]
+parse: ingredient: "abc\ndef": "literal-string"
+parse: ingredient: {"abc\ndef": "literal-string"}
:(scenario string_literal_can_skip_past_comments)
def main [
Expand All @@ -188,10 +188,10 @@ def main [
bar
]
]
+parse: ingredient: "\n # ']' inside comment\n bar\n ": "literal-string"
+parse: ingredient: {"\n # ']' inside comment\n bar\n ": "literal-string"}
:(scenario string_literal_empty)
def main [
copy []
]
+parse: ingredient: "": "literal-string"
+parse: ingredient: {"": "literal-string"}
2 changes: 1 addition & 1 deletion 015literal_noninteger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def main [
1:number <- copy 3.14159
]
+parse: ingredient: 3.14159: "literal-fractional-number"
+parse: ingredient: {3.14159: "literal-fractional-number"}

:(after "Parsing reagent(string s)")
if (is_noninteger(s)) {
Expand Down
18 changes: 7 additions & 11 deletions 020run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
def main [
1:number <- copy 23
]
+run: 1:number <- copy 23
+run: {1: "number"} <- copy {23: "literal"}
+mem: storing 23 in location 1

:(scenario copy)
def main [
1:number <- copy 23
2:number <- copy 1:number
]
+run: 2:number <- copy 1:number
+run: {2: "number"} <- copy {1: "number"}
+mem: location 1 is 23
+mem: storing 23 in location 2

Expand Down Expand Up @@ -87,7 +87,7 @@ void run_current_routine()
}
}
if (SIZE(products) < SIZE(current_instruction().products)) {
raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << to_string(current_instruction()) << '\n' << end();
raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << to_original_string(current_instruction()) << '\n' << end();
}
else {
for (int i = 0; i < SIZE(current_instruction().products); ++i) {
Expand Down Expand Up @@ -275,7 +275,7 @@ void write_memory(reagent x, const vector<double>& data) {
// End Preprocess write_memory(x)
if (x.value == 0) return;
if (size_mismatch(x, data)) {
raise << maybe(current_recipe_name()) << "size mismatch in storing to " << x.original_string << " (" << size_of(x.type) << " vs " << SIZE(data) << ") at '" << to_string(current_instruction()) << "'\n" << end();
raise << maybe(current_recipe_name()) << "size mismatch in storing to " << x.original_string << " (" << size_of(x.type) << " vs " << SIZE(data) << ") at '" << to_original_string(current_instruction()) << "'\n" << end();
return;
}
// End write_memory(reagent x) Special-cases
Expand Down Expand Up @@ -305,10 +305,6 @@ bool size_mismatch(const reagent& x, const vector<double>& data) {
return size_of(x) != SIZE(data);
}

inline bool is_dummy(const reagent& x) {
return x.name == "_";
}

inline bool is_literal(const reagent& r) {
if (!r.type) return false;
if (r.type->value == 0)
Expand Down Expand Up @@ -343,15 +339,15 @@ def main [
1:number <- copy 23
2:number <- copy 1:number
]
+run: 1:number <- copy 23
+run: 2:number <- copy 1:number
+run: {1: "number"} <- copy {23: "literal"}
+run: {2: "number"} <- copy {1: "number"}
-run: +foo

:(scenario run_dummy)
def main [
_ <- copy 0
]
+run: _ <- copy 0
+run: _ <- copy {0: "literal"}

:(scenario write_to_0_disallowed)
% Hide_errors = true;
Expand Down
3 changes: 1 addition & 2 deletions 021check_instruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Transform.push_back(check_instruction); // idempotent
:(code)
void check_instruction(const recipe_ordinal r) {
trace(9991, "transform") << "--- perform checks for recipe " << get(Recipe, r).name << end();
//? cerr << "--- perform checks for recipe " << get(Recipe, r).name << '\n';
map<string, vector<type_ordinal> > metadata;
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
instruction& inst = get(Recipe, r).steps.at(i);
Expand All @@ -23,7 +22,7 @@ void check_instruction(const recipe_ordinal r) {
// Primitive Recipe Checks
case COPY: {
if (SIZE(inst.products) != SIZE(inst.ingredients)) {
raise << "ingredients and products should match in '" << to_string(inst) << "'\n" << end();
raise << "ingredients and products should match in '" << to_original_string(inst) << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
Expand Down
Loading

0 comments on commit acc4792

Please sign in to comment.