From 9edabeaa21186c089a9b11f63ba3164f9fa753fb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 10 Aug 2015 23:15:00 -0700 Subject: 1975 - let's start using traces in lessons More friendly way to 'stash' stuff in the trace so that you can toggle lines of code to see their stashed traces. --- 029tools.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to '029tools.cc') diff --git a/029tools.cc b/029tools.cc index 9b090eb2..05753e4b 100644 --- a/029tools.cc +++ b/029tools.cc @@ -37,6 +37,53 @@ recipe main [ ] +app: foo +//: a smarter but more limited version of 'trace' + +:(before "End Primitive Recipe Declarations") +STASH, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["stash"] = STASH; +:(before "End Primitive Recipe Implementations") +case STASH: { + ostringstream out; + for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) { + out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i)); + } + trace(1, "app") << out.str() << end(); + break; +} + +:(scenario stash_literal_string) +recipe main [ + stash [foo] +] ++app: foo + +:(scenario stash_literal_number) +recipe main [ + stash [foo: ], 4 +] ++app: foo: 4 + +:(scenario stash_number) +recipe main [ + 1:number <- copy 34 + stash [foo: ], 1:number +] ++app: foo: 34 + +:(code) +string print_mu(const reagent& r, const vector& data) { + if (is_literal(r)) + return r.name; + // End print Special-cases(reagent r, data) + ostringstream out; + for (long long i = 0; i < SIZE(data); ++i) { + out << data.at(i) << ' '; + } + return out.str(); +} + :(before "End Primitive Recipe Declarations") HIDE_WARNINGS, :(before "End Primitive Recipe Numbers") -- cgit 1.4.1-2-gfad0