fixed: wrong struct cast

This commit is contained in:
Sven Vogel 2024-06-08 23:26:40 +02:00
parent 98ecd8a6ae
commit d5193f66be
3 changed files with 26 additions and 19 deletions

View File

@ -179,10 +179,7 @@ static void build_target(ModuleFileStack *unit, const TargetConfig *target) {
if (setup_target_environment(target) == 0) { if (setup_target_environment(target) == 0) {
print_ast_to_file(ast, target); print_ast_to_file(ast, target);
Module* test = create_set(ast); Module* module = create_set(ast);
// TODO: parse AST to semantic values
Module* module = NULL;
run_backend_codegen(module, target); run_backend_codegen(module, target);
} }

View File

@ -198,7 +198,7 @@ BackendError get_type_impl(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope,
break; break;
case TypeKindBox: case TypeKindBox:
err = err =
impl_box_type(unit, scope, &gemstone_type->impl.box, llvm_type); impl_box_type(unit, scope, gemstone_type->impl.box, llvm_type);
break; break;
default: default:
PANIC("invalid type kind: %ld", gemstone_type->kind); PANIC("invalid type kind: %ld", gemstone_type->kind);
@ -279,6 +279,16 @@ BackendError impl_type(LLVMBackendCompileUnit* unit, Type* gemstone_type,
return err; return err;
} }
BackendError impl_type_define(LLVMBackendCompileUnit* unit, Typedefine* gemstone_type,
const char* alias, LLVMGlobalScope* scope) {
BackendError err = SUCCESS;
DEBUG("implementing type of kind: %ld as %s", gemstone_type->type->kind, alias);
err = impl_type(unit, gemstone_type->type, alias, scope);
return err;
}
BackendError impl_types(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope, BackendError impl_types(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope,
GHashTable* types) { GHashTable* types) {
DEBUG("implementing given types of %p", types); DEBUG("implementing given types of %p", types);
@ -291,7 +301,7 @@ BackendError impl_types(LLVMBackendCompileUnit* unit, LLVMGlobalScope* scope,
BackendError err; BackendError err;
while (g_hash_table_iter_next(&iterator, &key, &val) != FALSE) { while (g_hash_table_iter_next(&iterator, &key, &val) != FALSE) {
err = impl_type(unit, (Type*)val, (const char*)key, scope); err = impl_type_define(unit, (Typedefine*) val, (const char*)key, scope);
if (err.kind != Success) { if (err.kind != Success) {
break; break;
@ -417,7 +427,7 @@ BackendError get_type_default_value(LLVMBackendCompileUnit* unit,
err = get_reference_default_value(llvm_type, llvm_value); err = get_reference_default_value(llvm_type, llvm_value);
break; break;
case TypeKindBox: case TypeKindBox:
err = get_box_default_value(unit, scope, &gemstone_type->impl.box, err = get_box_default_value(unit, scope, gemstone_type->impl.box,
llvm_type, llvm_value); llvm_type, llvm_value);
break; break;
default: default:

View File

@ -150,7 +150,7 @@ int get_type_decl(const char *name, Type **type) {
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }
int impl_composite_type(AST_NODE_PTR ast_type, CompositeType *composite) { int set_impl_composite_type(AST_NODE_PTR ast_type, CompositeType *composite) {
assert(ast_type != NULL); assert(ast_type != NULL);
assert(composite != NULL); assert(composite != NULL);
@ -229,7 +229,7 @@ int impl_composite_type(AST_NODE_PTR ast_type, CompositeType *composite) {
* @param type pointer output for the type * @param type pointer output for the type
* @return the gemstone type implementation * @return the gemstone type implementation
*/ */
int get_type_impl(AST_NODE_PTR currentNode, Type **type) { int set_get_type_impl(AST_NODE_PTR currentNode, Type **type) {
assert(currentNode != NULL); assert(currentNode != NULL);
assert(currentNode->kind == AST_Type); assert(currentNode->kind == AST_Type);
assert(currentNode->child_count > 0); assert(currentNode->child_count > 0);
@ -278,7 +278,7 @@ int get_type_impl(AST_NODE_PTR currentNode, Type **type) {
new_type->kind = TypeKindComposite; new_type->kind = TypeKindComposite;
new_type->impl.composite.nodePtr = currentNode; new_type->impl.composite.nodePtr = currentNode;
status = impl_composite_type(currentNode, &new_type->impl.composite); status = set_impl_composite_type(currentNode, &new_type->impl.composite);
*type = new_type; *type = new_type;
return status; return status;
@ -312,7 +312,7 @@ int createRef(AST_NODE_PTR currentNode, Type** reftype) {
referenceType->nodePtr = currentNode; referenceType->nodePtr = currentNode;
int signal = get_type_impl(currentNode->children[0],&type); int signal = set_get_type_impl(currentNode->children[0], &type);
if(signal) { if(signal) {
//TODO free type //TODO free type
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
@ -346,7 +346,7 @@ int createDecl(AST_NODE_PTR currentNode, GArray **variables) {
break; break;
case AST_Type: case AST_Type:
DEBUG("fill Type"); DEBUG("fill Type");
status = get_type_impl(AST_get_node(currentNode,i), &decl.type); status = set_get_type_impl(AST_get_node(currentNode, i), &decl.type);
break; break;
case AST_IdentList: case AST_IdentList:
break; break;
@ -409,7 +409,7 @@ int createDef(AST_NODE_PTR currentNode, GArray **variables) {
break; break;
case AST_Type: case AST_Type:
DEBUG("fill Type"); DEBUG("fill Type");
status = get_type_impl(declaration->children[i], &decl.type); status = set_get_type_impl(declaration->children[i], &decl.type);
break; break;
case AST_IdentList: case AST_IdentList:
break; break;
@ -1114,7 +1114,7 @@ int createTypeCast(Expression* ParentExpression, AST_NODE_PTR currentNode){
} }
Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type)); Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type));
int status = get_type_impl(currentNode->children[1], &target); int status = set_get_type_impl(currentNode->children[1], &target);
if (status) { if (status) {
print_diagnostic(current_file, &currentNode->children[1]->location, Error, "Unknown type"); print_diagnostic(current_file, &currentNode->children[1]->location, Error, "Unknown type");
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
@ -1133,7 +1133,7 @@ int createTransmute(Expression* ParentExpression, AST_NODE_PTR currentNode){
} }
Type* target = mem_alloc(MemoryNamespaceSet,sizeof(Type)); Type* target = mem_alloc(MemoryNamespaceSet,sizeof(Type));
int status = get_type_impl(currentNode->children[1], &target); int status = set_get_type_impl(currentNode->children[1], &target);
if (status){ if (status){
print_diagnostic(current_file, &currentNode->children[1]->location, Error, "Unknown type"); print_diagnostic(current_file, &currentNode->children[1]->location, Error, "Unknown type");
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
@ -1652,7 +1652,7 @@ int createParam(GArray * Paramlist ,AST_NODE_PTR currentNode){
PANIC("IO_Qualifier has not the right amount of children"); PANIC("IO_Qualifier has not the right amount of children");
} }
int signal = get_type_impl(paramdecl->children[0], &(decl.type)); int signal = set_get_type_impl(paramdecl->children[0], &(decl.type));
if(signal){ if(signal){
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }
@ -1803,7 +1803,7 @@ int createFunction(GHashTable* functions, AST_NODE_PTR currentNode){
int createDeclMember(BoxType * ParentBox, AST_NODE_PTR currentNode){ int createDeclMember(BoxType * ParentBox, AST_NODE_PTR currentNode){
Type * declType = mem_alloc(MemoryNamespaceSet,sizeof(Type)); Type * declType = mem_alloc(MemoryNamespaceSet,sizeof(Type));
int status = get_type_impl(currentNode->children[0],&declType); int status = set_get_type_impl(currentNode->children[0], &declType);
if(status){ if(status){
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }
@ -1830,7 +1830,7 @@ int createDefMember(BoxType *ParentBox, AST_NODE_PTR currentNode){
AST_NODE_PTR nameList = declNode->children[1]; AST_NODE_PTR nameList = declNode->children[1];
Type * declType = mem_alloc(MemoryNamespaceSet,sizeof(Type)); Type * declType = mem_alloc(MemoryNamespaceSet,sizeof(Type));
int status = get_type_impl(currentNode->children[0],&declType); int status = set_get_type_impl(currentNode->children[0], &declType);
if(status){ if(status){
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }
@ -1916,7 +1916,7 @@ int createTypeDef(GHashTable *types, AST_NODE_PTR currentNode){
Type * type = mem_alloc(MemoryNamespaceSet,sizeof(Type)); Type * type = mem_alloc(MemoryNamespaceSet,sizeof(Type));
int status = get_type_impl( typeNode, &type); int status = set_get_type_impl(typeNode, &type);
if(status){ if(status){
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }