Fix some more alignment issues and partial rename of Type_type
This commit is contained in:
parent
f05e3e2761
commit
9564118202
@ -39,11 +39,11 @@
|
||||
#define END_OF_CHAIN UINT32_MAX
|
||||
|
||||
#define GET_ENTRY(t, i) ((t)->entries.data + (t)->entries.stride*(i))
|
||||
#define ENTRIES_TYPE(type) (&(TypeInfo){.size=sizeof(array_t), .align=alignof(array_t), .tag=ArrayInfo, .ArrayInfo.item=(&(TypeInfo){.size=entry_size(type), .align=entry_align(type), .tag=OpaqueInfo})})
|
||||
#define ENTRIES_TYPE(type) (&(TypeInfo){.size=sizeof(array_t), .align=__alignof__(array_t), .tag=ArrayInfo, .ArrayInfo.item=(&(TypeInfo){.size=entry_size(type), .align=entry_align(type), .tag=OpaqueInfo})})
|
||||
|
||||
TypeInfo MemoryPointer_typeinfo = {
|
||||
.size=sizeof(void*),
|
||||
.align=alignof(void*),
|
||||
.align=__alignof__(void*),
|
||||
.tag=PointerInfo,
|
||||
.PointerInfo={
|
||||
.sigil="@",
|
||||
@ -53,7 +53,7 @@ TypeInfo MemoryPointer_typeinfo = {
|
||||
|
||||
TypeInfo StrToVoidStarTable_type = {
|
||||
.size=sizeof(table_t),
|
||||
.align=alignof(table_t),
|
||||
.align=__alignof__(table_t),
|
||||
.tag=TableInfo,
|
||||
.TableInfo={.key=&Str_type.type, .value=&MemoryPointer_typeinfo},
|
||||
};
|
||||
|
22
compile.c
22
compile.c
@ -441,8 +441,8 @@ CORD compile(env_t *env, ast_t *ast)
|
||||
|
||||
// Typeinfo:
|
||||
CORD_appendf(&env->code->typedefs, "typedef struct { TypeInfo type; } %s_namespace_t;\n", def->name);
|
||||
CORD_appendf(&env->code->typedefs, "extern %s_namespace_t %s_type;\n", def->name, def->name);
|
||||
CORD_appendf(&env->code->typeinfos, "public %s_namespace_t %s_type = {.type={.tag=CustomInfo, .CustomInfo={.as_str=(void*)%s__as_str}}};\n", def->name, def->name, def->name);
|
||||
CORD_appendf(&env->code->typedefs, "extern %s_namespace_t %s;\n", def->name, def->name);
|
||||
CORD_appendf(&env->code->typeinfos, "public %s_namespace_t %s = {.type={.tag=CustomInfo, .CustomInfo={.as_str=(void*)%s__as_str}}};\n", def->name, def->name, def->name);
|
||||
|
||||
CORD cord_func = CORD_asprintf("static CORD %s__as_str(%s_t *obj, bool use_color) {\n"
|
||||
"\tif (!obj) return \"%s\";\n", def->name, def->name, def->name);
|
||||
@ -576,16 +576,16 @@ CORD compile_type_info(env_t *env, type_t *t)
|
||||
{
|
||||
switch (t->tag) {
|
||||
case BoolType: return "&Bool_type.type";
|
||||
case IntType: return CORD_asprintf("&Int%ld_type.type", Match(t, IntType)->bits);
|
||||
case NumType: return CORD_asprintf("&Num%ld_type.type", Match(t, NumType)->bits);
|
||||
case StringType: return CORD_all("&", Match(t, StringType)->dsl ? Match(t, StringType)->dsl : "Str", "_type.type");
|
||||
case StructType: return CORD_all("&", Match(t, StructType)->name, "_type.type");
|
||||
case EnumType: return CORD_all("&", Match(t, EnumType)->name, "_type.type");
|
||||
case IntType: return CORD_asprintf("&Int%ld.type", Match(t, IntType)->bits);
|
||||
case NumType: return CORD_asprintf("&Num%ld.type", Match(t, NumType)->bits);
|
||||
case StringType: return CORD_all("&", Match(t, StringType)->dsl ? Match(t, StringType)->dsl : "Str", ".type");
|
||||
case StructType: return CORD_all("&", Match(t, StructType)->name, ".type");
|
||||
case EnumType: return CORD_all("&", Match(t, EnumType)->name, ".type");
|
||||
case ArrayType: {
|
||||
type_t *item_t = Match(t, ArrayType)->item_type;
|
||||
return CORD_asprintf(
|
||||
"&((TypeInfo){.size=%zu, .align=%zu, .tag=ArrayInfo, .ArrayInfo.item=%r})",
|
||||
sizeof(array_t), alignof(array_t),
|
||||
sizeof(array_t), __alignof__(array_t),
|
||||
compile_type_info(env, item_t));
|
||||
}
|
||||
case TableType: {
|
||||
@ -593,7 +593,7 @@ CORD compile_type_info(env_t *env, type_t *t)
|
||||
type_t *value_type = Match(t, TableType)->value_type;
|
||||
return CORD_asprintf(
|
||||
"&((TypeInfo){.size=%zu, .align=%zu, .tag=TableInfo, .TableInfo.key=%r, .TableInfo.value=%r})",
|
||||
sizeof(table_t), alignof(table_t),
|
||||
sizeof(table_t), __alignof__(table_t),
|
||||
compile_type_info(env, key_type),
|
||||
compile_type_info(env, value_type));
|
||||
}
|
||||
@ -603,12 +603,12 @@ CORD compile_type_info(env_t *env, type_t *t)
|
||||
if (ptr->is_readonly) sigil = CORD_cat(sigil, "(readonly)");
|
||||
return CORD_asprintf(
|
||||
"&((TypeInfo){.size=%zu, .align=%zu, .tag=PointerInfo, .PointerInfo.sigil=\"%r\", .PointerInfo.pointed=%r})",
|
||||
sizeof(void*), alignof(void*),
|
||||
sizeof(void*), __alignof__(void*),
|
||||
sigil, compile_type_info(env, ptr->pointed));
|
||||
}
|
||||
case FunctionType: {
|
||||
return CORD_asprintf("&((TypeInfo){.size=%zu, .align=%zu, .tag=FunctionInfo, .FunctionInfo.type_str=\"%r\"})",
|
||||
sizeof(void*), alignof(void*), type_to_cord(t));
|
||||
sizeof(void*), __alignof__(void*), type_to_cord(t));
|
||||
}
|
||||
case ClosureType: {
|
||||
errx(1, "No typeinfo for closures yet");
|
||||
|
16
types.c
16
types.c
@ -500,22 +500,22 @@ size_t type_align(type_t *t)
|
||||
switch (t->tag) {
|
||||
case UnknownType: case AbortType: case VoidType: return 0;
|
||||
case MemoryType: errx(1, "Memory has undefined type alignment");
|
||||
case BoolType: return alignof(bool);
|
||||
case BoolType: return __alignof__(bool);
|
||||
case IntType: return Match(t, IntType)->bits/8;
|
||||
case NumType: return Match(t, NumType)->bits/8;
|
||||
case StringType: return alignof(CORD);
|
||||
case ArrayType: return alignof(array_t);
|
||||
case TableType: return alignof(table_t);
|
||||
case FunctionType: return alignof(void*);
|
||||
case ClosureType: return alignof(void*);
|
||||
case PointerType: return alignof(void*);
|
||||
case StringType: return __alignof__(CORD);
|
||||
case ArrayType: return __alignof__(array_t);
|
||||
case TableType: return __alignof__(table_t);
|
||||
case FunctionType: return __alignof__(void*);
|
||||
case ClosureType: return __alignof__(void*);
|
||||
case PointerType: return __alignof__(void*);
|
||||
case StructType: {
|
||||
errx(1, "Not implemented");
|
||||
}
|
||||
case EnumType: {
|
||||
errx(1, "Not implemented");
|
||||
}
|
||||
case TypeInfoType: return alignof(TypeInfo);
|
||||
case TypeInfoType: return __alignof__(TypeInfo);
|
||||
case PlaceholderType: errx(1, "This should not be reachable");
|
||||
}
|
||||
errx(1, "This should not be reachable");
|
||||
|
Loading…
Reference in New Issue
Block a user