summary refs log tree commit diff stats
path: root/compiler/platform.nim
Commit message (Collapse)AuthorAgeFilesLines
* let's assume littleEndian in JS backend (#16886)flywind2021-02-011-1/+1
| | | | | * let's assume littleEndian in JS and VM backend * Update compiler/platform.nim
* some comments for amd64 and nimvm CPU (#16756)Timothee Cour2021-01-201-1/+2
|
* Add 32-bit RISC-V support (#16231)Alf-André Walla2020-12-031-1/+2
|
* Fixing issue #15302 -- lwip doesn't support signals (#15303)Jaremy Creechley2020-09-141-1/+1
| | | | | | | | * Fixing issue #15302 -- lwip doesn't support signals * Adding test to catch issue #15302 -- lwip/freertos net library don't try to build / run on windows, it'll compile only but not run Fixing issue #15302 -- reworking test to compile on other platforms
* Changes for FreeRTOS/LwIP Port for the ESP32 (ESP-IDF) (#15250)Jaremy Creechley2020-08-311-2/+7
| | | | | | | | | | | | | | | | | | | * Changes for FreeRTOS/LwIP Port for the ESP32 (ESP-IDF) Adding FreeRTOS/LwIP to compiler: * adding freertos option * dyncalls for freertos * add freertos to posix os list * adding lwip option Setting up networking FreeRTOS/LwIP Port: * setting up lwip network for freertos * fixing posix / networking for freertos * disable setInheritable for freerots * using lwip for net control items * Fix builds by ignoring lib/posix/posix_freertos_consts.nim similar to lib/posix/posix_other_consts.nim
* Added 'ansic' os support for minimal (embedded) targets (#13088)Ico Doornekamp2020-01-151-1/+5
| | | | | | | | * os:any implementation * os:asny: omit flock/funlock calls in echoBinSafe * Disabled default "unhandled expection" reporting for `--os:any` to reduce code size. Added unhandledExceptionHook instead which can be used to get a notification from Nim and handle it from the application.
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-4/+4
| | | | | | | | | | | | | | | | | | * Cleanup compiler code base * Unify add calls * Unify len invocations * Unify range operators * Fix oversight * Remove {.procvar.} pragma * initCandidate -> newCandidate where reasonable * Unify safeLen calls
* Add build support for Linux/hppa (#12271)John Paul Adrian Glaubitz2019-09-261-3/+4
| | | | | | * build.sh: Enable CPU detection for hppa * compiler: Add hppa as target architecture on Linux * lib/system: Add platform support for hppa
* Add --os:ios switch and docs. (#12204)treeform2019-09-181-1/+5
|
* styleCheck: make the compiler and large parts of the stdlib compatible with ↵Araq2019-07-101-1/+1
| | | | --styleCheck:error
* list available options for --cpu, --os and --cc if the passed option is not ↵Ico Doornekamp2019-05-251-0/+8
| | | | found (#11328)
* Replace countup(x, y) with x .. yClyybber2019-05-071-2/+2
|
* add wasm32 platformJacek Sieka2019-03-031-2/+3
|
* fixes #8081Araq2018-09-221-4/+3
|
* Nintendo switch support (#8069)Joey2018-06-271-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | * Add config section for Nintendo Switch * Add compiler configuration for Nintendo Switch and it's CPU * Add specific lib code for Nintendo Switch * Add GC support for Nintendo Switch * Update changelog for Nintendo Switch * Update changelog with more info about fixed paths * Cleaned up GC memory management a bit * Relocate docs for Switch * Rename aarch64NoneElfGcc to nintendoSwitchGCC * Remove armv8a57 * Fix installer.ini * Reuse code in linux and amd64 * Add posix defs for nintendo switch * Add more defined sections for nintendo switch * Remove old comment * Add what's not supported for Nintendo Switch docs * Make nintendoswitch == posix * Remove DEVKITPRO references from nim.cfg * Make PR extccomp changes * Remove Result type alias * Add separate switch consts file * Update docs for nintendo switch * Fix travis errors with undefined consts and add correct wait.h procs
* rename 'nimrodVM' to 'nimVM'Andreas Rumpf2018-05-281-4/+4
|
* platform.nim doesn't use globals anymore; prepare msgs.nim for not using globalsAndreas Rumpf2018-05-181-28/+24
|
* Add RISC-V (riscv64) support (#7417)Federico Ceratto2018-04-071-2/+3
|
* Introduce first class support for Android (#5772)Fredrik Høisæther Rasch2017-08-061-2/+6
|
* Add mips64 and mips64el CPU platforms (#5866)James Cowgill2017-08-031-2/+5
|
* support for the Genode OS framework (#5560)Emery Hemingway2017-03-311-1/+6
|
* Make DragonFlyBSD a first class BSD-like OS (#5548)Eugene Kabanov2017-03-161-2/+9
|
* define sparc64 platformSergey Avseyev2016-07-211-2/+3
|
* nimrod -> nimErik Johansson Andersson2016-02-051-1/+1
|
* add msp430 cpu supportKeerthan Jaic2015-08-261-2/+3
|
* Add arm64 support (untested)def2015-07-311-1/+2
|
* Add powerpc64el support (untested)def2015-07-311-2/+3
|
* Add Mipsel CPU support (untested)def2015-07-311-1/+2
|
* codegen doesn't produce line tracing commands anymore; fixes #1344Araq2015-03-211-142/+142
|
* merged #2083 manuallyAraq2015-02-081-1/+1
|
* the compiler knows vxWorks is an OSAraq2015-01-281-3/+7
|
* minor improvement to the barrier implementationAraq2014-12-091-1/+1
|
* case consistency part 4Araq2013-12-271-4/+4
|
* case consistency part 1Araq2013-12-271-6/+6
|
* --os:standalone works againAraq2013-06-301-1/+1
|
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
|
* EcmaScript => JS. Fixes #330Simon Hafner2013-02-151-4/+4
| | | | No one calls it EcmaScript anymore.
* added some support for HaikuAraq2012-07-291-1/+5
|
* implemented support for the AVR CPU and standalone OSAraq2012-03-311-4/+10
|
* year 2012 for most copyright headersAraq2012-01-021-1/+1
|
* new compiler option tlsEmulationAraq2011-10-271-5/+5
|
* first steps to thread local heapsAraq2011-06-021-2/+3
|
* big repo cleanupAraq2011-04-121-0/+213
id=2187d42ab79a087af1ea4227b90e4600a291b341'>^
5497090a ^
6d17ef49 ^
ac0e9db5 ^
6d17ef49 ^
ac0e9db5 ^
6d17ef49 ^





45ca3bb7 ^






6ca059ef ^
5eddbc16 ^
6ca059ef ^
363be37f ^
6ca059ef ^
5eddbc16 ^
7f73795c ^
45ca3bb7 ^
5e14ce10 ^
ac0e9db5 ^
31401373 ^
6d17ef49 ^
0487a30e ^
827898fc ^
6ca059ef ^

afbe301d ^
d9a7e6ab ^


bc643692 ^

d9a7e6ab ^

bc643692 ^
d9a7e6ab ^
bc643692 ^
d9a7e6ab ^
afbe301d ^


5eddbc16 ^
bc643692 ^

afbe301d ^

bc643692 ^

afbe301d ^

d7494165 ^
afbe301d ^
bc643692 ^
afbe301d ^
bc643692 ^
afbe301d ^
bc643692 ^
afbe301d ^
bc643692 ^
d9a7e6ab ^
5e14ce10 ^

bc643692 ^
00b808d9 ^

bc643692 ^
00b808d9 ^
5e14ce10 ^

5497090a ^
bc643692 ^
5e14ce10 ^


6d17ef49 ^
6d17ef49 ^
5497090a ^
6d17ef49 ^

bc643692 ^
6d17ef49 ^


1326a4ec ^

d9a7e6ab ^
bc643692 ^

d9a7e6ab ^





bc643692 ^
d9a7e6ab ^












bc643692 ^

d9a7e6ab ^


82ceda30 ^
45ca3bb7 ^
00b808d9 ^






bc643692 ^
00b808d9 ^


45ca3bb7 ^
ac0e9db5 ^
45ca3bb7 ^

00b808d9 ^
00b808d9 ^

45ca3bb7 ^


ac0e9db5 ^
00b808d9 ^
45ca3bb7 ^





82ceda30 ^




5497090a ^
bc643692 ^
82ceda30 ^
5497090a ^
82ceda30 ^

bc643692 ^
82ceda30 ^







363be37f ^
82ceda30 ^

e4630643 ^







ac0e9db5 ^
0487a30e ^
ac0e9db5 ^
05d17773 ^

82ceda30 ^


cfb142b9 ^
827898fc ^
82ceda30 ^

9d670bb5 ^
45ca3bb7 ^

9d670bb5 ^


363be37f ^
9d670bb5 ^

e4630643 ^







ac0e9db5 ^

9d670bb5 ^






a6cdf15c ^

134dad7c ^

363be37f ^
134dad7c ^

e4630643 ^







ac0e9db5 ^

134dad7c ^








a6cdf15c ^

363be37f ^
a6cdf15c ^

ac0e9db5 ^
00b808d9 ^
a6cdf15c ^


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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

                                                                             
 
                     
           
                         

                      
                            
   

           
                    


             
 

                                                                                               
                                       


                                                                                                                 
                                                                 

                                  

                                          




                          
                       





                                   
                       
                          

                                        

                          
                 

                                         
                                     
                                                              
                                
                           

                                              
                                                          
                                             
                                  
                                     

                                         


                            




                          
                                                      
                                           








                                                       

                                                                                                                            
                                           
                                
                                       

             


   









                                                                       
                        
                                                  
                        
                 
 
                                                           
 
                                                                             
                                                             
                              
                 
                       
                                  





                                   






                                                                   
                                             
              
                                        
                                                
                                                
                     
                                                              
                                                    
                         
                                                                             
                                                                             
                                  
                     
                                            

        
 


                                         

                    

             
                        
             
                        
 


                                          
                         

                    

           

                    

             
                             
             
                        
             
                        
             
                        
             
                        
 

                                    
                            

                      
                            
   

           
                             
                             


                             
                                            
           
                                     

           
                      


                             

                                                                
                                              

                                                                         





                                                             
                    












                                                                                  

                    


             
 
                                                               






                                                                              
                    


             
                                 
                                                    

                                                                 
                                

                                      


       
                                                        
                                                                                   





                                           




                                                              
                                              
                                                                             
                                                                                          
                                                   

           
                     







                                                                 
                                                

                                                







                                                                                                                                                                                                                        
                                             
                            
                                                      

                                     


            
                     
                                   

        
 

                          


                                             
                                    

                                                







                                                                                                                                                                                                                  

                                                      






                                      

                                             

                                        
                              

                                                







                                                                                                                                                                                                               

                                                      








                                             

                                        
                                                  

                                                
                                                      
                                                                                                                           


        
//: Run a second routine concurrently using 'start-running', without any
//: guarantees on how the operations in each are interleaved with each other.

:(scenario scheduler)
recipe f1 [
  start-running f2:recipe
  # wait for f2 to run
  {
    jump-unless 1:number, -1
  }
]
recipe f2 [
  1:number <- copy 1
]
+schedule: f1
+schedule: f2

//: first, add a deadline to run(routine)
//: these changes are ugly and brittle; just close your nose and get through the next few lines
:(replace "void run_current_routine()")
void run_current_routine(long long int time_slice)
:(replace "while (!Current_routine->completed())" following "void run_current_routine(long long int time_slice)")
long long int ninstrs = 0;
while (Current_routine->state == RUNNING && ninstrs < time_slice)
:(after "Running One Instruction")
ninstrs++;

//: now the rest of the scheduler is clean

:(before "struct routine")
enum routine_state {
  RUNNING,
  COMPLETED,
  // End routine States
};
:(before "End routine Fields")
enum routine_state state;
:(before "End routine Constructor")
state = RUNNING;

:(before "End Globals")
vector<routine*> Routines;
long long int Current_routine_index = 0;
long long int Scheduling_interval = 500;
:(before "End Setup")
Scheduling_interval = 500;
Routines.clear();
:(replace{} "void run(recipe_ordinal r)")
void run(recipe_ordinal r) {
  Routines.push_back(new routine(r));
  Current_routine_index = 0, Current_routine = Routines.at(0);
  while (!all_routines_done()) {
    skip_to_next_routine();
    assert(Current_routine);
    assert(Current_routine->state == RUNNING);
    trace("schedule") << current_routine_label() << end();
    run_current_routine(Scheduling_interval);
    // Scheduler State Transitions
    if (Current_routine->completed())
      Current_routine->state = COMPLETED;
    // End Scheduler State Transitions

    // Scheduler Cleanup
    // End Scheduler Cleanup
  }
}

:(code)
bool all_routines_done() {
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    if (Routines.at(i)->state == RUNNING) {
      return false;
    }
  }
  return true;
}

// skip Current_routine_index past non-RUNNING routines
void skip_to_next_routine() {
  assert(!Routines.empty());
  assert(Current_routine_index < SIZE(Routines));
  for (long long int i = (Current_routine_index+1)%SIZE(Routines);  i != Current_routine_index;  i = (i+1)%SIZE(Routines)) {
    if (Routines.at(i)->state == RUNNING) {
      Current_routine_index = i;
      Current_routine = Routines.at(i);
      return;
    }
  }
}

string current_routine_label() {
  ostringstream result;
  call_stack calls = Current_routine->calls;
  for (call_stack::iterator p = calls.begin(); p != calls.end(); ++p) {
    if (p != calls.begin()) result << '/';
    result << Recipe[p->running_recipe].name;
  }
  return result.str();
}

:(before "End Teardown")
for (long long int i = 0; i < SIZE(Routines); ++i)
  delete Routines.at(i);
Routines.clear();

//:: To schedule new routines to run, call 'start-running'.

//: 'start-running' will return a unique id for the routine that was created.
//: routine id is a number, but don't do any arithmetic on it
:(before "End routine Fields")
long long int id;
:(before "End Globals")
long long int Next_routine_id = 1;
:(before "End Setup")
Next_routine_id = 1;
:(before "End routine Constructor")
id = Next_routine_id;
Next_routine_id++;

//: routines save the routine that spawned them
:(before "End routine Fields")
// todo: really should be routine_id, but that's less efficient.
long long int parent_index;  // only < 0 if there's no parent_index
:(before "End routine Constructor")
parent_index = -1;

:(before "End Primitive Recipe Declarations")
START_RUNNING,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["start-running"] = START_RUNNING;
:(before "End Primitive Recipe Implementations")
case START_RUNNING: {
  routine* new_routine = new routine(ingredients.at(0).at(0));
  new_routine->parent_index = Current_routine_index;
  // populate ingredients
  for (long long int i = 1; i < SIZE(current_instruction().ingredients); ++i)
    new_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
  Routines.push_back(new_routine);
  products.resize(1);
  products.at(0).push_back(new_routine->id);
  break;
}

:(scenario scheduler_runs_single_routine)
% Scheduling_interval = 1;
recipe f1 [
  1:number <- copy 0
  2:number <- copy 0
]
+schedule: f1
+run: 1:number <- copy 0
+schedule: f1
+run: 2:number <- copy 0

:(scenario scheduler_interleaves_routines)
% Scheduling_interval = 1;
recipe f1 [
  start-running f2:recipe
  1:number <- copy 0
  2:number <- copy 0
]
recipe f2 [
  3:number <- copy 0
  4:number <- copy 0
]
+schedule: f1
+run: start-running f2:recipe
+schedule: f2
+run: 3:number <- copy 0
+schedule: f1
+run: 1:number <- copy 0
+schedule: f2
+run: 4:number <- copy 0
+schedule: f1
+run: 2:number <- copy 0

:(scenario start_running_takes_args)
recipe f1 [
  start-running f2:recipe, 3
  # wait for f2 to run
  {
    jump-unless 1:number, -1
  }
]
recipe f2 [
  1:number <- next-ingredient
  2:number <- add 1:number, 1
]
+mem: storing 4 in location 2

:(scenario start_running_returns_routine_id)
recipe f1 [
  1:number <- start-running f2:recipe
]
recipe f2 [
  12:number <- copy 44
]
+mem: storing 2 in location 1

//: this scenario will require some careful setup in escaped C++
//: (straining our tangle capabilities to near-breaking point)
:(scenario scheduler_skips_completed_routines)
% recipe_ordinal f1 = load("recipe f1 [\n1:number <- copy 0\n]").front();
% recipe_ordinal f2 = load("recipe f2 [\n2:number <- copy 0\n]").front();
% Routines.push_back(new routine(f1));  // f1 meant to run
% Routines.push_back(new routine(f2));
% Routines.back()->state = COMPLETED;  // f2 not meant to run
#? % Trace_stream->dump_layer = "all";
# must have at least one routine without escaping
recipe f3 [
  3:number <- copy 0
]
# by interleaving '+' lines with '-' lines, we allow f1 and f3 to run in any order
+schedule: f1
+mem: storing 0 in location 1
-schedule: f2
-mem: storing 0 in location 2
+schedule: f3
+mem: storing 0 in location 3

:(scenario scheduler_starts_at_middle_of_routines)
% Routines.push_back(new routine(COPY));
% Routines.back()->state = COMPLETED;
recipe f1 [
  1:number <- copy 0
  2:number <- copy 0
]
+schedule: f1
-run: idle

//:: Routines are marked completed when their parent completes.

:(scenario scheduler_kills_orphans)
recipe main [
  start-running f1:recipe
  # f1 never actually runs because its parent completes without waiting for it
]
recipe f1 [
  1:number <- copy 0
]
-schedule: f1

:(before "End Scheduler Cleanup")
for (long long int i = 0; i < SIZE(Routines); ++i) {
  if (Routines.at(i)->state == COMPLETED) continue;
  if (Routines.at(i)->parent_index < 0) continue;  // root thread
  if (has_completed_parent(i)) {
    Routines.at(i)->state = COMPLETED;
  }
}

:(code)
bool has_completed_parent(long long int routine_index) {
  for (long long int j = routine_index; j >= 0; j = Routines.at(j)->parent_index) {
    if (Routines.at(j)->state == COMPLETED)
      return true;
  }
  return false;
}

//:: 'routine-state' can tell if a given routine id is running

:(scenario routine_state_test)
% Scheduling_interval = 2;
recipe f1 [
  1:number/child-id <- start-running f2:recipe
  12:number <- copy 0  # race condition since we don't care about location 12
  # thanks to Scheduling_interval, f2's one instruction runs in between here and completes
  2:number/state <- routine-state 1:number/child-id
]
recipe f2 [
  12:number <- copy 0
  # trying to run a second instruction marks routine as completed
]
# recipe f2 should be in state COMPLETED
+mem: storing 1 in location 2

:(before "End Primitive Recipe Declarations")
ROUTINE_STATE,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["routine-state"] = ROUTINE_STATE;
:(before "End Primitive Recipe Implementations")
case ROUTINE_STATE: {
  if (SIZE(ingredients) != 1) {
    raise << current_recipe_name() << ": 'routine-state' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
    break;
  }
  if (!scalar(ingredients.at(0))) {
    raise << current_recipe_name() << ": first ingredient of 'routine-state' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
    break;
  }
  long long int id = ingredients.at(0).at(0);
  long long int result = -1;
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    if (Routines.at(i)->id == id) {
      result = Routines.at(i)->state;
      break;
    }
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

//:: miscellaneous helpers

:(before "End Primitive Recipe Declarations")
RESTART,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["restart"] = RESTART;
:(before "End Primitive Recipe Implementations")
case RESTART: {
  if (SIZE(ingredients) != 1) {
    raise << current_recipe_name() << ": 'restart' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
    break;
  }
  if (!scalar(ingredients.at(0))) {
    raise << current_recipe_name() << ": first ingredient of 'restart' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
    break;
  }
  long long int id = ingredients.at(0).at(0);
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    if (Routines.at(i)->id == id) {
      Routines.at(i)->state = RUNNING;
      break;
    }
  }
  break;
}

:(before "End Primitive Recipe Declarations")
STOP,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["stop"] = STOP;
:(before "End Primitive Recipe Implementations")
case STOP: {
  if (SIZE(ingredients) != 1) {
    raise << current_recipe_name() << ": 'stop' requires exactly one ingredient, but got " << current_instruction().to_string() << '\n' << end();
    break;
  }
  if (!scalar(ingredients.at(0))) {
    raise << current_recipe_name() << ": first ingredient of 'stop' should be a routine id generated by 'start-running', but got " << current_instruction().ingredients.at(0).original_string << '\n' << end();
    break;
  }
  long long int id = ingredients.at(0).at(0);
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    if (Routines.at(i)->id == id) {
      Routines.at(i)->state = COMPLETED;
      break;
    }
  }
  break;
}

:(before "End Primitive Recipe Declarations")
_DUMP_ROUTINES,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["$dump-routines"] = _DUMP_ROUTINES;
:(before "End Primitive Recipe Implementations")
case _DUMP_ROUTINES: {
  for (long long int i = 0; i < SIZE(Routines); ++i) {
    cerr << i << ": " << Routines.at(i)->id << ' ' << Routines.at(i)->state << ' ' << Routines.at(i)->parent_index << '\n';
  }
  break;
}