about summary refs log tree commit diff stats
path: root/arc/.traces/fork-copies-args
blob: be4ed6d36ac7391d2d3059b5b14824b3a8599962 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
c{0: 0 (((2 integer)) <- ((next-input))) -- nil
c{1: 0 ✓ (((2 integer)) <- ((next-input)))
c{0: 0 (((default-space space-address)) <- ((new)) ((space literal)) ((5 literal))) -- nil
c{0: 1 (((x integer)) <- ((copy)) ((4 literal))) -- nil
c{0: 2 (((fork)) ((f1 fn)) ((nil literal) (globals)) ((nil literal) (limit)) ((x integer))) -- nil
c{0: 3 (((x integer)) <- ((copy)) ((0 literal))) -- nil
c{1: 0 ✓ (((default-space space-address)) <- ((new)) ((space literal)) ((5 literal)))
c{1: 1 ✓ (((x integer)) <- ((copy)) ((4 literal)))
c{1: 2 ✓ (((fork)) ((f1 fn)) ((nil literal) (globals)) ((nil literal) (limit)) ((x integer)))
c{1: 3 ✓ (((x integer)) <- ((copy)) ((0 literal)))
cn0: convert-names in f1
cn0: (((2 integer)) <- ((next-input))) nil nil
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn0: convert-names in main
cn0: (((default-space space-address)) <- ((new)) ((space literal)) ((5 literal))) nil nil
cn0: checking arg ((space literal))
cn0: checking arg ((5 literal))
cn0: checking oarg ((default-space space-address))
maybe-add: ((default-space space-address))
cn0: (((x integer)) <- ((copy)) ((4 literal))) nil nil
cn0: checking arg ((4 literal))
cn0: checking oarg ((x integer))
maybe-add: ((x integer))
cn0: location for oarg ((x integer)): 1
cn0: (((fork)) ((f1 fn)) ((nil literal) (globals)) ((nil literal) (limit)) ((x integer))) ((x 1)) nil
cn0: checking arg ((f1 fn))
cn0: checking arg ((nil literal) (globals))
cn0: checking arg ((nil literal) (limit))
cn0: checking arg ((x integer))
maybe-add: ((x integer))
cn0: (((x integer)) <- ((copy)) ((0 literal))) ((x 1)) nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((x integer))
maybe-add: ((x integer))
cn1: (((2 integer)) <- ((next-input)))
cn1: (((default-space space-address)) <- ((new)) ((space literal)) ((5 literal)))
cn1: (((1 integer)) <- ((copy)) ((4 literal)))
cn1: (((fork)) ((f1 fn)) ((nil literal) (globals)) ((nil literal) (limit)) ((1 integer)))
cn1: (((1 integer)) <- ((copy)) ((0 literal)))
schedule: main
run: main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((5 literal)))
run: main 0: 1000 => ((default-space space-address))
run: main 1: (((1 integer)) <- ((copy)) ((4 literal)))
run: main 1: 4 => ((1 integer))
mem: ((1 integer)): 1002 <= 4
run: main 2: (((fork)) ((f1 fn)) ((nil literal) (globals)) ((nil literal) (limit)) ((1 integer)))
mem: ((1 integer)) => 4
run: main 3: (((1 integer)) <- ((copy)) ((0 literal)))
run: main 3: 0 => ((1 integer))
mem: ((1 integer)): 1002 <= 0
schedule: done with routine nil
schedule: f1
run: f1 0: (((2 integer)) <- ((next-input)))
arg: nil 0 (4)
run: f1 0: 4 => ((2 integer))
mem: ((2 integer)): 2 <= 4
schedule: done with routine nil
ss */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
//: Calls can take ingredients just like primitives. To access a recipe's
//: ingredients, use 'next-ingredient'.

:(scenario next_ingredient)
recipe main [
  f 2
]
recipe f [
  12:number <- next-ingredient
  13:number <- add 1, 12:number
]
+mem: storing 3 in location 13

:(scenario next_ingredient_missing)
recipe main [
  f
]
recipe f [
  _, 12:number <- next-ingredient
]
+mem: storing 0 in location 12

:(before "End call Fields")
vector<vector<double> > ingredient_atoms;
vector<type_tree*> ingredient_types;
long long int next_ingredient_to_process;
:(before "End call Constructor")
next_ingredient_to_process = 0;

:(before "End Call Housekeeping")
for (long long int i = 0; i < SIZE(ingredients); ++i) {
  current_call().ingredient_atoms.push_back(ingredients.at(i));
  reagent ingredient = call_instruction.ingredients.at(i);
  canonize_type(ingredient);
  current_call().ingredient_types.push_back(ingredient.type);
  ingredient.type = NULL;  // release long-lived pointer
}
:(before "End call Destructor")
for (long long int i = 0; i < SIZE(ingredient_types); ++i) {
  delete ingredient_types.at(i);
}

:(before "End Primitive Recipe Declarations")
NEXT_INGREDIENT,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "next-ingredient", NEXT_INGREDIENT);
:(before "End Primitive Recipe Checks")
case NEXT_INGREDIENT: {
  if (!inst.ingredients.empty()) {
    raise_error << maybe(get(Recipe, r).name) << "'next-ingredient' didn't expect any ingredients in '" << inst.to_string() << "'\n" << end();
    break;
  }
  break;
}
:(before "End Primitive Recipe Implementations")
case NEXT_INGREDIENT: {
  assert(!Current_routine->calls.empty());
  if (current_call().next_ingredient_to_process < SIZE(current_call().ingredient_atoms)) {
    reagent product = current_instruction().products.at(0);
    canonize_type(product);
    if (!types_match(product,
                     current_call().ingredient_types.at(current_call().next_ingredient_to_process),
                     current_call().ingredient_atoms.at(current_call().next_ingredient_to_process)
                     )) {
      raise_error << maybe(current_recipe_name()) << "wrong type for ingredient " << current_instruction().products.at(0).original_string << '\n' << end();
    }
    products.push_back(
        current_call().ingredient_atoms.at(current_call().next_ingredient_to_process));
    assert(SIZE(products) == 1);  products.resize(2);  // push a new vector
    products.at(1).push_back(1);
    ++current_call().next_ingredient_to_process;
  }
  else {
    if (SIZE(current_instruction().products) < 2)
      raise_error << maybe(current_recipe_name()) << "no ingredient to save in " << current_instruction().products.at(0).original_string << '\n' << end();
    if (current_instruction().products.empty()) break;
    products.resize(2);
    // pad the first product with sufficient zeros to match its type
    long long int size = size_of(current_instruction().products.at(0));
    for (long long int i = 0; i < size; ++i) {
      products.at(0).push_back(0);
    }
    products.at(1).push_back(0);
  }
  break;
}

:(scenario next_ingredient_fail_on_missing)
% Hide_errors = true;
recipe main [
  f
]
recipe f [
  11:number <- next-ingredient
]
+error: f: no ingredient to save in 11:number

:(scenario rewind_ingredients)
recipe main [
  f 2
]
recipe f [
  12:number <- next-ingredient  # consume ingredient
  _, 1:boolean <- next-ingredient  # will not find any ingredients
  rewind-ingredients
  13:number, 2:boolean <- next-ingredient  # will find ingredient again
]
+mem: storing 2 in location 12
+mem: storing 0 in location 1
+mem: storing 2 in location 13
+mem: storing 1 in location 2

:(before "End Primitive Recipe Declarations")
REWIND_INGREDIENTS,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "rewind-ingredients", REWIND_INGREDIENTS);
:(before "End Primitive Recipe Checks")
case REWIND_INGREDIENTS: {
  break;
}
:(before "End Primitive Recipe Implementations")
case REWIND_INGREDIENTS: {
  current_call().next_ingredient_to_process = 0;
  break;
}

:(scenario ingredient)
recipe main [
  f 1, 2
]
recipe f [
  12:number <- ingredient 1  # consume second ingredient first
  13:number, 1:boolean <- next-ingredient  # next-ingredient tries to scan past that
]
+mem: storing 2 in location 12
+mem: storing 0 in location 1

:(before "End Primitive Recipe Declarations")
INGREDIENT,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "ingredient", INGREDIENT);
:(before "End Primitive Recipe Checks")
case INGREDIENT: {
  if (SIZE(inst.ingredients) != 1) {
    raise_error << maybe(get(Recipe, r).name) << "'ingredient' expects exactly one ingredient, but got '" << inst.to_string() << "'\n" << end();
    break;
  }
  if (!is_literal(inst.ingredients.at(0)) && !is_mu_number(inst.ingredients.at(0))) {
    raise_error << maybe(get(Recipe, r).name) << "'ingredient' expects a literal ingredient, but got " << inst.ingredients.at(0).original_string << '\n' << end();
    break;
  }
  break;
}
:(before "End Primitive Recipe Implementations")
case INGREDIENT: {
  if (static_cast<long long int>(ingredients.at(0).at(0)) < SIZE(current_call().ingredient_atoms)) {
    current_call().next_ingredient_to_process = ingredients.at(0).at(0);
    products.push_back(
        current_call().ingredient_atoms.at(current_call().next_ingredient_to_process));
    assert(SIZE(products) == 1);  products.resize(2);  // push a new vector
    products.at(1).push_back(1);
    ++current_call().next_ingredient_to_process;
  }
  else {
    if (SIZE(current_instruction().products) > 1) {
      products.resize(2);
      products.at(0).push_back(0);  // todo: will fail noisily if we try to read a compound value
      products.at(1).push_back(0);
    }
  }
  break;
}