Fixes to parsing and function pointers. It's a hack but it... works? kinda?

This commit is contained in:
Curle 2021-03-15 15:59:15 +00:00
parent d848425701
commit 2bdbe6e6c0
Signed by: TheCurle
GPG Key ID: 5942F13718443F79
7 changed files with 19 additions and 8 deletions

View File

@ -374,12 +374,10 @@ struct SymbolTableEntry* AddSymbol(char* Name, int Type, int Structure, int Stor
* * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void Die(char* Error); void Die(char* Error);
void DieMessage(char* Error, char* Reason); void DieMessage(char* Error, char* Reason);
void DieDecimal(char* Error, int Number); void DieDecimal(char* Error, int Number);
void DieChar(char* Error, int Char); void DieChar(char* Error, int Char);
void DieBinary(char* Error, int Number);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * *

View File

@ -216,6 +216,18 @@ void DieDecimal(char* Error, int Number) {
exit(1); exit(1);
} }
/**
* A variant of Die that prints the int in binary.
*/
void DieBinary(char* Error, int Number) {
char buf[33];
itoa(Number, buf, 2);
printf("%s: %s\n", Error, buf);
fclose(OutputFile);
unlink(OutputFileName);
exit(1);
}
/* /*
* A variant of Die with an extra character attached. * A variant of Die with an extra character attached.
*/ */

View File

@ -208,6 +208,7 @@ struct ASTNode* ParseFunction(int Type) {
if(NewFunction) { if(NewFunction) {
NewFunction->Elements = ParamCount; NewFunction->Elements = ParamCount;
NewFunction->Start = Params; NewFunction->Start = Params;
NewFunction->Type = RET_LONG;
OldFunction = NewFunction; OldFunction = NewFunction;
} }
@ -507,7 +508,7 @@ struct ASTNode* PostfixStatement() {
// (as functions have been called and arrays have been indexed) // (as functions have been called and arrays have been indexed)
// Check that the variable is recognized.. // Check that the variable is recognized..
if((Entry = FindSymbol(CurrentIdentifier)) == NULL || Entry->Structure != ST_VAR || Entry->Structure != ST_FUNC) { if((Entry = FindSymbol(CurrentIdentifier)) == NULL || (Entry->Structure != ST_VAR && Entry->Structure != ST_FUNC)) {
DumpAllLists(); DumpAllLists();
DieMessage("Unknown Variable", CurrentIdentifier); DieMessage("Unknown Variable", CurrentIdentifier);
} }

View File

@ -67,7 +67,7 @@ static struct SymbolTableEntry* SearchList(char* Name, struct SymbolTableEntry*
struct SymbolTableEntry* FindSymbol(char* Symbol) { struct SymbolTableEntry* FindSymbol(char* Symbol) {
struct SymbolTableEntry* Node; struct SymbolTableEntry* Node;
if(CurrentFunction) { if(FunctionEntry) {
Node = SearchList(Symbol, FunctionEntry->Start); Node = SearchList(Symbol, FunctionEntry->Start);
if(Node) if(Node)
return Node; return Node;

View File

@ -48,7 +48,7 @@ int PrimitiveSize(int Type) {
case RET_INT: return 4; case RET_INT: return 4;
case RET_LONG: return 8; case RET_LONG: return 8;
default: default:
DieDecimal("Bad type in PrimitiveSize", Type); DieBinary("Bad type in PrimitiveSize", Type);
} }
return 0; return 0;
} }

View File

@ -36,5 +36,5 @@ int :: main(int argc, char** argv) {
glutDisplayFunc(display); glutDisplayFunc(display);
glutMainLoop(); glutMainLoop();
return 0; return (0);
} }