diff --git a/aq/aq.c b/aq/aq.c index 11f0988..e5f1339 100644 --- a/aq/aq.c +++ b/aq/aq.c @@ -12,8 +12,8 @@ int main(int argc, char *argv[]) { // TODO(Aqvm): Finish this function after completing AQVM development. if (Aqvm_InitVm() != 0) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 2, "Aqmain_InitVmError", "Initializing Aqvm met error.", NULL}); + AqvmRuntimeDebugger_OutputReport(2, "Aqmain_InitVmError", + "Initializing Aqvm met error.", NULL); return -1; } return 0; diff --git a/aqvm/memory/memory.c b/aqvm/memory/memory.c index 5dd9e0d..ef851f2 100644 --- a/aqvm/memory/memory.c +++ b/aqvm/memory/memory.c @@ -15,51 +15,51 @@ int AqvmMemory_CheckMemoryConditions() { int warning_count = 0; if (sizeof(aqint) != 4) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_IntLengthWarning", "The length requirement for the int type does not conform to the type " "definition.", - NULL}); + NULL); ++warning_count; } if (sizeof(aqlong) != 8) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_LongLengthWarning", "The length requirement for the long type does not conform to the type " "definition.", - NULL}); + NULL); ++warning_count; } if (sizeof(aqfloat) != 4) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_FloatLengthWarning", "The length requirement for the float type does not conform to the " "type definition.", - NULL}); + NULL); ++warning_count; } if (sizeof(aqdouble) != 4) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_DoubleLengthWarning", "The length requirement for the double type does not conform to the " "type definition.", - NULL}); + NULL); ++warning_count; } if (sizeof(aqchar) != 1) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_CharLengthWarning", "The length requirement for the char type does not conform to the type " "definition.", - NULL}); + NULL); ++warning_count; } if (sizeof(aqbool) != 1) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 1, "AqvmMemoryCheckMemoryConditions_BoolLengthWarning", "The length requirement for the bool type does not conform to the type " "definition.", - NULL}); + NULL); ++warning_count; } @@ -71,9 +71,9 @@ struct AqvmMemory_Memory* AqvmMemory_CreateMemory(void* data, void* type, struct AqvmMemory_Memory* memory_ptr = (struct AqvmMemory_Memory*)malloc(sizeof(struct AqvmMemory_Memory)); if (memory_ptr == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ + AqvmRuntimeDebugger_OutputReport( 2, "AqvmMemoryCreateMemory_MemoryAllocationFailure", - "Failed to allocate memory.", NULL}); + "Failed to allocate memory.", NULL); return NULL; } @@ -91,30 +91,26 @@ void AqvmMemory_FreeMemory(struct AqvmMemory_Memory* memory_ptr) { int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index, uint8_t type) { if (memory == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemorySetType_NullMemoryPointer", "The memory pointer is NULL.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_NullMemoryPointer", + "The memory pointer is NULL.", NULL); return -1; } if (memory->type == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemorySetType_NullTypePointer", "The type pointer is NULL.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_NullTypePointer", + "The type pointer is NULL.", NULL); return -2; } if (index > memory->size) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemorySetType_OutOfMemoryRange", - "The index is out of memory range.", NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_OutOfMemoryRange", + "The index is out of memory range.", NULL); return -3; } if (type > 0x0F) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemorySetType_OutOfTypeRange", "The type is out of range.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemorySetType_OutOfTypeRange", + "The type is out of range.", NULL); return -4; } @@ -129,23 +125,20 @@ int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index, uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) { if (memory == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryGetType_NullMemoryPointer", "The memory pointer is NULL.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_NullMemoryPointer", + "The memory pointer is NULL.", NULL); return 0x11; } if (memory->type == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryGetType_NullTypePointer", "The type pointer is NULL.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_NullTypePointer", + "The type pointer is NULL.", NULL); return 0x12; } if (index > memory->size) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryGetType_OutOfMemoryRange", - "The index is out of memory range.", NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryGetType_OutOfMemoryRange", + "The index is out of memory range.", NULL); return 0x13; } @@ -159,29 +152,26 @@ uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) { int AqvmMemory_WriteData(struct AqvmMemory_Memory* memory, size_t index, void* data_ptr, size_t size) { if (memory == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryWriteData_NullMemoryPointer", - "The memory pointer is NULL.", NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullMemoryPointer", + "The memory pointer is NULL.", NULL); return -1; } if (memory->type == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryWriteData_NullTypePointer", "The type pointer is NULL.", - NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullTypePointer", + "The type pointer is NULL.", NULL); return -2; } if (index > memory->size) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryWriteData_OutOfMemoryRange", - "The index is out of memory range.", NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_OutOfMemoryRange", + "The index is out of memory range.", NULL); return -3; } if (data_ptr == NULL) { - AqvmRuntimeDebugger_OutputReport((struct AqvmRuntimeDebugger_DebugReport){ - 1, "AqvmMemoryWriteData_NullDataPointer", "The data pointer is NULL.", NULL}); + AqvmRuntimeDebugger_OutputReport(1, "AqvmMemoryWriteData_NullDataPointer", + "The data pointer is NULL.", NULL); return -4; } diff --git a/aqvm/runtime/debugger/debugger.h b/aqvm/runtime/debugger/debugger.h index 38b5eed..b3e752d 100644 --- a/aqvm/runtime/debugger/debugger.h +++ b/aqvm/runtime/debugger/debugger.h @@ -22,9 +22,15 @@ struct AqvmRuntimeDebugger_DebugReport { // Outputs |report| with time, errno and so on to printing to the console or // other devices and writing to a log file. No return. -// NOTICE: The output is json format. -void AqvmRuntimeDebugger_OutputReport( - struct AqvmRuntimeDebugger_DebugReport report); +// |type| is the type of the report. In |type|, 0 is INFO, 1 is WARNING, and 2 +// is ERROR. |type|, |code|, and |message| are necessary and shouldn't be set to +// NULL in common. |other_info| is a pointer to the other information and it can +// be set to NULL if it is not needed. +// NOTICE: If you need to use it, please use json format. The output is json +// format. +void AqvmRuntimeDebugger_OutputReport(uint8_t type, const char* code, + const char* message, + const char* other_info); // INTERNAL USE ONLY. // Gets the current time in a string format based on ISO 8601 standard and @@ -34,11 +40,11 @@ void AqvmRuntimeDebugger_OutputReport( void AqvmRuntimeDebugger_GetCurrentTime(char* return_time); // INTERNAL USE ONLY. -// Formats |report| and returns type string accroding to the type in |report|. -// If code, message, or other_info are NULL, They will be set to the string -// "NULL". +// If |code|, |message|, or |other_info| is NULL, It will be set to the string +// "NULL". Returns type string accroding to the |type|. // NOTICE: The output is json format. -const char* AqvmRuntimeDebugger_FormatReport( - struct AqvmRuntimeDebugger_DebugReport* report); +const char* AqvmRuntimeDebugger_FormatReport(uint8_t type, const char* code, + const char* message, + const char* other_info); #endif \ No newline at end of file