From 469524d6defc0c94c11b7aec9f9a724f01e58407 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 13 Jul 2015 14:15:09 -0700 Subject: 1767 --- 025trace.cc | 31 ------------------ 026assert.cc | 21 ------------ 027debug.cc | 105 ----------------------------------------------------------- 027trace.cc | 31 ++++++++++++++++++ 028assert.cc | 21 ++++++++++++ 029debug.cc | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+), 157 deletions(-) delete mode 100644 025trace.cc delete mode 100644 026assert.cc delete mode 100644 027debug.cc create mode 100644 027trace.cc create mode 100644 028assert.cc create mode 100644 029debug.cc diff --git a/025trace.cc b/025trace.cc deleted file mode 100644 index 71a113ba..00000000 --- a/025trace.cc +++ /dev/null @@ -1,31 +0,0 @@ -//: Allow mu programs to log facts just like we've been doing in C++ so far. - -:(scenario trace) -recipe main [ - trace [foo], [this is a trace in mu] -] -+foo: this is a trace in mu - -:(before "End Primitive Recipe Declarations") -TRACE, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["trace"] = TRACE; -:(before "End Primitive Recipe Implementations") -case TRACE: { - assert(is_literal(current_instruction().ingredients.at(0))); - string label = current_instruction().ingredients.at(0).name; - assert(is_literal(current_instruction().ingredients.at(1))); - string message = current_instruction().ingredients.at(1).name; - trace(1, label) << message; - break; -} - -:(before "End Primitive Recipe Declarations") -HIDE_WARNINGS, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["hide-warnings"] = HIDE_WARNINGS; -:(before "End Primitive Recipe Implementations") -case HIDE_WARNINGS: { - Hide_warnings = true; - break; -} diff --git a/026assert.cc b/026assert.cc deleted file mode 100644 index f864d43e..00000000 --- a/026assert.cc +++ /dev/null @@ -1,21 +0,0 @@ -:(scenario assert) -% Hide_warnings = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. -recipe main [ - assert 0:literal, [this is an assert in mu] -] -+warn: this is an assert in mu - -:(before "End Primitive Recipe Declarations") -ASSERT, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["assert"] = ASSERT; -:(before "End Primitive Recipe Implementations") -case ASSERT: { - assert(SIZE(ingredients) == 2); - assert(scalar(ingredients.at(0))); - if (!ingredients.at(0).at(0)) { - assert(is_literal(current_instruction().ingredients.at(1))); - raise << current_instruction().ingredients.at(1).name << '\n' << die(); - } - break; -} diff --git a/027debug.cc b/027debug.cc deleted file mode 100644 index 301cd01a..00000000 --- a/027debug.cc +++ /dev/null @@ -1,105 +0,0 @@ -//: Recipe to look at elements of containers. - -:(before "End Primitive Recipe Declarations") -_PRINT, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$print"] = _PRINT; -:(before "End Primitive Recipe Implementations") -case _PRINT: { - for (long long int i = 0; i < SIZE(ingredients); ++i) { - if (is_literal(current_instruction().ingredients.at(i))) { - trace(Primitive_recipe_depth, "run") << "$print: " << current_instruction().ingredients.at(i).name; - cout << current_instruction().ingredients.at(i).name; - } - else { - for (long long int j = 0; j < SIZE(ingredients.at(i)); ++j) { - trace(Primitive_recipe_depth, "run") << "$print: " << ingredients.at(i).at(j); - if (j > 0) cout << " "; - cout << ingredients.at(i).at(j); - } - } - } - break; -} - -:(before "End Primitive Recipe Declarations") -_START_TRACING, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$start-tracing"] = _START_TRACING; -:(before "End Primitive Recipe Implementations") -case _START_TRACING: { - if (current_instruction().ingredients.empty()) - Trace_stream->dump_layer = "all"; - else - Trace_stream->dump_layer = current_instruction().ingredients.at(0).name; -//? cout << Trace_stream << ": " << Trace_stream->dump_layer << '\n'; //? 1 - break; -} - -:(before "End Primitive Recipe Declarations") -_STOP_TRACING, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$stop-tracing"] = _STOP_TRACING; -:(before "End Primitive Recipe Implementations") -case _STOP_TRACING: { - Trace_stream->dump_layer = ""; - break; -} - -:(before "End Primitive Recipe Declarations") -_CLOSE_TRACE, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$close-trace"] = _CLOSE_TRACE; -:(before "End Primitive Recipe Implementations") -case _CLOSE_TRACE: { - if (Trace_stream) { - delete Trace_stream; - Trace_stream = NULL; - } - break; -} - -:(before "End Primitive Recipe Declarations") -_EXIT, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$exit"] = _EXIT; -:(before "End Primitive Recipe Implementations") -case _EXIT: { - exit(0); - break; -} - -:(before "End Primitive Recipe Declarations") -_DUMP_TRACE, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$dump-trace"] = _DUMP_TRACE; -:(before "End Primitive Recipe Implementations") -case _DUMP_TRACE: { - if (ingredients.empty()) { - DUMP(""); - } - else { - DUMP(current_instruction().ingredients.at(0).name); - } - break; -} - -:(before "End Primitive Recipe Declarations") -_CLEAR_TRACE, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$clear-trace"] = _CLEAR_TRACE; -:(before "End Primitive Recipe Implementations") -case _CLEAR_TRACE: { - CLEAR_TRACE; - break; -} - -:(before "End Primitive Recipe Declarations") -_DUMP_MEMORY, -:(before "End Primitive Recipe Numbers") -Recipe_ordinal["$dump-memory"] = _DUMP_MEMORY; -:(before "End Primitive Recipe Implementations") -case _DUMP_MEMORY: { - dump_memory(); - break; -} diff --git a/027trace.cc b/027trace.cc new file mode 100644 index 00000000..71a113ba --- /dev/null +++ b/027trace.cc @@ -0,0 +1,31 @@ +//: Allow mu programs to log facts just like we've been doing in C++ so far. + +:(scenario trace) +recipe main [ + trace [foo], [this is a trace in mu] +] ++foo: this is a trace in mu + +:(before "End Primitive Recipe Declarations") +TRACE, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["trace"] = TRACE; +:(before "End Primitive Recipe Implementations") +case TRACE: { + assert(is_literal(current_instruction().ingredients.at(0))); + string label = current_instruction().ingredients.at(0).name; + assert(is_literal(current_instruction().ingredients.at(1))); + string message = current_instruction().ingredients.at(1).name; + trace(1, label) << message; + break; +} + +:(before "End Primitive Recipe Declarations") +HIDE_WARNINGS, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["hide-warnings"] = HIDE_WARNINGS; +:(before "End Primitive Recipe Implementations") +case HIDE_WARNINGS: { + Hide_warnings = true; + break; +} diff --git a/028assert.cc b/028assert.cc new file mode 100644 index 00000000..f864d43e --- /dev/null +++ b/028assert.cc @@ -0,0 +1,21 @@ +:(scenario assert) +% Hide_warnings = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. +recipe main [ + assert 0:literal, [this is an assert in mu] +] ++warn: this is an assert in mu + +:(before "End Primitive Recipe Declarations") +ASSERT, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["assert"] = ASSERT; +:(before "End Primitive Recipe Implementations") +case ASSERT: { + assert(SIZE(ingredients) == 2); + assert(scalar(ingredients.at(0))); + if (!ingredients.at(0).at(0)) { + assert(is_literal(current_instruction().ingredients.at(1))); + raise << current_instruction().ingredients.at(1).name << '\n' << die(); + } + break; +} diff --git a/029debug.cc b/029debug.cc new file mode 100644 index 00000000..301cd01a --- /dev/null +++ b/029debug.cc @@ -0,0 +1,105 @@ +//: Recipe to look at elements of containers. + +:(before "End Primitive Recipe Declarations") +_PRINT, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$print"] = _PRINT; +:(before "End Primitive Recipe Implementations") +case _PRINT: { + for (long long int i = 0; i < SIZE(ingredients); ++i) { + if (is_literal(current_instruction().ingredients.at(i))) { + trace(Primitive_recipe_depth, "run") << "$print: " << current_instruction().ingredients.at(i).name; + cout << current_instruction().ingredients.at(i).name; + } + else { + for (long long int j = 0; j < SIZE(ingredients.at(i)); ++j) { + trace(Primitive_recipe_depth, "run") << "$print: " << ingredients.at(i).at(j); + if (j > 0) cout << " "; + cout << ingredients.at(i).at(j); + } + } + } + break; +} + +:(before "End Primitive Recipe Declarations") +_START_TRACING, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$start-tracing"] = _START_TRACING; +:(before "End Primitive Recipe Implementations") +case _START_TRACING: { + if (current_instruction().ingredients.empty()) + Trace_stream->dump_layer = "all"; + else + Trace_stream->dump_layer = current_instruction().ingredients.at(0).name; +//? cout << Trace_stream << ": " << Trace_stream->dump_layer << '\n'; //? 1 + break; +} + +:(before "End Primitive Recipe Declarations") +_STOP_TRACING, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$stop-tracing"] = _STOP_TRACING; +:(before "End Primitive Recipe Implementations") +case _STOP_TRACING: { + Trace_stream->dump_layer = ""; + break; +} + +:(before "End Primitive Recipe Declarations") +_CLOSE_TRACE, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$close-trace"] = _CLOSE_TRACE; +:(before "End Primitive Recipe Implementations") +case _CLOSE_TRACE: { + if (Trace_stream) { + delete Trace_stream; + Trace_stream = NULL; + } + break; +} + +:(before "End Primitive Recipe Declarations") +_EXIT, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$exit"] = _EXIT; +:(before "End Primitive Recipe Implementations") +case _EXIT: { + exit(0); + break; +} + +:(before "End Primitive Recipe Declarations") +_DUMP_TRACE, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$dump-trace"] = _DUMP_TRACE; +:(before "End Primitive Recipe Implementations") +case _DUMP_TRACE: { + if (ingredients.empty()) { + DUMP(""); + } + else { + DUMP(current_instruction().ingredients.at(0).name); + } + break; +} + +:(before "End Primitive Recipe Declarations") +_CLEAR_TRACE, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$clear-trace"] = _CLEAR_TRACE; +:(before "End Primitive Recipe Implementations") +case _CLEAR_TRACE: { + CLEAR_TRACE; + break; +} + +:(before "End Primitive Recipe Declarations") +_DUMP_MEMORY, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$dump-memory"] = _DUMP_MEMORY; +:(before "End Primitive Recipe Implementations") +case _DUMP_MEMORY: { + dump_memory(); + break; +} -- cgit 1.4.1-2-gfad0