Fixed a bug where function prototypes were not being deallocated
correctly when they were overridden by the actual function. git-svn-id: http://picoc.googlecode.com/svn/trunk@529 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
e17f6f955f
commit
de95adb36a
5
parse.c
5
parse.c
|
@ -160,7 +160,10 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
|
||||||
if (TableGet(&GlobalTable, Identifier, &OldFuncValue, NULL, NULL))
|
if (TableGet(&GlobalTable, Identifier, &OldFuncValue, NULL, NULL))
|
||||||
{
|
{
|
||||||
if (OldFuncValue->Val->FuncDef.Body.Pos == NULL)
|
if (OldFuncValue->Val->FuncDef.Body.Pos == NULL)
|
||||||
TableDelete(&GlobalTable, Identifier); /* override an old function prototype */
|
{
|
||||||
|
/* override an old function prototype */
|
||||||
|
VariableFree(TableDelete(&GlobalTable, Identifier));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "'%s' is already defined", Identifier);
|
ProgramFail(Parser, "'%s' is already defined", Identifier);
|
||||||
}
|
}
|
||||||
|
|
7
table.c
7
table.c
|
@ -106,8 +106,11 @@ struct Value *TableDelete(struct Table *Tbl, const char *Key)
|
||||||
{
|
{
|
||||||
if ((*EntryPtr)->p.v.Key == Key)
|
if ((*EntryPtr)->p.v.Key == Key)
|
||||||
{
|
{
|
||||||
struct Value *Val = (*EntryPtr)->p.v.Val;
|
struct TableEntry *DeleteEntry = *EntryPtr;
|
||||||
*EntryPtr = (*EntryPtr)->Next;
|
struct Value *Val = DeleteEntry->p.v.Val;
|
||||||
|
*EntryPtr = DeleteEntry->Next;
|
||||||
|
HeapFreeMem(DeleteEntry);
|
||||||
|
|
||||||
return Val;
|
return Val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,11 @@ Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include<stdio.h>
|
#include <stdio.h>
|
||||||
#include<stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
|
||||||
#define N 4 /* This is the number of "disks" on tower A initially. */
|
#define N 4 /* This is the number of "disks" on tower A initially. */
|
||||||
/* Taken to be 64 in the legend. The number of moves
|
/* Taken to be 64 in the legend. The number of moves
|
||||||
|
@ -67,16 +70,33 @@ PrintAll()
|
||||||
|
|
||||||
int Move(int *source, int *dest)
|
int Move(int *source, int *dest)
|
||||||
{
|
{
|
||||||
int i=0,j=0;
|
int i,j;
|
||||||
|
int done = FALSE;
|
||||||
|
|
||||||
while((*(source + i)==0)&&(i<N))i++;
|
for (i=0; i<N && !done; )
|
||||||
while((*(dest + j)==0)&&(j<N))j++;
|
{
|
||||||
|
if (source[i] != 0)
|
||||||
|
done = TRUE;
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
done = FALSE;
|
||||||
|
for (j=0; j<N && !done; )
|
||||||
|
{
|
||||||
|
if (dest[j] != 0)
|
||||||
|
done = TRUE;
|
||||||
|
else
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
//while (source[i]==0 && i<N) i++;
|
||||||
|
//while(dest[j]==0 && j<N) j++;
|
||||||
|
|
||||||
|
|
||||||
*(dest+j-1) = *(source+i);
|
dest[j-1] = source[i];
|
||||||
*(source + i) = 0;
|
source[i] = 0;
|
||||||
PrintAll(); /* Print configuration after each move. */
|
PrintAll(); /* Print configuration after each move. */
|
||||||
return *(dest+j-1);
|
return dest[j-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue