fixed bugs and added enough runtime to execute first code after the compiler segfaults at shutdown

This commit is contained in:
Samuel D. Crow
2021-03-24 18:17:33 -05:00
parent 7c5bf76778
commit 48505d1ef8
11 changed files with 152 additions and 79 deletions

View File

@@ -94,7 +94,6 @@ void shutDown();
/* process command line parameters */
int main(int argc, char *argv[])
{
atexit(shutDown);
switch (argc)
{
case 1:
@@ -152,6 +151,7 @@ int main(int argc, char *argv[])
helpText(argv[0]);
break;
}
cout << "vamanos!" <<endl;
return 0;
}
@@ -179,15 +179,26 @@ void setUp()
funcs_h.open("output/functions.h");
consts_h.open("output/consts.h");
heap_h.open("output/heap.h");
output_cpp << "#include <runtime.h>\n#include \"consts.h\"\n"
output_cpp << "#include \"../runtime/runtime.h\"\n#include \"consts.h\"\n"
<< "#include \"heap.h\"\n#include \"functions.h\"\n"
<< "int main(int argc, char *argv[])\n{\n"
<< "unsigned int state=start;\nint run(){\nwhile (state>=start){\n"
<< "switch(state){\ncase start:" << endl;
if (DUMP)
{
varNames.open("varnames.txt");
}
<< "unsigned int state=START;\nunsigned int run(){\n"
<< "while (state>=START){\n"
<< "switch(state){\ncase START:" << endl;
}
else
{
output_cpp.open("/dev/null");
funcs_h.open("/dev/null");
consts_h.open("/dev/null");
heap_h.open("/dev/null");
}
if (DUMP)
{
varNames.open("varnames.log");
}
else
{
varNames.open("/dev/null");
}
if (DEBUG)
{
@@ -195,10 +206,15 @@ void setUp()
logfile.open("parse.log");
logger("Setup complete.");
}
else
{
logfile.open("/dev/null");
}
}
[[noreturn]] void error(enum COMPILE_ERRORS e)
{
cerr << COMPILE_ERROR_NAMES[e] << endl;
errorLevel=e;
exit(1);
}
@@ -220,7 +236,7 @@ void logger(string s)
if (DEBUG)
{
indent();
logfile << s << endl;
logfile << s << "\n";
}
}
@@ -230,19 +246,23 @@ void shutDown()
if (errorLevel != E_OK) cerr << "\nERROR: "
<< COMPILE_ERROR_NAMES[errorLevel] << "\n\n" << endl;
logger("Dumping stack.");
if (DUMP && (logfile))
if (DUMP && (logfile)) fn::dumpCallStack();
if (DUMP)
{
fn::dumpCallStack();
}
varNames << "Global Variables\n";
for(auto iter=globals.begin(); iter!=globals.end(); ++iter)
{
varNames << "variable " << iter->first
<< " has ID " << iter->second << "\n";
}
varNames << endl;
varNames << "Global Variables\n";
for(auto iter=globals.begin(); iter!=globals.end(); ++iter)
{
varNames << "variable " << iter->first
<< " has ID " << iter->second->getID() << "\n";
}
varNames << endl;
label::dumpLabels();
output_cpp << "}\n}return state;\n}"<< endl;
}
if (COMPILE)
{
output_cpp << "default:\nstate=UNDEFINED_STATE_ERROR;\n"
<< "break;\n}\n}\nreturn state;\n}"<< endl;
}
}
void testInt()
@@ -255,6 +275,7 @@ void testInt()
shared_ptr<printSegment>print=shared_ptr<printSegment>(
new printSegment(shared_ptr<expression>(new expression(v))));
print->generate();
label::generateEnd();
}
/* open files and compile */
@@ -266,4 +287,3 @@ void compile()
shutDown();
}