about summary refs log tree commit diff stats
path: root/011load.cc
Commit message (Expand)AuthorAgeFilesLines
* 2803Kartik K. Agaram2016-03-211-28/+28
* 2799 - new approach to undoing changes in testsKartik K. Agaram2016-03-201-20/+0
* 2773 - switch to 'int'Kartik K. Agaram2016-03-131-3/+3
* 2735 - define recipes using 'def'Kartik K. Agaram2016-03-081-20/+21
* 2712Kartik K. Agaram2016-02-261-9/+9
* 2709Kartik K. Agaram2016-02-251-1/+0
* 2704 - eradicate all mention of warnings from coreKartik K. Agaram2016-02-251-9/+9
* 2702Kartik K. Agaram2016-02-251-12/+12
* 2681 - drop reagent types from reagent propertiesKartik K. Agaram2016-02-211-42/+35
* 2689 - consistently use s-exp syntax in tracesKartik K. Agaram2016-02-191-4/+4
* 2686Kartik K. Agaram2016-02-191-1/+1
* 2685Kartik K. Agaram2016-02-191-4/+4
* 2648Kartik K. Agaram2016-02-111-0/+1
* 2643Kartik K. Agaram2016-02-101-2/+2
* 2617 - better error messagesKartik K. Agaram2016-01-301-1/+3
* 2603 - bugfix: defining main with commandline argsKartik K. Agaram2016-01-251-1/+1
* 2553 - keep failed specializations from generating spurious errorsKartik K. Agaram2015-12-281-2/+0
* three bugs fixedKartik K. Agaram2015-12-151-8/+13
* 2622Kartik K. Agaram2015-12-131-9/+9
* 2615Kartik K. Agaram2015-12-021-4/+16
* 2614 - still fixing bugs with missing '['Kartik K. Agaram2015-12-021-27/+9
* 2454Kartik K. Agaram2015-11-171-13/+13
* 2407 - bugfix: parsing recipe headersKartik K. Agaram2015-11-091-1/+3
* 2384 - tests pass until layer 54Kartik K. Agaram2015-11-071-1/+2
* 2379 - further improvements to map operationsKartik K. Agaram2015-11-061-1/+1
* 2378Kartik K. Agaram2015-11-061-1/+1
* 2377 - stop using operator[] in mapKartik K. Agaram2015-11-061-7/+7
* 2334Kartik K. Agaram2015-10-311-0/+2
* 2323 - static dispatch!Kartik K. Agaram2015-10-291-1/+1
* 2321 - more preparations for static dispatchKartik K. Agaram2015-10-291-9/+2
* 2316 - preparing for static dispatchKartik K. Agaram2015-10-291-14/+15
* 2314 - final tweaks to traceKartik K. Agaram2015-10-291-1/+1
* 2310 - add some more tracingKartik K. Agaram2015-10-291-4/+7
* 2306 - recipe headersKartik K. Agaram2015-10-281-8/+7
* 2293Kartik K. Agaram2015-10-271-3/+3
* 2287 - new lexing rulesKartik K. Agaram2015-10-271-5/+14
* 2286Kartik K. Agaram2015-10-271-1/+2
* 2285Kartik K. Agaram2015-10-261-2/+3
* 2283 - represent each /property as a treeKartik K. Agaram2015-10-261-7/+2
* 2282Kartik K. Agaram2015-10-261-28/+28
* 2277 - reagents now have a tree of typesKartik K. Agaram2015-10-251-3/+4
* 2276Kartik K. Agaram2015-10-251-1/+1
* 2274Kartik K. Agaram2015-10-251-3/+0
* 2273 - start expanding the type systemKartik K. Agaram2015-10-251-6/+0
* 2258 - separate warnings from errorsKartik K. Agaram2015-10-061-11/+11
* 2193Kartik K. Agaram2015-09-141-2/+2
* 2154 - check types only after loading all layersKartik K. Agaram2015-09-051-1/+0
* 2150 - recipe! to explicitly redefineKartik K. Agaram2015-09-051-16/+46
* 2149Kartik K. Agaram2015-09-051-2/+2
* 2134 - bugfix: comment terminated by eofKartik K. Agaram2015-09-021-5/+17
div class='alt'>
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

                                                                      






                                       
                             
 






                                                                             
                    






                                                    
                       



                                     

                        


                                 











                                                             
 
                                                                        
          
                                                        
                                                                
                                                                                                           

          
                                                  


                                                        
                                                                        
 


                                            
 
 
                                   


                                                                           
                 


                                      
 



                        
//: So far the recipes we define can't run each other. Let's fix that.

:(scenario "calling_recipe")
recipe main [
  f
]
recipe f [
  3:integer <- add 2:literal, 2:literal
]
+mem: storing 4 in location 3

:(before "struct routine {")
// Everytime a recipe runs another, we interrupt it and start running the new
// recipe. When that finishes, we continue this one where we left off.
// This requires maintaining a 'stack' of interrupted recipes or 'calls'.
struct call {
  recipe_number running_recipe;
  size_t pc;
  // End call Fields
  call(recipe_number r) :running_recipe(r), pc(0) {}
};
typedef stack<call> call_stack;

:(replace{} "struct routine")
struct routine {
  call_stack calls;
  // End routine Fields
  routine(recipe_number r);
};
:(code)
  routine::routine(recipe_number r) {
    calls.push(call(r));
  }

//:: now update routine's helpers

:(replace{} "inline size_t& running_at(routine& rr)")
inline size_t& running_at(routine& rr) {
  return rr.calls.top().pc;
}
:(replace{} "inline string recipe_name(routine& rr)")
inline string recipe_name(routine& rr) {
  return Recipe[rr.calls.top().running_recipe].name;
}
:(replace{} "inline vector<instruction>& steps(routine& rr)")
inline vector<instruction>& steps(routine& rr) {
  return Recipe[rr.calls.top().running_recipe].steps;
}

:(replace{} "default:" following "End Primitive Recipe Implementations")
default: {
  // not a primitive; try to look up the book of recipes
  if (Recipe.find(instructions[pc].operation) == Recipe.end()) {
    raise << "undefined operation " << instructions[pc].operation << ": " << instructions[pc].name << '\n';
    break;
  }
  rr.calls.push(call(instructions[pc].operation));
  continue;  // not done with caller; don't increment pc
}

//:: finally, we need to fix the termination conditions for the run loop

:(replace{} "inline bool done(routine& rr)")
inline bool done(routine& rr) {
  return rr.calls.empty();
}

:(before "Running one instruction")
// when we reach the end of one call, we may reach the end of the one below
// it, and the one below that, and so on
while (running_at(rr) >= steps(rr).size()) {
  rr.calls.pop();
  if (rr.calls.empty()) return;
  // todo: no results returned warning
  ++running_at(rr);
}

:(before "End Includes")
#include <stack>
using std::stack;