about summary refs log tree commit diff stats
path: root/033exclusive_container.cc
Commit message (Expand)AuthorAgeFilesLines
* 4266 - space for alloc-id in heap allocationsKartik Agaram2018-06-241-36/+0
* 4265Kartik Agaram2018-06-171-2/+2
* 4264Kartik Agaram2018-06-171-0/+495
* 4259Kartik Agaram2018-06-161-459/+0
* 4258 - undo 4257Kartik Agaram2018-06-151-5/+3
* 4257 - abortive attempt at safe fat pointersKartik Agaram2018-06-151-3/+5
* 4256 - get rid of container metadata entirelyKartik Agaram2018-06-091-24/+11
* 4104Kartik K. Agaram2017-11-031-5/+5
* 3887 - clean up early exits in interpreter loopKartik K. Agaram2017-05-281-1/+2
* 3877Kartik K. Agaram2017-05-261-6/+6
* 3841Kartik K. Agaram2017-04-271-1/+1
* 3643Kartik K. Agaram2016-11-071-4/+4
* 3637 - better 'missing type ingredient' errorsKartik K. Agaram2016-11-061-3/+3
* 3561Kartik K. Agaram2016-10-221-1/+1
* 3522Kartik K. Agaram2016-10-191-2/+2
* 3383Kartik K. Agaram2016-09-171-1/+1
* 3381Kartik K. Agaram2016-09-171-4/+4
* 3380Kartik K. Agaram2016-09-171-63/+63
* 3321Kartik K. Agaram2016-09-101-3/+4
* 3313Kartik K. Agaram2016-09-101-1/+1
* 3309Kartik K. Agaram2016-09-091-11/+24
* 3307Kartik K. Agaram2016-09-091-5/+5
* 3123Kartik K. Agaram2016-07-221-5/+16
* 3120Kartik K. Agaram2016-07-211-5/+5
* 3108Kartik K. Agaram2016-07-101-1/+0
* 3048 - bugfix: checking 'merge' instructionsKartik K. Agaram2016-06-111-1/+21
* 3046Kartik K. Agaram2016-06-111-3/+3
* 2990Kartik K. Agaram2016-05-201-9/+9
* 2965 - update refcounts when copying containersKartik K. Agaram2016-05-151-3/+7
* 2955 - back to more refcount housekeepingKartik K. Agaram2016-05-121-3/+3
* 2936Kartik K. Agaram2016-05-071-2/+2
* 2935Kartik K. Agaram2016-05-071-3/+3
* 2934 - all layers running againKartik K. Agaram2016-05-071-2/+0
* 2931 - be explicit about making copiesKartik K. Agaram2016-05-061-13/+13
* 2898 - start filling in missing refcountsKartik K. Agaram2016-05-031-6/+7
* 2893Kartik K. Agaram2016-05-031-0/+424
* 2863Kartik K. Agaram2016-04-241-414/+0
* 2861 - 'maybe-convert' no longer returns addressKartik K. Agaram2016-04-231-13/+51
* 2818Kartik K. Agaram2016-03-281-2/+2
* 2803Kartik K. Agaram2016-03-211-6/+6
* 2773 - switch to 'int'Kartik K. Agaram2016-03-131-8/+8
* 2769 - fix build_and_test_until 043space.ccKartik K. Agaram2016-03-131-3/+3
* 2735 - define recipes using 'def'Kartik K. Agaram2016-03-081-13/+13
* 2712Kartik K. Agaram2016-02-261-8/+8
* 2709Kartik K. Agaram2016-02-251-5/+0
* 2704 - eradicate all mention of warnings from coreKartik K. Agaram2016-02-251-1/+1
* 2681 - drop reagent types from reagent propertiesKartik K. Agaram2016-02-211-4/+3
* 2677Kartik K. Agaram2016-02-201-1/+1
* 2671 - never use debug_string() in tracesKartik K. Agaram2016-02-191-4/+4
* 2685Kartik K. Agaram2016-02-191-4/+4
tik.com> 2015-10-06 22:15:45 -0700 2258 - separate warnings from errors' href='/akkartik/mu/commit/021check_instruction.cc?h=main&id=5f98a10cc78829a03c9fa5a137392e7d5e9030ac'>5f98a10c ^
a0fc38c9 ^


5f98a10c ^
a0fc38c9 ^










c6034af3 ^







70f70118 ^
795f5244 ^

1fa53058 ^

c6034af3 ^

a0fc38c9 ^

1fa53058 ^


37b8273e ^
795f5244 ^

1fa53058 ^





a0fc38c9 ^
c3deac87 ^
a0fc38c9 ^


c6034af3 ^
a0fc38c9 ^
795f5244 ^
a0fc38c9 ^


c6034af3 ^
a0fc38c9 ^
795f5244 ^
a0fc38c9 ^
a0d7a155 ^

c6034af3 ^
a0d7a155 ^
ae256ea1 ^

795f5244 ^

4e49b29e ^


c6034af3 ^
4e49b29e ^
ae256ea1 ^
4e49b29e ^

