summary refs log tree commit diff stats
path: root/compiler/cgendata.nim
Commit message (Expand)AuthorAgeFilesLines
* Dead code elimination for entire modules and their init procs if empty (#10032)cooldome2018-12-301-5/+5
* Simplify cgen forward proc (#9635)Jacek Sieka2018-11-071-6/+5
* Make the registered passes local to the ModuleGraph (#9259)LemonBoy2018-10-091-2/+2
* compiler refactoring; use typesafe path handing; docgen: render symbols betwe...Andreas Rumpf2018-09-071-3/+3
* Fixes 8535 (#8591)LemonBoy2018-08-171-1/+0
* fixex merge conflictsAraq2018-06-081-0/+2
|\
| * Fixes #7982Yuriy Glukhov2018-06-071-0/+2
* | remove the last global variables in the C code generatorAndreas Rumpf2018-05-281-1/+12
* | remove more global variables in the Nim compilerAndreas Rumpf2018-05-271-2/+1
|/
* options.nim: no global variables anymoreAndreas Rumpf2018-05-131-1/+1
* C code generator compiles againAndreas Rumpf2018-05-121-2/+5
* sem pass compiles againAndreas Rumpf2018-05-121-0/+3
* C codegen: preparations for different seq and string implementationsAndreas Rumpf2018-04-031-1/+2
* fixes #7414 (#7434)cooldome2018-03-291-5/+4
* minor code cleanup: remove redundant .final markersAraq2017-11-301-2/+2
* work in progress: new implementation for 'a[^1]'Andreas Rumpf2017-10-291-1/+1
* removed compiler internal list implementation (#5371)Arne Döring2017-02-221-3/+7
* name mangling bugfixes; ndi file generation for debugger supportAndreas Rumpf2017-02-031-1/+2
* new name mangling scheme implementedAndreas Rumpf2017-02-021-3/+5
* tiny progress on the name manglingAndreas Rumpf2017-02-011-1/+1
* refactoring: explict config state instead of globalsAndreas Rumpf2017-02-011-0/+1
* made more tests greenAraq2016-12-051-1/+3
* refactoring: C codegen with fewer global variablesAraq2016-12-051-15/+17
* more tests workAraq2016-12-021-0/+1
* Merge branch 'devel' into sighashesAraq2016-12-011-1/+1
|\
| * fixes #5055Araq2016-11-301-1/+1
* | Merge branch 'devel' into sighashesAraq2016-11-281-0/+1
|\|
| * first version of the new memory tracking featureAndreas Rumpf2016-11-211-0/+1
* | signature hashing: more progressAraq2016-11-111-5/+6
* | C codegen: first version of signature hashing for better incremental buildsAraq2016-11-081-0/+1
|/
* fixes #4505, fixes #4230Andreas Rumpf2016-08-041-5/+5
* C code generation now deterministic; fixes #4364Andreas Rumpf2016-06-221-2/+3
* refactoring: flags instead of boolsAndreas Rumpf2016-05-181-7/+10
* Get rid of deprecation warningsdef2015-04-071-13/+13
* codegen doesn't produce line tracing commands anymore; fixes #1344Araq2015-03-211-5/+8
* lots of C++ codegen improvementsAraq2015-02-071-0/+3
* updated the compiler to use the new symbol namesAraq2014-08-281-3/+3
* Nimrod renamed to NimAraq2014-08-281-2/+2
* optimized method dispatchersAraq2014-06-121-0/+1
* iterators now return tyIter(T);Zahary Karadjov2014-03-051-1/+1
* Fixed #688 : return in except statments. Also fixed return in finally stateme...Audun Wilhelmsen2014-02-231-2/+5
* Fixed issue 391 (nested break in except-stmts)Audun Wilhelmsen2014-02-161-0/+1
* fixes #914Araq2014-02-141-1/+2
* Introduce a PreMain proc in the C codegenZahary Karadjov2013-12-301-1/+2
* case consistency: cs:partial bootstraps on windowsAraq2013-12-291-4/+4
* case consistency part 4Araq2013-12-271-2/+2
* implemented 'injectStmt'; more debug supportAraq2013-12-161-0/+1
* fixes a regression where memset was used without including <string.h>Araq2013-12-031-0/+1
* work-in-progress for compiling generics in their owner moduleZahary Karadjov2013-08-191-3/+1
* documented object constrs; endb works againAraq2013-03-091-4/+3
naked literals everywhere' href='/akkartik/mu/commit/039wait.cc?h=main&id=bc6436927640603675e2e700007f53c5ab213869'>bc643692 ^
363685b8 ^
6e698858 ^




363685b8 ^




ac0e9db5 ^
363685b8 ^





795f5244 ^
166e3c0d ^
363685b8 ^
166e3c0d ^
795f5244 ^
e4630643 ^

5f98a10c ^
795f5244 ^
e4630643 ^

166e3c0d ^



e4630643 ^
5f98a10c ^
e4630643 ^

363685b8 ^
6e698858 ^
cdd6fd09 ^
363685b8 ^



9d670bb5 ^


ac0e9db5 ^
05d17773 ^

ac0e9db5 ^
e4630643 ^
ac0e9db5 ^
6e698858 ^
dd2e01e4 ^
05d17773 ^

363685b8 ^


134dad7c ^



795f5244 ^
166e3c0d ^



134dad7c ^

ac0e9db5 ^
134dad7c ^

134dad7c ^






ac0e9db5 ^

134dad7c ^







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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167




                                                                             
                             
           
                    
                         
                            
                                                                       
                           

           
                     









                                                                     
                                  
                                  
                                   
                                                        





                                                  
                                                            



                                       

                                                

                                                        

                                                   

                                                                                                                                               





                                                     
                                                    
                                                 
                                            
                                                                                                                    
                                                              
                                    
                                                                                            

   
 
                                                   


                            
                    

                                              
                                                                       
                           

           
                     
 




                              




                                                                     
                                 





                                             
                                                          
                                       
                        
                                    
                                                                                                                                                     

          
                                              
                                                                                                                                                                                                                   

          



                                                
                                                       
                                                                                                                                           

          
                                   
                                                                
                                                                                   



                                           


                                                                           
                                                    

                                                    
                                                        
                                                                    
                                                      
                                                                       
                                                                                     

                                             


     



                                             
                                      



                                       

                                                
                                                  

                                      






                                             

                                                      







                                                      
//: Routines can be put in a 'waiting' state, from which it will be ready to
//: run again when a specific memory location changes its value. This is mu's
//: basic technique for orchestrating the order in which different routines
//: operate.

:(scenario wait_for_location)
recipe f1 [
  1:number <- copy 0
  start-running f2:recipe
  wait-for-location 1:number
  # now wait for f2 to run and modify location 1 before using its value
  2:number <- copy 1:number
]
recipe f2 [
  1:number <- copy 34
]
# if we got the synchronization wrong we'd be storing 0 in location 2
+mem: storing 34 in location 2

//: define the new state that all routines can be in

:(before "End routine States")
WAITING,
:(before "End routine Fields")
// only if state == WAITING
long long int waiting_on_location;
int old_value_of_waiting_location;
:(before "End routine Constructor")
waiting_on_location = old_value_of_waiting_location = 0;

//: primitive recipe to put routines in that state

:(before "End Primitive Recipe Declarations")
WAIT_FOR_LOCATION,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "wait-for-location", WAIT_FOR_LOCATION);
:(before "End Primitive Recipe Checks")
case WAIT_FOR_LOCATION: {
  break;
}
:(before "End Primitive Recipe Implementations")
case WAIT_FOR_LOCATION: {
  reagent loc = current_instruction().ingredients.at(0);
  canonize(loc);
  Current_routine->state = WAITING;
  Current_routine->waiting_on_location = loc.value;
  Current_routine->old_value_of_waiting_location = get_or_insert(Memory, loc.value);
  trace(9998, "run") << "waiting for location " << loc.value << " to change from " << no_scientific(get_or_insert(Memory, loc.value)) << end();
  break;
}

//: scheduler tweak to get routines out of that state

:(before "End Scheduler State Transitions")
for (long long int i = 0; i < SIZE(Routines); ++i) {
  if (Routines.at(i)->state != WAITING) continue;
  if (Routines.at(i)->waiting_on_location &&
      get_or_insert(Memory, Routines.at(i)->waiting_on_location) != Routines.at(i)->old_value_of_waiting_location) {
    trace(9999, "schedule") << "waking up routine\n" << end();
    Routines.at(i)->state = RUNNING;
    Routines.at(i)->waiting_on_location = Routines.at(i)->old_value_of_waiting_location = 0;
  }
}

//: also allow waiting on a routine to stop running

:(scenario wait_for_routine)
recipe f1 [
  1:number <- copy 0
  12:number/routine <- start-running f2:recipe
  wait-for-routine 12:number/routine
  # now wait for f2 to run and modify location 1 before using its value
  3:number <- copy 1:number
]
recipe f2 [
  1:number <- copy 34
]
+schedule: f1
+run: waiting for routine 2
+schedule: f2
+schedule: waking up routine 1
+schedule: f1
# if we got the synchronization wrong we'd be storing 0 in location 3
+mem: storing 34 in location 3

:(before "End routine Fields")
// only if state == WAITING
long long int waiting_on_routine;
:(before "End routine Constructor")
waiting_on_routine = 0;

:(before "End Primitive Recipe Declarations")
WAIT_FOR_ROUTINE,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "wait-for-routine", WAIT_FOR_ROUTINE);
:(before "End Primitive Recipe Checks")
case WAIT_FOR_ROUTINE: {
  if (SIZE(inst.ingredients) != 1) {
    raise_error << maybe(get(Recipe, r).name) << "'wait-for-routine' requires exactly one ingredient, but got " << inst.to_string() << '\n' << end();
    break;
  }
  if (!is_mu_number(inst.ingredients.at(0))) {
    raise_error << maybe(get(Recipe, r).name) << "first ingredient of 'wait-for-routine' should be a routine id generated by 'start-running', but got " << inst.ingredients.at(0).original_string << '\n' << end();
    break;
  }
  break;
}
:(before "End Primitive Recipe Implementations")
case WAIT_FOR_ROUTINE: {
  if (ingredients.at(0).at(0) == Current_routine->id) {
    raise_error << maybe(current_recipe_name()) << "routine can't wait for itself! " << current_instruction().to_string() << '\n' << end();
    break;
  }
  Current_routine->state = WAITING;
  Current_routine->waiting_on_routine = ingredients.at(0).at(0);
  trace(9998, "run") << "waiting for routine " << ingredients.at(0).at(0) << end();
  break;
}

:(before "End Scheduler State Transitions")
// Wake up any routines waiting for other routines to go to sleep.
// Important: this must come after the scheduler loop above giving routines
// waiting for locations to change a chance to wake up.
for (long long int i = 0; i < SIZE(Routines); ++i) {
  if (Routines.at(i)->state != WAITING) continue;
  if (!Routines.at(i)->waiting_on_routine) continue;
  long long int id = Routines.at(i)->waiting_on_routine;
  assert(id != Routines.at(i)->id);  // routine can't wait on itself
  for (long long int j = 0; j < SIZE(Routines); ++j) {
    if (Routines.at(j)->id == id && Routines.at(j)->state != RUNNING) {
      trace(9999, "schedule") << "waking up routine " << Routines.at(i)->id << end();
      Routines.at(i)->state = RUNNING;
      Routines.at(i)->waiting_on_routine = 0;
    }
  }
}

:(before "End Primitive Recipe Declarations")
SWITCH,
:(before "End Primitive Recipe Numbers")
put(Recipe_ordinal, "switch", SWITCH);
:(before "End Primitive Recipe Checks")
case SWITCH: {
  break;
}
:(before "End Primitive Recipe Implementations")
case SWITCH: {
  long long int id = some_other_running_routine();
  if (id) {
    assert(id != Current_routine->id);
    Current_routine->state = WAITING;
    Current_routine->waiting_on_routine = id;
  }
  break;
}

:(code)
long long int some_other_running_routine() {
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    if (i == Current_routine_index) continue;
    assert(Routines.at(i) != Current_routine);
    assert(Routines.at(i)->id != Current_routine->id);
    if (Routines.at(i)->state == RUNNING)
      return Routines.at(i)->id;
  }
  return 0;
}