about summary refs log tree commit diff stats
path: root/cpp/.traces
ModeNameSize
-rw-r--r--add1100log stats plain blame
-rw-r--r--add_literal460log stats plain blame
-rw-r--r--and1088log stats plain blame
-rw-r--r--array_length1502log stats plain blame
-rw-r--r--brace_conversion385log stats plain blame
-rw-r--r--break_cascading530log stats plain blame
-rw-r--r--break_cascading2956log stats plain blame
-rw-r--r--break_empty_block385log stats plain blame
-rw-r--r--break_if1046log stats plain blame
-rw-r--r--break_label477log stats plain blame
-rw-r--r--break_nested1114log stats plain blame
-rw-r--r--break_nested_degenerate901log stats plain blame
-rw-r--r--break_nested_degenerate2688log stats plain blame
-rw-r--r--break_unless905log stats plain blame
-rw-r--r--calling_recipe546log stats plain blame
-rw-r--r--convert_names341log stats plain blame
-rw-r--r--convert_names_handles_records489log stats plain blame
-rw-r--r--convert_names_passes_default_space415log stats plain blame
-rw-r--r--convert_names_passes_dummy389log stats plain blame
-rw-r--r--convert_names_passes_raw331log stats plain blame
-rw-r--r--convert_names_transforms_record_elements1145log stats plain blame
-rw-r--r--copy646log stats plain blame
-rw-r--r--copy_array1725log stats plain blame
-rw-r--r--copy_handles_nested_record_elements1388log stats plain blame
-rw-r--r--copy_indirect999log stats plain blame
-rw-r--r--copy_literal326log stats plain blame
-rw-r--r--copy_multiple_locations997log stats plain blame
-rw-r--r--deref_sidesteps_default_space1609log stats plain blame
-rw-r--r--divide1121log stats plain blame
-rw-r--r--divide_literal480log stats plain blame
-rw-r--r--divide_with_remainder1250log stats plain blame
-rw-r--r--divide_with_remainder_literal604log stats plain blame
-rw-r--r--equal1101log stats plain blame
-rw-r--r--equal21101log stats plain blame
-rw-r--r--factorial5385log stats plain blame
-rw-r--r--first_recipe191log stats plain blame
-rw-r--r--get1137log stats plain blame
-rw-r--r--get_address1111log stats plain blame
-rw-r--r--get_address_indirect1425log stats plain blame
-rw-r--r--get_handles_nested_record_elements1447log stats plain blame
-rw-r--r--get_indirect1464log stats plain blame
-rw-r--r--greater_or_equal1112log stats plain blame
-rw-r--r--greater_or_equal21112log stats plain blame
-rw-r--r--greater_or_equal31112log stats plain blame
-rw-r--r--greater_than1108log stats plain blame
-rw-r--r--greater_than21108log stats plain blame
-rw-r--r--include_nonderef_properties1473log stats plain blame
-rw-r--r--index1860log stats plain blame
-rw-r--r--index_address1752log stats plain blame
-rw-r--r--index_direct_offset2178log stats plain blame
-rw-r--r--index_indirect2246log stats plain blame
-rw-r--r--jump224log stats plain blame
-rw-r--r--jump_backward627log stats plain blame
-rw-r--r--jump_can_skip_instructions439log stats plain blame
-rw-r--r--jump_if573log stats plain blame
-rw-r--r--jump_if_fallthrough626log stats plain blame
-rw-r--r--jump_unless571log stats plain blame
-rw-r--r--jump_unless_fallthrough640log stats plain blame
-rw-r--r--lesser_or_equal1111log stats plain blame
-rw-r--r--lesser_or_equal21111log stats plain blame
-rw-r--r--lesser_or_equal31111log stats plain blame
-rw-r--r--lesser_than1107log stats plain blame
-rw-r--r--lesser_than21107log stats plain blame
-rw-r--r--loop948log stats plain blame
-rw-r--r--loop_label474log stats plain blame
-rw-r--r--loop_nested1205log stats plain blame
-rw-r--r--loop_unless906log stats plain blame
-rw-r--r--multiply1120log stats plain blame
-rw-r--r--multiply_literal482log stats plain blame
-rw-r--r--new1204log stats plain blame
-rw-r--r--new_array1333log stats plain blame
-rw-r--r--new_string1091log stats plain blame
-rw-r--r--next_ingredient880log stats plain blame
-rw-r--r--not661log stats plain blame
-rw-r--r--or1087log stats plain blame
-rw-r--r--parse_comment_after_instruction191log stats plain blame
-rw-r--r--parse_comment_amongst_instruction191log stats plain blame
-rw-r--r--parse_comment_amongst_instruction2191log stats plain blame
-rw-r--r--parse_comment_amongst_instruction3382log stats plain blame
-rw-r--r--parse_comment_outside_recipe191log stats plain blame
-rw-r--r--parse_label21log stats plain blame
-rw-r--r--parse_multiple_ingredients356log stats plain blame
-rw-r--r--parse_multiple_products272log stats plain blame
-rw-r--r--parse_multiple_properties211log stats plain blame
-rw-r--r--parse_multiple_types368log stats plain blame
-rw-r--r--parse_properties214log stats plain blame
-rw-r--r--reply1439log stats plain blame
-rw-r--r--reply_record1102log stats plain blame
-rw-r--r--run_dummy289log stats plain blame
-rw-r--r--run_label667log stats plain blame
-rw-r--r--set_default_space926log stats plain blame
-rw-r--r--store_indirect679log stats plain blame
-rw-r--r--string_literal363log stats plain blame
-rw-r--r--string_literal_nested369log stats plain blame
-rw-r--r--subtract1107log stats plain blame
-rw-r--r--subtract_literal457log stats plain blame
-rw-r--r--surrounding_space1848log stats plain blame
                                                            
         

                                                 


               







                                             
                       





                   

                    

                                                                              


                                                  


                        
:(after "Types")
// A program is a book of 'recipes' (functions)
typedef int recipe_number;
:(before "End Globals")
unordered_map<string, recipe_number> Recipe_number;
unordered_map<recipe_number, recipe> Recipe;
int Next_recipe_number = 1;

