[M3devel] reference to globals in globals?
    Jay K 
    jay.krell at cornell.edu
       
    Wed Aug 15 05:04:50 CEST 2012
    
    
  
Isn't it safe to take the address of a global?
I have something like this:
CONST UID_INTEGER = 1234;
CONST UID_FLOAT = 4567;
  ... several more ...
TYPE CType = OBJECT .. END;
VAR t_int: CType := ...;
VAR t_float: CType := ...;
  ... several more ...
MapTypeIdToType(UID_INTEGER, t_int);
MapTypeIdToType(UID_FLOAT, FLOAT);
  ... several more ...
but what I really want is more like:
TYPE RECORD = BuiltinUid_t = 
  typeid: INTEGER;
  ctype: REF CType;
END;
CONST BuiltinUids = ARRAY OF BuiltinUids {
  BuiltinUids{UID_INTEGER, &t_int},
  BuiltinUids{UID_FLOAT, &t_float},
  ... several more ...
};
FOR i := FIRST(BuiltinUids) TO LAST(BuiltinUids) DO
  MapTypeIdToType(BuiltinUids[i].typeid, BuiltinUids[i].ctype);
END;
Heck, even if these weren't global, is it that unreasonble,
from the programmer's point of view, for the language/compiler
to do some pointer escape analysis and let me take the address
of a local, as long as I don't store it somewhere that outlives
the local?
You can see this particular pattern currently in
m3-sys/m3cc/gcc/gcc/m3cg/parse.c
and I'm pretty busy now working on m3-sys/m3back/src/M3C.m3
where I encounter this.
Working in safe languages can be frustrating...
Thank you,
 - Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20120815/e6a4be2b/attachment-0001.html>
    
    
More information about the M3devel
mailing list