1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-25 21:33:44 +00:00

Factored out symdef function from vars.c

This commit is contained in:
Curtis F Kaylor 2018-02-08 22:06:25 -05:00
parent 512a31a458
commit 1cc877717a
4 changed files with 12 additions and 19 deletions

BIN
c02.exe

Binary file not shown.

BIN
c02.tag

Binary file not shown.

25
vars.c
View File

@ -16,25 +16,16 @@
#include "vars.h" #include "vars.h"
/* Lookup variable name in variable table * /* Lookup variable name in variable table *
* Returns index into varnam array * * Sets: varidx = index into varnam array *
* FALSE if variable was not found */ * varcnt if not found *
* Returns: TRUE if found, otherwise FALSE */
int fndvar(char *name) int fndvar(char *name)
{ {
int i;
DEBUG("Looking up variable '%s'\n", word); DEBUG("Looking up variable '%s'\n", word);
for (i=0; i<varcnt; i++) { for (varidx=0; varidx<varcnt; varidx++) {
if (strcmp(varnam[i], name) == 0) if (strcmp(varnam[varidx], name) == 0)
return i;
}
return -1;
}
/* Check if variable has been defined */
int symdef(char *name)
{
if (fndvar(name) > -1)
return TRUE; return TRUE;
else }
return FALSE; return FALSE;
} }
@ -48,7 +39,7 @@ void chksym(int alwreg, char *name)
if (alwreg) return; if (alwreg) return;
else ERROR("Illegal reference to register %s\n", name, EXIT_FAILURE); else ERROR("Illegal reference to register %s\n", name, EXIT_FAILURE);
} }
if (!symdef(name)) if (!fndvar(name))
ERROR("Undeclared variable '%s' encountered\n", name, EXIT_FAILURE); ERROR("Undeclared variable '%s' encountered\n", name, EXIT_FAILURE);
} }
@ -180,7 +171,7 @@ void setvar(int m, int t)
void addvar(int m, int t) void addvar(int m, int t)
{ {
strcpy(vrname, word); //Save Variable Name strcpy(vrname, word); //Save Variable Name
if (symdef(vrname)) if (fndvar(vrname))
ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE); ERROR("Duplicate declaration of variable '%s\n", word,EXIT_FAILURE);
if (t == VTVOID) if (t == VTVOID)
ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE); ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE);

2
vars.h
View File

@ -8,9 +8,11 @@ char varmod[MAXVAR+1]; //Variable Modifier
char vartyp[MAXVAR+1]; //Variable Type char vartyp[MAXVAR+1]; //Variable Type
char varsiz[MAXVAR+1][4]; //Variable Array char varsiz[MAXVAR+1][4]; //Variable Array
int varcnt; //Number of Variables in Table int varcnt; //Number of Variables in Table
int varidx; //Index into Variable Tables
char vrname[MAXVAR+1]; //Variable Name char vrname[MAXVAR+1]; //Variable Name
int vrwrtn; //Variables Written Flag int vrwrtn; //Variables Written Flag
/* /*
int varidx; //Index into Variable Table int varidx; //Index into Variable Table
int vrtype; //Variable Type int vrtype; //Variable Type