From 7452d0525ecfc12c11fe005c31b089a5b4d7a102 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 15 Mar 2018 23:29:08 -0700 Subject: 4228 --- html/026call.cc.html | 190 +++++++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 91 deletions(-) (limited to 'html/026call.cc.html') diff --git a/html/026call.cc.html b/html/026call.cc.html index 84581ebc..12ff47c9 100644 --- a/html/026call.cc.html +++ b/html/026call.cc.html @@ -198,97 +198,105 @@ if ('onhashchange' in window) { 133 //? return get(Recipe, call.running_recipe).steps.at(call.running_step_index); 134 //? } 135 -136 :(after "Defined Recipe Checks") -137 // not a primitive; check that it's present in the book of recipes -138 if (!contains_key(Recipe, inst.operation)) { -139 raise << maybe(get(Recipe, r).name) << "undefined operation in '" << to_original_string(inst) << "'\n" << end(); -140 break; -141 } -142 :(replace{} "default:" following "End Primitive Recipe Implementations") -143 default: { -144 if (contains_key(Recipe, current_instruction().operation)) { // error already raised in Checks above -145 // not a primitive; look up the book of recipes -146 if (Trace_stream) { -147 ++Trace_stream->callstack_depth; -148 trace("trace") << "incrementing callstack depth to " << Trace_stream->callstack_depth << end(); -149 assert(Trace_stream->callstack_depth < 9000); // 9998-101 plus cushion -150 } -151 const call& caller_frame = current_call(); -152 Current_routine->calls.push_front(call(to_instruction(caller_frame).operation)); -153 finish_call_housekeeping(to_instruction(caller_frame), ingredients); -154 // not done with caller -155 write_products = false; -156 fall_through_to_next_instruction = false; -157 // End Non-primitive Call(caller_frame) -158 } -159 } -160 :(code) -161 void finish_call_housekeeping(const instruction& call_instruction, const vector<vector<double> >& ingredients) { -162 // End Call Housekeeping -163 } -164 -165 :(scenario calling_undefined_recipe_fails) -166 % Hide_errors = true; -167 def main [ -168 foo -169 ] -170 +error: main: undefined operation in 'foo' -171 -172 :(scenario calling_undefined_recipe_handles_missing_result) -173 % Hide_errors = true; -174 def main [ -175 x:num <- foo -176 ] -177 +error: main: undefined operation in 'x:num <- foo' -178 -179 //:: finally, we need to fix the termination conditions for the run loop -180 -181 :(replace{} "bool routine::completed() const") -182 bool routine::completed() const { -183 return calls.empty(); -184 } -185 -186 :(replace{} "const vector<instruction>& routine::steps() const") -187 const vector<instruction>& routine::steps() const { -188 assert(!calls.empty()); -189 return get(Recipe, calls.front().running_recipe).steps; -190 } -191 -192 :(after "Running One Instruction") -193 // when we reach the end of one call, we may reach the end of the one below -194 // it, and the one below that, and so on -195 while (current_step_index() >= SIZE(Current_routine->steps())) { -196 // Falling Through End Of Recipe -197 if (Trace_stream) { -198 trace("trace") << "fall-through: exiting " << current_recipe_name() << "; decrementing callstack depth from " << Trace_stream->callstack_depth << end(); -199 --Trace_stream->callstack_depth; -200 assert(Trace_stream->callstack_depth >= 0); -201 } -202 Current_routine->calls.pop_front(); -203 if (Current_routine->calls.empty()) goto stop_running_current_routine; -204 // Complete Call Fallthrough -205 // todo: fail if no products returned -206 ++current_step_index(); -207 } -208 -209 :(before "End Primitive Recipe Declarations") -210 _DUMP_CALL_STACK, -211 :(before "End Primitive Recipe Numbers") -212 put(Recipe_ordinal, "$dump-call-stack", _DUMP_CALL_STACK); -213 :(before "End Primitive Recipe Checks") -214 case _DUMP_CALL_STACK: { -215 break; -216 } -217 :(before "End Primitive Recipe Implementations") -218 case _DUMP_CALL_STACK: { -219 dump(Current_routine->calls); -220 break; -221 } -222 :(code) -223 void dump(const call_stack& calls) { -224 for (call_stack::const_reverse_iterator p = calls.rbegin(); p != calls.rend(); ++p) -225 cerr << get(Recipe, p->running_recipe).name << ":" << p->running_step_index << " -- " << to_string(to_instruction(*p)) << '\n'; -226 } +136 :(code) +137 void dump_callstack() { +138 if (!Current_routine) return; +139 if (Current_routine->calls.size() <= 1) return; +140 for (call_stack::const_iterator p = ++Current_routine->calls.begin(); p != Current_routine->calls.end(); ++p) +141 raise << " called from " << get(Recipe, p->running_recipe).name << ": " << to_original_string(to_instruction(*p)) << '\n' << end(); +142 } +143 +144 :(after "Defined Recipe Checks") +145 // not a primitive; check that it's present in the book of recipes +146 if (!contains_key(Recipe, inst.operation)) { +147 raise << maybe(get(Recipe, r).name) << "undefined operation in '" << to_original_string(inst) << "'\n" << end(); +148 break; +149 } +150 :(replace{} "default:" following "End Primitive Recipe Implementations") +151 default: { +152 if (contains_key(Recipe, current_instruction().operation)) { // error already raised in Checks above +153 // not a primitive; look up the book of recipes +154 if (Trace_stream) { +155 ++Trace_stream->callstack_depth; +156 trace("trace") << "incrementing callstack depth to " << Trace_stream->callstack_depth << end(); +157 assert(Trace_stream->callstack_depth < 9000); // 9998-101 plus cushion +158 } +159 const call& caller_frame = current_call(); +160 Current_routine->calls.push_front(call(to_instruction(caller_frame).operation)); +161 finish_call_housekeeping(to_instruction(caller_frame), ingredients); +162 // not done with caller +163 write_products = false; +164 fall_through_to_next_instruction = false; +165 // End Non-primitive Call(caller_frame) +166 } +167 } +168 :(code) +169 void finish_call_housekeeping(const instruction& call_instruction, const vector<vector<double> >& ingredients) { +170 // End Call Housekeeping +171 } +172 +173 :(scenario calling_undefined_recipe_fails) +174 % Hide_errors = true; +175 def main [ +176 foo +177 ] +178 +error: main: undefined operation in 'foo' +179 +180 :(scenario calling_undefined_recipe_handles_missing_result) +181 % Hide_errors = true; +182 def main [ +183 x:num <- foo +184 ] +185 +error: main: undefined operation in 'x:num <- foo' +186 +187 //:: finally, we need to fix the termination conditions for the run loop +188 +189 :(replace{} "bool routine::completed() const") +190 bool routine::completed() const { +191 return calls.empty(); +192 } +193 +194 :(replace{} "const vector<instruction>& routine::steps() const") +195 const vector<instruction>& routine::steps() const { +196 assert(!calls.empty()); +197 return get(Recipe, calls.front().running_recipe).steps; +198 } +199 +200 :(after "Running One Instruction") +201 // when we reach the end of one call, we may reach the end of the one below +202 // it, and the one below that, and so on +203 while (current_step_index() >= SIZE(Current_routine->steps())) { +204 // Falling Through End Of Recipe +205 if (Trace_stream) { +206 trace("trace") << "fall-through: exiting " << current_recipe_name() << "; decrementing callstack depth from " << Trace_stream->callstack_depth << end(); +207 --Trace_stream->callstack_depth; +208 assert(Trace_stream->callstack_depth >= 0); +209 } +210 Current_routine->calls.pop_front(); +211 if (Current_routine->calls.empty()) goto stop_running_current_routine; +212 // Complete Call Fallthrough +213 // todo: fail if no products returned +214 ++current_step_index(); +215 } +216 +217 :(before "End Primitive Recipe Declarations") +218 _DUMP_CALL_STACK, +219 :(before "End Primitive Recipe Numbers") +220 put(Recipe_ordinal, "$dump-call-stack", _DUMP_CALL_STACK); +221 :(before "End Primitive Recipe Checks") +222 case _DUMP_CALL_STACK: { +223 break; +224 } +225 :(before "End Primitive Recipe Implementations") +226 case _DUMP_CALL_STACK: { +227 dump(Current_routine->calls); +228 break; +229 } +230 :(code) +231 void dump(const call_stack& calls) { +232 for (call_stack::const_reverse_iterator p = calls.rbegin(); p != calls.rend(); ++p) +233 cerr << get(Recipe, p->running_recipe).name << ":" << p->running_step_index << " -- " << to_string(to_instruction(*p)) << '\n'; +234 } -- cgit 1.4.1-2-gfad0