diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-08-10 23:15:00 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-08-10 23:15:00 -0700 |
commit | 9edabeaa21186c089a9b11f63ba3164f9fa753fb (patch) | |
tree | bf02bd60f67c53ea49ecd15fb67f3fd58b7138f2 | |
parent | ae2b59cf25e2cae2694af1974e550dd1bc5dd137 (diff) | |
download | mu-9edabeaa21186c089a9b11f63ba3164f9fa753fb.tar.gz |
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.
-rw-r--r-- | 029tools.cc | 47 | ||||
-rw-r--r-- | 030container.cc | 9 | ||||
-rw-r--r-- | 032array.cc | 10 | ||||
-rw-r--r-- | 043new.cc | 33 | ||||
-rw-r--r-- | 081run_interactive.cc | 18 |
5 files changed, 99 insertions, 18 deletions
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<double>& 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") diff --git a/030container.cc b/030container.cc index f7fe8e3a..5bc81a5f 100644 --- a/030container.cc +++ b/030container.cc @@ -100,6 +100,15 @@ if (t.kind == container) { return result; } +:(scenario stash_container) +recipe main [ + 1:number <- copy 34 # first + 2:number <- copy 35 + 3:number <- copy 36 + stash [foo: ], 1:point-number/raw +] ++app: foo: 34 35 36 + //:: To access elements of a container, use 'get' :(scenario get) recipe main [ diff --git a/032array.cc b/032array.cc index 7220e0f0..bf51382d 100644 --- a/032array.cc +++ b/032array.cc @@ -37,6 +37,16 @@ recipe main [ +mem: storing 15 in location 8 +mem: storing 16 in location 9 +:(scenario stash_array) +recipe main [ + 1:number <- copy 3 # length + 2:number <- copy 14 + 3:number <- copy 15 + 4:number <- copy 16 + stash [foo: ], 1:array:number +] ++app: foo: 3 14 15 16 + //: disable the size mismatch check since the destination array need not be initialized :(before "End size_mismatch(x) Cases") if (x.types.at(0) == Type_ordinal["array"]) return false; diff --git a/043new.cc b/043new.cc index 89c3cc23..74083660 100644 --- a/043new.cc +++ b/043new.cc @@ -346,6 +346,21 @@ long long int new_mu_string(const string& contents) { return result; } +//: stash recognizes strings + +:(scenario stash_string) +recipe main [ + x:address:array:character <- new [abc] + stash [foo: ], x:address:array:character +] ++app: foo: abc + +:(before "End print Special-cases(reagent r, data)") +if (is_mu_string(r)) { + assert(scalar(data)); + return read_mu_string(data.at(0)); +} + //: Allocate more to routine when initializing a literal string :(scenario new_string_overflow) % Initial_memory_per_routine = 2; @@ -369,3 +384,21 @@ long long int unicode_length(const string& s) { } return result; } + +bool is_mu_string(const reagent& x) { + return SIZE(x.types) == 3 + && x.types.at(0) == Type_ordinal["address"] + && x.types.at(1) == Type_ordinal["array"] + && x.types.at(2) == Type_ordinal["character"]; +} + +string read_mu_string(long long int address) { + long long int size = Memory[address]; + if (size == 0) return ""; + ostringstream tmp; + for (long long int curr = address+1; curr <= address+size; ++curr) { + // todo: unicode + tmp << (char)(int)Memory[curr]; + } + return tmp.str(); +} diff --git a/081run_interactive.cc b/081run_interactive.cc index e627b0f6..6ef85afd 100644 --- a/081run_interactive.cc +++ b/081run_interactive.cc @@ -240,17 +240,6 @@ string strip_comments(string in) { return result.str(); } -string read_mu_string(long long int address) { - long long int size = Memory[address]; - if (size == 0) return ""; - ostringstream tmp; - for (long long int curr = address+1; curr <= address+size; ++curr) { - // todo: unicode - tmp << (char)(int)Memory[curr]; - } - return tmp.str(); -} - long long int stringified_value_of_location(long long int address) { // convert to string ostringstream out; @@ -258,13 +247,6 @@ long long int stringified_value_of_location(long long int address) { return new_mu_string(out.str()); } -bool is_mu_string(const reagent& x) { - return SIZE(x.types) == 3 - && x.types.at(0) == Type_ordinal["address"] - && x.types.at(1) == Type_ordinal["array"] - && x.types.at(2) == Type_ordinal["character"]; -} - long long int trace_contents(const string& layer) { if (!Trace_stream) return 0; //? cerr << "trace stream exists\n"; //? 1 |