From 9542bb112419d575190a72baf7f964c3e32df223 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 25 Jul 2015 22:15:51 -0700 Subject: 1853 --- html/031address.cc.html | 107 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 82 insertions(+), 25 deletions(-) (limited to 'html/031address.cc.html') diff --git a/html/031address.cc.html b/html/031address.cc.html index 76971a4f..2f88d3e2 100644 --- a/html/031address.cc.html +++ b/html/031address.cc.html @@ -13,14 +13,16 @@ pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } * { font-size: 1.05em; } -.traceContains { color: #008000; } -.Constant { color: #00a0a0; } +.cSpecial { color: #008000; } .SalientComment { color: #00ffff; } +.Constant { color: #00a0a0; } +.CommentedCode { color: #6c6c6c; } +.Normal { color: #eeeeee; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Delimiter { color: #a04060; } .Special { color: #ff6060; } .Identifier { color: #804000; } -.CommentedCode { color: #6c6c6c; } +.traceContains { color: #008000; } --> @@ -61,37 +63,43 @@ x = canonize(x); :(code) reagent canonize(reagent x) { - if (is_literal(x)) return x; + if (is_literal(x)) return x; //? cout << "canonize\n"; //? 1 reagent r = x; //? cout << x.to_string() << " => " << r.to_string() << '\n'; //? 1 - while (has_property(r, "deref")) + while (has_property(r, "deref")) r = deref(r); return r; } reagent deref(reagent x) { //? cout << "deref: " << x.to_string() << "\n"; //? 2 - static const type_ordinal ADDRESS = Type_ordinal["address"]; + static const type_ordinal ADDRESS = Type_ordinal["address"]; reagent result; - assert(x.types.at(0) == ADDRESS); - + if (x.types.at(0) != ADDRESS) { + raise << current_recipe_name() << ": tried to /deref " << x.original_string << " but it isn't an address\n" << end(); + return result; + } // compute value + if (x.value == 0) { + raise << current_recipe_name() << ": tried to /deref 0\n" << end(); + return result; + } result.set_value(Memory[x.value]); - trace(Primitive_recipe_depth, "mem") << "location " << x.value << " is " << result.value; + trace(Primitive_recipe_depth, "mem") << "location " << x.value << " is " << result.value << end(); // populate types copy(++x.types.begin(), x.types.end(), inserter(result.types, result.types.begin())); // drop-one 'deref' - long long int i = 0; - long long int len = SIZE(x.properties); - for (i = 0; i < len; ++i) { - if (x.properties.at(i).first == "deref") break; + long long int i = 0; + long long int len = SIZE(x.properties); + for (i = 0; i < len; ++i) { + if (x.properties.at(i).first == "deref") break; result.properties.push_back(x.properties.at(i)); } ++i; // skip first deref - for (; i < len; ++i) { + for (; i < len; ++i) { result.properties.push_back(x.properties.at(i)); } return result; @@ -132,22 +140,71 @@ recipe main [ :(after "reagent base = " following "case GET_ADDRESS:") base = canonize(base); -//:: helpers +//:: Helpers for debugging -:(code) -bool has_property(reagent x, string name) { - for (long long int i = /*skip name:type*/1; i < SIZE(x.properties); ++i) { - if (x.properties.at(i).first == name) return true; +:(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); } - return false; + break; } -vector<string> property(const reagent& r, const string& name) { - for (long long int p = /*skip name:type*/1; p != SIZE(r.properties); ++p) { - if (r.properties.at(p).first == name) - return r.properties.at(p).second; +:(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; +} + +:(before "End Primitive Recipe Declarations") +_DUMP, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$dump"] = _DUMP; +:(before "End Primitive Recipe Implementations") +case _DUMP: { + reagent after_canonize = canonize(current_instruction().ingredients.at(0)); + cerr << current_recipe_name() << ": " << current_instruction().ingredients.at(0).name << ' ' << current_instruction().ingredients.at(0).value << " => " << after_canonize.value << " => " << Memory[after_canonize.value] << '\n'; + break; +} + +//: grab an address, and then dump its value at intervals +:(before "End Globals") +long long int foo = -1; +:(before "End Primitive Recipe Declarations") +_FOO, +:(before "End Primitive Recipe Numbers") +Recipe_ordinal["$foo"] = _FOO; +:(before "End Primitive Recipe Implementations") +case _FOO: { + if (current_instruction().ingredients.empty()) { + if (foo != -1) cerr << foo << ": " << Memory[foo] << '\n'; + else cerr << '\n'; + } + else { + foo = canonize(current_instruction().ingredients.at(0)).value; } - return vector<string>(); + break; } -- cgit 1.4.1-2-gfad0