Remove memory allocation bug

This commit is contained in:
2020-10-01 23:19:45 +05:30
parent a1c9e4894f
commit c55a1745a5
4 changed files with 43 additions and 8 deletions

View File

@@ -20,9 +20,6 @@ Any executeBGE::visitNumberedStmt(bfeParser::NumberedStmtContext *ctx){
}
Any executeBGE::visitPtrIncr(bfeParser::PtrIncrContext *ctx){
if(memory.size()<pointer){
memory.push_back(0);
}
memory[pointer]++;
return Any();
}
@@ -33,13 +30,23 @@ Any executeBGE::visitPtrDecr(bfeParser::PtrDecrContext *ctx){
}
Any executeBGE::visitPtrRight(bfeParser::PtrRightContext *ctx){
// too much -> throw this program out
if(memory.max_size()==memory.size()){
throw (std::string("Max Size Reached ")+to_string(memory.capacity()));
}
// its about to be incremented -> need to increase
if(memory.size()==pointer+1){
memory.push_back(0);
}
pointer++;
return Any();
}
Any executeBGE::visitPtrLeft(bfeParser::PtrLeftContext *ctx){
if(pointer==0) throw std::string("Decrement below zero");
if(pointer==0){
throw std::string("Decrement below zero");
}
pointer--;
return Any();
}