Changes between Version 106 and Version 107 of IR2
- Timestamp:
- 05/20/21 09:10:48 (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
IR2
v106 v107 312 312 <T1,T2> struct $pair { T1 left; T2 right; }; 313 313 <T1,T2> typedef struct $pair<T1,T2> $pair; 314 <T> $system alloc($heap * h, $int n); // heap allocation of n elements of type T315 $system $free($void * p); // frees something that was $alloc-ed314 <T> $system T * $alloc($heap * h, T obj); // add an object to a heap 315 $system $free($void * p); // remove an object from the heap 316 316 $system void $exit(); // terminate process immediately 317 317 $system $bool $terminated($proc p); // has the process terminated? … … 319 319 320 320 }}} 321 322 Notes 323 324 A heap is an abstraction for a set of objects of possibly different types which can be referenced by pointers. A C statement that mallocs 10 ints, e.g., 325 {{{ 326 int * p = malloc(10*sizeof(int)); 327 }}} 328 could be modeled as 329 {{{ 330 $int * p = $undef; 331 $int (*p1)[] = $undef; // pointer to array of $int 332 p1 = $alloc(&heap, $new_array(10, $int)); 333 p = ($int*)p1; // equivalently, p = &(*p1)[0]; 334 }}} 335 336 More generally, if the type of objects being malloced is not known, or changes dynamically, one could define a general "object" type... 321 337 322 338 === bundle.cvh ===
