yet another ktid type system refactoring
This commit is contained in:
@@ -13,11 +13,11 @@ I don't really like printf function (and its variants), so i made safer and more
|
||||
## how to use it:
|
||||
+ **format construction:**
|
||||
```
|
||||
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktId;
|
||||
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktid;
|
||||
```
|
||||
[more about `kprint_format`](kprint_format.md)
|
||||
+ fgColor and bgColor can be set to change console output color
|
||||
+ you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and ktId for other types
|
||||
+ you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and ktid for other types
|
||||
+ flags can be set to modify TypeDescriptor.toString() behavior
|
||||
+ don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
|
||||
|
||||
@@ -31,6 +31,6 @@ I don't really like printf function (and its variants), so i made safer and more
|
||||
should be sent as pointers
|
||||
```
|
||||
Maybe m=MaybeNull;
|
||||
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktId_MaybePtr, &m);
|
||||
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktid_MaybePtr, &m);
|
||||
```
|
||||
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktId_Null}}</span>
|
||||
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktid_Null}}</span>
|
||||
@@ -1,23 +1,23 @@
|
||||
#include "../String/StringBuilder.h"
|
||||
#include "kprint.h"
|
||||
|
||||
ktId __typeFromFormat(kprint_format f){
|
||||
ktId typeId=kprint_format_ktId(f);
|
||||
ktid __typeFromFormat(kprint_format f){
|
||||
ktid typeId=kprint_format_ktid(f);
|
||||
if(typeId)
|
||||
return typeId;
|
||||
switch(kprint_format_dataFormat(f)){
|
||||
case kprint_fmtInt:
|
||||
case kprint_fmtHex:
|
||||
case kprint_fmtBin:
|
||||
return ktId_Int64;
|
||||
return ktid_name(int64);
|
||||
case kprint_fmtUInt:
|
||||
return ktId_UInt64;
|
||||
return ktid_name(uint64);
|
||||
case kprint_fmtFloat:
|
||||
return ktId_Float64;
|
||||
return ktid_name(float64);
|
||||
case kprint_fmtChar:
|
||||
return ktId_Char;
|
||||
return ktid_char;
|
||||
case kprint_fmtString:
|
||||
return ktId_CharPtr;
|
||||
return ktid_ptrName(char);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@@ -25,13 +25,13 @@ ktId __typeFromFormat(kprint_format f){
|
||||
|
||||
Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
||||
// detecting type
|
||||
ktId typeId=__typeFromFormat(f);
|
||||
ktid typeId=__typeFromFormat(f);
|
||||
if(typeId==-1)
|
||||
safethrow("typeId is not set, can't autodetect type",;);
|
||||
ktDescriptor typeDesc=ktDescriptor_get(typeId);
|
||||
if(!typeDesc.toString)
|
||||
safethrow("type descriptor doesnt have toString() func",;);
|
||||
return SUCCESS(UniHeap(ktId_CharPtr, typeDesc.toString(object, f)));
|
||||
return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f)));
|
||||
}
|
||||
|
||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
@@ -43,7 +43,7 @@ Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
Unitype_free(mStr.value);
|
||||
}
|
||||
char* rezult=StringBuilder_build(strb).ptr;
|
||||
return SUCCESS(UniHeap(ktId_CharPtr, rezult));
|
||||
return SUCCESS(UniHeapPtr(char, rezult));
|
||||
}
|
||||
|
||||
Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
@@ -150,7 +150,7 @@ void kprint_setColor(kprint_format f){
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Maybe ksprint_ar(uint32 count, kprint_format format, ktId typeId, void* array){
|
||||
/* Maybe ksprint_ar(uint32 count, kprint_format format, ktid typeId, void* array){
|
||||
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
||||
if(!typeDesc.toString)
|
||||
safethrow("type descriptor doesnt have toString() func",;);
|
||||
|
||||
@@ -5,7 +5,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../base/std.h"
|
||||
#include "../base/type_system/ktId.h"
|
||||
#include "../base/type_system/ktid.h"
|
||||
|
||||
typedef enum kprint_dataFormat{
|
||||
// 00000000 00000000 00000000 00000000
|
||||
@@ -41,7 +41,7 @@ typedef uint32 kprint_format;
|
||||
#define kprint_format_fgColor(FMT) (kprint_fgColor)(FMT&0x8f000000)
|
||||
#define kprint_format_bgColor(FMT) (kprint_bgColor)(FMT&0x40f00000)
|
||||
#define kprint_format_dataFormat(FMT) (kprint_dataFormat)(FMT&0x000f0000)
|
||||
#define kprint_format_ktId(FMT) (kprint_dataFormat)(FMT&0x0000ffff)
|
||||
#define kprint_format_ktid(FMT) (kprint_dataFormat)(FMT&0x0000ffff)
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
```
|
||||
00000000 00000000 00000000 00000000
|
||||
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktId
|
||||
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktid
|
||||
bgColorSet─┘││ │ bgColor └data format
|
||||
prefix┬────┘│ └fgColor
|
||||
postfix └uppercase
|
||||
|
||||
Reference in New Issue
Block a user