From 1228ec731ead0abec824f469cfc81f59209a2dcb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 12 Mar 2015 22:24:18 -0700 Subject: 896 - c++: routine --- cpp/012run | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'cpp/012run') diff --git a/cpp/012run b/cpp/012run index 45a6048f..2145f360 100644 --- a/cpp/012run +++ b/cpp/012run @@ -27,27 +27,36 @@ struct call { }; typedef stack call_stack; +struct routine { + size_t alloc; + size_t alloc_max; + call_stack calls; + size_t limit; + size_t running_since; + // todo: sleep conditions +}; + :(code) void run(string form) { recipe_number r = add_recipe(form); - call_stack context; - context.push(call(r)); - run(context); + routine rr; + rr.calls.push(call(r)); + run(rr); } -void run(call_stack context) { +void run(routine rr) { // #defines save us the trouble of updating aliases when dependent variables // change. -#define TOP_RECIPE Recipe[context.top().running_recipe] +#define TOP_RECIPE Recipe[rr.calls.top().running_recipe] #define instructions TOP_RECIPE.steps - while (!context.empty()) { - while (context.top().pc >= instructions.size()) { - context.pop(); - if (context.empty()) return; + while (!rr.calls.empty()) { + while (rr.calls.top().pc >= instructions.size()) { + rr.calls.pop(); + if (rr.calls.empty()) return; // todo: no results returned warning - ++context.top().pc; + ++rr.calls.top().pc; } - size_t& pc = context.top().pc; + size_t& pc = rr.calls.top().pc; trace("run") << "instruction " << TOP_RECIPE.name << '/' << pc; switch (instructions[pc].operation) { // Primitive Recipe Implementations. -- cgit 1.4.1-2-gfad0