From: ken Date: Tue, 17 Jan 2017 00:59:58 +0000 (-0800) Subject: debug print formatting X-Git-Url: https://www.kengrimes.com/gitweb/?p=henge%2Fapc.git;a=commitdiff_plain;h=7dae7dc73dfbabdc895a78738f550f56561da644 debug print formatting --- diff --git a/src/ir.c b/src/ir.c index db97097..a175ef3 100644 --- a/src/ir.c +++ b/src/ir.c @@ -117,11 +117,15 @@ static void ir_free_pagenodes(struct pagenode_t*); static inline int bytes_identical(const uint8_t*,const uint8_t*); +static inline +int classnames_identical(const uint8_t*,const uint8_t*); static void* stack_alloc(size_t); #define struct_alloc(_T) ((struct _T*) stack_alloc(sizeof(struct _T))) static uint8_t* name_alloc(const uint8_t*); +static +uint8_t* classname_alloc(const uint8_t*); extern //apc.c long sys_pagesize; static @@ -209,7 +213,7 @@ struct ir_class_t* ir_class_addchild if (name == NULL) eprintf("Null child added to class %s\n", iter->name); check: - if (bytes_identical(iter->name, name)) + if (classnames_identical(iter->name, name)) return iter; if (iter->nextsib != NULL) { iter = iter->nextsib; @@ -218,7 +222,7 @@ struct ir_class_t* ir_class_addchild alloc: iter = struct_alloc(ir_class_t); iter->nextsib = class->nextchild; - iter->name = name_alloc(name); + iter->name = classname_alloc(name); return class->nextchild = iter; } @@ -325,6 +329,19 @@ int bytes_identical return (ca == cb); } +static inline +int classnames_identical +( const uint8_t* stra, + const uint8_t* strb +) +{ int ca, cb; + do { + ca = *stra++; + cb = *strb++; + } while (ca && ca == cb); + return (ca == cb); +} + /* Assign Setdata to Set */ @@ -549,3 +566,26 @@ uint8_t* name_alloc *(namepages.head->header.head)++ = '\0'; return name; } + +static +uint8_t* classname_alloc +( const uint8_t* name_src ) +{ const uint8_t* iter; + uint8_t* name; + int head_mem; + copy: + name = (uint8_t*)namepages.head->header.head; + iter = name_src; + for (head_mem = PL_HEADMEM(namepages); *iter && head_mem; head_mem--) + *(namepages.head->header.head)++ = *iter++; + if (head_mem == 0) //not enough room + { namepages.head->header.next = (struct pagenode_t*) calloc(namepages.pagesize,1); + if (namepages.head->header.next == NULL) + eprintf("Memory allocation error\n"); + namepages.head = namepages.head->header.next; + namepages.head->header.head = namepages.head->root; + goto copy; + } + *(namepages.head->header.head)++ = '\0'; + return name; +} diff --git a/src/lexer.rl b/src/lexer.rl index c7600ae..920d62d 100644 --- a/src/lexer.rl +++ b/src/lexer.rl @@ -141,18 +141,11 @@ int lexer_lexstring { uint8_t* p, * ts, * pe, * eof; int cs, ntok; YYSTYPE lval; - ntok = 0; p = ts = str; pe = eof = p + size + 1; - - dprintf("\n|---Begin lexstring on p = %U, pe = %p.---|\n",p, pe); - %%write init; %%write exec; - - dprintf("\n|---Ending lexstring of file %U, pushed %d tokens.---|\n",str, ntok); - return ntok; } @@ -177,6 +170,7 @@ int lexer_lexfile // Mark the end of the filename filename_end = iter; // Lex from either the last period, if present, or filename end + dprintf("%U\n\t",filename); ntok = (last_period) ? lexer_lexstring(filename, (int)(last_period - filename)) : lexer_lexstring(filename, (int)(iter - filename)); @@ -185,6 +179,7 @@ int lexer_lexfile if (*iter == '\0') *iter = '_'; PUSHPATH(filename); + dprintf("\n\t[%i Token%s]\n", ntok, (ntok > 1) ? "s" : ""); return ntok + 1; } @@ -192,14 +187,18 @@ int lexer_lexdir ( uint8_t* dirname ) { int ntok; ntok = 0; + if (DEBUG) putchar('\t'); PUSHNAME(dirname); PUSHOP(CLOPEN); + if (DEBUG) putchar('\n'); return ntok; } int lexer_closedir ( void ) { int ntok = 0; + if (DEBUG) putchar('\t'); PUSHOP(CLCLOSE); + if (DEBUG) putchar('\n'); return ntok; } diff --git a/src/parser.y b/src/parser.y index ff2d257..d7a02cd 100644 --- a/src/parser.y +++ b/src/parser.y @@ -129,6 +129,7 @@ frame_spec: NUM NUM { $$ = (struct frame_spec_t) {SFACE,$1,$2}; } | FACING { $$ = (struct frame_spec_t) {$1,0,0}; } | FACING NUM NUM { $$ = (struct frame_spec_t) {$1,$2,$3}; } +| %empty { $$ = (struct frame_spec_t) {SFACE,0,0}; } ; %%