diff --git a/src/calculation.c b/src/calculation.c index 21b8506..b1f8a3b 100644 --- a/src/calculation.c +++ b/src/calculation.c @@ -25,16 +25,16 @@ typedef enum { TheEnd , varPush - , var2stack // copy variable to stack w/o incrementing stack - , var2stackBranch // same, then jump - , stack2var // copy stack to variable w/o decrementing stack - , stack2varBranch // same, then jump - , ArrElmValPush // push value of array alement + , var2stack /* copy variable to stack w/o incrementing stack */ + , var2stackBranch /* same, then jump */ + , stack2var /* copy stack to variable w/o decrementing stack */ + , stack2varBranch /* same, then jump */ + , ArrElmValPush /* push value of array alement */ , stack2ArrElm - , val2stack // copy value to stack w/o incrementing stack + , val2stack /* copy value to stack w/o incrementing stack */ , valPush , Afunction - , Pop // decrement stack + , Pop /* decrement stack */ , Branch , PopBranch , valPushBranch @@ -211,7 +211,7 @@ typedef struct fortharray size_t index; size_t rank; size_t* extent; - size_t* stride; // Product of extents + size_t* stride; /* Product of extents*/ } fortharray; typedef union stackvalue @@ -392,7 +392,6 @@ static fortharray* getArrayPointer(fortharray** arrp, char* name) Boolean initialise(fortharray* curarrp, size_t size) { curarrp->index = 0; - //assert(curarrp->pval == 0); assert(curarrp->pval == 0 || curarrp->size == size); if(curarrp->pval == 0) curarrp->pval = (forthvalue*)bmalloc(size * sizeof(forthvalue)); @@ -426,7 +425,6 @@ static fortharray* getOrCreateArrayPointer(fortharray** arrp, char* name, size_t if(curarrp == 0) { curarrp = *arrp; - //assert(*arrp == 0); *arrp = (fortharray*)bmalloc(sizeof(fortharray)); if(*arrp) { @@ -1461,7 +1459,7 @@ static stackvalue* trcBody(forthMemory* mem) double ret = 0; naam = wordp->u.that->name; printf("%s\n", naam); - stackvalue* res = ftrc(sp, wordp, &ret); // May fail! + stackvalue* res = ftrc(sp, wordp, &ret); /* May fail! */ printf("%s DONE\n", naam); if(!res) return 0; @@ -1914,7 +1912,7 @@ static int polish1(psk code, Boolean commentsAllowed) C = polish1(code->RIGHT, TRUE); if(C == -1) return -1; - if(C == 0) // This results in a NoOp + if(C == 0) /* This results in a NoOp */ return 7 + R + C; if(R == 0 || C == 0) return R + C; /* Function definition on the left and/or right side. */ @@ -2249,12 +2247,7 @@ static psk IntegerNode(double val) char jotter[512]; if(val <= (double)INT64_MIN || val > (double)INT64_MAX) { -#if defined __EMSCRIPTEN__ -// long long long1 = (long long)1; - int64_t long1 = (int64_t)1; -#else int64_t long1 = (int64_t)1; -#endif double fcac = (double)(long1 << 52); int exponent; ULONG flg = 0; @@ -2513,7 +2506,7 @@ static Boolean shortcutJumpChains(forthword* wordp) wordp->offset = (unsigned int)(label - wstart); } } - //#define SHOWOPTIMIZATIONS +/*#define SHOWOPTIMIZATIONS*/ #ifdef SHOWOPTIMIZATIONS if(res) printf("shortcutJumpChains\n"); #endif @@ -3102,20 +3095,20 @@ static Boolean eliminateBranch(forthword* wstart) 125 Pop times 126 floor 127 stack2ArrElm T - 128 var2stackBranch 131 j // This must be some unconditional branch + 128 var2stackBranch 131 j This must be some unconditional branch 129 stack2ArrElm T - 118 NoOp fand // Branch -> NoOp + 118 NoOp fand Branch -> NoOp 119 varPush J 120 valPush 10.000000 - 121 PopB < 128 // 119 -> 129 -> 128 + 121 PopB < 128 119 -> 129 -> 128 122 var2stack J 123 valPush 25.600000 124 Pop times 125 floor 126 stack2ArrElm T 127 var2stackBranch 131 j - 128 val2stack 0.000000 //val2stackBranch -> val2stack + 128 val2stack 0.000000 val2stackBranch -> val2stack 129 stack2ArrElm T Label 119 replaced by (label of 119) @@ -3321,7 +3314,7 @@ static Boolean combinePopThenPop(forthword* wstart, char* marks) for(forthword* wordp = wstart; wordp->action != TheEnd; ++wordp) { forthword* label; - if(marks[(wordp + 1) - wstart] != 1) // Nobody is jumping to the next word + if(marks[(wordp + 1) - wstart] != 1) /* Nobody is jumping to the next word */ { switch(wordp->action) { @@ -3742,7 +3735,6 @@ static forthword* polish2(forthMemory* mem, jumpblock* jumps, psk code, forthwor wordp = polish2(mem, jumps, code->RIGHT, wordp, TRUE); if(!wordp) { - //showProblematicNode("wordp==0", code->RIGHT); return 0; } if(wordp == saveword) @@ -4036,9 +4028,7 @@ static forthword* polish2(forthMemory* mem, jumpblock* jumps, psk code, forthwor size_t rank = arr->rank; if(rank == 0) { - // errorprintf( "idx: Array \"%s\" has unknown rank and extent(s). Assuming %zu, based on idx.\n", arrname, h); rank = arr->rank = h; - // return 0; } if(h != rank) { @@ -4108,7 +4098,7 @@ static forthword* polish2(forthMemory* mem, jumpblock* jumps, psk code, forthwor { for(func = currentMem->functions; func; func = func->nextFnc) { - if(func != childMem // No recursion! (Has to be tested during compilation) + if(func != childMem /* No recursion! (Has to be tested during compilation)*/ && func->name && !strcmp(func->name, name) ) @@ -4126,7 +4116,6 @@ static forthword* polish2(forthMemory* mem, jumpblock* jumps, psk code, forthwor if(!is_op(rhs) && parms > func->parameters) { errorprintf("Too few parameters when calling \"%s\".\n", name); - // return 0; } psk parm; if(Op(rhs) == COMMA) @@ -4231,7 +4220,7 @@ static forthword* polish2(forthMemory* mem, jumpblock* jumps, psk code, forthwor { for(func = currentMem->functions; func; func = func->nextFnc) { - if(func != childMem // No recursion! (Has to be tested during compilation) + if(func != childMem /* No recursion! (Has to be tested during compilation)*/ && func->name && !strcmp(func->name, name) ) @@ -4383,7 +4372,7 @@ static Boolean setparm(size_t Ndecl, forthMemory* forthstuff, psk declaration, B return FALSE; } - if(declaration->LEFT->u.sobj == 's') // scalar + if(declaration->LEFT->u.sobj == 's') /* scalar */ { if(is_op(declaration->RIGHT)) { @@ -4404,7 +4393,7 @@ static Boolean setparm(size_t Ndecl, forthMemory* forthstuff, psk declaration, B npar->u.v = var; } } - else // array + else /* array */ { fortharray* a = haveArray(forthstuff, declaration->RIGHT, in_function); if(a) @@ -4634,15 +4623,9 @@ static forthMemory* calcnew(psk arg, forthMemory* parent, Boolean in_function) jumpblock* j5 = (jumpblock*)(forthstuff->word); j5->j[estart].offset = (unsigned int)((&(j5->j[0]) + sizeof(jumpblock) / sizeof(forthword)) - forthstuff->word); j5->j[estart].action = Branch; - //j5->j[epopS].offset = 1; - //j5->j[epopS].action = Pop; - //j5->j[eS].offset = 0; - //j5->j[eS].action = TheEnd; j5->j[epopF].offset = 1; j5->j[epopF].action = Pop; - //j5->j[eF].offset = 0; - //j5->j[eF].action = TheEnd; - + mustpop = enopop; lastword = polish2(forthstuff, j5, code, forthstuff->word + sizeof(jumpblock) / sizeof(forthword), FALSE); @@ -4688,7 +4671,7 @@ static forthMemory* calcnew(psk arg, forthMemory* parent, Boolean in_function) somethingdone |= dissolveNextWordBranches(forthstuff->word); somethingdone |= combineUnconditionalBranchTovalPush(forthstuff->word); memset(marks, 0, length * sizeof(char)); - somethingdone |= combineval2stack(forthstuff->word, marks); // FAULTY! + somethingdone |= combineval2stack(forthstuff->word, marks); /* FAULTY! */ memset(marks, 0, length * sizeof(char)); somethingdone |= combinePopThenPop(forthstuff->word, marks); somethingdone |= eliminateBranch(forthstuff->word); diff --git a/src/functions.c b/src/functions.c index d33c80d..7b787d9 100644 --- a/src/functions.c +++ b/src/functions.c @@ -6,7 +6,6 @@ #include "globals.h" #include "branch.h" #include "variables.h" -//#include "input.h" #include "wipecopy.h" #include "eval.h" #include "filewrite.h" @@ -505,7 +504,7 @@ static psk applyFncToString(psk fnc, psk elm, ULONG fl) nnode->v.fl = fl; nnode->v.fl &= COPYFILTER;/* ~ALL_REFCOUNT_BITS_SET;*/ nnode->LEFT = same_as_w(fnc); - nnode->RIGHT = elm;// charcopy(oldsubject, subject); + nnode->RIGHT = elm; psk rlnode = setIndex(nnode); if(rlnode) nnode = rlnode; @@ -529,15 +528,10 @@ static psk applyFncToString(psk fnc, psk elm, ULONG fl) static void SortMOP(psk fun, psk datanode, ULONG inop, psk outopnode, ULONG fl, ppsk pPnode) { ULONG outop; - /* - printf("datanode:\n"); - result(datanode); - printf("\n"); - */ if(outopnode) - outop = Op(outopnode->RIGHT) | SUCCESS; // specific out-operator + outop = Op(outopnode->RIGHT) | SUCCESS; /* specific out - operator */ else - outop = WHITE | SUCCESS; // default out-operator + outop = WHITE | SUCCESS; /* default out-operator*/ fun = same_as_w(fun); datanode = same_as_w(datanode); wipe(*pPnode); @@ -554,39 +548,27 @@ static void SortMOP(psk fun, psk datanode, ULONG inop, psk outopnode, ULONG fl, { psk resultnode = datanode; psk fnc = fun; - int repeat = 0; // Merge sort: make every second op an inop instead of '+' or '*', then rearrange, then repeat + int repeat = 0; /* Merge sort : make every second op an inop instead of '+' or '*', then rearrange, then repeat*/ int inops = 0; while(Op(datanode) == inop) { ++inops; datanode = datanode->RIGHT; } - //printf("inops %d\n", inops); - + do { psk evaluatedNode; ppsk presultnode = &resultnode; datanode = resultnode; repeat = 0; - //printf("\ndo loop inops %d\n", inops); while(repeat < inops) { - /* - printf("datanode in loop:\n"); - result(datanode); - printf("\nrepeat %d\n", repeat); - */ assert(Op(datanode) == inop); evaluatedNode = applyFncToElem_w(fnc, datanode->LEFT, fl); - /* - printf("evaluatedNode:\n"); - result(evaluatedNode); - */ psk nxt = datanode->RIGHT; if(!is_op(evaluatedNode) && hasnil && evaluatedNode->u.lobj == theNil) { - //printf("\nwipe\n"); wipe(evaluatedNode); --inops; } @@ -596,43 +578,29 @@ static void SortMOP(psk fun, psk datanode, ULONG inop, psk outopnode, ULONG fl, ++repeat; if(fnc) /* Only true in first iteration! */ { - //printf("\nbmalloc\n"); newnode = (psk)bmalloc(sizeof(knode)); } else { /* Reuse cell that was allocated in first iteration. */ - //printf("\nreuse\n"); wipe(datanode->LEFT); /* Do not wipe the rhs. We do need that one. (Except if it is the last one.) */ newnode = datanode; } newnode->LEFT = evaluatedNode; newnode->RIGHT = nxt; - if(repeat % 2) // ODD + if(repeat % 2) /* ODD */ newnode->v.fl = outop; else - { // EVEN + { /* EVEN */ newnode->v.fl = inop; } *presultnode = newnode; presultnode = &(newnode->RIGHT); } - /* - printf("resultnode:\n"); - result(resultnode); - */ datanode = nxt; } - /* - printf("\nAAA\n"); - result(datanode); - */ *presultnode = applyFncToElem_w(fnc, datanode, fl); /* If the evaluation of the last (or only) datanode results in a neutral element, we still have to put that at the end of the list. What else?*/ - /* - printf("\nBBB\n"); - result(datanode); - */ if(fnc) /* if fnc == 0 then all previously allocated operators can be reused. So we do not wipe them all. */ { wipe(*pPnode); @@ -641,35 +609,18 @@ static void SortMOP(psk fun, psk datanode, ULONG inop, psk outopnode, ULONG fl, { wipe(datanode); /* Only the last element in the data list must still be deleted. */ } - /* - printf("\nCCC\n"); - result(datanode); - */ + fnc = 0; ppsk A; psk B; - /* - printf("\nresultnodeA\n"); - result(resultnode); - printf("\nDatWasresultnodeA\n"); - */ A = &resultnode; repeat = 0; inops /= 2; - //printf("inopsIsNu %d\n", inops); - + for(; ++repeat <= inops;) { - /*printf("repeat %d\n", repeat); - if(Op(*A) != (outop & OPERATOR)) - { - printf("OEPS\n"); - result(*A); - printf("\n"); - } - */ assert(Op(*A) == (outop & OPERATOR)); B = (*A)->RIGHT; assert(is_op(B)); @@ -684,14 +635,8 @@ static void SortMOP(psk fun, psk datanode, ULONG inop, psk outopnode, ULONG fl, A = &((*A)->RIGHT); } *pPnode = resultnode; - /* - printf("resultnodeB\n"); - result(resultnode); - printf("\nDatWasresultnodeB inops=%d\n\n", inops); - */ } while(inops); - //printf("Done!\n"); } else { @@ -1279,7 +1224,7 @@ function_return_type functions(psk Pnode) CASE(MAP) /* map $ (.) */ { if(is_op(rnode)) - {/*XXX*/ + { psk nnode; psk nPnode; ppsk ppnode = &nPnode; @@ -1291,7 +1236,7 @@ function_return_type functions(psk Pnode) #else nnode = (psk)bmalloc(sizeof(knode)); nnode->v.fl = Pnode->v.fl; - nnode->v.fl &= COPYFILTER;/* ~ALL_REFCOUNT_BITS_SET;*/ + nnode->v.fl &= COPYFILTER; nnode->LEFT = same_as_w(rnode->LEFT); nnode->RIGHT = same_as_w(rrnode->LEFT); rlnode = setIndex(nnode); @@ -1306,12 +1251,6 @@ function_return_type functions(psk Pnode) rlnode = functions(nnode); if(rlnode) { - /* - if(!isSUCCESS(rlnode)) - { - wipe(nnode); - return functionFail(Pnode); - }*/ nnode = rlnode; } else @@ -1341,7 +1280,7 @@ function_return_type functions(psk Pnode) #else nnode = (psk)bmalloc(sizeof(knode)); nnode->v.fl = Pnode->v.fl; - nnode->v.fl &= COPYFILTER;/* ~ALL_REFCOUNT_BITS_SET;*/ + nnode->v.fl &= COPYFILTER; nnode->LEFT = same_as_w(rnode->LEFT); nnode->RIGHT = same_as_w(rrnode); rlnode = setIndex(nnode); @@ -1387,20 +1326,19 @@ function_return_type functions(psk Pnode) */ { if(is_op(rnode)) - {/*XXX*/ - psk nnode; - //psk fun = rnode->LEFT; // mop$(fun. ...) + {/* mop$(fun. ...)*/ + psk nnode; rrnode = rnode->RIGHT; ULONG fl = Pnode->v.fl; if(Op(rnode) == DOT) { if(Op(rrnode) == DOT) { - rlnode = rrnode->LEFT; // mop$(fun.rlnode.rrnode ...) + rlnode = rrnode->LEFT; /* mop$(fun.rlnode.rrnode ...) */ rrnode = rrnode->RIGHT; if(Op(rrnode) == DOT) { - nnode = rrnode->RIGHT; // mop$(fun.rlnode.rrnode.nnode) : rlnode is data, rrnode is in-operator, nnode is out-operator + nnode = rrnode->RIGHT; /* mop$(fun.rlnode.rrnode.nnode) : rlnode is data, rrnode is in-operator, nnode is out-operator */ rrnode = rrnode->LEFT; } else @@ -1409,7 +1347,7 @@ function_return_type functions(psk Pnode) } if(Op(rrnode) == EQUALS) { - intVal.ul = Op(rrnode->RIGHT); // in-operator + intVal.ul = Op(rrnode->RIGHT); /* in-operator */ if(intVal.ul) { if(nnode) @@ -1464,7 +1402,7 @@ function_return_type functions(psk Pnode) Second form splits in characters. */ { if(is_op(rnode)) - {/*XXX*/ + { rrnode = rnode->RIGHT; if(is_op(rrnode)) { /* first form */ @@ -1674,8 +1612,6 @@ function_return_type functions(psk Pnode) Pnode = scopy((const char*)strerror(errno)); return functionOk(Pnode); } - /* sprintf(draft,"%d",errno); - break;*/ } } #endif diff --git a/src/memory.c b/src/memory.c index 19ec7d7..3bd9665 100644 --- a/src/memory.c +++ b/src/memory.c @@ -509,7 +509,7 @@ static void checkBounds(void* p) { #ifndef NDEBUG size_t stepSize = (*q)->sizeOfElement / sizeof(struct memoryElement); -#endif // !NDEBUG +#endif if((*q)->lowestAddress <= (struct memoryElement*)p && (struct memoryElement*)p < (*q)->highestAddress) { assert(lp[stepSize - 1] == ('t' << 24) + ('e' << 16) + ('n' << 8) + ('d')); diff --git a/src/potu.c b/src/potu.c index 1d694e6..a6f9943 100644 --- a/src/potu.c +++ b/src/potu.c @@ -20,8 +20,8 @@ email: bartj@hum.ku.dk */ -#define DATUM "10 November 2024" -#define VERSION "6.26.1" +#define DATUM "11 November 2024" +#define VERSION "6.26.2" #define BUILD "310" /* COMPILATION @@ -171,7 +171,6 @@ blank " ", the comma "," and the full stop ".". (The interpunction symbols #include "charput.h" #if defined SINGLESOURCE -//#define NODESTRUCT_H #define UNICASECONV_H #define UNICHARTYPES_H #define GLOBALS_H @@ -209,7 +208,6 @@ blank " ", the comma "," and the full stop ".". (The interpunction symbols #define FILESTATUS_H #define SIMIL_H #define OBJECTDEF_H -//#define FUNCTIONS_H #define CANONIZATION_C #define EVALUATE_H @@ -699,7 +697,6 @@ int startProc( "(nestML=a L B s e x HT5.:?L&whl'(!arg:%?a ?arg&!a !L:?L)&!L:?arg&:?L:?B:" "?s&whl'(!arg:%?a ?arg&(!a:(.?e.)&(!L.) !B:?B&:?L&!e !s:?s|(!a:(?e.?,?" ")&!a|!a:(?e.?x)&(!s:!e ?s&(!e.!x,!L) (!B:(%?L.) ?B&)|!a)|!a) !L:?L))&" -// "(low$!s:html&!L:?B ((?.?,?) ?:?L)&!B (!s.,!L)|!L)),", "(low$!s:html&!L:?B ((?.?,?) ?:?L)&!B (!s.,!L):?L|)&(!L:(? (\241DOCTYPE." "@(?:? ~<>html ?)) ?|? (~<>html.?) ?)&(HT5=L M e x a C p g A.(p=li&(g=li)" "|(dt|dd)&(g=dt|dd)|p&(g=address|article|aside|blockquote|details|div|dl|" diff --git a/src/result.c b/src/result.c index 5168472..ef13672 100644 --- a/src/result.c +++ b/src/result.c @@ -186,12 +186,7 @@ static int printflags(psk Root) #define LHS 1 #define RHS 2 -#if DATAMATCHESITSELF -//#define SM(Root) {if((Root)->v.fl & SELFMATCHING) (*process)(';');} #define SM(Root) -#else -#define SM(Root) -#endif static void endnode(psk Root, int space) {