Merge branch 'main' into network
This commit is contained in:
commit
3d15cb35af
3
Makefile
3
Makefile
@ -1,4 +1,6 @@
|
||||
###### Build cbuild/default_tasks #######
|
||||
all: build_exec
|
||||
|
||||
build_exec:
|
||||
@cbuild/call_task.sh build_exec
|
||||
build_exec_dbg:
|
||||
@ -21,4 +23,3 @@ exec: build_exec
|
||||
valgrind: build_exec_dbg
|
||||
@cbuild/call_task.sh valgrind
|
||||
|
||||
all: build_exec
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
#!/bin/bash
|
||||
CONFIG_VERSION=3
|
||||
CBUILD_VERSION=2
|
||||
CBUILD_VERSION=3
|
||||
CONFIG_VERSION=4
|
||||
|
||||
PROJECT=kerep
|
||||
CMP_C=gcc
|
||||
CMP_CPP=g++
|
||||
STD_C=c11
|
||||
STD_CPP=c++17
|
||||
WARN_C="-Wall -Wno-discarded-qualifiers -Wno-int-conversion"
|
||||
WARN_C="-Wall -Wno-discarded-qualifiers"
|
||||
WARN_CPP="-Wall"
|
||||
SRC_C="$( find src -name '*.c')"
|
||||
SRC_CPP="$( find src -name '*.cpp')"
|
||||
|
||||
@ -13,7 +13,7 @@ Array_declare(FilePath);
|
||||
typedef FILE File;
|
||||
ktid_declare(File);
|
||||
|
||||
typedef enum FileOpenMode{
|
||||
PACK_ENUM(FileOpenMode,
|
||||
// open a file for reading
|
||||
FileOpenMode_Read=1,
|
||||
// (re)create a file for writing
|
||||
@ -24,7 +24,7 @@ typedef enum FileOpenMode{
|
||||
FileOpenMode_ReadWrite=FileOpenMode_Read|FileOpenMode_Write,
|
||||
// opens file for readng/writing additional data to the end / creates new file
|
||||
FileOpenMode_ReadAppend=FileOpenMode_Read|FileOpenMode_Append
|
||||
} FileOpenMode;
|
||||
)
|
||||
|
||||
|
||||
/// @brief opens file
|
||||
|
||||
@ -10,6 +10,7 @@ extern "C" {
|
||||
#include "optime.h"
|
||||
#include "type_system/type_system.h"
|
||||
#include "../kprint/kprintf.h"
|
||||
#include "endian.h"
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
13
src/base/endian.c
Normal file
13
src/base/endian.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include "endian.h"
|
||||
|
||||
static const union
|
||||
{
|
||||
uint16 number;
|
||||
Endian bytes[2];
|
||||
} _endian_union={ .number=0x0102 };
|
||||
|
||||
Endian getEndian(){
|
||||
// if 0x0102 == { 1, 2 } then BigEndian
|
||||
// if 0x0102 == { 2, 1 } then LittleEndian
|
||||
return _endian_union.bytes[1];
|
||||
}
|
||||
9
src/base/endian.h
Normal file
9
src/base/endian.h
Normal file
@ -0,0 +1,9 @@
|
||||
#include "std.h"
|
||||
|
||||
PACK_ENUM(Endian,
|
||||
UnknownEndian=0,
|
||||
LittleEndian=1,
|
||||
BigEndian=2
|
||||
);
|
||||
|
||||
Endian getEndian();
|
||||
@ -7,13 +7,13 @@ extern "C" {
|
||||
#include "std.h"
|
||||
#include "type_system/unitype.h"
|
||||
|
||||
typedef enum ErrorId {
|
||||
PACK_ENUM(ErrorId,
|
||||
SUCCESS, // not an error
|
||||
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
|
||||
ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
|
||||
ERR_KEYNOTFOUND, ERR_FORMAT, ERR_UNEXPECTEDVAL,
|
||||
ERR_IO, ERR_IO_EOF
|
||||
} ErrorId;
|
||||
)
|
||||
|
||||
char* errname(ErrorId err);
|
||||
|
||||
|
||||
@ -2,24 +2,40 @@
|
||||
|
||||
#include "std.h"
|
||||
|
||||
// executes codeblock and prints execution time
|
||||
#ifdef CLOCK_REALTIME // non-standard high-precision clock
|
||||
#define __optime_print(opname, t)\
|
||||
char tnames[3][3]={"s\0","ms","us"};\
|
||||
int tni=0;\
|
||||
if(t>1000000){\
|
||||
t/=1000000;\
|
||||
tni=0;\
|
||||
} else if(t>1000){\
|
||||
t/=1000;\
|
||||
tni=1;\
|
||||
} else tni=2;\
|
||||
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%f \e[93m%s\n",\
|
||||
opname, t, tnames[tni]);
|
||||
|
||||
#ifdef CLOCK_REALTIME
|
||||
/// executes codeblock and prints execution time
|
||||
/// uint64 op_i is counter of the internal loop
|
||||
/// uses non-standard high-precision clock
|
||||
#define optime(opname,repeats,codeblock) ({\
|
||||
struct timespec start, stop;\
|
||||
clock_gettime(CLOCK_REALTIME, &start);\
|
||||
for(uint64 ___OPREP=0;___OPREP<(uint64)repeats;___OPREP++)\
|
||||
for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\
|
||||
(codeblock);\
|
||||
clock_gettime(CLOCK_REALTIME, &stop);\
|
||||
double t=(double)(stop.tv_sec-start.tv_sec+(double)(stop.tv_nsec-start.tv_nsec)/1000000000)/repeats;\
|
||||
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
||||
double t=(double)(stop.tv_sec-start.tv_sec)*1000000+(double)(stop.tv_nsec-start.tv_nsec)/1000;\
|
||||
__optime_print(opname,t)\
|
||||
})
|
||||
#else // standard low precision clock
|
||||
#else
|
||||
/// uses standard low precision clock
|
||||
#define optime(opname,repeats,codeblock) ({\
|
||||
clock_t start=clock();\
|
||||
for(uint64 ___OPREP=0;___OPREP<(uint64)repeats;___OPREP++)\
|
||||
for(uint64 op_i=0;op_i<(uint64)repeats;op_i++)\
|
||||
(codeblock);\
|
||||
clock_t stop=clock();\
|
||||
double t=(double)(stop-start)/CLOCKS_PER_SEC/repeats;\
|
||||
kprintf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
||||
double t=(double)(stop-start)/CLOCKS_PER_SEC*1000000;\
|
||||
__optime_print(opname,t)\
|
||||
})
|
||||
#endif
|
||||
|
||||
@ -76,14 +76,52 @@ typedef uint8 bool;
|
||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||
a24,a25,a26,a27,a28,a29,a30,a31,\
|
||||
a32,...) a32
|
||||
a32,a33,a34,a35,a36,a37,a38,a39,\
|
||||
a40,a41,a42,a43,a44,a45,a46,a47,\
|
||||
a48,a49,a50,a51,a52,a53,a54,a55,\
|
||||
a56,a57,a58,a59,a60,a61,a62,a63,\
|
||||
a64,...) a64
|
||||
// Macro for counting variadic arguments (max 64)
|
||||
// (see usage in kprint.h)
|
||||
#define count_args(ARGS...) __count_args(\
|
||||
ARGS,\
|
||||
64,63,62,61,60,59,58,57,\
|
||||
56,55,54,53,52,51,50,49,\
|
||||
48,47,46,45,44,43,42,41,\
|
||||
40,39,38,37,36,35,34,33,\
|
||||
32,31,30,29,28,27,26,25,\
|
||||
24,23,22,21,20,19,18,17,\
|
||||
16,15,14,13,12,11,10,9,\
|
||||
8, 7, 6, 5, 4, 3, 2, 1, 0)
|
||||
|
||||
/*
|
||||
Cross-platform warning supression.
|
||||
WARNING_DISABLE( W_EXAMPLE,
|
||||
some code producing W_EXAMPLE;
|
||||
);
|
||||
You can even embed it into macro in header (see kprint.h)
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#define PRAGMA_WARNING_PUSH __pragma(warning( push ))
|
||||
#define DISABLE_WARNING(wNumber) __pragma(warning( disable : wNumber ))
|
||||
#define PRAGMA_WARNING_POP __pragma(warning( pop ))
|
||||
#else
|
||||
#define _PRAGMA(P) _Pragma(#P)
|
||||
#define PRAGMA_WARNING_PUSH _PRAGMA(GCC diagnostic push)
|
||||
#define PRAGMA_WARNING_DISABLE(wName) _PRAGMA(GCC diagnostic ignored wName)
|
||||
#define PRAGMA_WARNING_POP _PRAGMA(GCC diagnostic pop)
|
||||
#define W_INT_CONVERSION "-Wint-conversion"
|
||||
#endif
|
||||
#define WARNING_DISABLE(WARNING, CODE)\
|
||||
PRAGMA_WARNING_PUSH\
|
||||
PRAGMA_WARNING_DISABLE(WARNING)\
|
||||
CODE;\
|
||||
PRAGMA_WARNING_POP
|
||||
|
||||
#define PACK_ENUM(ENUM_NAME, ENUM_MEMBERS...) typedef enum ENUM_NAME {\
|
||||
ENUM_MEMBERS\
|
||||
} __attribute__((__packed__)) ENUM_NAME;
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -4,14 +4,14 @@
|
||||
|
||||
char* __toString_char(void* c, uint32 fmt) {
|
||||
//*c=char
|
||||
if(kprint_format_dataFormat(fmt)==kprint_fmtChar){
|
||||
if(kp_fmt_dataFormat(fmt)==kp_c){
|
||||
char* cc=malloc(2);
|
||||
cc[0]=*(char*)c;
|
||||
cc[1]=0;
|
||||
return cc;
|
||||
}
|
||||
// *c=cstring
|
||||
else if(kprint_format_dataFormat(fmt)==kprint_fmtString){
|
||||
else if(kp_fmt_dataFormat(fmt)==kp_s){
|
||||
return cptr_copy(*(char**)c);
|
||||
}
|
||||
else throw(ERR_FORMAT);
|
||||
@ -19,7 +19,7 @@ char* __toString_char(void* c, uint32 fmt) {
|
||||
|
||||
char* __toString_bool(void* c, uint32 fmt) {
|
||||
static const char _strbool[4][6]={ "false", "true\0", "False", "True\0" };
|
||||
uint8 strind=*(bool*)c==1 + kprint_format_uppercase(fmt)*2;
|
||||
uint8 strind=*(bool*)c==1 + kp_fmt_isUpper(fmt)*2;
|
||||
char* rez=malloc(6);
|
||||
rez[0]=_strbool[strind][0];
|
||||
rez[1]=_strbool[strind][1];
|
||||
@ -31,72 +31,90 @@ char* __toString_bool(void* c, uint32 fmt) {
|
||||
}
|
||||
|
||||
char* toString_int(int64 n){
|
||||
int64 d=n;
|
||||
int64 d=n<0 ? -1*n : n;
|
||||
char str[32];
|
||||
uint8 i=sizeof(str);
|
||||
str[--i]=0;
|
||||
while(d!=0){
|
||||
if(d==0)
|
||||
str[--i]='0';
|
||||
else while(d!=0){
|
||||
str[--i]='0' + d%10;
|
||||
d/=10;
|
||||
}
|
||||
if(n>>63)
|
||||
if(n<0)
|
||||
str[--i]='-';
|
||||
return cptr_copy((char*)str+i);
|
||||
}
|
||||
|
||||
char* toString_uint(uint64 n, bool withPostfix, bool uppercase){
|
||||
uint64 d=n;
|
||||
char str[32];
|
||||
uint8 i=sizeof(str);
|
||||
str[--i]=0;
|
||||
if(withPostfix)
|
||||
str[--i]= uppercase ? 'U' : 'u';
|
||||
while(d!=0){
|
||||
str[--i]='0' + d%10;
|
||||
d/=10;
|
||||
if(n==0)
|
||||
str[--i]='0';
|
||||
else while(n!=0){
|
||||
str[--i]='0' + n%10;
|
||||
n/=10;
|
||||
}
|
||||
return cptr_copy((char*)str+i);
|
||||
}
|
||||
|
||||
char* toString_float(float64 n, bool withPostfix, bool uppercase){
|
||||
// int64 d=n;
|
||||
// float64 r=n-d;
|
||||
// char* strint=toString_int(d);
|
||||
// char strfract[32];
|
||||
// uint8 i=0;
|
||||
// strfract[i++]='.';
|
||||
// while(r!=0){
|
||||
// r*=10.0;
|
||||
// char fc=r;
|
||||
// strfract[i++]=fc;
|
||||
// r-=fc;
|
||||
// }
|
||||
// if(withPostfix)
|
||||
// strfract[i++]= uppercase ? 'F' : 'f';
|
||||
// strfract[i]=0;
|
||||
// char* str==cptr_concat(strint, strfract);
|
||||
// free(strint);
|
||||
// return str;
|
||||
return cptr_copy("<float>");
|
||||
#define _toString_float_impl(bufsize, maxPrecision) {\
|
||||
char str[bufsize];\
|
||||
if(precision>maxPrecision)\
|
||||
throw("too big precision");\
|
||||
if(precision==0)\
|
||||
precision=toString_float_default_precision;\
|
||||
int cn=sprintf(str, "%.*f", precision, n);\
|
||||
/* remove trailing zeroes except .0*/\
|
||||
while(str[cn-1]=='0' && str[cn-2]!='.')\
|
||||
cn--;\
|
||||
if(withPostfix)\
|
||||
str[cn++]= uppercase ? 'F' : 'f';\
|
||||
str[cn]='\0';\
|
||||
return cptr_copy(str);\
|
||||
}
|
||||
|
||||
char* toString_bin(void* _bytes, uint32 size, bool withPrefix){
|
||||
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase)
|
||||
_toString_float_impl(48, toString_float32_max_precision)
|
||||
|
||||
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase)
|
||||
_toString_float_impl(512, toString_float64_max_precision)
|
||||
|
||||
#define byte_to_bits(byte) {\
|
||||
str[cn++]='0' + (uint8)((byte>>7)&1); /* 8th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>6)&1); /* 7th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>5)&1); /* 6th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>4)&1); /* 5th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>3)&1); /* 4th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>2)&1); /* 3th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>1)&1); /* 2th bit */\
|
||||
str[cn++]='0' + (uint8)((byte>>0)&1); /* 1th bit */\
|
||||
}
|
||||
|
||||
char* toString_bin(void* _bytes, uint32 size, bool inverse, bool withPrefix){
|
||||
char* bytes=_bytes;
|
||||
char* str=malloc(size*8 + (withPrefix?2:0) +1);
|
||||
uint32 cn=0;
|
||||
uint32 cn=0; // char number
|
||||
if(withPrefix){
|
||||
str[cn++]='0';
|
||||
str[cn++]='b';
|
||||
}
|
||||
for(uint32 bn=0; bn<size; bn++){
|
||||
unsigned char byte=bytes[bn];
|
||||
for(uint8 i=0; i<8; i++)
|
||||
str[cn++]='0' + (byte & (char)128>>i);
|
||||
if(inverse){
|
||||
// byte number
|
||||
for(int32 bn=size-1; bn>=0; bn--)
|
||||
byte_to_bits(bytes[bn])
|
||||
} else {
|
||||
for(int32 bn=0; bn<size; bn++)
|
||||
byte_to_bits(bytes[bn])
|
||||
}
|
||||
str[cn]=0;
|
||||
return str;
|
||||
}
|
||||
|
||||
// converts number from 0 to F to char
|
||||
char _4bitsHex(uint8 u, bool uppercase){
|
||||
switch(u){
|
||||
case 0: case 1: case 2: case 3: case 4:
|
||||
@ -112,18 +130,30 @@ char _4bitsHex(uint8 u, bool uppercase){
|
||||
}
|
||||
}
|
||||
|
||||
char* toString_hex(void* _bytes, uint32 size, bool withPrefix, bool uppercase){
|
||||
char* toString_hex(void* _bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase){
|
||||
char* bytes=_bytes;
|
||||
char* str=malloc(size*2 + (withPrefix?2:0) + 1);
|
||||
uint32 cn=0;
|
||||
uint32 cn=0; // char number
|
||||
if(withPrefix){
|
||||
str[cn++]='0';
|
||||
str[cn++]='x';
|
||||
}
|
||||
for(uint32 bn=0; bn<size; bn++){
|
||||
// left to right
|
||||
if(inverse){
|
||||
// byte number
|
||||
for(int32 bn=size-1; bn>=0; bn--){
|
||||
unsigned char byte=bytes[bn];
|
||||
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||
}
|
||||
}
|
||||
// right to left
|
||||
else {
|
||||
for(int32 bn=0; bn<size; bn++){ // byte number
|
||||
unsigned char byte=bytes[bn];
|
||||
str[cn++]=_4bitsHex(byte/16, uppercase);
|
||||
str[cn++]=_4bitsHex(byte%16, uppercase);
|
||||
}
|
||||
}
|
||||
str[cn]=0;
|
||||
return str;
|
||||
@ -131,16 +161,16 @@ char* toString_hex(void* _bytes, uint32 size, bool withPrefix, bool uppercase){
|
||||
|
||||
|
||||
#define __toString_int_def(BITS) char* __toString_int##BITS(void* _n, uint32 f){\
|
||||
switch(kprint_format_dataFormat(f)){\
|
||||
case kprint_fmtInt: ;\
|
||||
switch(kp_fmt_dataFormat(f)){\
|
||||
case kp_i: ;\
|
||||
int##BITS n=*(int##BITS*)_n;\
|
||||
return toString_int(n);\
|
||||
case kprint_fmtBin:\
|
||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
||||
case kprint_fmtHex:\
|
||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
||||
case kp_b:\
|
||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||
case kp_h:\
|
||||
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||
default:\
|
||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
||||
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||
throw(ERR_FORMAT);\
|
||||
return NULL;\
|
||||
}\
|
||||
@ -151,16 +181,16 @@ __toString_int_def(32)
|
||||
__toString_int_def(64)
|
||||
|
||||
#define __toString_uint_def(BITS) char* __toString_uint##BITS(void* _n, uint32 f){\
|
||||
switch(kprint_format_dataFormat(f)){\
|
||||
case kprint_fmtUInt: ;\
|
||||
switch(kp_fmt_dataFormat(f)){\
|
||||
case kp_u: ;\
|
||||
uint##BITS n=*(uint##BITS*)_n;\
|
||||
return toString_uint(n, kprint_format_withPostfix(f), kprint_format_uppercase(f));\
|
||||
case kprint_fmtBin:\
|
||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
||||
case kprint_fmtHex:\
|
||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
||||
return toString_uint(n, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||
case kp_b:\
|
||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||
case kp_h:\
|
||||
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||
default:\
|
||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
||||
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||
throw(ERR_FORMAT);\
|
||||
return NULL;\
|
||||
}\
|
||||
@ -171,16 +201,16 @@ __toString_uint_def(32)
|
||||
__toString_uint_def(64)
|
||||
|
||||
#define __toString_float_def(BITS) char* __toString_float##BITS(void* _n, uint32 f){\
|
||||
switch(kprint_format_dataFormat(f)){\
|
||||
case kprint_fmtFloat: ;\
|
||||
switch(kp_fmt_dataFormat(f)){\
|
||||
case kp_f: ;\
|
||||
float##BITS n=*(float##BITS*)_n;\
|
||||
return toString_float(n, kprint_format_withPostfix(f), kprint_format_uppercase(f));\
|
||||
case kprint_fmtBin:\
|
||||
return toString_bin(_n, BITS/8, kprint_format_withPrefix(f));\
|
||||
case kprint_fmtHex:\
|
||||
return toString_hex(_n, BITS/8, kprint_format_withPrefix(f), kprint_format_uppercase(f));\
|
||||
return toString_float64(n, toString_float_default_precision, kp_fmt_withPostfix(f), kp_fmt_isUpper(f));\
|
||||
case kp_b:\
|
||||
return toString_bin(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f));\
|
||||
case kp_h:\
|
||||
return toString_hex(_n, BITS/8, getEndian()==LittleEndian, kp_fmt_withPrefix(f), kp_fmt_isUpper(f));\
|
||||
default:\
|
||||
kprintf("\n%u\n", kprint_format_dataFormat(f));\
|
||||
kprintf("\n%u\n", kp_fmt_dataFormat(f));\
|
||||
throw(ERR_FORMAT);\
|
||||
return NULL;\
|
||||
}\
|
||||
|
||||
@ -6,30 +6,41 @@ extern "C" {
|
||||
|
||||
#include "../errors.h"
|
||||
|
||||
// functions for base types
|
||||
// char and cstring
|
||||
// has different output for fmtChar and fmtString
|
||||
char* __toString_char(void* c, uint32 fmt);
|
||||
|
||||
// bool
|
||||
char* __toString_bool(void* c, uint32 fmt);
|
||||
|
||||
// signed int
|
||||
char* toString_int(int64 n);
|
||||
char* __toString_int8(void* n, uint32 fmt);
|
||||
char* __toString_int16(void* n, uint32 fmt);
|
||||
char* __toString_int32(void* n, uint32 fmt);
|
||||
char* __toString_int64(void* n, uint32 fmt);
|
||||
|
||||
// unsigned int
|
||||
char* toString_uint(uint64 n, bool withPostfix, bool uppercase);
|
||||
char* __toString_uint8(void* n, uint32 fmt);
|
||||
char* __toString_uint16(void* n, uint32 fmt);
|
||||
char* __toString_uint32(void* n, uint32 fmt);
|
||||
char* __toString_uint64(void* n, uint32 fmt);
|
||||
|
||||
char* toString_float(float64 n, bool withPostfix, bool uppercase); // very bad implimentation
|
||||
// float
|
||||
#define toString_float32_max_precision 6
|
||||
#define toString_float64_max_precision 15
|
||||
#define toString_float_default_precision 6
|
||||
char* toString_float32(float32 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||
char* toString_float64(float64 n, uint8 precision, bool withPostfix, bool uppercase); // uses sprintf
|
||||
char* __toString_float32(void* n, uint32 fmt);
|
||||
char* __toString_float64(void* n, uint32 fmt);
|
||||
|
||||
// universal functions
|
||||
char* toString_bin(void* bytes, uint32 size, bool withPrefix);
|
||||
char* toString_hex(void* bytes, uint32 size, bool withPrefix, bool uppercase);
|
||||
|
||||
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||
char* toString_bin(void* bytes, uint32 size, bool inverse, bool withPrefix);
|
||||
///@param inverse set to true for little endian numbers (their bytes are in reverse order)
|
||||
char* toString_hex(void* bytes, uint32 size, bool inverse, bool withPrefix, bool uppercase);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ void ktDescriptors_initKerepTypes(){
|
||||
|
||||
// string
|
||||
kt_register(string, NULL, NULL);
|
||||
kt_register(string, ____Autoarr_free_string, NULL);
|
||||
kt_register(Autoarr_string, ____Autoarr_free_string, NULL);
|
||||
// StringBuilder
|
||||
kt_register(StringBuilder, __StringBuilder_free, NULL);
|
||||
}
|
||||
|
||||
@ -1,36 +1,50 @@
|
||||
# kprintf
|
||||
It is just my variant of printf.
|
||||
It is just my cross-plaform variant of printf.
|
||||
Unlike in standard printf, `%l...` and `%ll...` placeholders dont depend on size of `long int` and `long long int`. And you can change terminal colors by unix codes (`\e[92m`) even on Windows.
|
||||
|
||||
| type | placeholder |
|
||||
|-------------------------|-------------------------|
|
||||
| int8 / int16 / int32 | %i / %d |
|
||||
| int64 | %li / %ld / %lld / %lli |
|
||||
| uint8 / uint16 / uint32 | %u |
|
||||
| uint64 | %lu / %llu |
|
||||
| float32 / float64 | %f |
|
||||
| char | %c |
|
||||
| char[] | %s |
|
||||
| void\* | %p / %x |
|
||||
|
||||
<br>
|
||||
|
||||
# kprint
|
||||
I don't really like printf function (and its variants), so i made safer and more convinient replacement.
|
||||
|
||||
| function | returns | arguments |
|
||||
|----------|---------|-----------|
|
||||
| kprint | void/throw | kprint_format, void*, kprint_format, void*... |
|
||||
| ksprint | Maybe<char*> | kprint_format, void*, kprint_format, void*... |
|
||||
| kfprint | Maybe<void> | FILE*, kprint_format, void*, kprint_format, void*... |
|
||||
| kprint | void/throw | kp_fmt, void\*, kp_fmt, void\*... |
|
||||
| ksprint | Maybe<char\*>| kp_fmt, void\*, kp_fmt, void\*... |
|
||||
| kfprint | Maybe<void> | FILE\*, kp_fmt, void\*, kp_fmt, void\*... |
|
||||
|
||||
## how to use it:
|
||||
+ **format construction:**
|
||||
```
|
||||
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktid;
|
||||
kp_fmt fmt= kp_fgColor | kp_bgColor | kprint_fdataFmt | flags | ktid;
|
||||
```
|
||||
[more about `kprint_format`](kprint_format.md)
|
||||
[more about `kp_fmt`](kp_fmt.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
|
||||
|
||||
+ **using base type arguments:**
|
||||
you can just put them into a function
|
||||
```
|
||||
kprint(kprint_fmtHex | kprint_fmtUppercase | kprint_fmtWithPrefix, 255);
|
||||
kprint(kp_h|kp_upper|kp_prefix, 255);
|
||||
```
|
||||
output: 0xFF
|
||||
+ **using other registered types:**
|
||||
should be sent as pointers
|
||||
```
|
||||
Maybe m=MaybeNull;
|
||||
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktid_MaybePtr, &m);
|
||||
kprint(kp_fgBlue|kp_s, "Maybe: ", kp_fgGreen|ktid_MaybePtr, &m);
|
||||
```
|
||||
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktid_Null}}</span>
|
||||
@ -1,29 +1,29 @@
|
||||
#include "../String/StringBuilder.h"
|
||||
#include "kprint.h"
|
||||
|
||||
ktid __typeFromFormat(kprint_format f){
|
||||
ktid typeId=kprint_format_ktid(f);
|
||||
ktid __typeFromFormat(kp_fmt f){
|
||||
ktid typeId=kp_fmt_ktid(f);
|
||||
if(typeId)
|
||||
return typeId;
|
||||
switch(kprint_format_dataFormat(f)){
|
||||
case kprint_fmtInt:
|
||||
case kprint_fmtHex:
|
||||
case kprint_fmtBin:
|
||||
switch(kp_fmt_dataFormat(f)){
|
||||
case kp_i:
|
||||
case kp_h:
|
||||
case kp_b:
|
||||
return ktid_name(int64);
|
||||
case kprint_fmtUInt:
|
||||
case kp_u:
|
||||
return ktid_name(uint64);
|
||||
case kprint_fmtFloat:
|
||||
case kp_f:
|
||||
return ktid_name(float64);
|
||||
case kprint_fmtChar:
|
||||
case kp_c:
|
||||
return ktid_char;
|
||||
case kprint_fmtString:
|
||||
case kp_s:
|
||||
return ktid_ptrName(char);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
||||
Maybe __next_toString(kp_fmt f, __kp_value_union* object){
|
||||
// detecting type
|
||||
ktid typeId=__typeFromFormat(f);
|
||||
if(typeId==-1)
|
||||
@ -34,7 +34,14 @@ Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
||||
return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f)));
|
||||
}
|
||||
|
||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
Maybe check_argsN(uint8 n){
|
||||
if(n%2 != 0) safethrow("kprint recieved non-even number of arguments",;);
|
||||
if(n > 32) safethrow("kprint recieved >32 number of arguments",;);
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||
try(check_argsN(n), _,;);
|
||||
n/=2;
|
||||
StringBuilder* strb=StringBuilder_create();
|
||||
for(uint8 i=0; i<n; i++){
|
||||
@ -46,7 +53,8 @@ Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
return SUCCESS(UniHeapPtr(char, rezult));
|
||||
}
|
||||
|
||||
Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
Maybe __kfprint(FILE* file, uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||
try(check_argsN(n), _,;);
|
||||
n/=2;
|
||||
for(uint8 i=0; i<n; i++){
|
||||
try(__next_toString(formats[i], &objects[i]),maybeStr,;);
|
||||
@ -58,10 +66,11 @@ Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_unio
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects){
|
||||
tryLast(check_argsN(n), _);
|
||||
n/=2;
|
||||
for(uint8 i=0; i<n; i++){
|
||||
kprint_format fmt=formats[i];
|
||||
kp_fmt fmt=formats[i];
|
||||
kprint_setColor(fmt);
|
||||
tryLast(__next_toString(fmt, &objects[i]),maybeStr);
|
||||
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF)\
|
||||
@ -76,72 +85,72 @@ void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||
#include <windows.h>
|
||||
#define FOREGROUND_YELLOW FOREGROUND_GREEN | FOREGROUND_RED
|
||||
|
||||
DWORD kprint_fgColor_toWin(kprint_fgColor f){
|
||||
DWORD kp_fgColor_toWin(kp_fgColor f){
|
||||
//kprintf("fg: %x\n", f);
|
||||
switch(f){
|
||||
case kprint_fgBlack: return 0;
|
||||
case kprint_fgDarkRed: return FOREGROUND_RED;
|
||||
case kprint_fgDarkGreen: return FOREGROUND_GREEN;
|
||||
case kprint_fgDarkYellow: return FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
case kprint_fgDarkBlue: return FOREGROUND_BLUE;
|
||||
case kprint_fgDarkMagenta: return FOREGROUND_RED | FOREGROUND_BLUE;
|
||||
case kprint_fgDarkCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN;
|
||||
case kprint_fgGray: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
case kprint_fgDarkGray: return FOREGROUND_INTENSITY;
|
||||
case kprint_fgRed: return FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kprint_fgGreen: return FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
case kprint_fgYellow: return FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kprint_fgBlue: return FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||
case kprint_fgMagenta: return FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kprint_fgCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
case kprint_fgWhite: return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
case kp_fgBlack: return 0;
|
||||
case kp_fgRedD: return FOREGROUND_RED;
|
||||
case kp_fgGreenD: return FOREGROUND_GREEN;
|
||||
case kp_fgYellowD: return FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
case kp_fgBlueD: return FOREGROUND_BLUE;
|
||||
case kp_fgMagentaD: return FOREGROUND_RED | FOREGROUND_BLUE;
|
||||
case kp_fgCyanD: return FOREGROUND_BLUE | FOREGROUND_GREEN;
|
||||
case kp_fgGray: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
||||
case kp_fgGrayD: return FOREGROUND_INTENSITY;
|
||||
case kp_fgRed: return FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kp_fgGreen: return FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
case kp_fgYellow: return FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kp_fgBlue: return FOREGROUND_BLUE | FOREGROUND_INTENSITY;
|
||||
case kp_fgMagenta: return FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
|
||||
case kp_fgCyan: return FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
case kp_fgWhite: return FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
|
||||
default: throw(ERR_FORMAT);
|
||||
}
|
||||
}
|
||||
|
||||
DWORD kprint_bgColor_toWin(kprint_bgColor f){
|
||||
DWORD kp_bgColor_toWin(kp_bgColor f){
|
||||
//kprintf("bg: %x\n", f);
|
||||
switch(f){
|
||||
case kprint_bgBlack: return 0;
|
||||
case kprint_bgDarkRed: return BACKGROUND_RED;
|
||||
case kprint_bgDarkGreen: return BACKGROUND_GREEN;
|
||||
case kprint_bgDarkYellow: return BACKGROUND_GREEN | BACKGROUND_RED;
|
||||
case kprint_bgDarkBlue: return BACKGROUND_BLUE;
|
||||
case kprint_bgDarkMagenta: return BACKGROUND_RED | BACKGROUND_BLUE;
|
||||
case kprint_bgDarkCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN;
|
||||
case kprint_bgGray: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
|
||||
case kprint_bgDarkGray: return BACKGROUND_INTENSITY;
|
||||
case kprint_bgRed: return BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kprint_bgGreen: return BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
case kprint_bgYellow: return BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kprint_bgBlue: return BACKGROUND_BLUE | BACKGROUND_INTENSITY;
|
||||
case kprint_bgMagenta: return BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kprint_bgCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
case kprint_bgWhite: return BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
case kp_bgBlack: return 0;
|
||||
case kp_bgRedD: return BACKGROUND_RED;
|
||||
case kp_bgGreenD: return BACKGROUND_GREEN;
|
||||
case kp_bgYellowD: return BACKGROUND_GREEN | BACKGROUND_RED;
|
||||
case kp_bgBlueD: return BACKGROUND_BLUE;
|
||||
case kp_bgMagentaD: return BACKGROUND_RED | BACKGROUND_BLUE;
|
||||
case kp_bgCyanD: return BACKGROUND_BLUE | BACKGROUND_GREEN;
|
||||
case kp_bgGray: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
|
||||
case kp_bgGrayD: return BACKGROUND_INTENSITY;
|
||||
case kp_bgRed: return BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kp_bgGreen: return BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
case kp_bgYellow: return BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kp_bgBlue: return BACKGROUND_BLUE | BACKGROUND_INTENSITY;
|
||||
case kp_bgMagenta: return BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
|
||||
case kp_bgCyan: return BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
case kp_bgWhite: return BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY;
|
||||
default: throw(ERR_FORMAT);
|
||||
}
|
||||
}
|
||||
|
||||
void kprint_setColor(kprint_format f){
|
||||
void kprint_setColor(kp_fmt f){
|
||||
DWORD color=0;
|
||||
if(!kprint_format_fgColorChanged(f) & !kprint_format_bgColorChanged(f))
|
||||
if(!kp_fmt_fgColorSet(f) & !kp_fmt_bgColorSet(f))
|
||||
return;
|
||||
if(kprint_format_fgColorChanged(f))
|
||||
color+=kprint_fgColor_toWin(kprint_format_fgColor(f));
|
||||
if(kprint_format_bgColorChanged(f))
|
||||
color+=kprint_bgColor_toWin(kprint_format_bgColor(f));
|
||||
if(kp_fmt_fgColorSet(f))
|
||||
color+=kp_fgColor_toWin(kp_fmt_fgColor(f));
|
||||
if(kp_fmt_bgColorSet(f))
|
||||
color+=kp_bgColor_toWin(kp_fmt_bgColor(f));
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hConsole, color);
|
||||
}
|
||||
#else
|
||||
void kprint_setColor(kprint_format f){
|
||||
if(kprint_format_fgColorChanged(f)){
|
||||
void kprint_setColor(kp_fmt f){
|
||||
if(kp_fmt_fgColorSet(f)){
|
||||
uint8 fg=(f&0x0f000000)>>24;
|
||||
if(fg<8) fg+=30;
|
||||
else fg+=90-8;
|
||||
printf("\e[%um", fg);
|
||||
}
|
||||
if(kprint_format_bgColorChanged(f)){
|
||||
if(kp_fmt_bgColorSet(f)){
|
||||
uint8 bg=(f&0x00f00000)>>20;
|
||||
if(bg<8) bg+=40;
|
||||
else bg+=100-8;
|
||||
@ -150,7 +159,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, kp_fmt format, ktid typeId, void* array){
|
||||
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
||||
if(!typeDesc.toString)
|
||||
safethrow("type descriptor doesnt have toString() func",;);
|
||||
|
||||
@ -8,65 +8,98 @@ extern "C" {
|
||||
#include "kprint_colors.h"
|
||||
#include "kprint_format.h"
|
||||
|
||||
/*
|
||||
|
||||
This file looks like a mess, but all cotnent here just solves the problem of putting variadic arguments to array of formats and array of objects.
|
||||
|
||||
*/
|
||||
|
||||
typedef union {
|
||||
int64 i64;
|
||||
uint64 u64;
|
||||
float64 f64;
|
||||
void* ptr;
|
||||
} __kprint_value_union;
|
||||
#define __kprintVU(value) (__kprint_value_union){ value }
|
||||
} __kp_value_union;
|
||||
|
||||
#define __kprint_argsToFormats8(\
|
||||
|
||||
static inline __kp_value_union __kpVU_f(float64 f) { return (__kp_value_union){ .f64=f }; }
|
||||
inline __kp_value_union __kpVU_i(int64 f) { return (__kp_value_union){ .i64=f }; }
|
||||
|
||||
#define __kpVU_selectType(V) _Generic(V, float: __kpVU_f, double: __kpVU_f, default: __kpVU_i)(V)
|
||||
|
||||
#define __kpVU(V) __kpVU_selectType(V)
|
||||
|
||||
#define __kp_argsToFmts8(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||
((int32[]){ a0,a2,a4,a6 })
|
||||
#define __kprint_argsToObjects8(\
|
||||
#define __kp_argsToObjs8(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,...)\
|
||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7) })
|
||||
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7) })
|
||||
|
||||
#define __kprint_argsToFormats16(\
|
||||
#define __kp_argsToFmts16(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14 })
|
||||
#define __kprint_argsToObjects16(\
|
||||
#define __kp_argsToObjs16(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||
a8, a9, a10,a11,a12,a13,a14,a15,...)\
|
||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7),__kprintVU(a9),__kprintVU(a11),__kprintVU(a13),__kprintVU(a15) })
|
||||
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7),__kpVU(a9),__kpVU(a11),__kpVU(a13),__kpVU(a15) })
|
||||
|
||||
#define __kprint_argsToFormats32(\
|
||||
#define __kp_argsToFmts32(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
||||
((int32[]){ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 })
|
||||
#define __kprint_argsToObjects32(\
|
||||
#define __kp_argsToObjs32(\
|
||||
a0, a1, a2, a3, a4, a5, a6, a7,\
|
||||
a8, a9, a10,a11,a12,a13,a14,a15,\
|
||||
a16,a17,a18,a19,a20,a21,a22,a23,\
|
||||
a24,a25,a26,a27,a28,a29,a30,a31,...)\
|
||||
((__kprint_value_union[]){ __kprintVU(a1),__kprintVU(a3),__kprintVU(a5),__kprintVU(a7),__kprintVU(a9),__kprintVU(a11),__kprintVU(a13),__kprintVU(a15),__kprintVU(a17),__kprintVU(a19),__kprintVU(a21),__kprintVU(a23),__kprintVU(a25),__kprintVU(a27),__kprintVU(a29),__kprintVU(a31) })
|
||||
((__kp_value_union[]){ __kpVU(a1),__kpVU(a3),__kpVU(a5),__kpVU(a7),__kpVU(a9),__kpVU(a11),__kpVU(a13),__kpVU(a15),__kpVU(a17),__kpVU(a19),__kpVU(a21),__kpVU(a23),__kpVU(a25),__kpVU(a27),__kpVU(a29),__kpVU(a31) })
|
||||
|
||||
#define __32zeroes 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
|
||||
#define __kprint_argsToArrs(COUNT,ARGS...)\
|
||||
(kprint_format*)(COUNT<=8 ? __kprint_argsToFormats8(ARGS) :\
|
||||
COUNT<=16 ? __kprint_argsToFormats16(ARGS) :\
|
||||
__kprint_argsToFormats32(ARGS)),\
|
||||
(__kprint_value_union*)(COUNT<=8 ? __kprint_argsToObjects8(ARGS) :\
|
||||
COUNT<=16 ? __kprint_argsToObjects16(ARGS) :\
|
||||
__kprint_argsToObjects32(ARGS))
|
||||
#define __kp_argsToArrs(COUNT,ARGS...)\
|
||||
(kp_fmt*)(\
|
||||
COUNT<=8 ? __kp_argsToFmts8(ARGS) :\
|
||||
COUNT<=16 ? __kp_argsToFmts16(ARGS) :\
|
||||
__kp_argsToFmts32(ARGS)),\
|
||||
(__kp_value_union*)(\
|
||||
COUNT<=8 ? __kp_argsToObjs8(ARGS) :\
|
||||
COUNT<=16 ? __kp_argsToObjs16(ARGS) :\
|
||||
__kp_argsToObjs32(ARGS))
|
||||
|
||||
|
||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
||||
#define ksprint(ARGS...) __ksprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
||||
Maybe __ksprint(uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||
|
||||
Maybe __kfprint(FILE* fd, uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
||||
#define kfprint(FD, ARGS...) __kfprint(FD, count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
||||
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
||||
///@returns Maybe<char*>
|
||||
#define ksprint(ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||
__ksprint(count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||
)
|
||||
/*-Wint-conversion warning was produced during value to __kp_value_union conversion*/
|
||||
|
||||
void __kprint(uint8 n, kprint_format* formats, __kprint_value_union* objects);
|
||||
#define kprint(ARGS...) __kprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS, __32zeroes))
|
||||
Maybe __kfprint(FILE* fd, uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||
|
||||
// can take (bgColor | fgColor)
|
||||
void kprint_setColor(kprint_format f);
|
||||
/// @param FD FILE*
|
||||
/// @param ARGS kp_fmt, value, kp_fmt, value...
|
||||
///@returns Maybe<void>
|
||||
#define kfprint(FD, ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||
__kfprint(FD, count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||
)
|
||||
|
||||
void __kprint(uint8 n, kp_fmt* formats, __kp_value_union* objects);
|
||||
|
||||
///can use non-catchable throw !!!
|
||||
///@param ARGS kp_fmt, value, kp_fmt, value...
|
||||
///@returns void
|
||||
#define kprint(ARGS...) WARNING_DISABLE( W_INT_CONVERSION,\
|
||||
__kprint(count_args(ARGS), __kp_argsToArrs(count_args(ARGS),ARGS, __32zeroes))\
|
||||
)
|
||||
|
||||
///@param f bgColor | fgColor
|
||||
void kprint_setColor(kp_fmt f);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@ -4,51 +4,82 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum kprint_fgColor{
|
||||
// 10000000 00000000 00000000 00000000
|
||||
// ^ ^^^^
|
||||
// | color num
|
||||
// fgColorChanged flag
|
||||
// fgColorSet flag
|
||||
PACK_ENUM(kp_fgColor,
|
||||
/// black foreground
|
||||
kp_fgBlack = 0x80000000,
|
||||
/// dark red foreground
|
||||
kp_fgRedD = 0x81000000,
|
||||
/// dark green foreground
|
||||
kp_fgGreenD = 0x82000000,
|
||||
/// dark yellow foreground
|
||||
kp_fgYellowD = 0x83000000,
|
||||
/// dark blue foreground
|
||||
kp_fgBlueD = 0x84000000,
|
||||
/// dark magenta foreground
|
||||
kp_fgMagentaD= 0x85000000,
|
||||
/// dark cyan foreground
|
||||
kp_fgCyanD = 0x86000000,
|
||||
/// gray foreground
|
||||
kp_fgGray = 0x87000000,
|
||||
/// dark gray foreground
|
||||
kp_fgGrayD = 0x88000000,
|
||||
/// red foreground
|
||||
kp_fgRed = 0x89000000,
|
||||
/// green foreground
|
||||
kp_fgGreen = 0x8a000000,
|
||||
/// yellow foreground
|
||||
kp_fgYellow = 0x8b000000,
|
||||
/// blue foreground
|
||||
kp_fgBlue = 0x8c000000,
|
||||
/// magenta foreground
|
||||
kp_fgMagenta = 0x8d000000,
|
||||
/// cyan foreground
|
||||
kp_fgCyan = 0x8e000000,
|
||||
/// white foreground
|
||||
kp_fgWhite = 0x8f000000
|
||||
)
|
||||
|
||||
kprint_fgBlack = 0x80000000,
|
||||
kprint_fgDarkRed = 0x81000000,
|
||||
kprint_fgDarkGreen = 0x82000000,
|
||||
kprint_fgDarkYellow = 0x83000000,
|
||||
kprint_fgDarkBlue = 0x84000000,
|
||||
kprint_fgDarkMagenta= 0x85000000,
|
||||
kprint_fgDarkCyan = 0x86000000,
|
||||
kprint_fgGray = 0x87000000,
|
||||
kprint_fgDarkGray = 0x88000000,
|
||||
kprint_fgRed = 0x89000000,
|
||||
kprint_fgGreen = 0x8a000000,
|
||||
kprint_fgYellow = 0x8b000000,
|
||||
kprint_fgBlue = 0x8c000000,
|
||||
kprint_fgMagenta = 0x8d000000,
|
||||
kprint_fgCyan = 0x8e000000,
|
||||
kprint_fgWhite = 0x8f000000
|
||||
} kprint_fgColor;
|
||||
|
||||
typedef enum kprint_bgColor{
|
||||
// 01000000 00000000 00000000 00000000
|
||||
// ^ ^^^^
|
||||
// bgColorChanged flag color num
|
||||
kprint_bgBlack = 0x40000000,
|
||||
kprint_bgDarkRed = 0x40100000,
|
||||
kprint_bgDarkGreen = 0x40200000,
|
||||
kprint_bgDarkYellow = 0x40300000,
|
||||
kprint_bgDarkBlue = 0x40400000,
|
||||
kprint_bgDarkMagenta= 0x40500000,
|
||||
kprint_bgDarkCyan = 0x40600000,
|
||||
kprint_bgGray = 0x40700000,
|
||||
kprint_bgDarkGray = 0x40800000,
|
||||
kprint_bgRed = 0x40900000,
|
||||
kprint_bgGreen = 0x40a00000,
|
||||
kprint_bgYellow = 0x40b00000,
|
||||
kprint_bgBlue = 0x40c00000,
|
||||
kprint_bgMagenta = 0x40d00000,
|
||||
kprint_bgCyan = 0x40e00000,
|
||||
kprint_bgWhite = 0x40f00000
|
||||
} kprint_bgColor;
|
||||
// bgColorSet flag color num
|
||||
PACK_ENUM(kp_bgColor,
|
||||
/// black background
|
||||
kp_bgBlack = 0x40000000,
|
||||
/// dark red background
|
||||
kp_bgRedD = 0x40100000,
|
||||
/// dark green background
|
||||
kp_bgGreenD = 0x40200000,
|
||||
/// dark yellow background
|
||||
kp_bgYellowD = 0x40300000,
|
||||
/// dark blue background
|
||||
kp_bgBlueD = 0x40400000,
|
||||
/// dark magenta background
|
||||
kp_bgMagentaD= 0x40500000,
|
||||
/// dark cyan background
|
||||
kp_bgCyanD = 0x40600000,
|
||||
/// gray background
|
||||
kp_bgGray = 0x40700000,
|
||||
/// dark gray background
|
||||
kp_bgGrayD = 0x40800000,
|
||||
/// red background
|
||||
kp_bgRed = 0x40900000,
|
||||
/// green background
|
||||
kp_bgGreen = 0x40a00000,
|
||||
/// yellow background
|
||||
kp_bgYellow = 0x40b00000,
|
||||
/// blue background
|
||||
kp_bgBlue = 0x40c00000,
|
||||
/// magenta background
|
||||
kp_bgMagenta = 0x40d00000,
|
||||
/// cyan background
|
||||
kp_bgCyan = 0x40e00000,
|
||||
/// white background
|
||||
kp_bgWhite = 0x40f00000
|
||||
)
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@ -7,41 +7,42 @@ extern "C" {
|
||||
#include "../base/std.h"
|
||||
#include "../base/type_system/ktid.h"
|
||||
|
||||
typedef enum kprint_dataFormat{
|
||||
/// kprint_format
|
||||
typedef uint32 kp_fmt;
|
||||
|
||||
PACK_ENUM(kp_dataFmt,
|
||||
// 00000000 00000000 00000000 00000000
|
||||
// ^^^^
|
||||
// type
|
||||
kprint_fmtInt = 0x00000000,
|
||||
kprint_fmtUInt = 0x00010000,
|
||||
kprint_fmtHex = 0x00020000,
|
||||
kprint_fmtBin = 0x00030000,
|
||||
kprint_fmtFloat = 0x00040000,
|
||||
kprint_fmtChar = 0x00050000,
|
||||
kprint_fmtString = 0x00060000,
|
||||
kp_i = 0x00000000,
|
||||
kp_u = 0x00010000,
|
||||
kp_h = 0x00020000,
|
||||
kp_b = 0x00030000,
|
||||
kp_f = 0x00040000,
|
||||
kp_c = 0x00050000,
|
||||
kp_s = 0x00060000,
|
||||
|
||||
// 00100000 00000000 00000000 00000000
|
||||
// ^
|
||||
// prefix/postfix flag
|
||||
kprint_fmtWithPrefix=0x20000000,
|
||||
kprint_fmtWithPostfix=kprint_fmtWithPrefix,
|
||||
kp_pre=0x20000000,
|
||||
kp_post=kp_pre,
|
||||
|
||||
// 00010000 00000000 00000000 00000000
|
||||
// ^
|
||||
// uppercase flag
|
||||
kprint_fmtUppercase=0x10000000
|
||||
} kprint_dataFormat;
|
||||
kp_upper=0x10000000
|
||||
)
|
||||
|
||||
typedef uint32 kprint_format;
|
||||
|
||||
#define kprint_format_fgColorChanged(FMT) (FMT&0x80000000)
|
||||
#define kprint_format_bgColorChanged(FMT) (FMT&0x40000000)
|
||||
#define kprint_format_withPrefix(FMT) (FMT&kprint_fmtWithPrefix)
|
||||
#define kprint_format_withPostfix(FMT) (FMT&kprint_fmtWithPostfix)
|
||||
#define kprint_format_uppercase(FMT) (FMT&kprint_fmtUppercase)
|
||||
#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 kp_fmt_fgColorSet(FMT) (bool)((FMT&0x80000000)!=0)
|
||||
#define kp_fmt_bgColorSet(FMT) (bool)((FMT&0x40000000)!=0)
|
||||
#define kp_fmt_withPrefix(FMT) (bool)((FMT&kp_pre)!=0)
|
||||
#define kp_fmt_withPostfix(FMT) (bool)((FMT&kp_post)!=0)
|
||||
#define kp_fmt_isUpper(FMT) (bool)((FMT&kp_upper)!=0)
|
||||
#define kp_fmt_fgColor(FMT) (kp_fgColor)(FMT&0x8f000000)
|
||||
#define kp_fmt_bgColor(FMT) (kp_bgColor)(FMT&0x40f00000)
|
||||
#define kp_fmt_dataFormat(FMT) (kp_dataFmt)(FMT&0x000f0000)
|
||||
#define kp_fmt_ktid(FMT) (ktid)(FMT&0x0000ffff)
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
@ -12,17 +12,17 @@ bgColorSet─┘││ │ bgColor └data format
|
||||
## Console colors
|
||||
### *Foreground*
|
||||
|
||||
| kprint_fg | hex | bin |
|
||||
|-----------|-----|-----|
|
||||
| kp_fg | hex | bin |
|
||||
|-------|-----|-----|
|
||||
| Black | 0x80000000 | 10000000 00000000... |
|
||||
| DarkRed | 0x81000000 | 10000001 00000000... |
|
||||
| DarkGreen | 0x82000000 | 10000010 00000000... |
|
||||
| DarkYellow | 0x83000000 | 10000011 00000000... |
|
||||
| DarkBlue | 0x84000000 | 10000100 00000000... |
|
||||
| DarkMagenta | 0x85000000 | 10000101 00000000... |
|
||||
| DarkCyan | 0x86000000 | 10000110 00000000... |
|
||||
| RedD | 0x81000000 | 10000001 00000000... |
|
||||
| GreenD | 0x82000000 | 10000010 00000000... |
|
||||
| YellowD | 0x83000000 | 10000011 00000000... |
|
||||
| BlueD | 0x84000000 | 10000100 00000000... |
|
||||
| MagentaD | 0x85000000 | 10000101 00000000... |
|
||||
| CyanD | 0x86000000 | 10000110 00000000... |
|
||||
| Gray | 0x87000000 | 10000111 00000000... |
|
||||
| DarkGray | 0x88000000 | 10001000 00000000... |
|
||||
| GrayD | 0x88000000 | 10001000 00000000... |
|
||||
| Red | 0x89000000 | 10001001 00000000... |
|
||||
| Green | 0x8a000000 | 10001010 00000000... |
|
||||
| Yellow | 0x8b000000 | 10001011 00000000... |
|
||||
@ -32,17 +32,17 @@ bgColorSet─┘││ │ bgColor └data format
|
||||
| White | 0x8f000000 | 10001111 00000000... |
|
||||
|
||||
### *Background*
|
||||
| kprint_bg | hex | bin |
|
||||
|-----------|-----|-----|
|
||||
| kp_bg | hex | bin |
|
||||
|-------|-----|-----|
|
||||
| Black | 0x40000000 | 01000000 00000000... |
|
||||
| DarkRed | 0x40100000 | 01000000 00010000... |
|
||||
| DarkGreen | 0x40200000 | 01000000 00100000... |
|
||||
| DarkYellow | 0x40300000 | 01000000 00110000... |
|
||||
| DarkBlue | 0x40400000 | 01000000 01000000... |
|
||||
| DarkMagenta | 0x40500000 | 01000000 01010000... |
|
||||
| DarkCyan | 0x40600000 | 01000000 01100000... |
|
||||
| RedD | 0x40100000 | 01000000 00010000... |
|
||||
| GreenD | 0x40200000 | 01000000 00100000... |
|
||||
| YellowD | 0x40300000 | 01000000 00110000... |
|
||||
| BlueD | 0x40400000 | 01000000 01000000... |
|
||||
| MagentaD | 0x40500000 | 01000000 01010000... |
|
||||
| CyanD | 0x40600000 | 01000000 01100000... |
|
||||
| Gray | 0x40700000 | 01000000 01110000... |
|
||||
| DarkGray | 0x40800000 | 01000000 10000000... |
|
||||
| GrayD | 0x40800000 | 01000000 10000000... |
|
||||
| Red | 0x40900000 | 01000000 10010000... |
|
||||
| Green | 0x40a00000 | 01000000 10100000... |
|
||||
| Yellow | 0x40b00000 | 01000000 10110000... |
|
||||
@ -54,19 +54,19 @@ bgColorSet─┘││ │ bgColor └data format
|
||||
|
||||
## Data format
|
||||
|
||||
| kprint_fmt | possible flags | data types | hex value | bin value |
|
||||
|------------|----------------|------------|-----------|-----------|
|
||||
| Int | | int8... int64 | 0x00000000 | 00000000 00000000... |
|
||||
| UInt | WithPostfix, Uppercase | uint8... uint64 | 0x00010000 | 00000000 00000001... |
|
||||
| Hex | WithPrefix, Uppercase | any | 0x00020000 | 00000000 00000010... |
|
||||
| Bin | WithPrefix, | any | 0x00030000 | 00000000 00000011... |
|
||||
| Float | WithPostfix, Uppercase | float32, float64 | 0x00040000 | 00000000 00000100... |
|
||||
| Char | | char | 0x00050000 | 00000000 00000101... |
|
||||
| String | | char* | 0x00060000 | 00000000 00000110... |
|
||||
| format | possible flags | data types | hex value | bin value |
|
||||
|-----------|----------------|------------|-----------|-----------|
|
||||
| kp_i | | int8... int64 | 0x00000000 | 00000000 00000000... |
|
||||
| kp_u | Postfix, Upper | uint8... uint64 | 0x00010000 | 00000000 00000001... |
|
||||
| kp_h | Prefix, Upper | any | 0x00020000 | 00000000 00000010... |
|
||||
| kp_b | Prefix | any | 0x00030000 | 00000000 00000011... |
|
||||
| kp_f | Postfix, Upper | float32, float64 | 0x00040000 | 00000000 00000100... |
|
||||
| kp_c | | char | 0x00050000 | 00000000 00000101... |
|
||||
| kp_sing | | char* | 0x00060000 | 00000000 00000110... |
|
||||
|
||||
### *Flags*
|
||||
| kprint_fmt | hex value | bin value |
|
||||
|-------------|------------|-----------|
|
||||
| withPrefix | 0x20000000 | 00100000 00000000... |
|
||||
| withPostfix | 0x20000000 | 00100000 00000000... |
|
||||
| upperase | 0x10000000 | 00010000 00000000... |
|
||||
| flag | hex value | bin value |
|
||||
|------|------------|-----------|
|
||||
| kp_pre | 0x20000000 | 00100000 00000000... |
|
||||
| kp_post | 0x20000000 | 00100000 00000000... |
|
||||
| kp_upper | 0x10000000 | 00010000 00000000... |
|
||||
|
||||
@ -53,42 +53,35 @@ void kprintf(const char* format, ...){
|
||||
for(char c=format[i++]; c!=0; c=format[i++]){
|
||||
if(c=='%'){
|
||||
char* argstr=NULL;
|
||||
bool l=false;
|
||||
c=format[i++];
|
||||
format_escape_seq:
|
||||
switch (c) {
|
||||
case 'u':
|
||||
argstr=toString_uint(va_arg(vl, uint64),0,0);
|
||||
argstr=toString_uint(
|
||||
l ? va_arg(vl, uint64) : va_arg(vl, uint32)
|
||||
,0,0);
|
||||
break;
|
||||
case 'i': case 'd':
|
||||
argstr=toString_int(va_arg(vl, uint64));
|
||||
argstr=toString_int(
|
||||
l ? va_arg(vl, int64) : va_arg(vl, int32)
|
||||
);
|
||||
break;
|
||||
case 'f':
|
||||
argstr=toString_float(va_arg(vl, float64),0,0);
|
||||
// float32 is promoted to float64 when passed through '...'
|
||||
argstr=toString_float64(va_arg(vl, float64), toString_float_default_precision,0,0);
|
||||
break;
|
||||
case 'l':
|
||||
l=true;
|
||||
if((c=format[i++]))
|
||||
goto format_escape_seq;
|
||||
break;
|
||||
// switch (c) {
|
||||
// case 'u':
|
||||
// argstr=toString_uint(va_arg(vl, uint64),0,0);
|
||||
// break;
|
||||
// case 'i':
|
||||
// argstr=toString_int(va_arg(vl, uint64));
|
||||
// break;
|
||||
// case 'f':
|
||||
// argstr=toString_float(va_arg(vl, float64),0,0);
|
||||
// break;
|
||||
// default:
|
||||
// throw(ERR_FORMAT);
|
||||
// }
|
||||
// break;
|
||||
case 'p':
|
||||
case 'x':
|
||||
case 'x': ;
|
||||
uint64 px=va_arg(vl, uint64);
|
||||
argstr=toString_hex(&px,sizeof(px),1,0);
|
||||
argstr=toString_hex(&px,getEndian()==LittleEndian,sizeof(px),1,0);
|
||||
break;
|
||||
case 's':
|
||||
case 's': ;
|
||||
char* cptr=va_arg(vl,char*);
|
||||
if(!cptr)
|
||||
cptr="<nullstr>";
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// cross-platform kprintf analog
|
||||
// cross-platform printf analog
|
||||
void kprintf(const char* format, ...);
|
||||
|
||||
#if __cplusplus
|
||||
|
||||
@ -1,26 +1,12 @@
|
||||
#include "tests.h"
|
||||
|
||||
void test_all(){
|
||||
test_string();
|
||||
test_safethrow();
|
||||
test_searchtree();
|
||||
test_autoarr();
|
||||
test_autoarrVsVector();
|
||||
test_hash_functions();
|
||||
test_hashtable();
|
||||
test_dtsod();
|
||||
test_rng_algorithms();
|
||||
test_kprint_colors();
|
||||
kprintf("\e[96m--------------------------------------\e[0m\n");
|
||||
}
|
||||
int main(){
|
||||
if(!setlocale(LC_ALL, "C.UTF8"))
|
||||
kprintf("\e[93msetlocale failed\n");
|
||||
ktDescriptors_beginInit();
|
||||
ktDescriptors_initKerepTypes();
|
||||
ktDescriptors_endInit();
|
||||
kprintf("\e[97mkerep tests are starting!\n");
|
||||
optime("test_all",1,test_all());
|
||||
test_all();
|
||||
ktDescriptors_free();
|
||||
kprintf("\e[0m\n");
|
||||
return 0;
|
||||
|
||||
@ -7,28 +7,21 @@ int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){
|
||||
kprintf("\e[94mblock count: %u block length: %u count: " IFWIN("%llu", "%lu") "\n", blockCount, blockLength, (uint64)count);
|
||||
Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength);
|
||||
std::vector<int64> vec=std::vector<int64>();
|
||||
optime("Autoarr_add", 1, ({
|
||||
for(uint32 i=0; i< count; i++)
|
||||
Autoarr_add(ar, i);
|
||||
}));
|
||||
optime("vector_push_back", 1, ({
|
||||
for(uint32 i=0; i< count; i++)
|
||||
vec.push_back(i);
|
||||
}));
|
||||
optime("Autoarr_add", count,
|
||||
Autoarr_add(ar, op_i));
|
||||
optime("vector_push_back", count,
|
||||
vec.push_back(op_i));
|
||||
int64 t=0;
|
||||
optime("Autoarr_get", 1, ({
|
||||
for(uint32 i=0; i< count; i++)
|
||||
t=Autoarr_get(ar, i);
|
||||
}));
|
||||
optime("vector_get", 1, ({
|
||||
for(uint32 i=0; i< count; i++)
|
||||
t=vec[i];
|
||||
}));
|
||||
optime("Autoarr_get", count,
|
||||
t=Autoarr_get(ar, op_i));
|
||||
optime("vector_get", count,
|
||||
t=vec[op_i]);
|
||||
Autoarr_free(ar, true);
|
||||
return t;
|
||||
}
|
||||
|
||||
void test_autoarrVsVector(){
|
||||
optime(__func__, 1, ({
|
||||
kprintf("\e[96m-------[test_autoarr_vs_vector]-------\n");
|
||||
_autoarrVsVector(4, 16);
|
||||
_autoarrVsVector(16, 64);
|
||||
@ -37,4 +30,5 @@ void test_autoarrVsVector(){
|
||||
_autoarrVsVector(32, 1024);
|
||||
_autoarrVsVector(256, 256);
|
||||
_autoarrVsVector(1024, 1024);
|
||||
}));
|
||||
}
|
||||
|
||||
50
tests/test_kprint.c
Normal file
50
tests/test_kprint.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include "tests.h"
|
||||
#include "../src/kprint/kprint.h"
|
||||
|
||||
void test_kprint(){
|
||||
//int
|
||||
kprint(kp_fgCyan|
|
||||
kp_i,-8888, kp_c,' ', kp_i,0, kp_c,' ', kp_i,1234567890987654321LL,kp_s,"\n");
|
||||
//uint
|
||||
kprint(kp_fgGreen|
|
||||
kp_u|kp_post,-8888, kp_c|kp_post|kp_upper,' ', kp_u,0, kp_c,' ',
|
||||
kp_u,1234567890987654321LL, kp_c,'\n');
|
||||
//float
|
||||
kprint(kp_fgCyanD|
|
||||
kp_f,-4000.0109f, kp_c,' ', kp_f,-0.000020004f, kp_c,'\n',
|
||||
kp_f,-1.0f, kp_c,' ', kp_f,0.0f, kp_c,' ', kp_f,1.0f, kp_c,'\n',
|
||||
kp_f|kp_post,0.000020004f, kp_c,' ',
|
||||
kp_f|kp_post|kp_upper,4000.0109f, kp_c,'\n');
|
||||
//double
|
||||
kprint(kp_fgYellowD|
|
||||
kp_f,-4000.0109, kp_c,' ', kp_f,-0.000020004, kp_c,'\n',
|
||||
kp_f,-1.0, kp_c,' ', kp_f,0.0, kp_c,' ', kp_f,1.0, kp_c,'\n',
|
||||
kp_f|kp_post,0.000020004, kp_c,' ',
|
||||
kp_f|kp_post|kp_upper,4000.0109, kp_c,'\n');
|
||||
//hex
|
||||
kprint(kp_fgYellow|
|
||||
kp_h,0, kp_c,' ', kp_h,1, kp_c,' ', kp_h,-1, kp_c,' ', kp_h,15, kp_c,'\n',
|
||||
kp_h,4095, kp_c,' ', kp_h,-4095, kp_c,'\n',
|
||||
kp_h,1234567890987654321LL, kp_c,'\n', kp_h,-1234567890987654321LL, kp_c,'\n');
|
||||
kprint(
|
||||
kp_h,-1.0f, kp_c,' ', kp_h,0.0f, kp_c,' ', kp_h,1.0f, kp_c,'\n',
|
||||
kp_h, 0.00016f, kp_c,' ', kp_h,-115515.009f, kp_c,'\n');
|
||||
kprint(
|
||||
kp_h|kp_pre, 0.00016, kp_c,'\n',
|
||||
kp_h|kp_pre|kp_upper,-115515.009, kp_c,'\n');
|
||||
//bin
|
||||
kprint(kp_fgBlue|
|
||||
kp_b,0, kp_c,'\n', kp_b,1, kp_c,'\n', kp_b,-1, kp_c,'\n', kp_b,15, kp_c,'\n',
|
||||
kp_b,4095, kp_c,'\n', kp_b,-4095, kp_c,'\n',
|
||||
kp_b,1234567890987654321LL, kp_c,'\n', kp_b,-1234567890987654321LL, kp_c,'\n');
|
||||
kprint(
|
||||
kp_b,-1.0f, kp_c,'\n', kp_b,0.0f, kp_c,'\n', kp_b,1.0f, kp_c,'\n',
|
||||
kp_b, 0.00016f, kp_c,'\n', kp_b,-115515.009f, kp_c,'\n');
|
||||
kprint(
|
||||
kp_b|kp_pre, 0.00016, kp_c,'\n',
|
||||
kp_b|kp_pre|kp_upper,-115515.009, kp_c,'\n');
|
||||
//string
|
||||
kprint(kp_s|kp_fgYellow, "\n ooo \n",
|
||||
kp_s|kp_fgWhite, "gg",
|
||||
kp_fgGray|kp_bgBlack|kp_s, "\n");
|
||||
}
|
||||
@ -5,11 +5,11 @@
|
||||
#endif
|
||||
|
||||
#define testColor(COLOR) \
|
||||
kprint_setColor(kprint_bgBlack | kprint_fg##COLOR);\
|
||||
kprint_setColor(kp_bgBlack|kp_fg##COLOR);\
|
||||
kprintf(#COLOR " ");\
|
||||
kprint_setColor(kprint_bg##COLOR | kprint_fgGray);\
|
||||
kprint_setColor(kp_bg##COLOR|kp_fgGray);\
|
||||
kprintf(#COLOR);\
|
||||
kprint_setColor(kprint_bgBlack | kprint_fgBlack);\
|
||||
kprint_setColor(kp_bgBlack|kp_fgBlack);\
|
||||
kprintf("\n");
|
||||
|
||||
void test_kprint_colors(){
|
||||
@ -29,14 +29,14 @@ void test_kprint_colors(){
|
||||
kprintf("\n"); */
|
||||
|
||||
testColor(Black);
|
||||
testColor(DarkRed);
|
||||
testColor(DarkGreen);
|
||||
testColor(DarkYellow);
|
||||
testColor(DarkBlue);
|
||||
testColor(DarkMagenta);
|
||||
testColor(DarkCyan);
|
||||
testColor(RedD);
|
||||
testColor(GreenD);
|
||||
testColor(YellowD);
|
||||
testColor(BlueD);
|
||||
testColor(MagentaD);
|
||||
testColor(CyanD);
|
||||
testColor(Gray);
|
||||
testColor(DarkGray);
|
||||
testColor(GrayD);
|
||||
testColor(Red);
|
||||
testColor(Green);
|
||||
testColor(Yellow);
|
||||
@ -44,7 +44,5 @@ void test_kprint_colors(){
|
||||
testColor(Magenta);
|
||||
testColor(Cyan);
|
||||
testColor(White);
|
||||
kprint_setColor(kprint_bgBlack | kprint_fgGray);
|
||||
|
||||
kprint(kprint_fmtInt | kprint_fgCyan, 8888, kprint_fmtString | kprint_fgYellow, " ooo ", kprint_fmtFloat | kprint_bgDarkGreen | kprint_fgRed, 4.01, kprint_fmtString | kprint_fgWhite, "\ngg\n");
|
||||
kprint_setColor(kp_bgBlack|kp_fgGray);
|
||||
}
|
||||
9
tests/test_type_system.c
Normal file
9
tests/test_type_system.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include "tests.h"
|
||||
|
||||
void test_type_system(){
|
||||
for(ktid id=0; id<ktid_last; id++){
|
||||
ktDescriptor d=ktDescriptor_get(id);
|
||||
kprintf("\e[37m{ id:%u name:%s size:%u freeMembers:%p toString:%p }\n",
|
||||
d.id, d.name, d.size, d.freeMembers, d.toString);
|
||||
}
|
||||
}
|
||||
@ -13,9 +13,30 @@ void test_autoarr();
|
||||
void test_hash_functions();
|
||||
void test_hashtable();
|
||||
void test_dtsod();
|
||||
void test_kprint_colors();
|
||||
void test_autoarrVsVector();
|
||||
void test_rng_algorithms();
|
||||
void test_kprint_colors();
|
||||
void test_kprint();
|
||||
void test_type_system();
|
||||
|
||||
inline void test_all(){
|
||||
kprintf("\e[97mkerep tests are starting!\n");
|
||||
optime(__func__, 1, ({
|
||||
test_type_system();
|
||||
test_string();
|
||||
test_safethrow();
|
||||
test_searchtree();
|
||||
test_autoarr();
|
||||
test_autoarrVsVector();
|
||||
test_hash_functions();
|
||||
test_hashtable();
|
||||
test_dtsod();
|
||||
test_rng_algorithms();
|
||||
test_kprint_colors();
|
||||
test_kprint();
|
||||
kprintf("\e[96m--------------------------------------\e[0m\n");
|
||||
}));
|
||||
}
|
||||
|
||||
#define PRINT_SIZEOF(T) kprintf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user