about summary refs log tree commit diff stats
path: root/cpp/.traces/divide
Commit message (Collapse)AuthorAgeFilesLines
* 968Kartik K. Agaram2015-03-241-3/+3
|
* 949 - paving the way for jumps to labelsKartik K. Agaram2015-03-171-7/+7
| | | | Addresses for reagents are now computed after all transforms.
* 941 - c++: basic break/loop conversionKartik K. Agaram2015-03-161-0/+4
|
* 940 - c++: some changes to instruction modelKartik K. Agaram2015-03-161-7/+7
|
* 832 - call-stack for C++ versionKartik K. Agaram2015-02-251-3/+3
| | | | | | | | | | These #defines and references now span many different layers. Let's see if the lack of encapsulation causes problems. Also interesting to run into a case where I need to modify a foundational layer and touch every single scenario/trace. Only alternative was to duplicate all the different layers that add instructions. Sign of problems with this model?
* 787 - arithmetic operationsKartik K. Agaram2015-02-191-0/+24
Lots of duplication here; we'll clean it up later.
r: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
//: So far the recipes we define can't run each other. Let's change 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 for a matching recipe
  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;