fixed tester and parameter passing bugs

This commit is contained in:
Samuel D. Crow
2021-04-16 22:01:48 -05:00
parent 9ddac1afd6
commit 7c5f331395
4 changed files with 12 additions and 3 deletions

View File

@@ -338,6 +338,7 @@ void testFunc()
name=string("radius");
func->addParameter(name, T_FLOATVAR);
logger("param added");
v=variableType::getOrCreateVar(name, T_FLOATVAR);
e=new expression(new expression(v), O_MULTIPLY, new expression(v));
logger("expression made");
func->generateReturn(e);

View File

@@ -166,7 +166,6 @@ class operands
unsigned int id;
static unsigned int nextID;
protected:
void generateBox(enum SCOPES s);
/* constructor for parameter passing */
explicit operands(unsigned int id, enum TYPES t);
explicit operands(enum TYPES t);
@@ -179,6 +178,7 @@ public:
enum TYPES getSimpleVarType();
virtual string boxName();
static enum TYPES getSimpleVarType(enum TYPES t);
void generateBox(enum SCOPES s);
static operands *createOp(enum TYPES t);
virtual void dispose();
@@ -410,6 +410,7 @@ class fn
enum TYPES kind;
operands *rc;
label *startAddr;
label *skipDef;
/* stamdard constructor called by declare */
fn(enum CODES t, operands *returnCode=nullptr);
public:

View File

@@ -505,7 +505,7 @@ variableType::variableType(enum SCOPES s, string &name, enum TYPES t, fn *fnHand
string variableType::boxName()
{
ostringstream ss;
if (myScope==S_LOCAL)
if (myScope==S_LOCAL || myScope==S_PARAMETER)
{
ss << "sub" << this->handle->getID() << "->v" << this->getID();
return ss.str();

View File

@@ -67,6 +67,7 @@ variableType *fn::getLocalVar(string &name)
void fn::addParameter(string &name, enum TYPES t)
{
variableType *v=new variableType(S_PARAMETER, name, t, this);
v->generateBox(S_PARAMETER);
this->parameters[name]=v;
this->params.push_back(v);
}
@@ -228,28 +229,33 @@ void fn::close()
{
varNames << "paramater " << iter->first << " has id v"
<< iter->second->getID() << endl;
++iter;
} while (iter!=this->parameters.end());
}
}
locals.clear();
statics.clear();
skipDef->generate();
currentFunc=nullptr;
scopeGlobal=true;
}
fn *fn::declare(string &s, enum CODES t, operands *returnCode)
{
label *sd=new label();
/*check for nesting error */
if (!scopeGlobal) error(E_END_FUNCTION);
/*check if this function name is already used*/
if (fn::functions.find(s)!=fn::functions.end()) error(E_DUPLICATE_SYMBOL);
logger("declaration name cleared");
sd->generateJumpTo();
fn *self=new fn(t, returnCode);
logger("fn allocated");
fn::functions.insert({s,unique_ptr<fn>(self)});
logger("fn inserted");
/* initiate local scope */
self->skipDef=sd;
currentFunc=self;
scopeGlobal=false;
return self;
@@ -278,4 +284,5 @@ fn::fn(enum CODES t, operands *returnCode)
fn::~fn()
{
delete startAddr;
delete skipDef;
}