Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Examples of use of d2c's two word "General Representation".
- Int32, character, and float (single) values are stored in the "dataword" field, with the heapptr field containing a pointer to a single global proxy object for the appropriate class.
- Objects of all other classes (including #T and #F) are stored simply as a pointer to the heap allocated object placed in the heapptr field. The dataword field is unused (the assignment to 0 is redundant).
- There is no possible race condition in assigning a heap allocated object to a two-word descriptor. Storing the pointer into .heapptr sets both the type and the value.
- There is a possible race condition in assigning an integer, character, or float to a two-word descriptor. One thread might assign the new type and then before it writes the new value another thread could read the new type and the old value.
- Thus it is possible for the bits of a float to be interpreted as an int or char. Or for an int or char to be interpreted as a float.
- While this can cause incorrect results, it can never cause an out of language exception. (sole possible exception: signalling NANs. However I believe very few programs enable this IEEE feature.)
- There is *zero* possibility of an int or float being interpreted as a pointer to a heap allocated object, which is I think the danger that people imagine exists.
- --------------- Dylan code ---------------
- define function foo(i :: <integer>) => res;
- i;
- end;
- define function bar(s :: <byte-string>) => res;
- s;
- end;
- define function baz(c :: <character>) => res;
- c;
- end;
- --------------- generated C (slightly cleaned up) ---------------
- extern descriptor_t genrepZliteral; /* proxy for <integer> */
- extern descriptor_t genrepZliteral_2; /* proxy for <character> */
- descriptor_t genrepZgenrepZfoo_FUN(descriptor_t *orig_sp, long A_i /* i */)
- {
- descriptor_t L_temp;
- L_temp.heapptr = genrepZliteral.heapptr;
- L_temp.dataword.l = A_i;
- return L_temp;
- }
- descriptor_t genrepZgenrepZbar_FUN(descriptor_t *orig_sp, heapptr_t A_s /* s */)
- {
- descriptor_t L_temp;
- L_temp.heapptr = A_s;
- L_temp.dataword.l = 0;
- return L_temp;
- }
- descriptor_t genrepZgenrepZbaz_FUN(descriptor_t *orig_sp, long A_c /* c */)
- {
- descriptor_t L_temp;
- L_temp.heapptr = genrepZliteral_2.heapptr;
- L_temp.dataword.l = A_c;
- return L_temp;
- }
- ---------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement