@@ -88,28 +88,28 @@ LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node) {
8888 case LITERAL_INT :
8989 return LLVMConstInt (LLVMInt64TypeInContext (ctx -> context ),
9090 node -> expr .literal .value .int_val , false);
91-
91+
9292 case LITERAL_FLOAT :
9393 return LLVMConstReal (LLVMDoubleTypeInContext (ctx -> context ),
9494 node -> expr .literal .value .float_val );
9595
9696 case LITERAL_BOOL :
9797 return LLVMConstInt (LLVMInt1TypeInContext (ctx -> context ),
9898 node -> expr .literal .value .bool_val ? 1 : 0 , false);
99-
99+
100100 case LITERAL_CHAR :
101101 return LLVMConstInt (LLVMInt8TypeInContext (ctx -> context ),
102102 (unsigned char )node -> expr .literal .value .char_val ,
103103 false);
104-
104+
105105 case LITERAL_STRING : {
106106 char * processed_str =
107107 process_escape_sequences (node -> expr .literal .value .string_val );
108-
108+
109109 // String literals must be created in the current module
110110 LLVMModuleRef current_llvm_module =
111111 ctx -> current_module ? ctx -> current_module -> module : ctx -> module ;
112-
112+
113113 // Create the global string in the current module
114114 LLVMValueRef global_str =
115115 LLVMAddGlobal (current_llvm_module ,
@@ -145,9 +145,10 @@ LLVMValueRef codegen_expr_literal(CodeGenContext *ctx, AstNode *node) {
145145 case LITERAL_NULL :
146146 return LLVMConstNull (
147147 LLVMPointerType (LLVMInt8TypeInContext (ctx -> context ), 0 ));
148-
148+
149149 default :
150- fprintf (stderr , "ERROR: Unknown literal type: %d\n" , node -> expr .literal .lit_type );
150+ fprintf (stderr , "ERROR: Unknown literal type: %d\n" ,
151+ node -> expr .literal .lit_type );
151152 return NULL ;
152153 }
153154}
@@ -1063,7 +1064,14 @@ LLVMValueRef codegen_expr_index(CodeGenContext *ctx, AstNode *node) {
10631064
10641065 // If this is the last field in the chain, get its element type
10651066 if (i == chain_length - 1 ) {
1066- element_type = current_struct -> field_element_types [field_idx ];
1067+ LLVMTypeRef field_type = current_struct -> field_types [field_idx ];
1068+
1069+ // Check if this field is an array - if so, get its element type
1070+ if (LLVMGetTypeKind (field_type ) == LLVMArrayTypeKind ) {
1071+ element_type = LLVMGetElementType (field_type );
1072+ } else {
1073+ element_type = current_struct -> field_element_types [field_idx ];
1074+ }
10671075 break ;
10681076 }
10691077
0 commit comments