This commit is contained in:
Kartik K. Agaram 2016-10-19 22:10:35 -07:00
parent 5a82020505
commit 6c96a437ce
52 changed files with 331 additions and 331 deletions

View File

@ -48,7 +48,7 @@ while (argc > 1 && starts_with(*arg, "--")) {
// End Commandline Options(*arg)
else
cerr << "skipping unknown option " << *arg << '\n';
--argc; ++argv; ++arg;
--argc; ++argv; ++arg;
}
//:: Helper function used by the above fragment of code (and later layers too,
@ -67,7 +67,7 @@ bool is_equal(char* s, const char* lit) {
bool starts_with(const string& s, const string& pat) {
string::const_iterator a=s.begin(), b=pat.begin();
for (/*nada*/; a!=s.end() && b!=pat.end(); ++a, ++b)
for (/*nada*/; a!=s.end() && b!=pat.end(); ++a, ++b)
if (*a != *b) return false;
return b == pat.end();
}

View File

@ -53,9 +53,9 @@ if (Run_tests) {
// we run some tests and then exit; assume no state need be maintained afterward
// End Test Run Initialization
time_t t; time(&t);
time_t t; time(&t);
cerr << "C tests: " << ctime(&t);
for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
for (size_t i=0; i < sizeof(Tests)/sizeof(Tests[0]); ++i) {
//? cerr << i << '\n';
run_test(i);
}

View File

@ -149,7 +149,7 @@ void trace_stream::newline() {
string trace_stream::readable_contents(string label) {
ostringstream output;
label = trim(label);
for (vector<trace_line>::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
for (vector<trace_line>::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
if (label.empty() || label == p->label) {
output << std::setw(4) << p->depth << ' ' << p->label << ": " << p->contents << '\n';
}
@ -250,7 +250,7 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte
if (curr_expected_line == SIZE(expected_lines)) return true;
string label, contents;
split_label_contents(expected_lines.at(curr_expected_line), &label, &contents);
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
if (label != p->label) continue;
if (contents != trim(p->contents)) continue;
++curr_expected_line;
@ -287,7 +287,7 @@ void split_label_contents(const string& s, string* label, string* contents) {
}
bool line_exists_anywhere(const string& label, const string& contents) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
if (label != p->label) continue;
if (contents == trim(p->contents)) return true;
}
@ -301,7 +301,7 @@ int trace_count(string label) {
int trace_count(string label, string line) {
if (!Trace_stream) return 0;
long result = 0;
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
if (label == p->label) {
if (line == "" || trim(line) == trim(p->contents))
++result;
@ -313,7 +313,7 @@ int trace_count(string label, string line) {
int trace_count_prefix(string label, string prefix) {
if (!Trace_stream) return 0;
long result = 0;
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
if (label == p->label) {
if (starts_with(trim(p->contents), trim(prefix)))
++result;

View File

@ -63,7 +63,7 @@ struct reagent {
void clear();
reagent(const reagent& old);
reagent& operator=(const reagent& old);
void set_value(double v) { value = v; initialized = true; }
void set_value(double v) { value = v; initialized = true; }
};
:(before "struct reagent")
@ -148,8 +148,8 @@ void setup_types() {
// End Mu Types Initialization
}
void teardown_types() {
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
for (int i = 0; i < SIZE(p->second.elements); ++i)
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
for (int i = 0; i < SIZE(p->second.elements); ++i)
p->second.elements.clear();
}
Type_ordinal.clear();
@ -262,7 +262,7 @@ recipe::recipe() {
instruction::instruction() :is_label(false), operation(IDLE) {
// End instruction Constructor
}
void instruction::clear() { is_label=false; label.clear(); name.clear(); old_name.clear(); operation=IDLE; ingredients.clear(); products.clear(); original_string.clear(); }
void instruction::clear() { is_label=false; label.clear(); name.clear(); old_name.clear(); operation=IDLE; ingredients.clear(); products.clear(); original_string.clear(); }
bool instruction::is_empty() { return !is_label && name.empty(); }
// Reagents have the form <name>:<type>:<type>:.../<property>/<property>/...
@ -333,7 +333,7 @@ reagent::reagent(const reagent& other) {
name = other.name;
value = other.value;
initialized = other.initialized;
for (int i = 0; i < SIZE(other.properties); ++i) {
for (int i = 0; i < SIZE(other.properties); ++i) {
properties.push_back(pair<string, string_tree*>(other.properties.at(i).first,
other.properties.at(i).second ? new string_tree(*other.properties.at(i).second) : NULL));
}
@ -446,10 +446,10 @@ string_tree::string_tree(const string_tree& old) {
reagent& reagent::operator=(const reagent& other) {
original_string = other.original_string;
for (int i = 0; i < SIZE(properties); ++i)
for (int i = 0; i < SIZE(properties); ++i)
if (properties.at(i).second) delete properties.at(i).second;
properties.clear();
for (int i = 0; i < SIZE(other.properties); ++i)
for (int i = 0; i < SIZE(other.properties); ++i)
properties.push_back(pair<string, string_tree*>(other.properties.at(i).first, other.properties.at(i).second ? new string_tree(*other.properties.at(i).second) : NULL));
name = other.name;
value = other.value;
@ -465,7 +465,7 @@ reagent::~reagent() {
}
void reagent::clear() {
for (int i = 0; i < SIZE(properties); ++i) {
for (int i = 0; i < SIZE(properties); ++i) {
if (properties.at(i).second) {
delete properties.at(i).second;
properties.at(i).second = NULL;
@ -517,14 +517,14 @@ string slurp_until(istream& in, char delim) {
}
bool has_property(const reagent& x, const string& name) {
for (int i = 0; i < SIZE(x.properties); ++i) {
for (int i = 0; i < SIZE(x.properties); ++i) {
if (x.properties.at(i).first == name) return true;
}
return false;
}
string_tree* property(const reagent& r, const string& name) {
for (int p = 0; p != SIZE(r.properties); ++p) {
for (int p = 0; p != SIZE(r.properties); ++p) {
if (r.properties.at(p).first == name)
return r.properties.at(p).second;
}
@ -545,7 +545,7 @@ void skip_whitespace_but_not_newline(istream& in) {
}
void dump_memory() {
for (map<int, double>::iterator p = Memory.begin(); p != Memory.end(); ++p) {
for (map<int, double>::iterator p = Memory.begin(); p != Memory.end(); ++p) {
cout << p->first << ": " << no_scientific(p->second) << '\n';
}
}
@ -559,7 +559,7 @@ void dump_memory() {
string to_string(const recipe& r) {
ostringstream out;
out << "recipe " << r.name << " [\n";
for (int i = 0; i < SIZE(r.steps); ++i)
for (int i = 0; i < SIZE(r.steps); ++i)
out << " " << to_string(r.steps.at(i)) << '\n';
out << "]\n";
return out.str();
@ -569,14 +569,14 @@ string debug_string(const recipe& x) {
ostringstream out;
out << "- recipe " << x.name << '\n';
// Begin debug_string(recipe x)
for (int index = 0; index < SIZE(x.steps); ++index) {
for (int index = 0; index < SIZE(x.steps); ++index) {
const instruction& inst = x.steps.at(index);
out << "inst: " << to_string(inst) << '\n';
out << " ingredients\n";
for (int i = 0; i < SIZE(inst.ingredients); ++i)
for (int i = 0; i < SIZE(inst.ingredients); ++i)
out << " " << debug_string(inst.ingredients.at(i)) << '\n';
out << " products\n";
for (int i = 0; i < SIZE(inst.products); ++i)
for (int i = 0; i < SIZE(inst.products); ++i)
out << " " << debug_string(inst.products.at(i)) << '\n';
}
return out.str();
@ -585,13 +585,13 @@ string debug_string(const recipe& x) {
string to_original_string(const instruction& inst) {
if (inst.is_label) return inst.label;
ostringstream out;
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
if (i > 0) out << ", ";
out << inst.products.at(i).original_string;
}
if (!inst.products.empty()) out << " <- ";
out << inst.name << ' ';
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (i > 0) out << ", ";
out << inst.ingredients.at(i).original_string;
}
@ -601,13 +601,13 @@ string to_original_string(const instruction& inst) {
string to_string(const instruction& inst) {
if (inst.is_label) return inst.label;
ostringstream out;
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
if (i > 0) out << ", ";
out << to_string(inst.products.at(i));
}
if (!inst.products.empty()) out << " <- ";
out << inst.name << ' ';
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (i > 0) out << ", ";
out << to_string(inst.ingredients.at(i));
}
@ -620,7 +620,7 @@ string to_string(const reagent& r) {
out << "{";
out << r.name << ": " << names_to_string(r.type);
if (!r.properties.empty()) {
for (int i = 0; i < SIZE(r.properties); ++i)
for (int i = 0; i < SIZE(r.properties); ++i)
out << ", \"" << r.properties.at(i).first << "\": " << to_string(r.properties.at(i).second);
}
out << "}";

View File

@ -121,7 +121,7 @@ bool next_instruction(istream& in, instruction* curr) {
vector<string>::iterator p = words.begin();
if (find(words.begin(), words.end(), "<-") != words.end()) {
for (; *p != "<-"; ++p)
for (; *p != "<-"; ++p)
curr->products.push_back(reagent(*p));
++p; // skip <-
}
@ -133,14 +133,14 @@ bool next_instruction(istream& in, instruction* curr) {
curr->old_name = curr->name = *p; ++p;
// curr->operation will be set in a later layer
for (; p != words.end(); ++p)
for (; p != words.end(); ++p)
curr->ingredients.push_back(reagent(*p));
trace(9993, "parse") << "instruction: " << curr->name << end();
trace(9993, "parse") << " number of ingredients: " << SIZE(curr->ingredients) << end();
for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p)
for (vector<reagent>::iterator p = curr->ingredients.begin(); p != curr->ingredients.end(); ++p)
trace(9993, "parse") << " ingredient: " << to_string(*p) << end();
for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p)
for (vector<reagent>::iterator p = curr->products.begin(); p != curr->products.end(); ++p)
trace(9993, "parse") << " product: " << to_string(*p) << end();
if (!has_data(in)) {
raise << "9: unbalanced '[' for recipe\n" << end();

View File

@ -45,8 +45,8 @@ void initialize_transforms() {
void transform_all() {
trace(9990, "transform") << "=== transform_all()" << end();
for (int t = 0; t < SIZE(Transform); ++t) {
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
for (int t = 0; t < SIZE(Transform); ++t) {
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
recipe& r = p->second;
if (r.transformed_until != t-1) continue;
// End Transform Checks
@ -72,15 +72,15 @@ int Num_calls_to_transform_all = 0;
:(code)
void parse_int_reagents() {
trace(9991, "transform") << "--- parsing any uninitialized reagents as integers" << end();
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
recipe& r = p->second;
if (r.steps.empty()) continue;
for (int index = 0; index < SIZE(r.steps); ++index) {
for (int index = 0; index < SIZE(r.steps); ++index) {
instruction& inst = r.steps.at(index);
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
populate_value(inst.ingredients.at(i));
}
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
populate_value(inst.products.at(i));
}
}

View File

@ -9,7 +9,7 @@ void update_instruction_operations(recipe_ordinal r) {
trace(9991, "transform") << "--- compute instruction operations for recipe " << get(Recipe, r).name << end();
recipe& caller = get(Recipe, r);
//? cerr << "--- compute instruction operations for recipe " << caller.name << '\n';
for (int index = 0; index < SIZE(caller.steps); ++index) {
for (int index = 0; index < SIZE(caller.steps); ++index) {
instruction& inst = caller.steps.at(index);
if (inst.is_label) continue;
if (!contains_key(Recipe_ordinal, inst.name)) {

View File

@ -107,7 +107,7 @@ restore_type_abbreviations();
atexit(clear_type_abbreviations);
:(code)
void restore_type_abbreviations() {
for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) {
for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p) {
if (!contains_key(Type_abbreviations_snapshot, p->first))
delete p->second;
}
@ -115,7 +115,7 @@ void restore_type_abbreviations() {
Type_abbreviations = Type_abbreviations_snapshot;
}
void clear_type_abbreviations() {
for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p)
for (map<string, type_tree*>::iterator p = Type_abbreviations.begin(); p != Type_abbreviations.end(); ++p)
delete p->second;
Type_abbreviations.clear();
}
@ -169,14 +169,14 @@ void expand_type_abbreviations(const recipe_ordinal r) {
void expand_type_abbreviations(const recipe& caller) {
trace(9991, "transform") << "--- expand type abbreviations in recipe '" << caller.name << "'" << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
trace(9991, "transform") << "instruction '" << inst.original_string << end();
for (long int i = 0; i < SIZE(inst.ingredients); ++i) {
for (long int i = 0; i < SIZE(inst.ingredients); ++i) {
expand_type_abbreviations(inst.ingredients.at(i).type);
trace(9992, "transform") << "ingredient type after expanding abbreviations: " << names_to_string(inst.ingredients.at(i).type) << end();
}
for (long int i = 0; i < SIZE(inst.products); ++i) {
for (long int i = 0; i < SIZE(inst.products); ++i) {
expand_type_abbreviations(inst.products.at(i).type);
trace(9992, "transform") << "product type after expanding abbreviations: " << names_to_string(inst.products.at(i).type) << end();
}

View File

@ -62,7 +62,7 @@ void run(recipe_ordinal r) {
void run_current_routine() {
while (should_continue_running(Current_routine)) { // beware: later layers modify Current_routine here
// Running One Instruction
if (current_instruction().is_label) { ++current_step_index(); continue; }
if (current_instruction().is_label) { ++current_step_index(); continue; }
trace(Initial_callstack_depth + Trace_stream->callstack_depth, "run") << to_string(current_instruction()) << end();
if (get_or_insert(Memory, 0) != 0) {
raise << "something wrote to location 0; this should never happen\n" << end();
@ -71,7 +71,7 @@ void run_current_routine() {
// read all ingredients from memory, each potentially spanning multiple locations
vector<vector<double> > ingredients;
if (should_copy_ingredients()) {
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i)
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i)
ingredients.push_back(read_memory(current_instruction().ingredients.at(i)));
}
// instructions below will write to 'products'
@ -92,7 +92,7 @@ void run_current_routine() {
raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << to_original_string(current_instruction()) << '\n' << end();
}
else {
for (int i = 0; i < SIZE(current_instruction().products); ++i)
for (int i = 0; i < SIZE(current_instruction().products); ++i)
write_memory(current_instruction().products.at(i), products.at(i));
}
// End Write Products of Instruction
@ -207,15 +207,15 @@ else if (is_equal(*arg, "--trace")) {
:(code)
void dump_profile() {
for (map<string, int>::iterator p = Instructions_running.begin(); p != Instructions_running.end(); ++p) {
for (map<string, int>::iterator p = Instructions_running.begin(); p != Instructions_running.end(); ++p) {
cerr << p->first << ": " << p->second << '\n';
}
cerr << "== locations read\n";
for (map<string, int>::iterator p = Locations_read.begin(); p != Locations_read.end(); ++p) {
for (map<string, int>::iterator p = Locations_read.begin(); p != Locations_read.end(); ++p) {
cerr << p->first << ": " << p->second << '\n';
}
cerr << "== locations read by instruction\n";
for (map<string, int>::iterator p = Locations_read_by_instruction.begin(); p != Locations_read_by_instruction.end(); ++p) {
for (map<string, int>::iterator p = Locations_read_by_instruction.begin(); p != Locations_read_by_instruction.end(); ++p) {
cerr << p->first << ": " << p->second << '\n';
}
}
@ -259,7 +259,7 @@ bool is_directory(string path) {
void load_all(string dir) {
dirent** files;
int num_files = scandir(dir.c_str(), &files, NULL, alphasort);
for (int i = 0; i < num_files; ++i) {
for (int i = 0; i < num_files; ++i) {
string curr_file = files[i]->d_name;
if (isdigit(curr_file.at(0)))
load_file_or_directory(dir+'/'+curr_file);
@ -284,7 +284,7 @@ vector<double> read_memory(reagent/*copy*/ x) {
}
// End Preprocess read_memory(x)
int size = size_of(x);
for (int offset = 0; offset < size; ++offset) {
for (int offset = 0; offset < size; ++offset) {
double val = get_or_insert(Memory, x.value+offset);
trace(9999, "mem") << "location " << x.value+offset << " is " << no_scientific(val) << end();
result.push_back(val);
@ -311,7 +311,7 @@ void write_memory(reagent/*copy*/ x, const vector<double>& data) {
return;
}
// End write_memory(x) Special-cases
for (int offset = 0; offset < SIZE(data); ++offset) {
for (int offset = 0; offset < SIZE(data); ++offset) {
assert(x.value+offset > 0);
trace(9999, "mem") << "storing " << no_scientific(data.at(offset)) << " in location " << x.value+offset << end();
put(Memory, x.value+offset, data.at(offset));

View File

@ -15,7 +15,7 @@ Transform.push_back(check_instruction); // idempotent
void check_instruction(const recipe_ordinal r) {
trace(9991, "transform") << "--- perform checks for recipe " << get(Recipe, r).name << end();
map<string, vector<type_ordinal> > metadata;
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
instruction& inst = get(Recipe, r).steps.at(i);
if (inst.is_label) continue;
switch (inst.operation) {
@ -25,7 +25,7 @@ void check_instruction(const recipe_ordinal r) {
raise << maybe(get(Recipe, r).name) << "ingredients and products should match in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!types_coercible(inst.products.at(i), inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "can't copy '" << inst.ingredients.at(i).original_string << "' to '" << inst.products.at(i).original_string << "'; types don't match\n" << end();
goto finish_checking_instruction;

View File

@ -7,7 +7,7 @@ put(Recipe_ordinal, "add", ADD);
:(before "End Primitive Recipe Checks")
case ADD: {
// primary goal of these checks is to forbid address arithmetic
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'add' requires number ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -26,7 +26,7 @@ case ADD: {
:(before "End Primitive Recipe Implementations")
case ADD: {
double result = 0;
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
result += ingredients.at(i).at(0);
}
products.resize(1);
@ -78,7 +78,7 @@ case SUBTRACT: {
raise << maybe(get(Recipe, r).name) << "'subtract' has no ingredients\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (is_raw(inst.ingredients.at(i))) continue; // permit address offset computations in tests
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'subtract' requires number ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
@ -98,7 +98,7 @@ case SUBTRACT: {
:(before "End Primitive Recipe Implementations")
case SUBTRACT: {
double result = ingredients.at(0).at(0);
for (int i = 1; i < SIZE(ingredients); ++i)
for (int i = 1; i < SIZE(ingredients); ++i)
result -= ingredients.at(i).at(0);
products.resize(1);
products.at(0).push_back(result);
@ -135,7 +135,7 @@ MULTIPLY,
put(Recipe_ordinal, "multiply", MULTIPLY);
:(before "End Primitive Recipe Checks")
case MULTIPLY: {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'multiply' requires number ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -154,7 +154,7 @@ case MULTIPLY: {
:(before "End Primitive Recipe Implementations")
case MULTIPLY: {
double result = 1;
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
result *= ingredients.at(i).at(0);
}
products.resize(1);
@ -192,7 +192,7 @@ case DIVIDE: {
raise << maybe(get(Recipe, r).name) << "'divide' has no ingredients\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'divide' requires number ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -211,7 +211,7 @@ case DIVIDE: {
:(before "End Primitive Recipe Implementations")
case DIVIDE: {
double result = ingredients.at(0).at(0);
for (int i = 1; i < SIZE(ingredients); ++i)
for (int i = 1; i < SIZE(ingredients); ++i)
result /= ingredients.at(i).at(0);
products.resize(1);
products.at(0).push_back(result);
@ -258,7 +258,7 @@ case DIVIDE_WITH_REMAINDER: {
raise << maybe(get(Recipe, r).name) << "'divide-with-remainder' yields two products in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
if (!is_dummy(inst.products.at(i)) && !is_mu_number(inst.products.at(i))) {
raise << maybe(get(Recipe, r).name) << "'divide-with-remainder' should yield a number, but got '" << inst.products.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -741,7 +741,7 @@ case CHARACTER_TO_CODE: {
:(before "End Primitive Recipe Implementations")
case CHARACTER_TO_CODE: {
double result = 0;
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
result += ingredients.at(i).at(0);
}
products.resize(1);

View File

@ -6,7 +6,7 @@ AND,
put(Recipe_ordinal, "and", AND);
:(before "End Primitive Recipe Checks")
case AND: {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_scalar(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'and' requires boolean ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -25,7 +25,7 @@ case AND: {
:(before "End Primitive Recipe Implementations")
case AND: {
bool result = true;
for (int i = 0; i < SIZE(ingredients); ++i)
for (int i = 0; i < SIZE(ingredients); ++i)
result = result && ingredients.at(i).at(0);
products.resize(1);
products.at(0).push_back(result);
@ -64,7 +64,7 @@ OR,
put(Recipe_ordinal, "or", OR);
:(before "End Primitive Recipe Checks")
case OR: {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_scalar(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'and' requires boolean ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -83,7 +83,7 @@ case OR: {
:(before "End Primitive Recipe Implementations")
case OR: {
bool result = false;
for (int i = 0; i < SIZE(ingredients); ++i)
for (int i = 0; i < SIZE(ingredients); ++i)
result = result || ingredients.at(i).at(0);
products.resize(1);
products.at(0).push_back(result);
@ -126,13 +126,13 @@ case NOT: {
raise << "ingredients and products should match in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_scalar(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'not' requires boolean ingredients, but got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
}
}
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!is_mu_boolean(inst.products.at(i))) {
raise << maybe(get(Recipe, r).name) << "'not' should yield a boolean, but got '" << inst.products.at(i).original_string << "'\n" << end();
@ -144,7 +144,7 @@ case NOT: {
:(before "End Primitive Recipe Implementations")
case NOT: {
products.resize(SIZE(ingredients));
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
products.at(i).push_back(!ingredients.at(i).at(0));
}
break;

View File

@ -11,7 +11,7 @@ case EQUAL: {
break;
}
const reagent& exemplar = inst.ingredients.at(0);
for (int i = /*skip exemplar*/1; i < SIZE(inst.ingredients); ++i) {
for (int i = /*skip exemplar*/1; i < SIZE(inst.ingredients); ++i) {
if (!types_match(inst.ingredients.at(i), exemplar) && !types_match(exemplar, inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'equal' expects ingredients to be all of the same type, but got '" << inst.original_string << "'\n" << end();
goto finish_checking_instruction;
@ -31,7 +31,7 @@ case EQUAL: {
case EQUAL: {
vector<double>& exemplar = ingredients.at(0);
bool result = true;
for (int i = /*skip exemplar*/1; i < SIZE(ingredients); ++i) {
for (int i = /*skip exemplar*/1; i < SIZE(ingredients); ++i) {
if (!equal(ingredients.at(i).begin(), ingredients.at(i).end(), exemplar.begin())) {
result = false;
break;
@ -138,7 +138,7 @@ case GREATER_THAN: {
raise << maybe(get(Recipe, r).name) << "'greater-than' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'greater-than' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -157,7 +157,7 @@ case GREATER_THAN: {
:(before "End Primitive Recipe Implementations")
case GREATER_THAN: {
bool result = true;
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i-1).at(0) <= ingredients.at(i).at(0)) {
result = false;
}
@ -205,7 +205,7 @@ case LESSER_THAN: {
raise << maybe(get(Recipe, r).name) << "'lesser-than' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'lesser-than' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -224,7 +224,7 @@ case LESSER_THAN: {
:(before "End Primitive Recipe Implementations")
case LESSER_THAN: {
bool result = true;
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i-1).at(0) >= ingredients.at(i).at(0)) {
result = false;
}
@ -272,7 +272,7 @@ case GREATER_OR_EQUAL: {
raise << maybe(get(Recipe, r).name) << "'greater-or-equal' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'greater-or-equal' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -291,7 +291,7 @@ case GREATER_OR_EQUAL: {
:(before "End Primitive Recipe Implementations")
case GREATER_OR_EQUAL: {
bool result = true;
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i-1).at(0) < ingredients.at(i).at(0)) {
result = false;
}
@ -347,7 +347,7 @@ case LESSER_OR_EQUAL: {
raise << maybe(get(Recipe, r).name) << "'lesser-or-equal' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'lesser-or-equal' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -366,7 +366,7 @@ case LESSER_OR_EQUAL: {
:(before "End Primitive Recipe Implementations")
case LESSER_OR_EQUAL: {
bool result = true;
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i-1).at(0) > ingredients.at(i).at(0)) {
result = false;
}
@ -422,7 +422,7 @@ case MAX: {
raise << maybe(get(Recipe, r).name) << "'max' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'max' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -441,7 +441,7 @@ case MAX: {
:(before "End Primitive Recipe Implementations")
case MAX: {
int result = ingredients.at(0).at(0);
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i).at(0) > result) {
result = ingredients.at(i).at(0);
}
@ -461,7 +461,7 @@ case MIN: {
raise << maybe(get(Recipe, r).name) << "'min' needs at least two ingredients to compare in '" << inst.original_string << "'\n" << end();
break;
}
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (!is_mu_number(inst.ingredients.at(i))) {
raise << maybe(get(Recipe, r).name) << "'min' can only compare numbers; got '" << inst.ingredients.at(i).original_string << "'\n" << end();
goto finish_checking_instruction;
@ -480,7 +480,7 @@ case MIN: {
:(before "End Primitive Recipe Implementations")
case MIN: {
int result = ingredients.at(0).at(0);
for (int i = /**/1; i < SIZE(ingredients); ++i) {
for (int i = /**/1; i < SIZE(ingredients); ++i) {
if (ingredients.at(i).at(0) < result) {
result = ingredients.at(i).at(0);
}

View File

@ -28,7 +28,7 @@ int next_ingredient_to_process;
next_ingredient_to_process = 0;
:(before "End Call Housekeeping")
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
current_call().ingredient_atoms.push_back(ingredients.at(i));
reagent/*copy*/ ingredient = call_instruction.ingredients.at(i);
// End Compute Call Ingredient
@ -78,7 +78,7 @@ case NEXT_INGREDIENT: {
products.resize(2);
// pad the first product with sufficient zeros to match its type
int size = size_of(current_instruction().products.at(0));
for (int i = 0; i < size; ++i)
for (int i = 0; i < size; ++i)
products.at(0).push_back(0);
products.at(1).push_back(0);
}

View File

@ -35,7 +35,7 @@ case RETURN: {
Current_routine->calls.pop_front();
// just in case 'main' returns a value, drop it for now
if (Current_routine->calls.empty()) goto stop_running_current_routine;
for (int i = 0; i < SIZE(ingredients); ++i)
for (int i = 0; i < SIZE(ingredients); ++i)
trace(9998, "run") << "result " << i << " is " << to_string(ingredients.at(i)) << end();
// make reply products available to caller
copy(ingredients.begin(), ingredients.end(), inserter(products, products.begin()));
@ -51,13 +51,13 @@ Transform.push_back(check_types_of_reply_instructions);
void check_types_of_reply_instructions(recipe_ordinal r) {
const recipe& caller = get(Recipe, r);
trace(9991, "transform") << "--- check types of reply instructions in recipe " << caller.name << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& caller_instruction = caller.steps.at(i);
if (caller_instruction.is_label) continue;
if (caller_instruction.products.empty()) continue;
if (caller_instruction.operation < MAX_PRIMITIVE_RECIPES) continue;
const recipe& callee = get(Recipe, caller_instruction.operation);
for (int i = 0; i < SIZE(callee.steps); ++i) {
for (int i = 0; i < SIZE(callee.steps); ++i) {
const instruction& reply_inst = callee.steps.at(i);
if (reply_inst.operation != RETURN) continue;
// check types with the caller
@ -65,7 +65,7 @@ void check_types_of_reply_instructions(recipe_ordinal r) {
raise << maybe(caller.name) << "too few values returned from " << callee.name << '\n' << end();
break;
}
for (int i = 0; i < SIZE(caller_instruction.products); ++i) {
for (int i = 0; i < SIZE(caller_instruction.products); ++i) {
reagent/*copy*/ lhs = reply_inst.ingredients.at(i);
reagent/*copy*/ rhs = caller_instruction.products.at(i);
// End Check RETURN Copy(lhs, rhs)
@ -77,7 +77,7 @@ void check_types_of_reply_instructions(recipe_ordinal r) {
}
// check that any reply ingredients with /same-as-ingredient connect up
// the corresponding ingredient and product in the caller.
for (int i = 0; i < SIZE(caller_instruction.products); ++i) {
for (int i = 0; i < SIZE(caller_instruction.products); ++i) {
if (has_property(reply_inst.ingredients.at(i), "same-as-ingredient")) {
string_tree* tmp = property(reply_inst.ingredients.at(i), "same-as-ingredient");
if (!tmp || !tmp->atom) {
@ -149,7 +149,7 @@ string to_string(const vector<double>& in) {
return out.str();
}
out << "[";
for (int i = 0; i < SIZE(in); ++i) {
for (int i = 0; i < SIZE(in); ++i) {
if (i > 0) out << ", ";
out << no_scientific(in.at(i));
}

View File

@ -31,7 +31,7 @@ case TRACE: {
int depth = ingredients.at(0).at(0);
string label = current_instruction().ingredients.at(1).name;
ostringstream out;
for (int i = 2; i < SIZE(current_instruction().ingredients); ++i) {
for (int i = 2; i < SIZE(current_instruction().ingredients); ++i) {
if (i > 2) out << ' ';
out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
}
@ -52,7 +52,7 @@ case STASH: {
:(before "End Primitive Recipe Implementations")
case STASH: {
ostringstream out;
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
if (i) out << ' ';
out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
}
@ -85,7 +85,7 @@ string print_mu(const reagent& r, const vector<double>& data) {
return r.name;
// End print Special-cases(r, data)
ostringstream out;
for (long long i = 0; i < SIZE(data); ++i) {
for (long long i = 0; i < SIZE(data); ++i) {
if (i) out << ' ';
out << no_scientific(data.at(i));
}
@ -236,7 +236,7 @@ case _PRINT: {
}
:(before "End Primitive Recipe Implementations")
case _PRINT: {
for (int i = 0; i < SIZE(ingredients); ++i) {
for (int i = 0; i < SIZE(ingredients); ++i) {
if (is_literal(current_instruction().ingredients.at(i))) {
trace(9998, "run") << "$print: " << current_instruction().ingredients.at(i).name << end();
if (!has_property(current_instruction().ingredients.at(i), "newline")) {
@ -249,7 +249,7 @@ case _PRINT: {
}
}
else {
for (int j = 0; j < SIZE(ingredients.at(i)); ++j) {
for (int j = 0; j < SIZE(ingredients.at(i)); ++j) {
trace(9998, "run") << "$print: " << ingredients.at(i).at(j) << end();
if (j > 0) cout << " ";
cout << no_scientific(ingredients.at(i).at(j));
@ -330,7 +330,7 @@ case _LOG: {
:(before "End Primitive Recipe Implementations")
case _LOG: {
ostringstream out;
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
}
LOG << out.str() << '\n';

View File

@ -122,7 +122,7 @@ atexit(clear_container_metadata);
:(code)
// invariant: Container_metadata always contains a superset of Container_metadata_snapshot
void restore_container_metadata() {
for (int i = 0; i < SIZE(Container_metadata); ++i) {
for (int i = 0; i < SIZE(Container_metadata); ++i) {
assert(Container_metadata.at(i).first);
if (i < SIZE(Container_metadata_snapshot)) {
assert(Container_metadata.at(i).first == Container_metadata_snapshot.at(i).first);
@ -135,7 +135,7 @@ void restore_container_metadata() {
}
void clear_container_metadata() {
Container_metadata_snapshot.clear();
for (int i = 0; i < SIZE(Container_metadata); ++i) {
for (int i = 0; i < SIZE(Container_metadata); ++i) {
delete Container_metadata.at(i).first;
Container_metadata.at(i).first = NULL;
}
@ -180,12 +180,12 @@ Transform.push_back(compute_container_sizes);
void compute_container_sizes(recipe_ordinal r) {
recipe& caller = get(Recipe, r);
trace(9992, "transform") << "--- compute container sizes for " << caller.name << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
trace(9993, "transform") << "- compute container sizes for " << to_string(inst) << end();
for (int i = 0; i < SIZE(inst.ingredients); ++i)
for (int i = 0; i < SIZE(inst.ingredients); ++i)
compute_container_sizes(inst.ingredients.at(i));
for (int i = 0; i < SIZE(inst.products); ++i)
for (int i = 0; i < SIZE(inst.products); ++i)
compute_container_sizes(inst.products.at(i));
}
}
@ -237,7 +237,7 @@ void compute_container_sizes(const type_info& container_info, const type_tree* f
// (So it can only contain arrays if they're static and include their
// length in the type.)
container_metadata metadata;
for (int i = 0; i < SIZE(container_info.elements); ++i) {
for (int i = 0; i < SIZE(container_info.elements); ++i) {
reagent/*copy*/ element = container_info.elements.at(i);
// Compute Container Size(element, full_type)
compute_container_sizes(element.type, pending_metadata);
@ -248,7 +248,7 @@ void compute_container_sizes(const type_info& container_info, const type_tree* f
}
container_metadata& get(vector<pair<type_tree*, container_metadata> >& all, const type_tree* key) {
for (int i = 0; i < SIZE(all); ++i) {
for (int i = 0; i < SIZE(all); ++i) {
if (matches(all.at(i).first, key))
return all.at(i).second;
}
@ -258,7 +258,7 @@ container_metadata& get(vector<pair<type_tree*, container_metadata> >& all, cons
}
bool contains_key(const vector<pair<type_tree*, container_metadata> >& all, const type_tree* key) {
for (int i = 0; i < SIZE(all); ++i) {
for (int i = 0; i < SIZE(all); ++i) {
if (matches(all.at(i).first, key))
return true;
}
@ -635,7 +635,7 @@ case PUT: {
// optimization: directly write the element rather than updating 'product'
// and writing the entire container
// Write Memory in PUT in Run
for (int i = 0; i < SIZE(ingredients.at(2)); ++i) {
for (int i = 0; i < SIZE(ingredients.at(2)); ++i) {
trace(9999, "mem") << "storing " << no_scientific(ingredients.at(2).at(i)) << " in location " << address+i << end();
put(Memory, address+i, ingredients.at(2).at(i));
}
@ -815,8 +815,8 @@ Transform.push_back(expand_type_abbreviations_in_containers);
// extremely inefficient; we process all types over and over again, once for every single recipe
// but it doesn't seem to cause any noticeable slowdown
void expand_type_abbreviations_in_containers(unused const recipe_ordinal r) {
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
for (int i = 0; i < SIZE(p->second.elements); ++i)
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
for (int i = 0; i < SIZE(p->second.elements); ++i)
expand_type_abbreviations(p->second.elements.at(i).type);
}
}
@ -871,11 +871,11 @@ Transform.push_back(check_or_set_invalid_types); // idempotent
void check_or_set_invalid_types(const recipe_ordinal r) {
recipe& caller = get(Recipe, r);
trace(9991, "transform") << "--- check for invalid types in recipe " << caller.name << end();
for (int index = 0; index < SIZE(caller.steps); ++index) {
for (int index = 0; index < SIZE(caller.steps); ++index) {
instruction& inst = caller.steps.at(index);
for (int i = 0; i < SIZE(inst.ingredients); ++i)
for (int i = 0; i < SIZE(inst.ingredients); ++i)
check_or_set_invalid_types(inst.ingredients.at(i), caller, inst);
for (int i = 0; i < SIZE(inst.products); ++i)
for (int i = 0; i < SIZE(inst.products); ++i)
check_or_set_invalid_types(inst.products.at(i), caller, inst);
}
// End check_or_set_invalid_types
@ -933,10 +933,10 @@ check_container_field_types();
:(code)
void check_container_field_types() {
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
for (map<type_ordinal, type_info>::iterator p = Type.begin(); p != Type.end(); ++p) {
const type_info& info = p->second;
// Check Container Field Types(info)
for (int i = 0; i < SIZE(info.elements); ++i)
for (int i = 0; i < SIZE(info.elements); ++i)
check_invalid_types(info.elements.at(i).type, maybe(info.name), info.elements.at(i).name);
}
}

View File

@ -23,8 +23,8 @@ case MERGE: {
:(before "End Primitive Recipe Implementations")
case MERGE: {
products.resize(1);
for (int i = 0; i < SIZE(ingredients); ++i)
for (int j = 0; j < SIZE(ingredients.at(i)); ++j)
for (int i = 0; i < SIZE(ingredients); ++i)
for (int j = 0; j < SIZE(ingredients.at(i)); ++j)
products.at(0).push_back(ingredients.at(i).at(j));
break;
}
@ -115,7 +115,7 @@ Transform.push_back(check_merge_calls);
void check_merge_calls(const recipe_ordinal r) {
const recipe& caller = get(Recipe, r);
trace(9991, "transform") << "--- type-check merge instructions in recipe " << caller.name << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
if (inst.name != "merge") continue;
if (SIZE(inst.products) != 1) {

View File

@ -62,7 +62,7 @@ case CREATE_ARRAY: {
int size = size_of(product); // in locations
trace(9998, "run") << "creating array of size " << size << end();
// initialize array
for (int i = 1; i <= size_of(product); ++i) {
for (int i = 1; i <= size_of(product); ++i) {
put(Memory, base_address+i, 0);
}
// no need to update product
@ -434,7 +434,7 @@ case PUT_INDEX: {
// and writing the entire array
vector<double> value = read_memory(current_instruction().ingredients.at(2));
// Write Memory in PUT_INDEX in Run
for (int i = 0; i < SIZE(value); ++i) {
for (int i = 0; i < SIZE(value); ++i) {
trace(9999, "mem") << "storing " << no_scientific(value.at(i)) << " in location " << address+i << end();
put(Memory, address+i, value.at(i));
}

View File

@ -46,7 +46,7 @@ void compute_exclusive_container_sizes(const type_info& exclusive_container_info
// (So, like containers, it can only contain arrays if they're static and
// include their length in the type.)
container_metadata metadata;
for (int i = 0; i < SIZE(exclusive_container_info.elements); ++i) {
for (int i = 0; i < SIZE(exclusive_container_info.elements); ++i) {
reagent/*copy*/ element = exclusive_container_info.elements.at(i);
// Compute Exclusive Container Size(element, full_type)
compute_container_sizes(element.type, pending_metadata);
@ -166,7 +166,7 @@ case MAYBE_CONVERT: {
put(Memory, status.value, 1);
if (!is_dummy(product)) {
// Write Memory in Successful MAYBE_CONVERT in Run
for (int i = 0; i < size_of(variant); ++i) {
for (int i = 0; i < size_of(variant); ++i) {
double val = get_or_insert(Memory, base_address+/*skip tag*/1+i);
trace(9999, "mem") << "storing " << no_scientific(val) << " in location " << product.value+i << end();
put(Memory, product.value+i, val);

View File

@ -229,7 +229,7 @@ Transform.push_back(transform_new_to_allocate); // idempotent
:(code)
void transform_new_to_allocate(const recipe_ordinal r) {
trace(9991, "transform") << "--- convert 'new' to 'allocate' for recipe " << get(Recipe, r).name << end();
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
instruction& inst = get(Recipe, r).steps.at(i);
// Convert 'new' To 'allocate'
if (inst.name == "new") {
@ -299,7 +299,7 @@ int allocate(int size) {
const int result = Current_routine->alloc;
trace(9999, "mem") << "new alloc: " << result << end();
// initialize allocated space
for (int address = result; address < result+size; ++address) {
for (int address = result; address < result+size; ++address) {
trace(9999, "mem") << "storing 0 in location " << address << end();
put(Memory, address, 0);
}

View File

@ -168,7 +168,7 @@ bool canonize_type(reagent& r) {
}
void drop_one_lookup(reagent& r) {
for (vector<pair<string, string_tree*> >::iterator p = r.properties.begin(); p != r.properties.end(); ++p) {
for (vector<pair<string, string_tree*> >::iterator p = r.properties.begin(); p != r.properties.end(); ++p) {
if (p->first == "lookup") {
r.properties.erase(p);
return;

View File

@ -182,7 +182,7 @@ def main [
:(after "Write Memory in Successful MAYBE_CONVERT")
// TODO: double-check data here as well
vector<double> data;
for (int i = 0; i < size_of(product); ++i)
for (int i = 0; i < size_of(product); ++i)
data.push_back(get_or_insert(Memory, base_address+/*skip tag*/1+i));
update_any_refcounts(product, data);
@ -286,12 +286,12 @@ Transform.push_back(compute_container_address_offsets);
void compute_container_address_offsets(const recipe_ordinal r) {
recipe& caller = get(Recipe, r);
trace(9992, "transform") << "--- compute address offsets for " << caller.name << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
trace(9993, "transform") << "- compute address offsets for " << to_string(inst) << end();
for (int i = 0; i < SIZE(inst.ingredients); ++i)
for (int i = 0; i < SIZE(inst.ingredients); ++i)
compute_container_address_offsets(inst.ingredients.at(i));
for (int i = 0; i < SIZE(inst.products); ++i)
for (int i = 0; i < SIZE(inst.products); ++i)
compute_container_address_offsets(inst.products.at(i));
}
}
@ -341,7 +341,7 @@ void compute_container_address_offsets(const type_info& container_info, const ty
void compute_exclusive_container_address_offsets(const type_info& exclusive_container_info, const type_tree* full_type) {
container_metadata& metadata = get(Container_metadata, full_type);
trace(9994, "transform") << "compute address offsets for exclusive container " << exclusive_container_info.name << end();
for (int tag = 0; tag < SIZE(exclusive_container_info.elements); ++tag) {
for (int tag = 0; tag < SIZE(exclusive_container_info.elements); ++tag) {
set<tag_condition_info> key;
key.insert(tag_condition_info(/*tag is at offset*/0, tag));
append_addresses(/*skip tag offset*/1, variant_type(full_type, tag).type, metadata.address, key);
@ -356,7 +356,7 @@ void append_addresses(int base_offset, const type_tree* type, map<set<tag_condit
const type_tree* root = root_type(type);
const type_info& info = get(Type, root->value);
if (info.kind == CONTAINER) {
for (int curr_index = 0, curr_offset = base_offset; curr_index < SIZE(info.elements); ++curr_index) {
for (int curr_index = 0, curr_offset = base_offset; curr_index < SIZE(info.elements); ++curr_index) {
trace(9993, "transform") << "checking container " << root->name << ", element " << curr_index << end();
reagent/*copy*/ element = element_type(type, curr_index); // not root
// Compute Container Address Offset(element)
@ -372,7 +372,7 @@ void append_addresses(int base_offset, const type_tree* type, map<set<tag_condit
else if (is_mu_exclusive_container(element)) {
const type_tree* element_root_type = root_type(element.type);
const type_info& element_info = get(Type, element_root_type->value);
for (int tag = 0; tag < SIZE(element_info.elements); ++tag) {
for (int tag = 0; tag < SIZE(element_info.elements); ++tag) {
set<tag_condition_info> new_key = key;
new_key.insert(tag_condition_info(curr_offset, tag));
if (!contains_key(out, new_key))
@ -387,7 +387,7 @@ void append_addresses(int base_offset, const type_tree* type, map<set<tag_condit
}
}
else if (info.kind == EXCLUSIVE_CONTAINER) {
for (int tag = 0; tag < SIZE(info.elements); ++tag) {
for (int tag = 0; tag < SIZE(info.elements); ++tag) {
set<tag_condition_info> new_key = key;
new_key.insert(tag_condition_info(base_offset, tag));
if (!contains_key(out, new_key))
@ -682,9 +682,9 @@ void test_container_address_offsets_from_repeated_address_and_array_types() {
:(before "End Increment Refcounts(canonized_x)")
if (is_mu_container(canonized_x) || is_mu_exclusive_container(canonized_x)) {
const container_metadata& metadata = get(Container_metadata, canonized_x.type);
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
if (!all_match(data, p->first)) continue;
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info)
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info)
increment_refcount(data.at(info->offset));
}
}
@ -699,16 +699,16 @@ if (is_mu_container(canonized_x) || is_mu_exclusive_container(canonized_x)) {
vector<double> data = read_memory(tmp);
trace(9999, "mem") << "done reading old value of '" << to_string(canonized_x) << "'" << end();
const container_metadata& metadata = get(Container_metadata, canonized_x.type);
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
if (!all_match(data, p->first)) continue;
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info)
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info)
decrement_refcount(get_or_insert(Memory, canonized_x.value + info->offset), info->payload_type, size_of(info->payload_type)+/*refcount*/1);
}
}
:(code)
bool all_match(const vector<double>& data, const set<tag_condition_info>& conditions) {
for (set<tag_condition_info>::const_iterator p = conditions.begin(); p != conditions.end(); ++p) {
for (set<tag_condition_info>::const_iterator p = conditions.begin(); p != conditions.end(); ++p) {
if (data.at(p->offset) != p->tag)
return false;
}

View File

@ -37,7 +37,7 @@ void abandon(int address, const type_tree* payload_type, int payload_size) {
int array_length = get_or_insert(Memory, address+/*skip refcount*/1);
assert(element.type->name != "array");
int element_size = size_of(element);
for (int i = 0; i < array_length; ++i) {
for (int i = 0; i < array_length; ++i) {
element.set_value(address + /*skip refcount and length*/2 + i*element_size);
decrement_any_refcounts(element);
}
@ -49,7 +49,7 @@ void abandon(int address, const type_tree* payload_type, int payload_size) {
decrement_any_refcounts(tmp);
}
// clear memory
for (int curr = address; curr < address+payload_size; ++curr)
for (int curr = address; curr < address+payload_size; ++curr)
put(Memory, curr, 0);
// append existing free list to address
trace(9999, "abandon") << "saving " << address << " in free-list of size " << payload_size << end();
@ -64,7 +64,7 @@ if (get_or_insert(Current_routine->free_list, size)) {
trace(9999, "mem") << "new alloc from free list: " << result << end();
put(Current_routine->free_list, size, get_or_insert(Memory, result));
put(Memory, result, 0);
for (int curr = result; curr < result+size; ++curr) {
for (int curr = result; curr < result+size; ++curr) {
if (get_or_insert(Memory, curr) != 0) {
raise << maybe(current_recipe_name()) << "memory in free list was not zeroed out: " << curr << '/' << result << "; somebody wrote to us after free!!!\n" << end();
break; // always fatal

View File

@ -49,7 +49,7 @@ int new_mu_text(const string& contents) {
++curr_address; // skip length
int curr = 0;
const char* raw_contents = contents.c_str();
for (int i = 0; i < string_length; ++i) {
for (int i = 0; i < string_length; ++i) {
uint32_t curr_character;
assert(curr < SIZE(contents));
tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]);
@ -132,7 +132,7 @@ string read_mu_text(int address) {
int size = get_or_insert(Memory, address);
if (size == 0) return "";
ostringstream tmp;
for (int curr = address+1; curr <= address+size; ++curr) {
for (int curr = address+1; curr <= address+size; ++curr) {
tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr)));
}
return tmp.str();

View File

@ -40,7 +40,7 @@ case TO_LOCATION_ARRAY: {
// initialize array length
put(Memory, result+1, array_size);
// now copy over data
for (int i = 0; i < array_size; ++i)
for (int i = 0; i < array_size; ++i)
put(Memory, result+2+i, ingredients.at(0).at(i));
break;
}

View File

@ -40,7 +40,7 @@ void transform_braces(const recipe_ordinal r) {
// use signed integer for step index because we'll be doing arithmetic on it
list<pair<int/*OPEN/CLOSE*/, /*step*/int> > braces;
trace(9991, "transform") << "--- transform braces for recipe " << get(Recipe, r).name << end();
for (int index = 0; index < SIZE(get(Recipe, r).steps); ++index) {
for (int index = 0; index < SIZE(get(Recipe, r).steps); ++index) {
const instruction& inst = get(Recipe, r).steps.at(index);
if (inst.label == "{") {
trace(9993, "transform") << maybe(get(Recipe, r).name) << "push (open, " << index << ")" << end();
@ -52,7 +52,7 @@ void transform_braces(const recipe_ordinal r) {
}
}
stack</*step*/int> open_braces;
for (int index = 0; index < SIZE(get(Recipe, r).steps); ++index) {
for (int index = 0; index < SIZE(get(Recipe, r).steps); ++index) {
instruction& inst = get(Recipe, r).steps.at(index);
if (inst.label == "{") {
open_braces.push(index);
@ -134,7 +134,7 @@ void transform_braces(const recipe_ordinal r) {
// enable future signed arithmetic
int matching_brace(int index, const list<pair<int, int> >& braces, recipe_ordinal r) {
int stacksize = 0;
for (list<pair<int, int> >::const_iterator p = braces.begin(); p != braces.end(); ++p) {
for (list<pair<int, int> >::const_iterator p = braces.begin(); p != braces.end(); ++p) {
if (p->second < index) continue;
stacksize += (p->first ? 1 : -1);
if (stacksize == 0) return p->second;

View File

@ -24,7 +24,7 @@ Transform.push_back(transform_labels); // idempotent
:(code)
void transform_labels(const recipe_ordinal r) {
map<string, int> offset;
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
const instruction& inst = get(Recipe, r).steps.at(i);
if (starts_with(inst.label, "+")) {
if (!contains_key(offset, inst.label)) {
@ -37,7 +37,7 @@ void transform_labels(const recipe_ordinal r) {
}
}
}
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
instruction& inst = get(Recipe, r).steps.at(i);
if (inst.name == "jump") {
if (inst.ingredients.empty()) {

View File

@ -43,11 +43,11 @@ void transform_names(const recipe_ordinal r) {
// store the indices 'used' so far in the map
int& curr_idx = names[""];
++curr_idx; // avoid using index 0, benign skip in some other cases
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
// End transform_names(inst) Special-cases
// map names to addresses
for (int in = 0; in < SIZE(inst.ingredients); ++in) {
for (int in = 0; in < SIZE(inst.ingredients); ++in) {
reagent& ingredient = inst.ingredients.at(in);
// Begin transform_names Ingredient Special-cases(ingredient, inst, caller)
if (is_disqualified(ingredient, inst, caller.name)) continue;
@ -68,7 +68,7 @@ void transform_names(const recipe_ordinal r) {
return;
}
}
for (int out = 0; out < SIZE(inst.products); ++out) {
for (int out = 0; out < SIZE(inst.products); ++out) {
reagent& product = inst.products.at(out);
// Begin transform_names Product Special-cases(product, inst, caller)
if (is_disqualified(product, inst, caller.name)) continue;
@ -124,7 +124,7 @@ type_ordinal skip_addresses(type_tree* type) {
int find_element_name(const type_ordinal t, const string& name, const string& recipe_name) {
const type_info& container = get(Type, t);
for (int i = 0; i < SIZE(container.elements); ++i)
for (int i = 0; i < SIZE(container.elements); ++i)
if (container.elements.at(i).name == name) return i;
raise << maybe(recipe_name) << "unknown element '" << name << "' in container '" << get(Type, t).name << "'\n" << end();
return -1;

View File

@ -238,9 +238,9 @@ void try_reclaim_locals() {
if (inst.old_name != "local-scope") return;
// reclaim any local variables unless they're being returned
vector<double> zeros;
for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) {
for (int i = /*leave default space for last*/1; i < SIZE(exiting_recipe.steps); ++i) {
const instruction& inst = exiting_recipe.steps.at(i);
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
const reagent& product = inst.products.at(i);
// local variables only
if (has_property(product, "lookup")) continue;
@ -265,7 +265,7 @@ bool escaping(const reagent& r) {
assert(Current_routine); // run-time only
// nothing escapes when you fall through past end of recipe
if (current_step_index() >= SIZE(Current_routine->steps())) return false;
for (long long i = 0; i < SIZE(current_instruction().ingredients); ++i) {
for (long long i = 0; i < SIZE(current_instruction().ingredients); ++i) {
if (r == current_instruction().ingredients.at(i)) {
if (caller_uses_product(i))
return true;
@ -412,7 +412,7 @@ Hide_missing_default_space_errors = false;
:(code)
bool contains_non_special_name(const recipe_ordinal r) {
for (map<string, int>::iterator p = Name[r].begin(); p != Name[r].end(); ++p) {
for (map<string, int>::iterator p = Name[r].begin(); p != Name[r].end(); ++p) {
if (p->first.empty()) continue;
if (p->first.find("stash_") == 0) continue; // generated by rewrite_stashes_to_text (cross-layer)
if (!is_special_name(p->first))

View File

@ -49,7 +49,7 @@ int space_base(const reagent& x, int space_index, int base) {
}
int space_index(const reagent& x) {
for (int i = 0; i < SIZE(x.properties); ++i) {
for (int i = 0; i < SIZE(x.properties); ++i) {
if (x.properties.at(i).first == "space") {
if (!x.properties.at(i).second || x.properties.at(i).second->right)
raise << maybe(current_recipe_name()) << "/space metadata should take exactly one value in '" << x.original_string << "'\n" << end();

View File

@ -38,10 +38,10 @@ Transform.push_back(collect_surrounding_spaces); // idempotent
:(code)
void collect_surrounding_spaces(const recipe_ordinal r) {
trace(9991, "transform") << "--- collect surrounding spaces for recipe " << get(Recipe, r).name << end();
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) {
const instruction& inst = get(Recipe, r).steps.at(i);
if (inst.is_label) continue;
for (int j = 0; j < SIZE(inst.products); ++j) {
for (int j = 0; j < SIZE(inst.products); ++j) {
if (is_literal(inst.products.at(j))) continue;
if (inst.products.at(j).name != "0") continue;
if (!is_space(inst.products.at(j))) {
@ -100,7 +100,7 @@ int lookup_name(const reagent& x, const recipe_ordinal r, set<recipe_ordinal>& d
if (!Name[r].empty()) return Name[r][x.name];
if (contains_key(done, r)) {
raise << "can't compute address of '" << to_string(x) << "' because\n" << end();
for (int i = 1; i < SIZE(path); ++i) {
for (int i = 1; i < SIZE(path); ++i) {
raise << path.at(i-1) << " requires computing names of " << path.at(i) << '\n' << end();
}
raise << path.at(SIZE(path)-1) << " requires computing names of " << r << "..ad infinitum\n" << end();

View File

@ -22,13 +22,13 @@ void check_or_set_types_by_name(const recipe_ordinal r) {
trace(9991, "transform") << "--- deduce types for recipe " << get(Recipe, r).name << end();
recipe& caller = get(Recipe, r);
set<reagent> known;
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
for (int in = 0; in < SIZE(inst.ingredients); ++in) {
for (int in = 0; in < SIZE(inst.ingredients); ++in) {
deduce_missing_type(known, inst.ingredients.at(in));
check_type(known, inst.ingredients.at(in), caller);
}
for (int out = 0; out < SIZE(inst.products); ++out) {
for (int out = 0; out < SIZE(inst.products); ++out) {
deduce_missing_type(known, inst.products.at(out));
check_type(known, inst.products.at(out), caller);
}

View File

@ -119,7 +119,7 @@ Hide_missing_default_space_errors = false;
if (Num_core_mu_scenarios) {
time(&t);
cerr << "Mu tests: " << ctime(&t);
for (int i = 0; i < Num_core_mu_scenarios; ++i) {
for (int i = 0; i < Num_core_mu_scenarios; ++i) {
//? cerr << '\n' << i << ": " << Scenarios.at(i).name;
run_mu_scenario(Scenarios.at(i));
if (Passed) cerr << ".";
@ -130,7 +130,7 @@ run_app_scenarios:
if (Num_core_mu_scenarios != SIZE(Scenarios)) {
time(&t);
cerr << "App tests: " << ctime(&t);
for (int i = Num_core_mu_scenarios; i < SIZE(Scenarios); ++i) {
for (int i = Num_core_mu_scenarios; i < SIZE(Scenarios); ++i) {
//? cerr << '\n' << i << ": " << Scenarios.at(i).name;
run_mu_scenario(Scenarios.at(i));
if (Passed) cerr << ".";
@ -153,7 +153,7 @@ if (Test_only_app && Num_core_mu_scenarios < SIZE(Scenarios)) {
//: Convenience: run a single named scenario.
:(after "Test Runs")
for (int i = 0; i < SIZE(Scenarios); ++i) {
for (int i = 0; i < SIZE(Scenarios); ++i) {
if (Scenarios.at(i).name == argv[argc-1]) {
run_mu_scenario(Scenarios.at(i));
if (Passed) cerr << ".\n";
@ -401,7 +401,7 @@ void check_string(int address, const string& literal) {
return;
}
++address; // now skip length
for (int i = 0; i < SIZE(literal); ++i) {
for (int i = 0; i < SIZE(literal); ++i) {
trace(9999, "run") << "checking location " << address+i << end();
if (get_or_insert(Memory, address+i) != literal.at(i)) {
if (Current_scenario && !Scenario_testing_scenario) {
@ -518,7 +518,7 @@ void check_trace(const string& expected) {
vector<trace_line> expected_lines = parse_trace(expected);
if (expected_lines.empty()) return;
int curr_expected_line = 0;
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
if (expected_lines.at(curr_expected_line).label != p->label) continue;
if (expected_lines.at(curr_expected_line).contents != trim(p->contents)) continue;
// match
@ -539,7 +539,7 @@ void check_trace(const string& expected) {
vector<trace_line> parse_trace(const string& expected) {
vector<string> buf = split(expected, "\n");
vector<trace_line> result;
for (int i = 0; i < SIZE(buf); ++i) {
for (int i = 0; i < SIZE(buf); ++i) {
buf.at(i) = trim(buf.at(i));
if (buf.at(i).empty()) continue;
int delim = buf.at(i).find(": ");
@ -618,7 +618,7 @@ case TRACE_SHOULD_NOT_CONTAIN: {
bool check_trace_missing(const string& in) {
Trace_stream->newline();
vector<trace_line> lines = parse_trace(in);
for (int i = 0; i < SIZE(lines); ++i) {
for (int i = 0; i < SIZE(lines); ++i) {
if (trace_count(lines.at(i).label, lines.at(i).contents) != 0) {
raise << "unexpected [" << lines.at(i).contents << "] in trace with label '" << lines.at(i).label << "'\n" << end();
Passed = false;
@ -736,7 +736,7 @@ void mark_autogenerated(recipe_ordinal r) {
}
:(after "void transform_all()")
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
for (map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) {
const recipe& r = p->second;
if (r.name.find('_') == string::npos) continue;
if (r.is_autogenerated) continue; // created by previous call to transform_all()

View File

@ -79,7 +79,7 @@ void insert_fragments(recipe& r) {
made_progress = false;
// create a new vector because insertions invalidate iterators
vector<instruction> result;
for (int i = 0; i < SIZE(r.steps); ++i) {
for (int i = 0; i < SIZE(r.steps); ++i) {
const instruction& inst = r.steps.at(i);
if (!inst.is_label || !is_waypoint(inst.label) || inst.tangle_done) {
result.push_back(inst);
@ -115,12 +115,12 @@ void append_fragment(vector<instruction>& base, const vector<instruction>& patch
// so we'll keep jump targets local to the specific before/after fragment
// that introduces them.
set<string> jump_targets;
for (int i = 0; i < SIZE(patch); ++i) {
for (int i = 0; i < SIZE(patch); ++i) {
const instruction& inst = patch.at(i);
if (inst.is_label && is_jump_target(inst.label))
jump_targets.insert(inst.label);
}
for (int i = 0; i < SIZE(patch); ++i) {
for (int i = 0; i < SIZE(patch); ++i) {
instruction inst = patch.at(i);
if (inst.is_label) {
if (contains_key(jump_targets, inst.label))
@ -128,7 +128,7 @@ void append_fragment(vector<instruction>& base, const vector<instruction>& patch
base.push_back(inst);
continue;
}
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
reagent& x = inst.ingredients.at(j);
if (!is_literal(x)) continue;
if (x.type->name == "label" && contains_key(jump_targets, x.name))
@ -152,11 +152,11 @@ bool is_waypoint(string label) {
check_insert_fragments();
:(code)
void check_insert_fragments() {
for (map<string, recipe>::iterator p = Before_fragments.begin(); p != Before_fragments.end(); ++p) {
for (map<string, recipe>::iterator p = Before_fragments.begin(); p != Before_fragments.end(); ++p) {
if (!contains_key(Fragments_used, p->first))
raise << "could not locate insert before label " << p->first << '\n' << end();
}
for (map<string, recipe>::iterator p = After_fragments.begin(); p != After_fragments.end(); ++p) {
for (map<string, recipe>::iterator p = After_fragments.begin(); p != After_fragments.end(); ++p) {
if (!contains_key(Fragments_used, p->first))
raise << "could not locate insert after label " << p->first << '\n' << end();
}

View File

@ -109,10 +109,10 @@ def main # comment
:(after "Begin debug_string(recipe x)")
out << "ingredients:\n";
for (int i = 0; i < SIZE(x.ingredients); ++i)
for (int i = 0; i < SIZE(x.ingredients); ++i)
out << " " << debug_string(x.ingredients.at(i)) << '\n';
out << "products:\n";
for (int i = 0; i < SIZE(x.products); ++i)
for (int i = 0; i < SIZE(x.products); ++i)
out << " " << debug_string(x.products.at(i)) << '\n';
//: If a recipe never mentions any ingredients or products, assume it has a header.
@ -126,7 +126,7 @@ def test [
:(before "End Recipe Body(result)")
if (!result.has_header) {
result.has_header = true;
for (int i = 0; i < SIZE(result.steps); ++i) {
for (int i = 0; i < SIZE(result.steps); ++i) {
const instruction& inst = result.steps.at(i);
if ((inst.name == "reply" && !inst.ingredients.empty())
|| (inst.name == "return" && !inst.ingredients.empty())
@ -158,9 +158,9 @@ def foo -> a:text [ # 'text' is an abbreviation
+mem: storing 97 in location 1
:(before "End Expand Type Abbreviations(caller)")
for (long int i = 0; i < SIZE(caller.ingredients); ++i)
for (long int i = 0; i < SIZE(caller.ingredients); ++i)
expand_type_abbreviations(caller.ingredients.at(i).type);
for (long int i = 0; i < SIZE(caller.products); ++i)
for (long int i = 0; i < SIZE(caller.products); ++i)
expand_type_abbreviations(caller.products.at(i).type);
//: Rewrite 'load-ingredients' to instructions to create all reagents in the header.
@ -169,7 +169,7 @@ for (long int i = 0; i < SIZE(caller.products); ++i)
if (curr.name == "load-ingredients") {
curr.clear();
recipe_ordinal op = get(Recipe_ordinal, "next-ingredient-without-typechecking");
for (int i = 0; i < SIZE(result.ingredients); ++i) {
for (int i = 0; i < SIZE(result.ingredients); ++i) {
curr.operation = op;
curr.name = "next-ingredient-without-typechecking";
curr.products.push_back(result.ingredients.at(i));
@ -205,7 +205,7 @@ case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: {
products.resize(2);
// pad the first product with sufficient zeros to match its type
int size = size_of(current_instruction().products.at(0));
for (int i = 0; i < size; ++i)
for (int i = 0; i < size; ++i)
products.at(0).push_back(0);
products.at(1).push_back(0);
}
@ -244,17 +244,17 @@ Transform.push_back(check_calls_against_header); // idempotent
void check_calls_against_header(const recipe_ordinal r) {
const recipe& caller = get(Recipe, r);
trace(9991, "transform") << "--- type-check calls inside recipe " << caller.name << end();
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
if (inst.operation < MAX_PRIMITIVE_RECIPES) continue;
const recipe& callee = get(Recipe, inst.operation);
if (!callee.has_header) continue;
for (long int i = 0; i < min(SIZE(inst.ingredients), SIZE(callee.ingredients)); ++i) {
for (long int i = 0; i < min(SIZE(inst.ingredients), SIZE(callee.ingredients)); ++i) {
// ingredients coerced from call to callee
if (!types_coercible(callee.ingredients.at(i), inst.ingredients.at(i)))
raise << maybe(caller.name) << "ingredient " << i << " has the wrong type at '" << inst.original_string << "'\n" << end();
}
for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) {
for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
// products coerced from callee to call
if (!types_coercible(inst.products.at(i), callee.products.at(i)))
@ -284,14 +284,14 @@ void check_reply_instructions_against_header(const recipe_ordinal r) {
const recipe& caller_recipe = get(Recipe, r);
if (!caller_recipe.has_header) return;
trace(9991, "transform") << "--- checking reply instructions against header for " << caller_recipe.name << end();
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
const instruction& inst = caller_recipe.steps.at(i);
if (inst.name != "reply" && inst.name != "return") continue;
if (SIZE(caller_recipe.products) != SIZE(inst.ingredients)) {
raise << maybe(caller_recipe.name) << "replied with the wrong number of products at '" << inst.original_string << "'\n" << end();
continue;
}
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
if (!types_match(caller_recipe.products.at(i), inst.ingredients.at(i)))
raise << maybe(caller_recipe.name) << "replied with the wrong type at '" << inst.original_string << "'\n" << end();
}
@ -329,7 +329,7 @@ void check_header_ingredients(const recipe_ordinal r) {
if (caller_recipe.products.empty()) return;
caller_recipe.ingredient_index.clear();
trace(9991, "transform") << "--- checking reply instructions against header for " << caller_recipe.name << end();
for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
if (contains_key(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name))
raise << maybe(caller_recipe.name) << "'" << caller_recipe.ingredients.at(i).name << "' can't repeat in the ingredients\n" << end();
put(caller_recipe.ingredient_index, caller_recipe.ingredients.at(i).name, i);
@ -360,20 +360,20 @@ void deduce_types_from_header(const recipe_ordinal r) {
if (caller_recipe.products.empty()) return;
trace(9991, "transform") << "--- deduce types from header for " << caller_recipe.name << end();
map<string, const type_tree*> header_type;
for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
for (int i = 0; i < SIZE(caller_recipe.ingredients); ++i) {
if (!caller_recipe.ingredients.at(i).type) continue; // error handled elsewhere
put(header_type, caller_recipe.ingredients.at(i).name, caller_recipe.ingredients.at(i).type);
trace(9993, "transform") << "type of " << caller_recipe.ingredients.at(i).name << " is " << names_to_string(caller_recipe.ingredients.at(i).type) << end();
}
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
if (!caller_recipe.products.at(i).type) continue; // error handled elsewhere
put(header_type, caller_recipe.products.at(i).name, caller_recipe.products.at(i).type);
trace(9993, "transform") << "type of " << caller_recipe.products.at(i).name << " is " << names_to_string(caller_recipe.products.at(i).type) << end();
}
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
instruction& inst = caller_recipe.steps.at(i);
trace(9992, "transform") << "instruction: " << to_string(inst) << end();
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (inst.ingredients.at(i).type) continue;
if (header_type.find(inst.ingredients.at(i).name) == header_type.end())
continue;
@ -381,7 +381,7 @@ void deduce_types_from_header(const recipe_ordinal r) {
inst.ingredients.at(i).type = new type_tree(*get(header_type, inst.ingredients.at(i).name));
trace(9993, "transform") << "type of " << inst.ingredients.at(i).name << " is " << names_to_string(inst.ingredients.at(i).type) << end();
}
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
trace(9993, "transform") << " product: " << to_string(inst.products.at(i)) << end();
if (inst.products.at(i).type) continue;
if (header_type.find(inst.products.at(i).name) == header_type.end())
@ -416,7 +416,7 @@ void fill_in_reply_ingredients(recipe_ordinal r) {
recipe& caller_recipe = get(Recipe, r);
if (!caller_recipe.has_header) return;
trace(9991, "transform") << "--- fill in reply ingredients from header for recipe " << caller_recipe.name << end();
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
for (int i = 0; i < SIZE(caller_recipe.steps); ++i) {
instruction& inst = caller_recipe.steps.at(i);
if (inst.name == "reply" || inst.name == "return")
add_header_products(inst, caller_recipe);
@ -435,7 +435,7 @@ void fill_in_reply_ingredients(recipe_ordinal r) {
void add_header_products(instruction& inst, const recipe& caller_recipe) {
assert(inst.name == "reply" || inst.name == "return");
// collect any products with the same names as ingredients
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
for (int i = 0; i < SIZE(caller_recipe.products); ++i) {
// if the ingredient is missing, add it from the header
if (SIZE(inst.ingredients) == i)
inst.ingredients.push_back(caller_recipe.products.at(i));

View File

@ -55,7 +55,7 @@ else {
:(code)
string matching_variant_name(const recipe& rr) {
const vector<recipe_ordinal>& variants = get_or_insert(Recipe_variants, rr.name);
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (!contains_key(Recipe, variants.at(i))) continue;
const recipe& candidate = get(Recipe, variants.at(i));
if (!all_reagents_match(rr, candidate)) continue;
@ -67,13 +67,13 @@ string matching_variant_name(const recipe& rr) {
bool all_reagents_match(const recipe& r1, const recipe& r2) {
if (SIZE(r1.ingredients) != SIZE(r2.ingredients)) return false;
if (SIZE(r1.products) != SIZE(r2.products)) return false;
for (int i = 0; i < SIZE(r1.ingredients); ++i) {
for (int i = 0; i < SIZE(r1.ingredients); ++i) {
expand_type_abbreviations(r1.ingredients.at(i).type);
expand_type_abbreviations(r2.ingredients.at(i).type);
if (!deeply_equal_type_names(r1.ingredients.at(i), r2.ingredients.at(i)))
return false;
}
for (int i = 0; i < SIZE(r1.products); ++i) {
for (int i = 0; i < SIZE(r1.products); ++i) {
expand_type_abbreviations(r1.products.at(i).type);
expand_type_abbreviations(r2.products.at(i).type);
if (!deeply_equal_type_names(r1.products.at(i), r2.products.at(i)))
@ -106,7 +106,7 @@ bool deeply_equal_type_names(const type_tree* a, const type_tree* b) {
}
string next_unused_recipe_name(const string& recipe_name) {
for (int i = 2; ; ++i) {
for (int i = 2; /*forever*/; ++i) {
ostringstream out;
out << recipe_name << '_' << i;
if (!contains_key(Recipe_ordinal, out.str()))
@ -131,9 +131,9 @@ def test a:num, b:num -> z:num [
//: support recipe headers in a previous transform to fill in missing types
:(before "End check_or_set_invalid_types")
for (int i = 0; i < SIZE(caller.ingredients); ++i)
for (int i = 0; i < SIZE(caller.ingredients); ++i)
check_or_set_invalid_types(caller.ingredients.at(i).type, maybe(caller.name), "recipe header ingredient");
for (int i = 0; i < SIZE(caller.products); ++i)
for (int i = 0; i < SIZE(caller.products); ++i)
check_or_set_invalid_types(caller.products.at(i).type, maybe(caller.name), "recipe header product");
//: after filling in all missing types (because we'll be introducing 'blank' types in this transform in a later layer, for shape-shifting recipes)
@ -153,7 +153,7 @@ list<call> resolve_stack;
void resolve_ambiguous_calls(recipe_ordinal r) {
recipe& caller_recipe = get(Recipe, r);
trace(9991, "transform") << "--- resolve ambiguous calls for recipe " << caller_recipe.name << end();
for (int index = 0; index < SIZE(caller_recipe.steps); ++index) {
for (int index = 0; index < SIZE(caller_recipe.steps); ++index) {
instruction& inst = caller_recipe.steps.at(index);
if (inst.is_label) continue;
if (non_ghost_size(get_or_insert(Recipe_variants, inst.name)) == 0) continue;
@ -196,7 +196,7 @@ string best_variant(instruction& inst, const recipe& caller_recipe) {
// error messages
if (get(Recipe_ordinal, inst.name) >= MAX_PRIMITIVE_RECIPES) { // we currently don't check types for primitive variants
raise << maybe(caller_recipe.name) << "failed to find a matching call for '" << inst.original_string << "'\n" << end();
for (list<call>::iterator p = /*skip*/++resolve_stack.begin(); p != resolve_stack.end(); ++p) {
for (list<call>::iterator p = /*skip*/++resolve_stack.begin(); p != resolve_stack.end(); ++p) {
const recipe& specializer_recipe = get(Recipe, p->running_recipe);
const instruction& specializer_inst = specializer_recipe.steps.at(p->running_step_index);
if (specializer_recipe.name != "interactive")
@ -221,7 +221,7 @@ string best_variant(instruction& inst, const recipe& caller_recipe) {
// phase 1
vector<recipe_ordinal> strictly_matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) {
vector<recipe_ordinal> result;
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (variants.at(i) == -1) continue;
trace(9992, "transform") << "checking variant (strict) " << i << ": " << header_label(variants.at(i)) << end();
if (all_header_reagents_strictly_match(inst, get(Recipe, variants.at(i))))
@ -231,13 +231,13 @@ vector<recipe_ordinal> strictly_matching_variants(const instruction& inst, vecto
}
bool all_header_reagents_strictly_match(const instruction& inst, const recipe& variant) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
if (!types_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) {
trace(9993, "transform") << "strict match failed: ingredient " << i << end();
return false;
}
}
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) {
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) {
trace(9993, "transform") << "strict match failed: product " << i << end();
@ -250,7 +250,7 @@ bool all_header_reagents_strictly_match(const instruction& inst, const recipe& v
// phase 2
vector<recipe_ordinal> strictly_matching_variants_except_literal_zero_against_address(const instruction& inst, vector<recipe_ordinal>& variants) {
vector<recipe_ordinal> result;
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (variants.at(i) == -1) continue;
trace(9992, "transform") << "checking variant (strict except literal-zero-against-address) " << i << ": " << header_label(variants.at(i)) << end();
if (all_header_reagents_strictly_match_except_literal_zero_against_address(inst, get(Recipe, variants.at(i))))
@ -260,13 +260,13 @@ vector<recipe_ordinal> strictly_matching_variants_except_literal_zero_against_ad
}
bool all_header_reagents_strictly_match_except_literal_zero_against_address(const instruction& inst, const recipe& variant) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
if (!types_strictly_match_except_literal_zero_against_address(variant.ingredients.at(i), inst.ingredients.at(i))) {
trace(9993, "transform") << "match failed: ingredient " << i << end();
return false;
}
}
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) {
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!types_strictly_match(variant.products.at(i), inst.products.at(i))) {
trace(9993, "transform") << "match failed: product " << i << end();
@ -285,7 +285,7 @@ bool types_strictly_match_except_literal_zero_against_address(const reagent& to,
// phase 4
vector<recipe_ordinal> strictly_matching_variants_except_literal_against_address_or_boolean(const instruction& inst, vector<recipe_ordinal>& variants) {
vector<recipe_ordinal> result;
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (variants.at(i) == -1) continue;
trace(9992, "transform") << "checking variant (strict except literal-against-boolean) " << i << ": " << header_label(variants.at(i)) << end();
if (all_header_reagents_strictly_match_except_literal_against_address_or_boolean(inst, get(Recipe, variants.at(i))))
@ -295,13 +295,13 @@ vector<recipe_ordinal> strictly_matching_variants_except_literal_against_address
}
bool all_header_reagents_strictly_match_except_literal_against_address_or_boolean(const instruction& inst, const recipe& variant) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
if (!types_strictly_match_except_literal_against_address_or_boolean(variant.ingredients.at(i), inst.ingredients.at(i))) {
trace(9993, "transform") << "match failed: ingredient " << i << end();
return false;
}
}
for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) {
for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!types_strictly_match_except_literal_against_address_or_boolean(variant.products.at(i), inst.products.at(i))) {
trace(9993, "transform") << "match failed: product " << i << end();
@ -320,7 +320,7 @@ bool types_strictly_match_except_literal_against_address_or_boolean(const reagen
// phase 5
vector<recipe_ordinal> matching_variants(const instruction& inst, vector<recipe_ordinal>& variants) {
vector<recipe_ordinal> result;
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (variants.at(i) == -1) continue;
trace(9992, "transform") << "checking variant " << i << ": " << header_label(variants.at(i)) << end();
if (all_header_reagents_match(inst, get(Recipe, variants.at(i))))
@ -330,13 +330,13 @@ vector<recipe_ordinal> matching_variants(const instruction& inst, vector<recipe_
}
bool all_header_reagents_match(const instruction& inst, const recipe& variant) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
if (!types_match(variant.ingredients.at(i), inst.ingredients.at(i))) {
trace(9993, "transform") << "match failed: ingredient " << i << end();
return false;
}
}
for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) {
for (int i = 0; i < min(SIZE(variant.products), SIZE(inst.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!types_match(variant.products.at(i), inst.products.at(i))) {
trace(9993, "transform") << "match failed: product " << i << end();
@ -351,7 +351,7 @@ const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& cand
assert(!candidates.empty());
int min_score = 999;
int min_index = 0;
for (int i = 0; i < SIZE(candidates); ++i) {
for (int i = 0; i < SIZE(candidates); ++i) {
const recipe& candidate = get(Recipe, candidates.at(i));
int score = abs(SIZE(candidate.products)-SIZE(inst.products))
+ abs(SIZE(candidate.ingredients)-SIZE(inst.ingredients));
@ -366,7 +366,7 @@ const recipe& best_variant(const instruction& inst, vector<recipe_ordinal>& cand
int non_ghost_size(vector<recipe_ordinal>& variants) {
int result = 0;
for (int i = 0; i < SIZE(variants); ++i)
for (int i = 0; i < SIZE(variants); ++i)
if (variants.at(i) != -1) ++result;
return result;
}
@ -374,7 +374,7 @@ int non_ghost_size(vector<recipe_ordinal>& variants) {
bool next_stash(const call& c, instruction* stash_inst) {
const recipe& specializer_recipe = get(Recipe, c.running_recipe);
int index = c.running_step_index;
for (++index; index < SIZE(specializer_recipe.steps); ++index) {
for (++index; index < SIZE(specializer_recipe.steps); ++index) {
const instruction& inst = specializer_recipe.steps.at(index);
if (inst.name == "stash") {
*stash_inst = inst;
@ -564,10 +564,10 @@ string header_label(recipe_ordinal r) {
string header_label(const recipe& caller) {
ostringstream out;
out << "recipe " << caller.name;
for (int i = 0; i < SIZE(caller.ingredients); ++i)
for (int i = 0; i < SIZE(caller.ingredients); ++i)
out << ' ' << to_string(caller.ingredients.at(i));
if (!caller.products.empty()) out << " ->";
for (int i = 0; i < SIZE(caller.products); ++i)
for (int i = 0; i < SIZE(caller.products); ++i)
out << ' ' << to_string(caller.products.at(i));
return out.str();
}

View File

@ -177,7 +177,7 @@ bool slurp_type_ingredients(istream& in, map<string, type_ordinal>& out, const s
bool type_ingredients_match(const map<string, type_ordinal>& a, const map<string, type_ordinal>& b) {
if (SIZE(a) != SIZE(b)) return false;
for (map<string, type_ordinal>::const_iterator p = a.begin(); p != a.end(); ++p) {
for (map<string, type_ordinal>::const_iterator p = a.begin(); p != a.end(); ++p) {
if (!contains_key(b, p->first)) return false;
if (p->second != get(b, p->first)) return false;
}
@ -341,7 +341,7 @@ void replace_type_ingredients(type_tree* element_type, const type_tree* callsite
const type_tree* nth_type_ingredient(const type_tree* callsite_type, int type_ingredient_index, const type_info& container_info) {
bool final = final_type_ingredient(type_ingredient_index, container_info);
const type_tree* curr = callsite_type;
for (int i = 0; i < type_ingredient_index; ++i) {
for (int i = 0; i < type_ingredient_index; ++i) {
assert(curr);
assert(!curr->atom);
//? cerr << "type ingredient " << i << " is " << to_string(curr->left) << '\n';

View File

@ -65,7 +65,7 @@ if (!candidates.empty()) {
// perform all transforms on the new specialization
if (!variant.steps.empty()) {
trace(9992, "transform") << "transforming new specialization: " << variant.name << end();
for (int t = 0; t < SIZE(Transform); ++t) {
for (int t = 0; t < SIZE(Transform); ++t) {
// one exception: skip tangle, which would have already occurred inside new_variant above
if (Transform.at(t) == /*disambiguate overloading*/static_cast<transform_fn>(insert_fragments))
continue;
@ -99,7 +99,7 @@ bool types_strictly_match_except_literal_zero_against_address(const reagent& to,
// phase 3 of static dispatch
vector<recipe_ordinal> strictly_matching_shape_shifting_variants(const instruction& inst, vector<recipe_ordinal>& variants) {
vector<recipe_ordinal> result;
for (int i = 0; i < SIZE(variants); ++i) {
for (int i = 0; i < SIZE(variants); ++i) {
if (variants.at(i) == -1) continue;
if (!any_type_ingredient_in_header(variants.at(i))) continue;
if (!all_concrete_header_reagents_strictly_match(inst, get(Recipe, variants.at(i)))) continue;
@ -109,13 +109,13 @@ vector<recipe_ordinal> strictly_matching_shape_shifting_variants(const instructi
}
bool all_concrete_header_reagents_strictly_match(const instruction& inst, const recipe& variant) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.ingredients), SIZE(variant.ingredients)); ++i) {
if (!concrete_type_names_strictly_match(variant.ingredients.at(i), inst.ingredients.at(i))) {
trace(9993, "transform") << "concrete-type match failed: ingredient " << i << end();
return false;
}
}
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.ingredients)); ++i) {
for (int i = 0; i < min(SIZE(inst.products), SIZE(variant.ingredients)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!concrete_type_names_strictly_match(variant.products.at(i), inst.products.at(i))) {
trace(9993, "transform") << "strict match failed: product " << i << end();
@ -130,7 +130,7 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector<recip
assert(!candidates.empty());
// primary score
int max_score = -1;
for (int i = 0; i < SIZE(candidates); ++i) {
for (int i = 0; i < SIZE(candidates); ++i) {
int score = number_of_concrete_type_names(candidates.at(i));
assert(score > -1);
if (score > max_score) max_score = score;
@ -138,7 +138,7 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector<recip
// break any ties at max_score by a secondary score
int min_score2 = 999;
int best_index = 0;
for (int i = 0; i < SIZE(candidates); ++i) {
for (int i = 0; i < SIZE(candidates); ++i) {
int score1 = number_of_concrete_type_names(candidates.at(i));
assert(score1 <= max_score);
if (score1 != max_score) continue;
@ -156,11 +156,11 @@ recipe_ordinal best_shape_shifting_variant(const instruction& inst, vector<recip
bool any_type_ingredient_in_header(recipe_ordinal variant) {
const recipe& caller = get(Recipe, variant);
for (int i = 0; i < SIZE(caller.ingredients); ++i) {
for (int i = 0; i < SIZE(caller.ingredients); ++i) {
if (contains_type_ingredient_name(caller.ingredients.at(i)))
return true;
}
for (int i = 0; i < SIZE(caller.products); ++i) {
for (int i = 0; i < SIZE(caller.products); ++i) {
if (contains_type_ingredient_name(caller.products.at(i)))
return true;
}
@ -176,9 +176,9 @@ bool concrete_type_names_strictly_match(reagent/*copy*/ to, reagent/*copy*/ from
int number_of_concrete_type_names(recipe_ordinal r) {
const recipe& caller = get(Recipe, r);
int result = 0;
for (int i = 0; i < SIZE(caller.ingredients); ++i)
for (int i = 0; i < SIZE(caller.ingredients); ++i)
result += number_of_concrete_type_names(caller.ingredients.at(i));
for (int i = 0; i < SIZE(caller.products); ++i)
for (int i = 0; i < SIZE(caller.products); ++i)
result += number_of_concrete_type_names(caller.products.at(i));
return result;
}
@ -252,7 +252,7 @@ recipe_ordinal new_variant(recipe_ordinal exemplar, const instruction& inst, con
compute_type_ingredient_mappings(get(Recipe, exemplar), inst, mappings, caller_recipe, &error);
if (!error) error = (SIZE(mappings) != type_ingredient_count_in_header(exemplar));
if (!error) replace_type_ingredients(new_recipe, mappings);
for (map<string, const type_tree*>::iterator p = mappings.begin(); p != mappings.end(); ++p)
for (map<string, const type_tree*>::iterator p = mappings.begin(); p != mappings.end(); ++p)
delete p->second;
if (error) return 0;
}
@ -264,16 +264,16 @@ recipe_ordinal new_variant(recipe_ordinal exemplar, const instruction& inst, con
void compute_type_names(recipe& variant) {
trace(9993, "transform") << "-- compute type names: " << variant.name << end();
map<string, type_tree*> type_names;
for (int i = 0; i < SIZE(variant.ingredients); ++i)
for (int i = 0; i < SIZE(variant.ingredients); ++i)
save_or_deduce_type_name(variant.ingredients.at(i), type_names, variant, "");
for (int i = 0; i < SIZE(variant.products); ++i)
for (int i = 0; i < SIZE(variant.products); ++i)
save_or_deduce_type_name(variant.products.at(i), type_names, variant, "");
for (int i = 0; i < SIZE(variant.steps); ++i) {
for (int i = 0; i < SIZE(variant.steps); ++i) {
instruction& inst = variant.steps.at(i);
trace(9993, "transform") << " instruction: " << to_string(inst) << end();
for (int in = 0; in < SIZE(inst.ingredients); ++in)
for (int in = 0; in < SIZE(inst.ingredients); ++in)
save_or_deduce_type_name(inst.ingredients.at(in), type_names, variant, " in '" + inst.original_string + "'");
for (int out = 0; out < SIZE(inst.products); ++out)
for (int out = 0; out < SIZE(inst.products); ++out)
save_or_deduce_type_name(inst.products.at(out), type_names, variant, " in '" + inst.original_string + "'");
}
}
@ -297,7 +297,7 @@ void save_or_deduce_type_name(reagent& x, map<string, type_tree*>& type, const r
void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& inst, map<string, const type_tree*>& mappings, const recipe& caller_recipe, bool* error) {
int limit = min(SIZE(inst.ingredients), SIZE(exemplar.ingredients));
for (int i = 0; i < limit; ++i) {
for (int i = 0; i < limit; ++i) {
const reagent& exemplar_reagent = exemplar.ingredients.at(i);
reagent/*copy*/ ingredient = inst.ingredients.at(i);
canonize_type(ingredient);
@ -305,7 +305,7 @@ void compute_type_ingredient_mappings(const recipe& exemplar, const instruction&
accumulate_type_ingredients(exemplar_reagent, ingredient, mappings, exemplar, inst, caller_recipe, error);
}
limit = min(SIZE(inst.products), SIZE(exemplar.products));
for (int i = 0; i < limit; ++i) {
for (int i = 0; i < limit; ++i) {
const reagent& exemplar_reagent = exemplar.products.at(i);
reagent/*copy*/ product = inst.products.at(i);
if (is_dummy(product)) continue;
@ -363,18 +363,18 @@ void replace_type_ingredients(recipe& new_recipe, const map<string, const type_t
// update its header
if (mappings.empty()) return;
trace(9993, "transform") << "replacing in recipe header ingredients" << end();
for (int i = 0; i < SIZE(new_recipe.ingredients); ++i)
for (int i = 0; i < SIZE(new_recipe.ingredients); ++i)
replace_type_ingredients(new_recipe.ingredients.at(i), mappings, new_recipe);
trace(9993, "transform") << "replacing in recipe header products" << end();
for (int i = 0; i < SIZE(new_recipe.products); ++i)
for (int i = 0; i < SIZE(new_recipe.products); ++i)
replace_type_ingredients(new_recipe.products.at(i), mappings, new_recipe);
// update its body
for (int i = 0; i < SIZE(new_recipe.steps); ++i) {
for (int i = 0; i < SIZE(new_recipe.steps); ++i) {
instruction& inst = new_recipe.steps.at(i);
trace(9993, "transform") << "replacing in instruction '" << to_string(inst) << "'" << end();
for (int j = 0; j < SIZE(inst.ingredients); ++j)
for (int j = 0; j < SIZE(inst.ingredients); ++j)
replace_type_ingredients(inst.ingredients.at(j), mappings, new_recipe);
for (int j = 0; j < SIZE(inst.products); ++j)
for (int j = 0; j < SIZE(inst.products); ++j)
replace_type_ingredients(inst.products.at(j), mappings, new_recipe);
// special-case for new: replace type ingredient in first ingredient *value*
if (inst.name == "new" && inst.ingredients.at(0).type->name != "literal-string") {
@ -425,9 +425,9 @@ void replace_type_ingredients(type_tree* type, const map<string, const type_tree
int type_ingredient_count_in_header(recipe_ordinal variant) {
const recipe& caller = get(Recipe, variant);
set<string> type_ingredients;
for (int i = 0; i < SIZE(caller.ingredients); ++i)
for (int i = 0; i < SIZE(caller.ingredients); ++i)
accumulate_type_ingredients(caller.ingredients.at(i).type, type_ingredients);
for (int i = 0; i < SIZE(caller.products); ++i)
for (int i = 0; i < SIZE(caller.products); ++i)
accumulate_type_ingredients(caller.products.at(i).type, type_ingredients);
return SIZE(type_ingredients);
}
@ -458,7 +458,7 @@ void dump_inspect(const type_tree* x, ostream& out) {
return;
}
out << '(';
for (const type_tree* curr = x; curr; curr = curr->right) {
for (const type_tree* curr = x; curr; curr = curr->right) {
if (curr != x) out << ' ';
if (curr->left)
dump_inspect(curr->left, out);
@ -470,15 +470,15 @@ void dump_inspect(const type_tree* x, ostream& out) {
void ensure_all_concrete_types(/*const*/ recipe& new_recipe, const recipe& exemplar) {
trace(9993, "transform") << "-- ensure all concrete types in recipe " << new_recipe.name << end();
for (int i = 0; i < SIZE(new_recipe.ingredients); ++i)
for (int i = 0; i < SIZE(new_recipe.ingredients); ++i)
ensure_all_concrete_types(new_recipe.ingredients.at(i), exemplar);
for (int i = 0; i < SIZE(new_recipe.products); ++i)
for (int i = 0; i < SIZE(new_recipe.products); ++i)
ensure_all_concrete_types(new_recipe.products.at(i), exemplar);
for (int i = 0; i < SIZE(new_recipe.steps); ++i) {
for (int i = 0; i < SIZE(new_recipe.steps); ++i) {
instruction& inst = new_recipe.steps.at(i);
for (int j = 0; j < SIZE(inst.ingredients); ++j)
for (int j = 0; j < SIZE(inst.ingredients); ++j)
ensure_all_concrete_types(inst.ingredients.at(j), exemplar);
for (int j = 0; j < SIZE(inst.products); ++j)
for (int j = 0; j < SIZE(inst.products); ++j)
ensure_all_concrete_types(inst.products.at(j), exemplar);
}
}

View File

@ -345,13 +345,13 @@ void check_immutable_ingredients(recipe_ordinal r) {
const recipe& caller = get(Recipe, r);
trace(9991, "transform") << "--- check mutability of ingredients in recipe " << caller.name << end();
if (!caller.has_header) return; // skip check for old-style recipes calling next-ingredient directly
for (int i = 0; i < SIZE(caller.ingredients); ++i) {
for (int i = 0; i < SIZE(caller.ingredients); ++i) {
const reagent& current_ingredient = caller.ingredients.at(i);
if (is_present_in_products(caller, current_ingredient.name)) continue; // not expected to be immutable
// End Immutable Ingredients Special-cases
set<reagent> immutable_vars;
immutable_vars.insert(current_ingredient);
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
check_immutable_ingredient_in_instruction(inst, immutable_vars, current_ingredient.name, caller);
if (inst.operation == INDEX && inst.ingredients.at(1).name == current_ingredient.name) continue;
@ -366,7 +366,7 @@ void update_aliases(const instruction& inst, set<reagent>& current_ingredient_an
// primitive recipe
switch (inst.operation) {
case COPY:
for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p)
for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p)
current_ingredient_and_aliases.insert(inst.products.at(*p).name);
break;
case GET:
@ -384,7 +384,7 @@ void update_aliases(const instruction& inst, set<reagent>& current_ingredient_an
else {
// defined recipe
set<int> contained_in_product_indices = scan_contained_in_product_indices(inst, current_ingredient_indices);
for (set<int>::iterator p = contained_in_product_indices.begin(); p != contained_in_product_indices.end(); ++p) {
for (set<int>::iterator p = contained_in_product_indices.begin(); p != contained_in_product_indices.end(); ++p) {
if (*p < SIZE(inst.products))
current_ingredient_and_aliases.insert(inst.products.at(*p));
}
@ -394,12 +394,12 @@ void update_aliases(const instruction& inst, set<reagent>& current_ingredient_an
set<int> scan_contained_in_product_indices(const instruction& inst, set<int>& ingredient_indices) {
set<reagent> selected_ingredients;
const recipe& callee = get(Recipe, inst.operation);
for (set<int>::iterator p = ingredient_indices.begin(); p != ingredient_indices.end(); ++p) {
for (set<int>::iterator p = ingredient_indices.begin(); p != ingredient_indices.end(); ++p) {
if (*p >= SIZE(callee.ingredients)) continue; // optional immutable ingredient
selected_ingredients.insert(callee.ingredients.at(*p));
}
set<int> result;
for (int i = 0; i < SIZE(callee.products); ++i) {
for (int i = 0; i < SIZE(callee.products); ++i) {
const reagent& current_product = callee.products.at(i);
// TODO
const string_tree* contained_in_name = property(current_product, "contained-in");
@ -437,7 +437,7 @@ def test-next x:&:test-list -> y:&:test-list/contained-in:x [
:(code)
void check_immutable_ingredient_in_instruction(const instruction& inst, const set<reagent>& current_ingredient_and_aliases, const string& original_ingredient_name, const recipe& caller) {
// first check if the instruction is directly modifying something it shouldn't
for (int i = 0; i < SIZE(inst.products); ++i) {
for (int i = 0; i < SIZE(inst.products); ++i) {
if (has_property(inst.products.at(i), "lookup")
&& current_ingredient_and_aliases.find(inst.products.at(i)) != current_ingredient_and_aliases.end()) {
string current_product_name = inst.products.at(i).name;
@ -451,7 +451,7 @@ void check_immutable_ingredient_in_instruction(const instruction& inst, const se
// check if there's any indirect modification going on
set<int> current_ingredient_indices = ingredient_indices(inst, current_ingredient_and_aliases);
if (current_ingredient_indices.empty()) return; // ingredient not found in call
for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) {
for (set<int>::iterator p = current_ingredient_indices.begin(); p != current_ingredient_indices.end(); ++p) {
const int current_ingredient_index = *p;
reagent current_ingredient = inst.ingredients.at(current_ingredient_index);
canonize_type(current_ingredient);
@ -494,7 +494,7 @@ bool is_modified_in_recipe(recipe_ordinal r, int ingredient_index, const recipe&
}
bool is_present_in_products(const recipe& callee, const string& ingredient_name) {
for (int i = 0; i < SIZE(callee.products); ++i) {
for (int i = 0; i < SIZE(callee.products); ++i) {
if (callee.products.at(i).name == ingredient_name)
return true;
}
@ -502,7 +502,7 @@ bool is_present_in_products(const recipe& callee, const string& ingredient_name)
}
bool is_present_in_ingredients(const recipe& callee, const string& ingredient_name) {
for (int i = 0; i < SIZE(callee.ingredients); ++i) {
for (int i = 0; i < SIZE(callee.ingredients); ++i) {
if (callee.ingredients.at(i).name == ingredient_name)
return true;
}
@ -511,7 +511,7 @@ bool is_present_in_ingredients(const recipe& callee, const string& ingredient_na
set<int> ingredient_indices(const instruction& inst, const set<reagent>& ingredient_names) {
set<int> result;
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (is_literal(inst.ingredients.at(i))) continue;
if (ingredient_names.find(inst.ingredients.at(i)) != ingredient_names.end())
result.insert(i);

View File

@ -39,10 +39,10 @@ void rewrite_literal_string_to_text(recipe_ordinal r) {
trace(9991, "transform") << "--- rewrite literal strings in recipe " << caller.name << end();
if (contains_numeric_locations(caller)) return;
vector<instruction> new_instructions;
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
if (recipes_taking_literal_strings.find(inst.name) == recipes_taking_literal_strings.end()) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
if (!is_literal_text(inst.ingredients.at(j))) continue;
instruction def;
ostringstream ingredient_name;
@ -61,12 +61,12 @@ void rewrite_literal_string_to_text(recipe_ordinal r) {
}
bool contains_numeric_locations(const recipe& caller) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
for (int in = 0; in < SIZE(inst.ingredients); ++in)
for (int in = 0; in < SIZE(inst.ingredients); ++in)
if (is_numeric_location(inst.ingredients.at(in)))
return true;
for (int out = 0; out < SIZE(inst.products); ++out)
for (int out = 0; out < SIZE(inst.products); ++out)
if (is_numeric_location(inst.products.at(out)))
return true;
}

View File

@ -67,11 +67,11 @@ void convert_ingredients_to_text(recipe_ordinal r) {
void convert_ingredients_to_text(recipe& caller) {
vector<instruction> new_instructions;
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
instruction& inst = caller.steps.at(i);
// all these cases are getting hairy. how can we make this extensible?
if (inst.name == "stash") {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
if (is_literal_text(inst.ingredients.at(j))) continue;
ostringstream ingredient_name;
ingredient_name << "stash_" << i << '_' << j << ":address:array:character";
@ -79,7 +79,7 @@ void convert_ingredients_to_text(recipe& caller) {
}
}
else if (inst.name == "trace") {
for (int j = /*skip*/2; j < SIZE(inst.ingredients); ++j) {
for (int j = /*skip*/2; j < SIZE(inst.ingredients); ++j) {
if (is_literal_text(inst.ingredients.at(j))) continue;
ostringstream ingredient_name;
ingredient_name << "trace_" << i << '_' << j << ":address:array:character";
@ -93,7 +93,7 @@ void convert_ingredients_to_text(recipe& caller) {
// append _:text, ___
// will never ever get used.
if (is_literal_text(inst.ingredients.at(0)) || is_mu_text(inst.ingredients.at(0))) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
for (int j = 0; j < SIZE(inst.ingredients); ++j) {
ostringstream ingredient_name;
ingredient_name << "append_" << i << '_' << j << ":address:array:character";
convert_ingredient_to_text(inst.ingredients.at(j), new_instructions, ingredient_name.str());

View File

@ -67,7 +67,7 @@ size_t hash_mu_address(size_t h, reagent& r) {
size_t hash_mu_text(size_t h, const reagent& r) {
string input = read_mu_text(get_or_insert(Memory, r.value));
for (int i = 0; i < SIZE(input); ++i) {
for (int i = 0; i < SIZE(input); ++i) {
h = hash_iter(h, static_cast<size_t>(input.at(i)));
//? cerr << i << ": " << h << '\n';
}
@ -79,7 +79,7 @@ size_t hash_mu_array(size_t h, const reagent& r) {
reagent/*copy*/ elem = r;
delete elem.type;
elem.type = copy_array_element(r.type);
for (int i=0, address = r.value+1; i < size; ++i, address += size_of(elem)) {
for (int i=0, address = r.value+1; i < size; ++i, address += size_of(elem)) {
reagent/*copy*/ tmp = elem;
tmp.set_value(address);
h = hash(h, tmp);
@ -92,7 +92,7 @@ size_t hash_mu_container(size_t h, const reagent& r) {
type_info& info = get(Type, root_type(r.type)->value);
int address = r.value;
int offset = 0;
for (int i = 0; i < SIZE(info.elements); ++i) {
for (int i = 0; i < SIZE(info.elements); ++i) {
reagent/*copy*/ element = element_type(r.type, i);
if (has_property(element, "ignore-for-hash")) continue;
element.set_value(address+offset);
@ -365,7 +365,7 @@ case HASH_OLD: {
string input = read_mu_text(ingredients.at(0).at(0));
size_t h = 0 ;
for (int i = 0; i < SIZE(input); ++i) {
for (int i = 0; i < SIZE(input); ++i) {
h += static_cast<size_t>(input.at(i));
h += (h<<10);
h ^= (h>>6);

View File

@ -58,11 +58,11 @@ void initialize_recipe_literal(reagent& x) {
x.set_value(get(Recipe_ordinal, x.name));
}
bool contains_reagent_with_type(const recipe& caller, const string& name) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
for (int i = 0; i < SIZE(inst.ingredients); ++i)
for (int i = 0; i < SIZE(inst.ingredients); ++i)
if (is_matching_non_recipe_literal(inst.ingredients.at(i), name)) return true;
for (int i = 0; i < SIZE(inst.products); ++i)
for (int i = 0; i < SIZE(inst.products); ++i)
if (is_matching_non_recipe_literal(inst.products.at(i), name)) return true;
}
return false;
@ -156,7 +156,7 @@ Transform.push_back(check_indirect_calls_against_header); // idempotent
void check_indirect_calls_against_header(const recipe_ordinal r) {
trace(9991, "transform") << "--- type-check 'call' instructions inside recipe " << get(Recipe, r).name << end();
const recipe& caller = get(Recipe, r);
for (int i = 0; i < SIZE(caller.steps); ++i) {
for (int i = 0; i < SIZE(caller.steps); ++i) {
const instruction& inst = caller.steps.at(i);
if (inst.operation != CALL) continue;
if (inst.ingredients.empty()) continue; // error raised above
@ -164,11 +164,11 @@ void check_indirect_calls_against_header(const recipe_ordinal r) {
if (!is_mu_recipe(callee)) continue; // error raised above
const recipe callee_header = is_literal(callee) ? get(Recipe, callee.value) : from_reagent(inst.ingredients.at(0));
if (!callee_header.has_header) continue;
for (long int i = /*skip callee*/1; i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1); ++i) {
for (long int i = /*skip callee*/1; i < min(SIZE(inst.ingredients), SIZE(callee_header.ingredients)+/*skip callee*/1); ++i) {
if (!types_coercible(callee_header.ingredients.at(i-/*skip callee*/1), inst.ingredients.at(i)))
raise << maybe(caller.name) << "ingredient " << i-/*skip callee*/1 << " has the wrong type at '" << inst.original_string << "'\n" << end();
}
for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee_header.products)); ++i) {
for (long int i = 0; i < min(SIZE(inst.products), SIZE(callee_header.products)); ++i) {
if (is_dummy(inst.products.at(i))) continue;
if (!types_coercible(callee_header.products.at(i), inst.products.at(i)))
raise << maybe(caller.name) << "product " << i << " has the wrong type at '" << inst.original_string << "'\n" << end();
@ -186,7 +186,7 @@ recipe from_reagent(const reagent& r) {
}
assert(root_type(r.type)->name == "recipe");
const type_tree* curr = r.type->right;
for (/*nada*/; curr && !curr->atom; curr = curr->right) {
for (/*nada*/; curr && !curr->atom; curr = curr->right) {
if (curr->left->atom && curr->left->name == "->") {
curr = curr->right; // skip delimiter
goto read_products;
@ -199,7 +199,7 @@ recipe from_reagent(const reagent& r) {
return result_header; // no products
}
read_products:
for (/*nada*/; curr && !curr->atom; curr = curr->right)
for (/*nada*/; curr && !curr->atom; curr = curr->right)
result_header.products.push_back(next_recipe_reagent(curr->left));
if (curr) {
assert(curr->atom);
@ -286,11 +286,11 @@ if (is_mu_recipe(to)) {
}
const recipe& rrhs = get(Recipe, from.value);
const recipe& rlhs = from_reagent(to);
for (long int i = 0; i < min(SIZE(rlhs.ingredients), SIZE(rrhs.ingredients)); ++i) {
for (long int i = 0; i < min(SIZE(rlhs.ingredients), SIZE(rrhs.ingredients)); ++i) {
if (!types_match(rlhs.ingredients.at(i), rrhs.ingredients.at(i)))
return false;
}
for (long int i = 0; i < min(SIZE(rlhs.products), SIZE(rrhs.products)); ++i) {
for (long int i = 0; i < min(SIZE(rlhs.products), SIZE(rrhs.products)); ++i) {
if (!types_match(rlhs.products.at(i), rrhs.products.at(i)))
return false;
}
@ -331,7 +331,7 @@ check_for_recipe_literals(inst, get(Recipe, r));
check_for_recipe_literals(inst, get(Recipe, r));
:(code)
void check_for_recipe_literals(const instruction& inst, const recipe& caller) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
for (int i = 0; i < SIZE(inst.ingredients); ++i) {
if (is_mu_recipe(inst.ingredients.at(i)))
raise << maybe(caller.name) << "missing type for " << inst.ingredients.at(i).original_string << " in '" << inst.original_string << "'\n" << end();
}

View File

@ -80,7 +80,7 @@ void run(routine* rr) {
}
bool all_routines_done() {
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state == RUNNING)
return false;
}
@ -107,7 +107,7 @@ string current_routine_label() {
string routine_label(routine* r) {
ostringstream result;
const call_stack& calls = r->calls;
for (call_stack::const_iterator p = calls.begin(); p != calls.end(); ++p) {
for (call_stack::const_iterator p = calls.begin(); p != calls.end(); ++p) {
if (p != calls.begin()) result << '/';
result << get(Recipe, p->running_recipe).name;
}
@ -115,7 +115,7 @@ string routine_label(routine* r) {
}
:(before "End Teardown")
for (int i = 0; i < SIZE(Routines); ++i)
for (int i = 0; i < SIZE(Routines); ++i)
delete Routines.at(i);
Routines.clear();
Current_routine = NULL;
@ -129,7 +129,7 @@ void run_main(int argc, char* argv[]) {
// pass in commandline args as ingredients to main
// todo: test this
Current_routine = main_routine;
for (int i = 1; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
vector<double> arg;
arg.push_back(new_mu_text(argv[i]));
current_call().ingredient_atoms.push_back(arg);
@ -179,7 +179,7 @@ case START_RUNNING: {
routine* new_routine = new routine(ingredients.at(0).at(0));
new_routine->parent_index = Current_routine_index;
// populate ingredients
for (int i = 1; i < SIZE(current_instruction().ingredients); ++i) {
for (int i = 1; i < SIZE(current_instruction().ingredients); ++i) {
new_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
reagent/*copy*/ ingredient = current_instruction().ingredients.at(i);
canonize_type(ingredient);
@ -382,7 +382,7 @@ def f1 [
-schedule: f1
:(before "End Scheduler Cleanup")
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state == COMPLETED) continue;
if (Routines.at(i)->parent_index < 0) continue; // root thread
// structured concurrency: http://250bpm.com/blog:71
@ -393,7 +393,7 @@ for (int i = 0; i < SIZE(Routines); ++i) {
:(code)
bool has_completed_parent(int routine_index) {
for (int j = routine_index; j >= 0; j = Routines.at(j)->parent_index) {
for (int j = routine_index; j >= 0; j = Routines.at(j)->parent_index) {
if (Routines.at(j)->state == COMPLETED)
return true;
}
@ -437,7 +437,7 @@ case ROUTINE_STATE: {
case ROUTINE_STATE: {
int id = ingredients.at(0).at(0);
int result = -1;
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->id == id) {
result = Routines.at(i)->state;
break;
@ -469,7 +469,7 @@ case STOP: {
:(before "End Primitive Recipe Implementations")
case STOP: {
int id = ingredients.at(0).at(0);
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->id == id) {
Routines.at(i)->state = COMPLETED;
break;
@ -488,7 +488,7 @@ case _DUMP_ROUTINES: {
}
:(before "End Primitive Recipe Implementations")
case _DUMP_ROUTINES: {
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
cerr << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << '\n';
}
break;
@ -540,7 +540,7 @@ if (Passed && any_routines_with_error()) {
:(code)
bool any_routines_with_error() {
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state == DISCONTINUED)
return true;
}
@ -575,7 +575,7 @@ case LIMIT_TIME: {
:(before "End Primitive Recipe Implementations")
case LIMIT_TIME: {
int id = ingredients.at(0).at(0);
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->id == id) {
Routines.at(i)->limit = ingredients.at(1).at(0);
break;
@ -610,7 +610,7 @@ case NUMBER_OF_INSTRUCTIONS: {
case NUMBER_OF_INSTRUCTIONS: {
int id = ingredients.at(0).at(0);
int result = -1;
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->id == id) {
result = Routines.at(i)->instructions_run;
break;

View File

@ -49,14 +49,14 @@ if (Passed && any_routines_with_error()) {
}
:(code)
bool any_routines_waiting() {
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state == WAITING)
return true;
}
return false;
}
void dump_waiting_routines() {
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state == WAITING)
cerr << i << ": " << routine_label(Routines.at(i)) << '\n';
}
@ -132,7 +132,7 @@ case RESET: {
//: scheduler tweak to get routines out of that state
:(before "End Scheduler State Transitions")
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state != WAITING) continue;
int loc = Routines.at(i)->waiting_on_location;
if (loc && get_or_insert(Memory, loc) == 0) {
@ -213,7 +213,7 @@ case GET_LOCATION: {
int offset = ingredients.at(1).at(0);
if (offset < 0 || offset >= SIZE(get(Type, base_root_type->value).elements)) break; // copied from Check above
int result = base_address;
for (int i = 0; i < offset; ++i)
for (int i = 0; i < offset; ++i)
result += size_of(element_type(base.type, i));
trace(9998, "run") << "address to copy is " << result << end();
products.resize(1);
@ -353,13 +353,13 @@ case WAIT_FOR_ROUTINE: {
// Wake up any routines waiting for other routines to complete.
// Important: this must come after the scheduler loop above giving routines
// waiting for locations to change a chance to wake up.
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state != WAITING) continue;
routine* waiter = Routines.at(i);
if (!waiter->waiting_on_routine) continue;
int id = waiter->waiting_on_routine;
assert(id != waiter->id); // routine can't wait on itself
for (int j = 0; j < SIZE(Routines); ++j) {
for (int j = 0; j < SIZE(Routines); ++j) {
const routine* waitee = Routines.at(j);
if (waitee->id == id && waitee->state != RUNNING && waitee->state != WAITING) {
// routine is COMPLETED or DISCONTINUED
@ -513,13 +513,13 @@ case WAIT_FOR_ROUTINE_TO_BLOCK: {
:(before "End Scheduler State Transitions")
// Wake up any routines waiting for other routines to stop running.
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->state != WAITING) continue;
routine* waiter = Routines.at(i);
if (!waiter->waiting_on_routine_to_block) continue;
int id = waiter->waiting_on_routine_to_block;
assert(id != waiter->id); // routine can't wait on itself
for (int j = 0; j < SIZE(Routines); ++j) {
for (int j = 0; j < SIZE(Routines); ++j) {
const routine* waitee = Routines.at(j);
if (waitee->id != id) continue;
if (waitee->state != RUNNING || waitee->blocked) {
@ -551,7 +551,7 @@ case RESTART: {
:(before "End Primitive Recipe Implementations")
case RESTART: {
int id = ingredients.at(0).at(0);
for (int i = 0; i < SIZE(Routines); ++i) {
for (int i = 0; i < SIZE(Routines); ++i) {
if (Routines.at(i)->id == id) {
if (Routines.at(i)->state == WAITING)
Routines.at(i)->state = RUNNING;

View File

@ -277,9 +277,9 @@ void deep_copy(const reagent& canonized_in, map<int, int>& addresses_copied, con
if (!contains_key(Container_metadata, canonized_in.type)) return;
trace(9991, "run") << "deep-copy: scanning for addresses in " << to_string(data) << end();
const container_metadata& metadata = get(Container_metadata, canonized_in.type);
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
for (map<set<tag_condition_info>, set<address_element_info> >::const_iterator p = metadata.address.begin(); p != metadata.address.end(); ++p) {
if (!all_match(data, p->first)) continue;
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info) {
for (set<address_element_info>::const_iterator info = p->second.begin(); info != p->second.end(); ++info) {
// construct a fake reagent that reads directly from the appropriate
// field of the container
reagent curr;

View File

@ -109,7 +109,7 @@ case CLEAR_LINE_ON_DISPLAY: {
case CLEAR_LINE_ON_DISPLAY: {
CHECK_SCREEN;
int width = tb_width();
for (int x = Display_column; x < width; ++x) {
for (int x = Display_column; x < width; ++x) {
tb_change_cell(x, Display_row, ' ', TB_WHITE, TB_BLACK);
}
tb_set_cursor(Display_column, Display_row);
@ -546,8 +546,8 @@ case CLEAR_DISPLAY_FROM: {
int left = ingredients.at(2).at(0);
int right = ingredients.at(3).at(0);
int height=tb_height();
for (; row < height; ++row, column=left) { // start column from left in every inner loop except first
for (; column <= right; ++column) {
for (/*nada*/; row < height; ++row, column=left) { // start column from left in every inner loop except first
for (/*nada*/; column <= right; ++column) {
tb_change_cell(column, row, ' ', TB_WHITE, TB_BLACK);
}
}

View File

@ -262,7 +262,7 @@ void check_screen(const string& expected_contents, const int color) {
raw_string_stream cursor(expected_contents);
// todo: too-long expected_contents should fail
int addr = screen_data_start+/*skip length*/1;
for (int row = 0; row < screen_height; ++row) {
for (int row = 0; row < screen_height; ++row) {
cursor.skip_whitespace_and_comments();
if (cursor.at_end()) break;
if (cursor.get() != '.') {
@ -401,9 +401,9 @@ void dump_screen() {
int screen_data_start = get_or_insert(Memory, screen_data_location) + /*skip refcount*/1; // type: array:character
assert(get_or_insert(Memory, screen_data_start) == screen_width*screen_height);
int curr = screen_data_start+1; // skip length
for (int row = 0; row < screen_height; ++row) {
for (int row = 0; row < screen_height; ++row) {
cerr << '.';
for (int col = 0; col < screen_width; ++col) {
for (int col = 0; col < screen_width; ++col) {
if (get_or_insert(Memory, curr))
cerr << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr)));
else

View File

@ -63,7 +63,7 @@ case ASSUME_CONSOLE: {
// store length
put(Memory, event_data_address+/*skip refcount*/1, num_events);
int curr_address = event_data_address + /*skip refcount and length*/2;
for (int i = 0; i < SIZE(r.steps); ++i) {
for (int i = 0; i < SIZE(r.steps); ++i) {
const instruction& inst = r.steps.at(i);
if (inst.name == "left-click") {
trace(9999, "mem") << "storing 'left-click' event starting at " << Current_routine->alloc << end();
@ -100,7 +100,7 @@ case ASSUME_CONSOLE: {
const char* raw_contents = contents.c_str();
int num_keyboard_events = unicode_length(contents);
int curr = 0;
for (int i = 0; i < num_keyboard_events; ++i) {
for (int i = 0; i < num_keyboard_events; ++i) {
trace(9999, "mem") << "storing 'text' tag at " << curr_address << end();
put(Memory, curr_address, /*tag for 'text' variant of 'event' exclusive-container*/0);
uint32_t curr_character;
@ -270,10 +270,10 @@ case REPLACE_IN_CONSOLE: {
int console_address = get_or_insert(Memory, CONSOLE);
int console_data = get_or_insert(Memory, console_address+1);
int length = get_or_insert(Memory, console_data); // array length
for (int i = 0, curr = console_data+1; i < length; ++i, curr+=size_of_event()) {
for (int i = 0, curr = console_data+1; i < length; ++i, curr+=size_of_event()) {
if (get_or_insert(Memory, curr) != /*text*/0) continue;
if (get_or_insert(Memory, curr+1) != ingredients.at(0).at(0)) continue;
for (int n = 0; n < size_of_event(); ++n)
for (int n = 0; n < size_of_event(); ++n)
put(Memory, curr+n, ingredients.at(1).at(n));
}
break;
@ -282,7 +282,7 @@ case REPLACE_IN_CONSOLE: {
:(code)
int count_events(const recipe& r) {
int result = 0;
for (int i = 0; i < SIZE(r.steps); ++i) {
for (int i = 0; i < SIZE(r.steps); ++i) {
const instruction& curr = r.steps.at(i);
if (curr.name == "type")
result += unicode_length(curr.ingredients.at(0).name);

View File

@ -170,7 +170,7 @@ string munge_resources_contents(const string& data, const string& filename, cons
in.get(); // skip leading '|'
string line;
getline(in, line);
for (int i = 0; i < SIZE(line); ++i) {
for (int i = 0; i < SIZE(line); ++i) {
if (line.at(i) == '|') break;
if (line.at(i) == '\\') {
++i; // skip
@ -190,7 +190,7 @@ string munge_resources_contents(const string& data, const string& filename, cons
void construct_resources_object(const map<string, string>& contents) {
int resources_data_address = allocate(SIZE(contents)*2 + /*array length*/1);
int curr = resources_data_address + /*skip refcount and length*/2;
for (map<string, string>::const_iterator p = contents.begin(); p != contents.end(); ++p) {
for (map<string, string>::const_iterator p = contents.begin(); p != contents.end(); ++p) {
put(Memory, curr, new_mu_text(p->first));
trace(9999, "mem") << "storing file name " << get(Memory, curr) << " in location " << curr << end();
put(Memory, get(Memory, curr), 1);

View File

@ -154,7 +154,7 @@ case _READ_FROM_SOCKET: {
:(before "End Primitive Recipe Implementations")
case _READ_FROM_SOCKET: {
long long int x = static_cast<long long int>(ingredients.at(0).at(0));
int bytes = static_cast<int>(ingredients.at(1).at(0)); //? Should this be something with more bytes?
int bytes = static_cast<int>(ingredients.at(1).at(0));
socket_t* socket = reinterpret_cast<socket_t*>(x);
int socket_fd = socket->fd;
char contents[bytes];