fixed tester and parameter passing bugs
This commit is contained in:
@@ -338,6 +338,7 @@ void testFunc()
|
|||||||
name=string("radius");
|
name=string("radius");
|
||||||
func->addParameter(name, T_FLOATVAR);
|
func->addParameter(name, T_FLOATVAR);
|
||||||
logger("param added");
|
logger("param added");
|
||||||
|
v=variableType::getOrCreateVar(name, T_FLOATVAR);
|
||||||
e=new expression(new expression(v), O_MULTIPLY, new expression(v));
|
e=new expression(new expression(v), O_MULTIPLY, new expression(v));
|
||||||
logger("expression made");
|
logger("expression made");
|
||||||
func->generateReturn(e);
|
func->generateReturn(e);
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ class operands
|
|||||||
unsigned int id;
|
unsigned int id;
|
||||||
static unsigned int nextID;
|
static unsigned int nextID;
|
||||||
protected:
|
protected:
|
||||||
void generateBox(enum SCOPES s);
|
|
||||||
/* constructor for parameter passing */
|
/* constructor for parameter passing */
|
||||||
explicit operands(unsigned int id, enum TYPES t);
|
explicit operands(unsigned int id, enum TYPES t);
|
||||||
explicit operands(enum TYPES t);
|
explicit operands(enum TYPES t);
|
||||||
@@ -179,6 +178,7 @@ public:
|
|||||||
enum TYPES getSimpleVarType();
|
enum TYPES getSimpleVarType();
|
||||||
virtual string boxName();
|
virtual string boxName();
|
||||||
static enum TYPES getSimpleVarType(enum TYPES t);
|
static enum TYPES getSimpleVarType(enum TYPES t);
|
||||||
|
void generateBox(enum SCOPES s);
|
||||||
|
|
||||||
static operands *createOp(enum TYPES t);
|
static operands *createOp(enum TYPES t);
|
||||||
virtual void dispose();
|
virtual void dispose();
|
||||||
@@ -410,6 +410,7 @@ class fn
|
|||||||
enum TYPES kind;
|
enum TYPES kind;
|
||||||
operands *rc;
|
operands *rc;
|
||||||
label *startAddr;
|
label *startAddr;
|
||||||
|
label *skipDef;
|
||||||
/* stamdard constructor called by declare */
|
/* stamdard constructor called by declare */
|
||||||
fn(enum CODES t, operands *returnCode=nullptr);
|
fn(enum CODES t, operands *returnCode=nullptr);
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -505,7 +505,7 @@ variableType::variableType(enum SCOPES s, string &name, enum TYPES t, fn *fnHand
|
|||||||
string variableType::boxName()
|
string variableType::boxName()
|
||||||
{
|
{
|
||||||
ostringstream ss;
|
ostringstream ss;
|
||||||
if (myScope==S_LOCAL)
|
if (myScope==S_LOCAL || myScope==S_PARAMETER)
|
||||||
{
|
{
|
||||||
ss << "sub" << this->handle->getID() << "->v" << this->getID();
|
ss << "sub" << this->handle->getID() << "->v" << this->getID();
|
||||||
return ss.str();
|
return ss.str();
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ variableType *fn::getLocalVar(string &name)
|
|||||||
void fn::addParameter(string &name, enum TYPES t)
|
void fn::addParameter(string &name, enum TYPES t)
|
||||||
{
|
{
|
||||||
variableType *v=new variableType(S_PARAMETER, name, t, this);
|
variableType *v=new variableType(S_PARAMETER, name, t, this);
|
||||||
|
v->generateBox(S_PARAMETER);
|
||||||
this->parameters[name]=v;
|
this->parameters[name]=v;
|
||||||
this->params.push_back(v);
|
this->params.push_back(v);
|
||||||
}
|
}
|
||||||
@@ -226,30 +227,35 @@ void fn::close()
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
varNames << "paramater " << iter->first << "has id v"
|
varNames << "paramater " << iter->first << " has id v"
|
||||||
<< iter->second->getID() << endl;
|
<< iter->second->getID() << endl;
|
||||||
|
++iter;
|
||||||
} while (iter!=this->parameters.end());
|
} while (iter!=this->parameters.end());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
locals.clear();
|
locals.clear();
|
||||||
statics.clear();
|
statics.clear();
|
||||||
|
skipDef->generate();
|
||||||
currentFunc=nullptr;
|
currentFunc=nullptr;
|
||||||
scopeGlobal=true;
|
scopeGlobal=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn *fn::declare(string &s, enum CODES t, operands *returnCode)
|
fn *fn::declare(string &s, enum CODES t, operands *returnCode)
|
||||||
{
|
{
|
||||||
|
label *sd=new label();
|
||||||
/*check for nesting error */
|
/*check for nesting error */
|
||||||
if (!scopeGlobal) error(E_END_FUNCTION);
|
if (!scopeGlobal) error(E_END_FUNCTION);
|
||||||
/*check if this function name is already used*/
|
/*check if this function name is already used*/
|
||||||
if (fn::functions.find(s)!=fn::functions.end()) error(E_DUPLICATE_SYMBOL);
|
if (fn::functions.find(s)!=fn::functions.end()) error(E_DUPLICATE_SYMBOL);
|
||||||
logger("declaration name cleared");
|
logger("declaration name cleared");
|
||||||
|
sd->generateJumpTo();
|
||||||
fn *self=new fn(t, returnCode);
|
fn *self=new fn(t, returnCode);
|
||||||
logger("fn allocated");
|
logger("fn allocated");
|
||||||
fn::functions.insert({s,unique_ptr<fn>(self)});
|
fn::functions.insert({s,unique_ptr<fn>(self)});
|
||||||
logger("fn inserted");
|
logger("fn inserted");
|
||||||
/* initiate local scope */
|
/* initiate local scope */
|
||||||
|
self->skipDef=sd;
|
||||||
currentFunc=self;
|
currentFunc=self;
|
||||||
scopeGlobal=false;
|
scopeGlobal=false;
|
||||||
return self;
|
return self;
|
||||||
@@ -278,4 +284,5 @@ fn::fn(enum CODES t, operands *returnCode)
|
|||||||
fn::~fn()
|
fn::~fn()
|
||||||
{
|
{
|
||||||
delete startAddr;
|
delete startAddr;
|
||||||
|
delete skipDef;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user