diff --git a/tester.cpp b/tester.cpp index 08c1b48..1d97e8d 100644 --- a/tester.cpp +++ b/tester.cpp @@ -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); diff --git a/yab2cpp.h b/yab2cpp.h index c5a7cdc..1db2394 100644 --- a/yab2cpp.h +++ b/yab2cpp.h @@ -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: diff --git a/yabDataStructures.cpp b/yabDataStructures.cpp index 40ff66c..455aa14 100644 --- a/yabDataStructures.cpp +++ b/yabDataStructures.cpp @@ -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(); diff --git a/yabFunctions.cpp b/yabFunctions.cpp index 11f723b..28b65fd 100644 --- a/yabFunctions.cpp +++ b/yabFunctions.cpp @@ -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); } @@ -226,30 +227,35 @@ void fn::close() { do { - varNames << "paramater " << iter->first << "has id v" + 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(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; }