Changes between Version 106 and Version 107 of IR2


Ignore:
Timestamp:
05/20/21 09:10:48 (5 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IR2

    v106 v107  
    312312<T1,T2> struct $pair { T1 left; T2 right; };
    313313<T1,T2> typedef struct $pair<T1,T2> $pair;
    314 <T> $system alloc($heap * h, $int n);  // heap allocation of n elements of type T
    315 $system $free($void * p);  // frees something that was $alloc-ed
     314<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
    316316$system void $exit();  // terminate process immediately
    317317$system $bool $terminated($proc p);  // has the process terminated?
     
    319319
    320320}}}
     321
     322Notes
     323
     324A 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{{{
     326int * p = malloc(10*sizeof(int));
     327}}}
     328could be modeled as
     329{{{
     330$int * p = $undef;
     331$int (*p1)[] = $undef; // pointer to array of $int
     332p1 = $alloc(&heap, $new_array(10, $int));
     333p = ($int*)p1; // equivalently, p = &(*p1)[0];
     334}}}
     335
     336More generally, if the type of objects being malloced is not known, or changes dynamically, one could define a general "object" type...
    321337
    322338=== bundle.cvh ===