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
This commit is contained in:
parent
8d76edfe4b
commit
b8aedfe050
3
TODO
3
TODO
|
@ -1,7 +1,6 @@
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
Bugs:
|
Bugs:
|
||||||
* defining multi-line functions from interactive mode
|
|
||||||
* defining functions with no parameters (in interactive mode?)
|
* defining functions with no parameters (in interactive mode?)
|
||||||
* int fact(int i) {
|
* int fact(int i) {
|
||||||
if (i < 2) {
|
if (i < 2) {
|
||||||
|
@ -10,12 +9,12 @@ Bugs:
|
||||||
return (i * fact(i - 1));
|
return (i * fact(i - 1));
|
||||||
}
|
}
|
||||||
* something wrong with interactive mode after error handling - not clearing token buffer correctly?
|
* 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:
|
Implement:
|
||||||
* operator precedence
|
* operator precedence
|
||||||
* pointer arithmetic
|
* pointer arithmetic
|
||||||
* casts
|
* casts
|
||||||
* fix #include
|
|
||||||
* char access/char array access/char * access
|
* char access/char array access/char * access
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
2
heap.c
2
heap.c
|
@ -99,6 +99,8 @@ void *HeapAlloc(int Size)
|
||||||
if (Size == 0)
|
if (Size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
assert(Size > 0);
|
||||||
|
|
||||||
if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL)
|
if (Bucket < FREELIST_BUCKETS && FreeListBucket[Bucket] != NULL)
|
||||||
{ /* try to allocate from a freelist bucket first */
|
{ /* try to allocate from a freelist bucket first */
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
|
|
14
lex.c
14
lex.c
|
@ -613,24 +613,24 @@ void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ /* it's spread across multiple lines */
|
{ /* 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)
|
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);
|
assert(ILine != NULL);
|
||||||
MemSize += &ILine->Tokens[InteractiveCurrentLine->NumBytes] - Pos;
|
MemSize += EndParser->Pos - (void *)&ILine->Tokens[0];
|
||||||
NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE);
|
NewTokens = VariableAlloc(StartParser, MemSize + 1, TRUE);
|
||||||
|
|
||||||
CopySize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes] - Pos;
|
CopySize = &InteractiveCurrentLine->Tokens[InteractiveCurrentLine->NumBytes-1] - Pos;
|
||||||
memcpy(NewTokens, Pos, CopySize);
|
memcpy(NewTokens, Pos, CopySize);
|
||||||
NewTokenPos = NewTokens + 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)
|
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);
|
memcpy(NewTokenPos, &ILine->Tokens[0], ILine->NumBytes-1);
|
||||||
NewTokenPos += ILine->NumBytes;
|
NewTokenPos += ILine->NumBytes-1;
|
||||||
}
|
}
|
||||||
assert(ILine != NULL);
|
assert(ILine != NULL);
|
||||||
memcpy(NewTokenPos, &ILine->Tokens[0], &ILine->Tokens[ILine->NumBytes] - Pos);
|
memcpy(NewTokenPos, &ILine->Tokens[0], EndParser->Pos - (void *)&ILine->Tokens[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue