Remove memory allocation bug
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user