summary refs log tree commit diff stats
path: root/compiler/rodwrite.nim
Commit message (Expand)AuthorAgeFilesLines
* CaaS in-memory cachingZahary Karadjov2012-11-281-6/+7
* caas is now drivable through stdinZahary Karadjov2012-11-281-7/+1
* term rewriting macros fully implemented; still buggyAraq2012-09-031-0/+3
* first steps towards term rewriting macrosAraq2012-08-301-2/+2
* year 2012 for most copyright headersAraq2012-01-021-1/+1
* path canonicalization for imported modules, relative paths written in rod filesZahary Karadjov2011-12-111-8/+9
* bugfixes for .rod files and visual C++Araq2011-12-031-0/+1
* cleaned up configuration file handling and documented the new behaviourAraq2011-11-301-1/+1
* implemented 'let' statementAraq2011-11-291-9/+2
* compilation cache: fixed recently introduced bug (lazy loading of bodies)Araq2011-11-061-5/+5
* lazy loading of body ast implementedAraq2011-10-301-1/+3
* compilation cache: slurped files are a dependency tooAraq2011-10-301-1/+1
* compilation cache: various bugfixes; works for the compiler itselfAraq2011-10-271-32/+46
* compilation cache: mostly working; generics not yetAraq2011-10-251-9/+16
* compilation cache: multi methods now workAraq2011-10-241-3/+2
* compilation cache: better dependency checkingAraq2011-10-231-0/+10
* compilation cache: small fixes; methods still not workingAraq2011-10-231-2/+3
* compilation cache: methods have a chance to workAraq2011-10-231-4/+12
* rod files: next trivial examples workingAraq2011-10-221-1/+1
* preparations for proper memmap'ed filesAraq2011-10-221-8/+16
* bugfix: nil -> emptyNodeAraq2011-10-221-1/+1
* bugfixes for ROD file generation; nimcache dir is now flatAraq2011-10-201-5/+5
* much more efficient rod file generationAraq2011-10-181-0/+1
* much more efficient rod file generationAraq2011-10-181-212/+307
* support for C++ code generation; importcpp and importobjc pragmasAraq2011-08-071-2/+2
* doc improvements; added lazarus exampleAraq2011-07-241-5/+5
* intsets are now a proper module and part of the stdlibAraq2011-06-141-3/+3
* big repo cleanupAraq2011-04-121-0/+449
tik.com> 2015-07-28 15:48:49 -0700 1874 - rudimentary type inference' href='/akkartik/mu/commit/048typecheck.cc?h=main&id=112613fe90b36b4678c7b09e379ef3f76f012c08'>112613fe ^
efb7c8d6 ^
112613fe ^




efb7c8d6 ^
112613fe ^




c91caafd ^






4814bf94 ^
d082b176 ^







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

                                                                              




                                                                           
 
                                                               




                       
                                       

                   
                                           

       
                                                  



                                                                   
                                                             


                                                                   
                                                           













                                                                                                             
                                                                                       
 
 
                                            










                                                                                             

                                                                                       

 
                                                       




                    
                                                                      




                             






                                                             
                                                







                                          
//: Some simple sanity checks for types, and also attempts to guess them where
//: they aren't provided.
//:
//: You still have to provide the full type the first time you mention a
//: variable in a recipe. You have to explicitly name :offset and :variant
//: every single time. You can't use the same name with multiple types in a
//: single recipe.

:(scenario transform_warns_on_reusing_name_with_different_type)
% Hide_warnings = true;
recipe main [
  x:number <- copy 1
  x:boolean <- copy 1
]
+warn: main: x used with multiple types

:(after "int main")
  Transform.push_back(check_types_by_name);

:(code)
void check_types_by_name(const recipe_ordinal r) {
  map<string, vector<type_ordinal> > metadata;
  for (long long int i = 0; i < SIZE(Recipe[r].steps); ++i) {
    instruction& inst = Recipe[r].steps.at(i);
    for (long long int in = 0; in < SIZE(inst.ingredients); ++in) {
      deduce_missing_type(metadata, inst.ingredients.at(in));
      check_metadata(metadata, inst.ingredients.at(in), r);
    }
    for (long long int out = 0; out < SIZE(inst.products); ++out) {
      deduce_missing_type(metadata, inst.products.at(out));
      check_metadata(metadata, inst.products.at(out), r);
    }
  }
}

void check_metadata(map<string, vector<type_ordinal> >& metadata, const reagent& x, const recipe_ordinal r) {
  if (is_literal(x)) return;
  if (is_raw(x)) return;
  // if you use raw locations you're probably doing something unsafe
  if (is_integer(x.name)) return;
  if (x.types.empty()) return;  // will throw a more precise warning elsewhere
  if (metadata.find(x.name) == metadata.end())
    metadata[x.name] = x.types;
  if (metadata[x.name] != x.types)
    raise << maybe(Recipe[r].name) << x.name << " used with multiple types\n" << end();
}

:(scenario transform_fills_in_missing_types)
recipe main [
  x:number <- copy 1
  y:number <- add x, 1
]

:(code)
void deduce_missing_type(map<string, vector<type_ordinal> >& metadata, reagent& x) {
  if (!x.types.empty()) return;
  if (metadata.find(x.name) == metadata.end()) return;
  copy(metadata[x.name].begin(), metadata[x.name].end(), inserter(x.types, x.types.begin()));
  assert(x.properties.at(0).second.empty());
  x.properties.at(0).second.resize(metadata[x.name].size());
  x.properties.push_back(pair<string, vector<string> >("as-before", vector<string>()));
}

:(scenario transform_fills_in_missing_types_in_product)
recipe main [
  x:number <- copy 1
  x <- copy 2
]

:(scenario transform_fills_in_missing_types_in_product_and_ingredient)
recipe main [
  x:number <- copy 1
  x <- add x, 1
]
+mem: storing 2 in location 1

:(scenario transform_warns_on_missing_types_in_first_mention)
% Hide_warnings = true;
recipe main [
  x <- copy 1
  x:number <- copy 2
]
+warn: main: missing type for x in 'x <- copy 1'

:(scenario typo_in_address_type_warns)
% Hide_warnings = true;
recipe main [
  y:address:charcter <- new character:type
  *y <- copy 67
]
+warn: unknown type: charcter