| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // Created by 李晓明 on 2023/6/14.
- //
- #ifndef CLOX__COMMON_H_
- #define CLOX__COMMON_H_
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define DEBUG_PRINT_CODE
- #define DEBUG_TRACE_EXECUTION
- #define DEBUG_STACK_INFO
- //#define DEBUG_STRESS_GC
- #define DEBUG_LOG_GC
- #define PRINT_METADATA
- #define UINT8_COUNT (UINT8_MAX + 1)
- #ifdef PRINT_METADATA
- #define PRINTLNF(format, ...) printf("("__FILE__ \
- ":%d) %s: " format "\n", \
- __LINE__, __FUNCTION__, ##__VA_ARGS__)
- #else
- #define PRINTLNF(format, ...) printf(format "\n", ##__VA_ARGS__)
- #endif
- #define PRINT_CHAR(char_value) PRINTLNF(#char_value ": %c", char_value)
- #define PRINT_WCHAR(char_value) PRINTLNF(#char_value ": %lc", char_value)
- #define PRINT_INT(int_value) PRINTLNF(#int_value " : %d", int_value)
- #define PRINT_LONG(long_value) PRINTLNF(#long_value ": %ld", long_value)
- #define PRINT_LLONG(long_value) PRINTLNF(#long_value ": %lld", long_value)
- #define PRINT_BINARY(int_value) PrintBinary((unsigned int) int_value);
- #define PRINT_HEX(int_value) PRINTLNF(#int_value ": %#x", int_value)
- #define PRINT_BOOL(bool_value) PRINTLNF(#bool_value ": %s", bool_value ? "true" : "false")
- #define PRINT_DOUBLE(double_value) PRINTLNF(#double_value ": %g", double_value)
- #define PRINT_STRING(string_value) PRINTLNF(#string_value ": %s", string_value)
- #define PRINT_ARRAY(format, array, length) \
- { \
- int array_index; \
- for (array_index = 0; array_index < length; ++array_index) { \
- printf(format, array[array_index]); \
- }; \
- printf("\n"); \
- }
- #define PRINT_INT_ARRAY_LN(array, length) \
- { \
- int i; \
- for (i = 0; i < length; ++i) { \
- PRINTLNF(#array "[%d]: %d", i, array[i]); \
- } \
- }
- #define PRINT_INT_ARRAY(array, length) PRINT_ARRAY("%d, ", array, length)
- #define PRINT_CHAR_ARRAY(array, length) PRINT_ARRAY("%c, ", array, length)
- #define PRINT_DOUBLE_ARRAY(array, length) PRINT_ARRAY("%g, ", array, length)
- #define PRINT_IF_ERROR(format, ...) \
- if (errno != 0) { \
- fprintf(stderr, format, ##__VA_ARGS__); \
- fprintf(stderr, ": %s\n", strerror(errno)); \
- }
- #endif//CLOX__COMMON_H_
|