Uri Guttman <[EMAIL PROTECTED]> wrote: > printf( "%d event.type\n", (char *)&kbevent.type ) - (char *)&kbevent ;
offsetof(struct, item) is used inside parrot/jit/* > want me to hack up this little script and c generation stuff? the hard > part is parsing the struct so i would have to assume some simple format > and not full c for the moment. the only thing needed by the parser is > all the member names. Very much appreciated. I thought of that too. A Perl script that takes a C struct and emits an *ManagedStruct initializer. WRT align: as such struct initializers are in library code and used by different machines, I'd rather have the alignment calculation inside the unmanagedstruct.pmc. But as a last resort this script could regenerate the offsets for a particular machine. ## &gen_struct() # struct event_t { # char x; /* optional comment */ # char y; # int flags; # }; ## &end_gen ## autogenerated from above template ## don't modifiy - rerun gen_struct $file .local pmc event_t_struct_init .include "datatypes.pasm" event_t_struct_init = new .OrderedHash event_t_struct_init["x"] = .DATATYPE_CHAR # optional comment event_t_struct_init[1] = 0 # no array of items event_t_struct_init[2] = 0 # automatic offset event_t_struct_init["y"] = .DATATYPE_CHAR event_t_struct_init[4] = 0 # no array of items event_t_struct_init[5] = 0 # automatic offset event_t_struct_init["flags"] = .DATATYPE_INT event_t_struct_init[7] = 0 # no array of items event_t_struct_init[8] = 0 # automatic offset _or_ 4/8 ## end autogen gen_struct --force-align file.imc could fill in the correct offset in the last line. Running gen_struct the first time should produce the autogenerated part. For PASM only, it could look like: ## &gen_struct(P23) ... new P23, .OrderedHash set P23["x"], ... You might have a look at F<runtime/parrot/include/datatypes.pasm> which is autogenerated too. *Struct.pmc doesn't yet handle all types, but this will be fixed. > uri leo