F diff --git a/src/backend/asm/intel/intel_asm.c b/src/backend/asm/intel/intel_asm.c --- a/src/backend/asm/intel/intel_asm.c +++ b/src/backend/asm/intel/intel_asm.cfor(it=object->data_block->first;it!=NULL;it=it->prev)save_intel_asm_instruction(it->data,out);fprintf(out,"\nsection .text\n");- fprintf(out,"\nextern _exit\n");for(it=object->instructions->first;it!=NULL;it=it->prev)save_intel_asm_instruction(it->data,out);}struct Intel_Asm_Memory_Location* reserve_static_space_for_string(struct Compile_Data_Intel_Asm *compile_data,struct Constant *string){struct Intel_Asm_Instruction *label;- struct Intel_Asm_Instruction *db;+ struct Intel_Asm_Instruction *db,*db2;struct Type_Array *string_type;wonky_assert(string->type->specifier==TS_ARRAY && string->value!=NULL);string_type=(struct Type_Array*)string->type;- db=get_intel_asm_define_bytes(string->value,string_type->size);+ db=get_intel_asm_define_bytes(string->value,string_type->size-2);+ db2=get_intel_asm_define_bytes("\0",1);label=get_intel_asm_new_unique_label(compile_data);Queue_Push(compile_data->data_block,label);Queue_Push(compile_data->data_block,db);+ Queue_Push(compile_data->data_block,db2);return get_intel_asm_label_location((struct Intel_Asm_Label*)label);}F diff --git a/src/backend/asm/intel/intel_asm.h b/src/backend/asm/intel/intel_asm.h --- a/src/backend/asm/intel/intel_asm.h +++ b/src/backend/asm/intel/intel_asm.hstruct Queue *instructions;int number_of_anon_labels;++ _Bool in_main;};struct Compiled_Object_Intel_Asm{F diff --git a/src/backend/asm/intel/intel_compile.c b/src/backend/asm/intel/intel_compile.c --- a/src/backend/asm/intel/intel_compile.c +++ b/src/backend/asm/intel/intel_compile.cvoid compile_return_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Return_Statement *ret){push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RAX));+ if(!compile_data->in_main)+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_RET));}void compile_object_declaration_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Object_Declaration *objd)}void compile_function_definition_to_intel_asm(struct Compile_Data_Intel_Asm *compile_data,struct AST_Function_Definition *def){+ export_function_definition(compile_data,def);+ if(!gstrn_cmp(def->function->id->data,"main",sizeof("main")-1))+ compile_data->in_main=0;+ else+ compile_data->in_main=1;+if(def->function->location==NULL){def->function->location=(struct Location*)}push_intel_asm_instruction(compile_data,(struct Intel_Asm_Instruction*)((struct Intel_Asm_Memory_Location_By_Label*)def->function->location)->label);+ push_intel_asm_instruction(compile_data,intel_asm_get_push(INTEL_ASM_REGISTER_RBP));compile_compound_statement_to_intel_asm(compile_data,def->body);+ if(!compile_data->in_main)+ push_intel_asm_instruction(compile_data,intel_asm_get_pop(INTEL_ASM_REGISTER_RBP));/*if there are no returns we return jiberrish*/push_intel_asm_instruction(compile_data,get_intel_asm_simple_instruction(INTEL_ASM_OP_RET));F diff --git a/src/backend/asm/intel/intel_instruction.c b/src/backend/asm/intel/intel_instruction.c --- a/src/backend/asm/intel/intel_instruction.c +++ b/src/backend/asm/intel/intel_instruction.cif(snprintf(label,1024,"_label_%d",compile_data->number_of_anon_labels)!=1024)label[1023]='\0';/*TODO throw an error*/+ ++compile_data->number_of_anon_labels;+ret=malloc(sizeof(struct Intel_Asm_Label));ret->type=INTEL_ASM_OP_LABEL;ret->label_name=label;F diff --git a/src/backend/asm/intel/intel_location.c b/src/backend/asm/intel/intel_location.c --- a/src/backend/asm/intel/intel_location.c +++ b/src/backend/asm/intel/intel_location.c[INTEL_ASM_REGISTER_R8]="R8",[INTEL_ASM_REGISTER_R9]="R9",[INTEL_ASM_REGISTER_RAX]="RAX",+ [INTEL_ASM_REGISTER_RBP]="RBP",};struct Intel_Asm_Memory_Location* get_intel_by_asm_register(enum Intel_Asm_Registers reg)F diff --git a/src/backend/asm/intel/intel_location.hh b/src/backend/asm/intel/intel_location.hh --- a/src/backend/asm/intel/intel_location.hh +++ b/src/backend/asm/intel/intel_location.hhINTEL_ASM_REGISTER_R9,INTEL_ASM_REGISTER_RAX,+ INTEL_ASM_REGISTER_RBP,INTEL_ASM_REGISTER_END};F diff --git a/src/debug/wobler/wobler_tests.h b/src/debug/wobler/wobler_tests.h --- a/src/debug/wobler/wobler_tests.h +++ b/src/debug/wobler/wobler_tests.h.how_much_time_should_execution_take=TEST_TIME_BASELINE,},{+ .filenames={"test_conditional_expression.c"},+ .test_function=should_compile,+ .how_much_time_should_execution_take=TEST_TIME_BASELINE,+ },+ {.filenames={"test_declaration_speed.c"},.test_function=should_compile,.how_much_time_should_execution_take=TEST_TIME_BASELINE,F diff --git a/src/semantics/ast.c b/src/semantics/ast.c --- a/src/semantics/ast.c +++ b/src/semantics/ast.c{struct Type *operand_type;+ if(operand->type==ERROR)+ return operand;+operand_type=extract_expresion_value_type(operand->value,translation_data);if(operand_type->specifier==TS_FLOAT){ret->left=left;ret->center=center;ret->right=right;+ if(!constraint_check_conditional_expression(left,center,right,translation_data))+ return (struct AST_Conditional_Expression*)get_error_tree((struct AST*)ret);+ ret->value=get_expression_value_rvalue(get_temp_object(extract_expresion_value_type(center->value,translation_data)));return ret;}F diff --git a/src/semantics/value/value.c b/src/semantics/value/value.c --- a/src/semantics/value/value.c +++ b/src/semantics/value/value.creturn ((struct Expression_Value_RValue*)expression_value)->temp_object->type;case VALUE_FUNCTION_DESIGNATOR:return ((struct Expression_Value_Function_Designator*)expression_value)->function->type;+ case VALUE_STRING:case VALUE_CONSTANT:return ((struct Expression_Value_Constant*)expression_value)->constant->type;case VALUE_VOID:return get_type_size(((struct Expression_Value_RValue*)expression_value)->temp_object->type);case VALUE_FUNCTION_DESIGNATOR:return get_type_size(((struct Expression_Value_Function_Designator*)expression_value)->function->type);+ case VALUE_STRING:case VALUE_CONSTANT:return get_type_size(((struct Expression_Value_Constant*)expression_value)->constant->type);case VALUE_VOID:{switch(expression_value->type){- case VALUE_LVALUE:- delete_expression_value_lvalue((struct Expression_Value_LValue*)expression_value);- return;- case VALUE_TEMP:- delete_expression_value_rvalue((struct Expression_Value_RValue*)expression_value);- return;- case VALUE_FUNCTION_DESIGNATOR:- delete_expression_value_function_designator((struct Expression_Value_Function_Designator*)expression_value);- return;- case VALUE_CONSTANT:- delete_expression_value_constant((struct Expression_Value_Constant*)expression_value);- return;- case VALUE_VOID:- delete_expression_value_void(expression_value);- return;+ case VALUE_LVALUE:+ delete_expression_value_lvalue((struct Expression_Value_LValue*)expression_value);+ return;+ case VALUE_TEMP:+ delete_expression_value_rvalue((struct Expression_Value_RValue*)expression_value);+ return;+ case VALUE_FUNCTION_DESIGNATOR:+ delete_expression_value_function_designator((struct Expression_Value_Function_Designator*)expression_value);+ return;+ case VALUE_STRING:+ case VALUE_CONSTANT:+ delete_expression_value_constant((struct Expression_Value_Constant*)expression_value);+ return;+ case VALUE_VOID:+ delete_expression_value_void(expression_value);+ return;}wonky_assert(SHOULD_NOT_REACH_HERE);}F diff --git a/tests/test_conditional_expression.c b/tests/test_conditional_expression.c new file mode 100644 --- /dev/null +++ b/tests/test_conditional_expression.c+ extern int printf(const char *format,...);++ int main()+ {+ printf("Hello world! I'm %s\n",(0?"10":"2"));+ return 0;+ }