:(before "End Types")
// Recipes are lists of instructions. To run a recipe, the computer runs its
// instructions.
struct recipe {
  string name;
  vector<instruction> steps;
  // End Recipe Fields
};

:(before "struct recipe")
// Each instruction is either of the form:
//   product1, product2, product3, ... <- operation ingredient1, ingredient2, ingredient3, ...
// or just a single 'label' followed by a colon
//   label:
// Labels don't do anything, they're just waypoints.
struct instruction {
  bool is_label;
  string label;  // only if is_label
  string name;  // only if !is_label
  recipe_number operation;  // Recipe_number[name]
  vector<reagent> ingredients;  // only if !is_label
  vector<reagent> products;  // only if !is_label
  instruction();
  void clear();
};

:(before "struct instruction")
// Ingredients and products are a single species -- a reagent. Reagents refer
// either to numbers or to locations in memory along with 'type' tags telling
// us how to interpret them. They also can contain arbitrary other lists of
// properties besides types, but we're getting ahead of ourselves.
struct reagent {
  vector<pair<string, vector<string> > > properties;
  string name;
  int value;
  bool initialized;
  vector<type_number> types;
  reagent(string s);
  reagent();
  void set_value(int v) { value = v; initialized = true; }
  string to_string();
};

:(before "struct reagent")
struct property {
  vector<string> values;
};

:(before "End Globals")
// Locations refer to a common 'memory'. Each location can store a number.
unordered_map<int, int> Memory;
:(before "End Setup")
  Memory.clear();

:(after "Types")
// Mu types encode how the numbers stored in different parts of memory are
// interpreted. A location tagged as a 'character' type will interpret the
// number 97 as the letter 'a', while a different location of type 'integer'
// would not.
//
// Unlike most computers today, mu stores types in a single big table, shared
// by all the mu programs on the computer. This is useful in providing a
// seamless experience to help understand arbitrary mu programs.
typedef int type_number;
:(before "End Globals")
unordered_map<string, type_number> Type_number;
unordered_map<type_number, type_info> Type;
int Next_type_number = 1;
:(code)
void setup_types() {
  Type.clear();  Type_number.clear();
  Type_number["literal"] = 0;
  Next_type_number = 1;
  // Mu Types Initialization.
  int integer = Type_number["integer"] = Next_type_number++;
  Type_number["location"] = Type_number["integer"];  // wildcard type
  Type[integer].name = "integer";
  int address = Type_number["address"] = Next_type_number++;
  Type[address].name = "address";
  int boolean = Type_number["boolean"] = Next_type_number++;
  Type[boolean].name = "boolean";
  int character = Type_number["character"] = Next_type_number++;
  Type[character].name = "character";
  int array = Type_number["array"] = Next_type_number++;
  Type[array].name = "array";
  // End Mu Types Initialization.
}
:(before "End Setup")
  setup_types();

