added on_exit arg to tryLast()

This commit is contained in:
Timerix22 2023-05-24 02:39:19 +06:00
parent 588453a2b7
commit 70807ed22b
5 changed files with 12 additions and 8 deletions

View File

@ -80,7 +80,7 @@ char* __unknownErr( );
} }
#endif #endif
#define tryLast(_funcCall, _rezult) Maybe _rezult=_funcCall; if(_rezult.errmsg){ \ #define tryLast(_funcCall, _rezult, ON_EXIT) Maybe _rezult=_funcCall; if(_rezult.errmsg){ \
_rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__); \ _rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__); \
__EXIT(_rezult.errmsg); \ __EXIT(_rezult.errmsg); \
} }

View File

@ -40,6 +40,10 @@ STRUCT(Unitype,
#define Unitype_isUniNull(UNI) (UNI.typeId==0 && UNI.Int64==0) #define Unitype_isUniNull(UNI) (UNI.typeId==0 && UNI.Int64==0)
#define UniCheckTypeId(UNI, TYPE_ID) (UNI.typeId==TYPE_ID)
#define UniCheckType(UNI, TYPE) UniCheckTypeId(UNI, ktid_name(TYPE))
#define UniCheckTypePtr(UNI, TYPE) UniCheckTypeId(UNI, ktid_ptrName(TYPE))
// frees VoidPtr value or does nothing if type isn't pointer // frees VoidPtr value or does nothing if type isn't pointer
void Unitype_free(Unitype u); void Unitype_free(Unitype u);
void __UnitypePtr_free(void* u); void __UnitypePtr_free(void* u);

View File

@ -71,12 +71,12 @@ Maybe __kfprint(FILE* file, u8 n, kp_fmt* formats, __kp_value_union* objects){
} }
void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){ void __kprint(u8 n, kp_fmt* formats, __kp_value_union* objects){
tryLast(check_argsN(n), _); tryLast(check_argsN(n), _,;);
n/=2; n/=2;
for(u8 i=0; i<n; i++){ for(u8 i=0; i<n; i++){
kp_fmt fmt=formats[i]; kp_fmt fmt=formats[i];
kprint_setColor(fmt); kprint_setColor(fmt);
tryLast(__next_toString(fmt, &objects[i]),maybeStr); tryLast(__next_toString(fmt, &objects[i]),maybeStr, kprint_setColor(kp_bgBlack|kp_fgGray));
if(fputs(maybeStr.value.VoidPtr, stdout)==EOF) \ if(fputs(maybeStr.value.VoidPtr, stdout)==EOF) \
throw("can't write string to stdout"); throw("can't write string to stdout");
//, Unitype_free(maybeStr.value) //, Unitype_free(maybeStr.value)

View File

@ -43,23 +43,23 @@ void test_dtsod(){
char* s; char* s;
optime("deserialize",1, optime("deserialize",1,
tryLast(DtsodV24_deserialize(text),r) tryLast(DtsodV24_deserialize(text),r,;)
dtsod=r.value.VoidPtr; dtsod=r.value.VoidPtr;
); );
print_dtsod(dtsod); print_dtsod(dtsod);
optime("serialize",1, optime("serialize",1,
tryLast(DtsodV24_serialize(dtsod),r) tryLast(DtsodV24_serialize(dtsod),r,;)
s=r.value.VoidPtr; s=r.value.VoidPtr;
); );
DtsodV24_free(dtsod); DtsodV24_free(dtsod);
kprintf("\e[92m%s",s); kprintf("\e[92m%s",s);
optime("reserialize",10, optime("reserialize",10,
tryLast(DtsodV24_deserialize(s),r) tryLast(DtsodV24_deserialize(s),r,;)
dtsod=r.value.VoidPtr; dtsod=r.value.VoidPtr;
free(s); free(s);
tryLast(DtsodV24_serialize(dtsod),rr) tryLast(DtsodV24_serialize(dtsod),rr,;)
s=rr.value.VoidPtr; s=rr.value.VoidPtr;
DtsodV24_free(dtsod); DtsodV24_free(dtsod);
); );

View File

@ -15,7 +15,7 @@ Maybe throw_errcode(){
Maybe test_maybe(){ Maybe test_maybe(){
kprintf("\e[94mdont_throw returns \e[92m"); kprintf("\e[94mdont_throw returns \e[92m");
tryLast(dont_throw(),rez0) tryLast(dont_throw(),rez0,;)
printMaybe(rez0); printMaybe(rez0);
kprintf("\n"); kprintf("\n");
try(throw_error(),rez1,;) try(throw_error(),rez1,;)