From b8aedfe050d5ee990e49c9ff8eb8bd6225da52cd Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 10 Mar 2009 02:01:12 +0000 Subject: [PATCH] Fixed bugs in LexCopyTokens() which were affecting multi-line function definitions in interactive mode git-svn-id: http://picoc.googlecode.com/svn/trunk@183 21eae674-98b7-11dd-bd71-f92a316d2d60 --- TODO | 3 +-- heap.c | 2 ++ lex.c | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index c7553ad..3a5bcc3 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ TODO Bugs: -* defining multi-line functions from interactive mode * defining functions with no parameters (in interactive mode?) * int fact(int i) { if (i < 2) { @@ -10,12 +9,12 @@ Bugs: return (i * fact(i - 1)); } * something wrong with interactive mode after error handling - not clearing token buffer correctly? +* parsing of statements not quite right - seems to optionally want extra tokens at end Implement: * operator precedence * pointer arithmetic * casts -* fix #include * char access/char array access/char * access Improvements: diff --git a/heap.c b/heap.c index 86cd35e..10b0a61 100644 --- a/heap.c +++ b/heap.c @@ -99,6 +99,8 @@ void *HeapAlloc(int Size) if (Size == 0) return NULL; + assert(Size > 0); + if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL) { /* try to allocate from a freelist bucket first */ #ifdef DEBUG_HEAP diff --git a/lex.c b/lex.c index 9ca632e..722e5e3 100644 --- a/lex.c +++ b/lex.c @@ -613,24 +613,24 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser } else { /* it's spread across multiple lines */ - MemSize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes] - Pos; + MemSize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes-1] - Pos; for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < (void *)&ILine->Tokens[0] || EndParser->Pos >= (void *)&ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) - MemSize += ILine->NumBytes; + MemSize += ILine->NumBytes - 1; assert(ILine != NULL); - MemSize += &ILine->Tokens[InteractiveCurrentLine->NumBytes] - Pos; + MemSize += EndParser->Pos - (void *)&ILine->Tokens[0]; NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE); - CopySize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes] - Pos; + CopySize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes-1] - Pos; memcpy(NewTokens, Pos, CopySize); NewTokenPos = NewTokens + CopySize; for (ILine = InteractiveCurrentLine->Next; ILine != NULL && (EndParser->Pos < (void *)&ILine->Tokens[0] || EndParser->Pos >= (void *)&ILine->Tokens[ILine->NumBytes]); ILine = ILine->Next) { - memcpy(NewTokenPos, &ILine->Tokens[0], ILine->NumBytes); - NewTokenPos += ILine->NumBytes; + memcpy(NewTokenPos, &ILine->Tokens[0], ILine->NumBytes-1); + NewTokenPos += ILine->NumBytes-1; } assert(ILine != NULL); - memcpy(NewTokenPos, &ILine->Tokens[0], &ILine->Tokens[ILine->NumBytes] - Pos); + memcpy(NewTokenPos, &ILine->Tokens[0], EndParser->Pos - (void *)&ILine->Tokens[0]); } }