diff --git a/.vscode/settings.json b/.vscode/settings.json index dd72655..5e8b592 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,11 @@ { "files.associations": { - "*.h": "c" + "*.h": "c", + "type_traits": "c", + "*.tcc": "c", + "functional": "c", + "istream": "c", + "ranges": "c", + "streambuf": "c" } } \ No newline at end of file diff --git a/DTLib/EventHandlerAsync.cs b/DTLib/Experimental/EventHandlerAsync.cs similarity index 100% rename from DTLib/EventHandlerAsync.cs rename to DTLib/Experimental/EventHandlerAsync.cs diff --git a/DTLib/TImer.cs b/DTLib/Timer.cs similarity index 100% rename from DTLib/TImer.cs rename to DTLib/Timer.cs diff --git a/DtsodC/Makefile b/DtsodC/Makefile index 0da58da..347f85f 100644 --- a/DtsodC/Makefile +++ b/DtsodC/Makefile @@ -1,38 +1,33 @@ -SRC=src/*.c +SRC=$(wildcard src/*c) $(wildcard src/**/*.c) OUTDIR=bin/ OUTFILE=dtsodc.com - -all: clear_c clear_bin test +CMP=gcc +all: clear_c build test +std: clear_c std_build std_test clear_c: clear - clear_bin: @echo "\e[36m-----------------[clear_bin]-------------------\e[0m" touch $(OUTDIR)_.com rm $(OUTDIR)*.com # using sdlib -STDARGS=-D STDLIB - +STDARGS=-D STDLIB -O std_build: @echo "\e[36m-------------[std_build]---------------\e[0m" - gcc $(STDARGS) $(SRC) -o $(OUTDIR)std_$(OUTFILE) - -std_test: std_build + $(CMP) $(STDARGS) $(SRC) -o $(OUTDIR)std_$(OUTFILE) +std_test: @echo "\e[36m----------------[std_test]------------------\e[0m" $(OUTDIR)std_$(OUTFILE) - # using cosmopolitan COSMARGS_PRE=-g -O -static -fno-pie -no-pie -mno-red-zone -nostdlib -nostdinc -D COSMOPOLITAN COSMARGS_POST=-Wl,--oformat=binary -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -fuse-ld=bfd -Wl,-T,cosmopolitan/ape.lds \ -include cosmopolitan/cosmopolitan.h cosmopolitan/crt.o ./cosmopolitan/ape.o cosmopolitan/cosmopolitan.a - build: @echo "\e[36m----------------[build]----------------\e[0m" - gcc $(COSMARGS_PRE) $(SRC) $(COSMARGS_POST) -o $(OUTDIR)$(OUTFILE) - -test: build + $(CMP) $(COSMARGS_PRE) $(SRC) $(COSMARGS_POST) -o $(OUTDIR)$(OUTFILE) +test: @echo "\e[36m-----------------[test]----------------\e[0m" - $(OUTDIR)$(OUTFILE) \ No newline at end of file + $(OUTDIR)$(OUTFILE) diff --git a/DtsodC/README.md b/DtsodC/README.md index 89d8dca..9654ece 100644 --- a/DtsodC/README.md +++ b/DtsodC/README.md @@ -20,5 +20,5 @@ make build If you see the `run-detectors: unable to find an interpreter` error, just execute this command: ```bash -sudo sh -c "echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register" +sudo echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register ``` \ No newline at end of file diff --git a/DtsodC/src/base/Autoarr.c b/DtsodC/src/Autoarr/Autoarr.c similarity index 99% rename from DtsodC/src/base/Autoarr.c rename to DtsodC/src/Autoarr/Autoarr.c index 760f1f2..d4cc9e1 100644 --- a/DtsodC/src/base/Autoarr.c +++ b/DtsodC/src/Autoarr/Autoarr.c @@ -144,7 +144,7 @@ void Autoarr_set_uint64(Autoarr *ar, uint32 index, uint64 element){ *(*((uint64**)ar->values+d.quot)+d.rem)=element; } -void Autoarr_free(Autoarr* ar){ +void Autoarr_clear(Autoarr* ar){ switch (ar->type) { case Int8: for(uint16 i = 0; i < ar->curr_block_count-1;i++) diff --git a/DtsodC/src/base/Autoarr.h b/DtsodC/src/Autoarr/Autoarr.h similarity index 93% rename from DtsodC/src/base/Autoarr.h rename to DtsodC/src/Autoarr/Autoarr.h index 8b825ac..158bac9 100644 --- a/DtsodC/src/base/Autoarr.h +++ b/DtsodC/src/Autoarr/Autoarr.h @@ -1,10 +1,8 @@ #pragma once -#include "std.h" -#include "base_types.h" -#include "errors.h" +#include "../base/base.h" -typedef struct Autoarr{ +typedef struct Autoarr{ // a collection with dynamic memory allocation base_type type; // type of data uint16 max_block_count; // max amount of blocks uint16 curr_block_count; // amount of blocks @@ -16,6 +14,7 @@ typedef struct Autoarr{ } Autoarr; Autoarr Autoarr_create(uint16 _max_block_count, uint16 _max_block_length, base_type _type); +void Autoarr_clear(Autoarr* ar); void Autoarr_add_int8(Autoarr *ar, int8 element); void Autoarr_add_uint8(Autoarr *ar, uint8 element); @@ -43,5 +42,3 @@ void Autoarr_set_int32(Autoarr *ar, uint32 index, int32 element); void Autoarr_set_uint32(Autoarr *ar, uint32 index, uint32 element); void Autoarr_set_int64(Autoarr *ar, uint32 index, int64 element); void Autoarr_set_uint64(Autoarr *ar, uint32 index, uint64 element); - -void Autoarr_free(Autoarr* ar); \ No newline at end of file diff --git a/DtsodC/src/DtsodV24.c b/DtsodC/src/DtsodV24.c deleted file mode 100644 index 139597f..0000000 --- a/DtsodC/src/DtsodV24.c +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/DtsodC/src/DtsodV24.h b/DtsodC/src/DtsodV24.h deleted file mode 100644 index 139597f..0000000 --- a/DtsodC/src/DtsodV24.h +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/DtsodC/src/SearchTree/SearchTree.c b/DtsodC/src/SearchTree/SearchTree.c new file mode 100644 index 0000000..d2e4180 --- /dev/null +++ b/DtsodC/src/SearchTree/SearchTree.c @@ -0,0 +1,72 @@ +#include "SearchTree.h" + +STNode* STNode_create(){ + STNode* node=malloc(sizeof(STNode)); + node->branches=NULL; + node->value.ptr=NULL; + node->value.type=Null; + return node; +} + + +void STNode_free(STNode* node){ + ifNthrow(node); + if(node->branches!=NULL){ + for(uint8 n32 = 0;n32<8;n32++){ + STNode*** ptrn32=(STNode***)node->branches[n32]; + if(ptrn32!=NULL){ + for(uint8 n4 = 0;n4<8;n4++){ + STNode** ptrn4=ptrn32[n4]; + if (ptrn4!=NULL){ + for(uint8 rem=0;rem<4;rem++){ + STNode* ptrrem=ptrn4[rem]; + if(ptrrem!=NULL){ + STNode_free(ptrrem); + free(ptrrem); + } + } + free(ptrn4); + } + } + free(ptrn32); + } + } + free(node->branches); + } + free(node->value.ptr); + free(node); +} + +typedef struct {uint8 n32, n4, rem;} indexes3; + +indexes3 splitindex(uint8 i){ + return (indexes3){ + .n32=i/32, + .n4=i%32/4, + .rem=i%32%4, + }; +} + +uint8 combinei3(indexes3 i3){ + return i3.n32*32+i3.n4*8; +} + + +// returns NULL or *STNode corresponding to the character +STNode* getcnode(STNode* node, uint8 c){ + indexes3 i3=splitindex(c); + ifNretN(node->branches); + STNode*** ptrn32=(STNode***)node->branches[i3.n32]; + ifNretN(ptrn32); + STNode** ptrn4=ptrn32[i3.n4]; + ifNretN(ptrn4); + return ptrn4[i3.rem]; +} + +void ST_push(STNode* node, const char* key, Unitype value){ + char c = *key; + for (uint16 i=0;c!='\0';){ + printf("[%u]%c ",i,c); + c=*(key+(++i)); + } +} diff --git a/DtsodC/src/SearchTree/SearchTree.h b/DtsodC/src/SearchTree/SearchTree.h new file mode 100644 index 0000000..11cc814 --- /dev/null +++ b/DtsodC/src/SearchTree/SearchTree.h @@ -0,0 +1,19 @@ +#pragma once + +#include "../base/base.h" + +typedef struct UniversalType{ + base_type type; + void* ptr; +} Unitype; + +typedef struct SearchTreeNode{ + struct SearchTreeNode**** branches; //*STNode[8][8][4] + Unitype value; +} STNode; + +STNode* STNode_create(void); +void STNode_free(STNode* node); + +void ST_push(STNode* node, const char* key, Unitype value); +Unitype ST_pull(STNode* node, const char* key); \ No newline at end of file diff --git a/DtsodC/src/SearchTree/SearchTree.md b/DtsodC/src/SearchTree/SearchTree.md new file mode 100644 index 0000000..a18d4e3 --- /dev/null +++ b/DtsodC/src/SearchTree/SearchTree.md @@ -0,0 +1,25 @@ +# Search Tree + +byte is dividing into indexes of 3d array of nodes +``` +STNode.branches byte +┃ +┣━[0]━┳━[0]━┳━[0] 0 +┃ ┃ ┣━... +┃ ┃ ┗━[3] 3 +┃ ┣━... +┃ ┃ +┃ ┗━[7]━┳━[0] 28 +┃ ┣━... +┃ ┗━[3] 31 +┣━... +┃ +┗━[7]━┳━[0]━┳━[0] 224 + ┃ ┣━... + ┃ ┗━[3] 227 + ┣━... + ┃ + ┗━[7]━┳━[0] 252 + ┣━... + ┗━[3] 255 +``` \ No newline at end of file diff --git a/DtsodC/src/base/base.h b/DtsodC/src/base/base.h new file mode 100644 index 0000000..59f6d8a --- /dev/null +++ b/DtsodC/src/base/base.h @@ -0,0 +1,3 @@ +#include "std.h" +#include "base_types.h" +#include "errors.h" \ No newline at end of file diff --git a/DtsodC/src/base/base_types.c b/DtsodC/src/base/base_types.c index 65cb849..3ee7f65 100644 --- a/DtsodC/src/base/base_types.c +++ b/DtsodC/src/base/base_types.c @@ -13,7 +13,7 @@ const char* typename(base_type t){ case UInt32: return "UInt32"; case Int64: return "Int64"; case UInt64: return "UInt64"; - default: throw(ERR_WRONGTYPE); break; + default: throw(ERR_WRONGTYPE); return "EEEEEE"; } } diff --git a/DtsodC/src/base/base_types.h b/DtsodC/src/base/base_types.h index 5d10320..40910fc 100644 --- a/DtsodC/src/base/base_types.h +++ b/DtsodC/src/base/base_types.h @@ -11,10 +11,9 @@ typedef int32_t int32; typedef uint32_t uint32; typedef int64_t int64; typedef uint64_t uint64; - typedef enum base_type{ - Null,Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64 -} base_type; + Null, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Char, Bool +} __attribute__ ((__packed__)) base_type; const char* typename(base_type t); diff --git a/DtsodC/src/base/errors.c b/DtsodC/src/base/errors.c index da1a2fd..ec9c252 100644 --- a/DtsodC/src/base/errors.c +++ b/DtsodC/src/base/errors.c @@ -8,15 +8,19 @@ const char* errname(err_t err){ case ERR_WRONGTYPE: return "ERR_WRONGTYPE"; case ERR_WRONGINDEX: return "ERR_WRONGINDEX"; case ERR_NOTIMPLEMENTED: return "ERR_NOTIMPLEMENTED"; + case ERR_NULLPTR: return "ERR_NULLPTR"; default: return "UNKNOWN_ERROR"; } } void _throwint(int err, const char* srcfile, int line, const char* funcname){ - printf("\e[31m[%s:%d/%s] throwed error: %s\e[0m\n",srcfile,line,funcname,errname(err)); - exit(err); + if(err){ // SUCCESS=0 is not an error + printf("\e[91m[%s:%d/%s] throwed error: %s\e[0m\n",srcfile,line,funcname,errname(err)); + exit(err); + } + else printf("\e[93m[%s:%d/%s] throwed SUCCESS as an error",srcfile,line,funcname); } void _throwstr(const char* errmesg, const char* srcfile, int line, const char* funcname){ - printf("\e[31m[%s:%d/%s] throwed error: %s\e[0m\n",srcfile,line,funcname,errmesg); + printf("\e[91m[%s:%d/%s] throwed error: %s\e[0m\n",srcfile,line,funcname,errmesg); exit(255); } \ No newline at end of file diff --git a/DtsodC/src/base/errors.h b/DtsodC/src/base/errors.h index 769140f..13100f6 100644 --- a/DtsodC/src/base/errors.h +++ b/DtsodC/src/base/errors.h @@ -1,14 +1,20 @@ #pragma once typedef enum err_t { - SUCCESS, ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED + SUCCESS, //not an error + ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR } err_t; + const char* errname(err_t err); + void _throwint(int err, const char* srcfile, int line, const char* funcname); void _throwstr(const char* errmesg, const char* srcfile, int line, const char* funcname); #pragma GCC diagnostic ignored "-Wint-conversion" #define throw(E) \ CHOOSE(IFTYPE(E,int), _throwint(E,__FILE__,__LINE__,__func__), \ CHOOSE(IFTYPE(E,char[]), _throwstr(E,__FILE__,__LINE__,__func__), \ - printf("NONE\n"))) - \ No newline at end of file + printf("\e[31m[%s:%d/%s] UNKNOWN ERROR\n",__FILE__,__LINE__,__func__))) + +#define ifNthrow(PTR) if (!PTR) throw(ERR_NULLPTR) +#define ifNretN(PTR) if (!PTR) return NULL +#define ifNret(PTR) if (!PTR) return \ No newline at end of file diff --git a/DtsodC/src/base/nsleep.c b/DtsodC/src/base/nsleep.c index 0127c27..99a5c29 100644 --- a/DtsodC/src/base/nsleep.c +++ b/DtsodC/src/base/nsleep.c @@ -1,5 +1,3 @@ -#pragma once - #include "std.h" #include "base_types.h" diff --git a/DtsodC/src/base/std.h b/DtsodC/src/base/std.h index 3989389..e7af73e 100644 --- a/DtsodC/src/base/std.h +++ b/DtsodC/src/base/std.h @@ -17,3 +17,4 @@ #define CHOOSE(B, Y, N) __builtin_choose_expr(B, Y, N) #define IFTYPE(X, T) __builtin_types_compatible_p(typeof(X), T) +#define dbg(N) printf("\e[95m%d\n",N) \ No newline at end of file diff --git a/DtsodC/src/main.c b/DtsodC/src/main.c index 2904db6..7164e6c 100644 --- a/DtsodC/src/main.c +++ b/DtsodC/src/main.c @@ -1,12 +1,16 @@ -#include "base/std.h" -#include "base/base_types.h" -#include "base/errors.h" -#include "base/Autoarr.h" +#include "base/base.h" +#include "tests/tests.h" +#include "Autoarr/Autoarr.h" +#include "SearchTree/SearchTree.h" #define clrscr() printf("\e[1;1H\e[2J") int main(){ setlocale(LC_ALL, "en-US.Unicode"); - printf("\e[92mdtsod parser in c language!\e[94m\n"); + printf("\e[92mdtsod parser in c language!\e[97m\n"); + test_all(); + Unitype a={Null,NULL}; + STNode* node=STNode_create(); + ST_push(node,"aboba", a); return 0; } diff --git a/DtsodC/src/tests/slimak.h b/DtsodC/src/tests/slimak.h index 1c8bb6c..11ba386 100644 --- a/DtsodC/src/tests/slimak.h +++ b/DtsodC/src/tests/slimak.h @@ -1,6 +1,6 @@ #pragma once -#include "std.h" +#include "../base/base.h" const wchar_t* slimak = U" ▄▄▄ \n" diff --git a/DtsodC/src/tests/test_all.c b/DtsodC/src/tests/test_all.c new file mode 100644 index 0000000..3131a58 --- /dev/null +++ b/DtsodC/src/tests/test_all.c @@ -0,0 +1,6 @@ +#include "tests.h" + +void test_all(void){ + test_autoarr(); + test_searchtree(); +} \ No newline at end of file diff --git a/DtsodC/src/tests/test_autoarr.c b/DtsodC/src/tests/test_autoarr.c index a6cfb1c..0202480 100644 --- a/DtsodC/src/tests/test_autoarr.c +++ b/DtsodC/src/tests/test_autoarr.c @@ -1,40 +1,43 @@ #include "tests.h" -#include "../base/Autoarr.h" +#include "../Autoarr/Autoarr.h" void ardesc(Autoarr* ar){ - printf("AUTOARR:%lu\n" - " type: %s\n" - " max_block_count: %u\n" - " curr_block_count: %u\n" - " max_block_length: %u\n" - " curr_block_length: %u\n" - " max_length: %u\n" - " curr_length: %u\n", - sizeof(Autoarr), - typename(ar->type), - ar->max_block_count, - ar->curr_block_count, - ar->max_block_length, - ar->curr_block_length, - ar->max_length, - ar->curr_length); + printf("\e[94m AUTOARR:%lu\n" + " type: %s\n" + " max_block_count: %u\n" + " curr_block_count: %u\n" + " max_block_length: %u\n" + " curr_block_length: %u\n" + " max_length: %u\n" + " curr_length: %u\n", + sizeof(Autoarr), + typename(ar->type), + ar->max_block_count, + ar->curr_block_count, + ar->max_block_length, + ar->curr_block_length, + ar->max_length, + ar->curr_length); } void fillar(Autoarr* ar){ for (uint16 i=0;imax_length;i++) Autoarr_add_uint16(ar,i); - ardesc(ar); } void printar(Autoarr* ar){ for (uint16 i=0;imax_length;i++) - printf("%u ", Autoarr_get_uint16(&ar,i)); + printf("%u ", Autoarr_get_uint16(ar,i)); } -void testar(){ +void test_autoarr(){ + printf("\e[96m------------[test_autoarr]-------------\n"); Autoarr ar=Autoarr_create(10,16,UInt16); + printf("\e[92m autoarr created\n\e[90m"); fillar(&ar); printar(&ar); - Autoarr_free(&ar); + printf("\n\e[92m autoarr filled up\n"); ardesc(&ar); + Autoarr_clear(&ar); + printf("\e[92m autoarr cleared\n"); } diff --git a/DtsodC/src/tests/test_searchtree.c b/DtsodC/src/tests/test_searchtree.c new file mode 100644 index 0000000..5fb57da --- /dev/null +++ b/DtsodC/src/tests/test_searchtree.c @@ -0,0 +1,23 @@ +#include "tests.h" +#include "../SearchTree/SearchTree.h" + +void printn(STNode* node){ + printf("\e[94m STNode: %lu\n" + " branches: %p\n" + " value.type: %s\n" + " value.ptr: %p\n", + sizeof(STNode), + node->branches, + typename(node->value.type), + node->value.ptr + ); +} + +void test_searchtree(){ + printf("\e[96m-----------[test_searchtree]-----------\n"); + STNode* node=STNode_create(); + printf("\e[92m node created\n"); + printn(node); + STNode_free(node); + printf("\e[92m node deleted\n"); +} diff --git a/DtsodC/src/tests/tests.h b/DtsodC/src/tests/tests.h index ed5a669..61303b9 100644 --- a/DtsodC/src/tests/tests.h +++ b/DtsodC/src/tests/tests.h @@ -3,3 +3,6 @@ #include "../base/std.h" void test_autoarr(void); +void test_searchtree(void); + +void test_all(void);