Skip to content

Commit

Permalink
add alignment field to data type description
Browse files Browse the repository at this point in the history
  • Loading branch information
plobsing committed Feb 18, 2011
1 parent 5aeabf5 commit dd8f285
Showing 1 changed file with 69 additions and 44 deletions.
113 changes: 69 additions & 44 deletions include/parrot/datatypes.h
Expand Up @@ -13,6 +13,10 @@
#ifndef PARROT_DATATYPES_H_GUARD
#define PARROT_DATATYPES_H_GUARD

/* TODO: detect these with configure */
#define HAS_LONGLONG 0
#define HAS_LONGDOUBLE 0

/* &gen_from_enum(datatypes.pasm) subst(s/enum_type_(\w+)/uc("DATATYPE_$1")/e) */
typedef enum {
enum_type_undef, /* illegal */
Expand Down Expand Up @@ -67,55 +71,76 @@ typedef enum {
/* &end_gen */
struct _data_types {
PARROT_OBSERVER const char *name;
int size;
size_t size;
size_t align;
};

#define ALIGNOF(x) offsetof(struct { char c; x d; }, d)

extern const struct _data_types data_types[];
#if defined(INSIDE_GLOBAL_SETUP)
const struct _data_types data_types[] = {
{ "INTVAL", INTVAL_SIZE }, /* parrot types */
{ "FLOATVAL", NUMVAL_SIZE },
{ "STRING", sizeof (void *) },
{ "PMC", sizeof (void *) }, /* actual PMCs have positive class numbers */

{ "char", sizeof (char) }, /* native integer types */
{ "short", sizeof (short) },
{ "int", sizeof (int) },
{ "long", sizeof (long) },
{ "longlong", 0 }, /* TODO */

{ "uchar", sizeof (char) }, /* native unsigned types */
{ "ushort", sizeof (short)},
{ "uint", sizeof (int) },
{ "ulong", sizeof (long) },
{ "ulonglong", 0 }, /* TODO */

{ "float", sizeof (float) }, /* native float types */
{ "double", sizeof (double) },
{ "longdouble", 0 }, /* TODO */

{ "int8", 1 },
{ "int16", 2 },
{ "int32", 4 },
{ "int64", 8 },

{ "uint1", 0 }, /* = bit */
{ "uint4", 0 },
{ "uint8", 1 }, /* unsigned variants */
{ "uint16", 2 },
{ "uint32", 4 },
{ "uint64", 8 },

{ "ptr", sizeof (void*) },
{ "cstr", sizeof (char *) },
{ "struct_ptr", sizeof (void*) },
{ "struct", 0 },
{ "union", 0 },
{ "func_ptr", sizeof (void (*)(void)) },

{ "sized", 0 },

{ "illegal", 0 }
/* parrot types */
{ "INTVAL", sizeof (INTVAL), ALIGNOF(INTVAL) },
{ "FLOATVAL", sizeof (FLOATVAL), ALIGNOF(FLOATVAL) },
{ "STRING", sizeof (STRING *), ALIGNOF(STRING *) },
{ "PMC", sizeof (PMC *), ALIGNOF(PMC *) },

/* native integer types */
{ "char", sizeof (char), ALIGNOF(char) },
{ "short", sizeof (short), ALIGNOF(short) },
{ "int", sizeof (int), ALIGNOF(int) },
{ "long", sizeof (long), ALIGNOF(long) },
#if HAS_LONGLONG
{ "longlong", sizeof (long long), ALIGNOF(long long) },
#else
{ "longlong", 0, 0 },
#endif

/* native unsigned types */
{ "uchar", sizeof (unsigned char), ALIGNOF(unsigned char) },
{ "ushort", sizeof (unsigned short), ALIGNOF(unsigned short) },
{ "uint", sizeof (unsigned int), ALIGNOF(unsigned int) },
{ "ulong", sizeof (unsigned long), ALIGNOF(unsigned long) },
#if HAS_LONGLONG
{ "ulonglong", sizeof (unsigned long long), ALIGNOF(unsigned long long) },
#else
{ "ulonglong", 0, 0 },
#endif

/* native float types */
{ "float", sizeof (float), ALIGNOF(float) },
{ "double", sizeof (double), ALIGNOF(double) },
#if HAS_LONGDOUBLE
{ "longdouble", sizeof (long double), ALIGNOF(long double)},
#else
{ "longdouble", 0, 0 },
#endif

/* explicitly sized integer types */
{ "int8", 1, ALIGNOF(int /* TODO */) },
{ "int16", 2, ALIGNOF(int /* TODO */) },
{ "int32", 4, ALIGNOF(int /* TODO */) },
{ "int64", 8, ALIGNOF(int /* TODO */) },

/* unsigned variants */
{ "uint1", 0, 0 }, /* = bit */
{ "uint4", 0, 0 },
{ "uint8", 1, ALIGNOF(int /* TODO */) },
{ "uint16", 2, ALIGNOF(int /* TODO */) },
{ "uint32", 4, ALIGNOF(int /* TODO */) },
{ "uint64", 8, ALIGNOF(int /* TODO */) },

{ "ptr", sizeof (void *), ALIGNOF(void *) },
{ "cstr", sizeof (char *), ALIGNOF(char *) },
{ "struct_ptr", sizeof (void *), ALIGNOF(void *) },
{ "struct", 0, 0 },
{ "union", 0, 0 },
{ "func_ptr", sizeof (funcptr_t), ALIGNOF(funcptr_t) },

{ "sized", 0, 0 },

{ "illegal", 0, 0 }
};
#endif /* INSIDE_GLOBAL_SETUP */

Expand Down

0 comments on commit dd8f285

Please sign in to comment.