a0d7a155 ^
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144


                                                                              





                                                                            
 
                                                             
                                       

       
                                                
                                                                                               
                                              

                                                                  
                                
                             
                                

                                                            
                                                                                                            



                                                                          
                                                                                                                                                                                                      




                                             
                                    
                

                                    






                                     
                     


                         
                                                                          

                                            
                     


                           
                                                                

                                              
                     


                                         
                                                                

                                              
                     


                             
                                                                  










                                                                                                       







                                                             
                                

                                                                 

                                        

                                                                                  

 


                                                                                       
                        

                                                                                                





                                                                                            
                               
                                


                             
                            
                                  
                                                     


                               
                            
                                  
                                                       
 

                              
                            
                    

                                                               

                                                                                                                


                              
                            
                    
                                                                                              

                                   
 
//: Introduce a new transform to perform various checks in instructions before
//: we start running them. It'll be extensible, so that we can add checks for
//: new recipes as we extend 'run' to support them.
//:
//: Doing checking in a separate part complicates things, because the values
//: of variables in memory and the processor (current_recipe_name,
//: current_instruction) aren't available at checking time. If I had a more
//: sophisticated layer system I'd introduce the simpler version first and
//: transform it in a separate layer or set of layers.

:(after "Transform.push_back(update_instruction_operations)")
Transform.push_back(check_instruction);

:(code)
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 (long long 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) {
      // Primitive Recipe Checks
      case COPY: {
        if (SIZE(inst.products) != SIZE(inst.ingredients)) {
          raise_error << "ingredients and products should match in '" << inst.to_string() << "'\n" << end();
          break;
        }
        for (long long int i = 0; i < SIZE(inst.ingredients); ++i) {
          if (!types_match(inst.products.at(i), inst.ingredients.at(i))) {
            raise_error << 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;
          }
        }
        break;
      }
      // End Primitive Recipe Checks
      default: {
        // Defined Recipe Checks
        // End Defined Recipe Checks
      }
    }
    finish_checking_instruction:;
  }
}

:(scenario copy_checks_reagent_count)
% Hide_errors = true;
recipe main [
  1:number <- copy 34, 35
]
+error: ingredients and products should match in '1:number <- copy 34, 35'

:(scenario write_scalar_to_array_disallowed)
% Hide_errors = true;
recipe main [
  1:array:number <- copy 34
]
+error: main: can't copy 34 to 1:array:number; types don't match

:(scenario write_scalar_to_array_disallowed_2)
% Hide_errors = true;
recipe main [
  1:number, 2:array:number <- copy 34, 35
]
+error: main: can't copy 35 to 2:array:number; types don't match

:(scenario write_scalar_to_address_disallowed)
% Hide_errors = true;
recipe main [
  1:address:number <- copy 34
]
+error: main: can't copy 34 to 1:address:number; types don't match

:(code)
bool types_match(reagent lhs, reagent rhs) {
  // '_' never raises type error
  if (is_dummy(lhs)) return true;
  // to sidestep type-checking, use /raw in the source.
  // this is unsafe, and will be highlighted in red inside vim. just for some tests.
  if (is_raw(rhs)) return true;
  // allow writing 0 to any address
  if (rhs.name == "0" && is_mu_address(lhs)) return true;
  if (is_literal(rhs)) return !is_mu_array(lhs) && !is_mu_address(lhs) && size_of(rhs) == size_of(lhs);
  if (!lhs.type) return !rhs.type;
  return types_match(lhs.type, rhs.type);
}

// two types match if the second begins like the first
// (trees perform the same check recursively on each subtree)
bool types_match(type_tree* lhs, type_tree* rhs) {
  if (!lhs) return true;
  if (!rhs || rhs->value == 0) {
    if (lhs->value == get(Type_ordinal, "array")) return false;
    if (lhs->value == get(Type_ordinal, "address")) return false;
    return size_of(rhs) == size_of(lhs);
  }
  if (lhs->value != rhs->value) return false;
  return types_match(lhs->left, rhs->left) && types_match(lhs->right, rhs->right);
}

// hacky version that allows 0 addresses
bool types_match(const reagent lhs, const type_tree* rhs, const vector<double>& data) {
  if (is_dummy(lhs)) return true;
  if (rhs->value == 0) {
    if (lhs.type->value == get(Type_ordinal, "array")) return false;
    if (lhs.type->value == get(Type_ordinal, "address")) return scalar(data) && data.at(0) == 0;
    return size_of(rhs) == size_of(lhs);
  }
  if (lhs.type->value != rhs->value) return false;
  return types_match(lhs.type->left, rhs->left) && types_match(lhs.type->right, rhs->right);
}

bool is_raw(const reagent& r) {
  return has_property(r, "raw");
}

bool is_mu_array(reagent r) {
  if (!r.type) return false;
  if (is_literal(r)) return false;
  return r.type->value == get(Type_ordinal, "array");
}

bool is_mu_address(reagent r) {
  if (!r.type) return false;
  if (is_literal(r)) return false;
  return r.type->value == get(Type_ordinal, "address");
}

bool is_mu_number(reagent r) {
  if (!r.type) return false;
  if (is_literal(r))
    return r.properties.at(0).second->value == "literal-number"
        || r.properties.at(0).second->value == "literal";
  if (r.type->value == get(Type_ordinal, "character")) return true;  // permit arithmetic on unicode code points
  return r.type->value == get(Type_ordinal, "number");
}

bool is_mu_scalar(reagent r) {
  if (!r.type) return false;
  if (is_literal(r))
    return !r.properties.at(0).second || r.properties.at(0).second->value != "literal-string";
  if (is_mu_array(r)) return false;
  return size_of(r) == 1;
}