:(before "End Types")
// You can construct arbitrary new types. Types are either 'records', containing
// 'fields' of other types, or 'array's of a single type repeated over and over.
//
// For example:
//  storing bank balance next to a person's name might require a record, and
//  high scores in a game might need an array of numbers.
struct type_info {
  string name;
  bool is_record;
  size_t size;  // only if is_record; primitives and addresses have size 1 while arrays are dynamic
  vector<vector<type_number> > elements;  // only if is_record
  vector<string> element_names;  // only if is_record
  // End type_info Fields.
  type_info() :is_record(false), size(0) {}
};

:(before "End Globals")
const int IDLE = 0;  // always the first entry in the recipe book
const int COPY = 1;
:(code)
// It's all very well to construct recipes out of other recipes, but we need
// to know how to do *something* out of the box. For the following
// recipes there are only codes, no entries in the book, because mu just knows
// what to do for them.
void setup_recipes() {
  Recipe.clear();  Recipe_number.clear();
  Next_recipe_number = 0;
  Recipe_number["idle"] = IDLE;
  assert(Next_recipe_number == IDLE);
  Next_recipe_number++;
  // Primitive Recipe Numbers.
  Recipe_number["copy"] = COPY;
  assert(Next_recipe_number == COPY);
  Next_recipe_number++;
  // End Primitive Recipe Numbers.
  assert(Next_recipe_number < 100);
  Next_recipe_number = 100;
}
:(before "End Setup")
  setup_recipes();



//: Helpers

:(code)
// indent members to avoid generating prototypes for them
  instruction::instruction() :is_label(false), operation(IDLE) {}
  void instruction::clear() { is_label=false; label.clear(); operation=IDLE; ingredients.clear(); products.clear(); }

  // Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...
  reagent::reagent(string s) :value(0), initialized(false) {
    istringstream in(s);
    in >> std::noskipws;
    // properties
    while (!in.eof()) {
      istringstream row(slurp_until(in, '/'));
      row >> std::noskipws;
      string name = slurp_until(row, ':');
      vector<string> values;
      while (!row.eof())
        values.push_back(slurp_until(row, ':'));
      properties.push_back(pair<string, vector<string> >(name, values));
    }
    // structures for the first row of properties
    name = properties[0].first;
    for (size_t i = 0; i < properties[0].second.size(); ++i) {
      types.push_back(Type_number[properties[0].second[i]]);
    }
    if (name == "_" && types.empty()) {
      types.push_back(0);
      properties[0].second.push_back("dummy");
    }
    else if (types.empty()) {  // hacky test for string
      types.push_back(0);
      properties[0].second.push_back("literal-string");
    }
  }
  reagent::reagent() :value(0), initialized(false) {
    // The first property is special, so ensure we always have it.
    // Other properties can be pushed back, but the first must always be
    // assigned to.
    properties.push_back(pair<string, vector<string> >("", vector<string>()));
  }
  string reagent::to_string() {
    ostringstream out;
    out << "{name: \"" << name << "\", value: " << value << ", type: ";
    for (size_t i = 0; i < types.size(); ++i) {
      out << types[i];
      if (i < types.size()-1) out << "-";
    }
    if (!properties.empty()) {
      out << ", properties: [";
      for (size_t i = 0; i < properties.size(); ++i) {
        out << "\"" << properties[i].first << "\": ";
        for (size_t j = 0; j < properties[i].second.size(); ++j) {
          out << "\"" << properties[i].second[j] << "\"";
          if (j < properties[i].second.size()-1) out << ":";
        }
        if (i < properties.size()-1) out << ", ";
        else out << "]";
      }
    }
    out << "}";
    return out.str();
  }

string slurp_until(istream& in, char delim) {
  ostringstream out;
  char c;
  while (in >> c) {
    if (c == delim) {
      // drop the delim
      break;
    }
    out << c;
  }
  return out.str();
}

void dump_memory() {
  map<int, int> ordered(Memory.begin(), Memory.end());
  for (map<int, int>::iterator p = ordered.begin(); p != ordered.end(); ++p) {
    cout << p->first << ": " << p->second << '\n';
  }
}
:(before "End Includes")
#include <map>
using std::map;