A scripting environment used to define precise output/input temporal relationships.

Dependencies:   SMARTWAV mbed HelloWorld

Dependents:   perturbRoom_legacy

Fork of HelloWorld by Simon Ford

Revision:
3:ae33b7f5a7c1
Parent:
2:298679fff37c
Child:
4:34aca2142df9
--- a/behave.cpp	Tue Jul 08 21:51:16 2014 +0000
+++ b/behave.cpp	Sat Jul 19 03:03:36 2014 +0000
@@ -770,6 +770,7 @@
 }
 
 void intOperation::set(int* intVarInput, const char* cmpString, int cmpValInput) {
+    
     intVal = intVarInput;
     cmpVal = new int(cmpValInput);
     randHigh = -1;
@@ -810,6 +811,7 @@
 }
 
 void intOperation::set(int* intVarInput, intOperation* operationInput) {
+    
     intVal = intVarInput;
     cmpVal = NULL;  
     randHigh = -1;
@@ -841,11 +843,14 @@
     
 
 int intOperation::execute() {
+    
     return (this->*executePtr)();
     
+    
 }
 
 int intOperation::add() {
+    
     if (intVal != NULL) {
         return (*intVal + *cmpVal);
     }
@@ -900,6 +905,7 @@
         *intVal = *cmpVal;
         return *intVal;
     } else if ((intVal != NULL) && (opPtr != NULL)) {
+        
         *intVal = opPtr->execute();
         return *intVal;    
     } else if (cmpVal != NULL){
@@ -2870,8 +2876,9 @@
                         
                         action* tmpAction = evaluateAssignmentForAction(tmpString);
                         
-                        if (tmpAction != NULL) {
+                        if (tmpAction != NULL) {                           
                             tmpAction->execute();
+                            
                             //delete tmpAction;   
                             tmpAction->release();                    
                         } else {                         
@@ -3043,9 +3050,9 @@
                 } else {
                     //tmpMessage->setMessage(portVector[portnum],1,-1);
                     if (tmpVar == NULL) { //a constant port number was given
-                        tmpMessage->setMessage(NULL,portnum,portVal);
+                        tmpMessage->setMessage(NULL,portnum,-1);
                     } else {
-                        tmpMessage->setMessage(tmpVar,0,portVal);
+                        tmpMessage->setMessage(tmpVar,0,-1);
                     }               
                 }
                 tmpAction->set(tmpMessage);
@@ -3126,27 +3133,37 @@
                         tmpOp->set(tmpVar, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
                     }
                     tmpAction->set(tmpOp);
-                    //pcPtr->printf("Action: change variable by constant amount\r\n");
+                    pcPtr->printf("Action: change variable by constant amount\r\n");
                 } else {
-                    //tmpOp2 = new intOperation(tmpVar2,multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
-                    //tmpOp = new intOperation(tmpVar, tmpOp2);
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
+                                              
                         tmpOp2->set(tmpVar2,multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
+                        //tmpOp->set(tmpVar, tmpOp2);
+                    }
+                    
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {
                         tmpOp->set(tmpVar, tmpOp2);
-                    }
+                    }  
+                    
                     tmpAction->set(tmpOp);
                     //pcPtr->printf("Action: variable equals expression\r\n");
                 }
                 
            } else if ((tmpVar3 != NULL) && isNumber(afterEqual.substr(0,stringInd2))) { //number +/- variable
                 if (tmpVar3 == tmpVar) {
-                    multiplier.append("=");
+                    multiplier.append("="); //makes "+=" or "-="
                     //tmpOp = new intOperation(tmpVar, multiplier.data(), atoi(afterEqual.substr(0,stringInd2).data()));
                     tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
                     if (tmpOp == NULL) {
@@ -3159,16 +3176,23 @@
                     tmpAction->set(tmpOp);
                     //pcPtr->printf("Action: change variable by constant amount\r\n");
                 } else {
-                    //tmpOp2 = new intOperation(tmpVar3, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));
-                    //tmpOp = new intOperation(tmpVar, tmpOp2);
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                                      
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
-                        tmpOp2->set(tmpVar3, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));
+                        tmpOp2->set(tmpVar3, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));                       
+                    }
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {                        
                         tmpOp->set(tmpVar, tmpOp2);
                     }
                     tmpAction->set(tmpOp);
@@ -3176,16 +3200,24 @@
                 }
                 
            } else if ((tmpVar2 != NULL) && (tmpVar3 != NULL)) { //variable +/- variable
-                //tmpOp2 = new intOperation(tmpVar2, multiplier.data(), tmpVar3);
-                //tmpOp = new intOperation(tmpVar, tmpOp2);
-                tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                              
                 tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                if (tmpOp2 == NULL) {
                     pcPtr->printf("Error: no memory slots available.\r\n");
                     tmpAction->release();
                     return NULL;
                 } else {
-                    tmpOp2->set(tmpVar2, multiplier.data(), tmpVar3);
+                    tmpOp2->set(tmpVar2, multiplier.data(), tmpVar3);                   
+                }
+                tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                
+                if (tmpOp == NULL) {
+                    pcPtr->printf("Error: no memory slots available.\r\n");
+                    tmpOp2->release();
+                    tmpAction->release();
+                    return NULL;
+                } else {
+                    
                     tmpOp->set(tmpVar, tmpOp2);
                 }
                 tmpAction->set(tmpOp);
@@ -3208,16 +3240,24 @@
                 int highVal = getRandomParam(afterEqual.substr(0,stringInd2));
             
                 if (highVal > 0) {
-                    //tmpOp2 = new intOperation(highVal, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
-                    //tmpOp = new intOperation(tmpVar, tmpOp2); 
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    
+                    
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
-                        tmpOp2->set(highVal, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));
+                        tmpOp2->set(highVal, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()));                       
+                    }
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {
                         tmpOp->set(tmpVar, tmpOp2);
                     }
                     tmpAction->set(tmpOp);
@@ -3231,16 +3271,23 @@
                 int highVal = getRandomParam(afterEqual.substr(0,stringInd2));
             
                 if (highVal > 0) {
-                    //tmpOp2 = new intOperation(highVal, multiplier.data(), tmpVar3);
-                    //tmpOp = new intOperation(tmpVar, tmpOp2); 
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                    
+                    
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
-                        tmpOp2->set(highVal, multiplier.data(), tmpVar3);
+                        tmpOp2->set(highVal, multiplier.data(), tmpVar3);                     
+                    }
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);                   
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {                       
                         tmpOp->set(tmpVar, tmpOp2);
                     }
                     tmpAction->set(tmpOp);
@@ -3256,16 +3303,23 @@
                 int highVal = getRandomParam(afterEqual.substr(stringInd2+1,std::string::npos));
             
                 if (highVal > 0) {
-                    //tmpOp2 = new intOperation(highVal, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));
-                    //tmpOp = new intOperation(tmpVar, tmpOp2); 
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                   
+                    
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
-                        tmpOp2->set(highVal, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));
+                        tmpOp2->set(highVal, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()));                        
+                    }
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);                   
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {                      
                         tmpOp->set(tmpVar, tmpOp2);
                     }
                     tmpAction->set(tmpOp);
@@ -3279,16 +3333,23 @@
                 int highVal = getRandomParam(afterEqual.substr(stringInd2+1,std::string::npos));
             
                 if (highVal > 0) {
-                    //tmpOp2 = new intOperation(highVal, multiplier.data(), tmpVar2);
-                    //tmpOp = new intOperation(tmpVar, tmpOp2); 
-                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
+                   
+                   
                     tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);
-                    if ((tmpOp == NULL)||(tmpOp2 == NULL)) {
+                    if (tmpOp2 == NULL) {
                         pcPtr->printf("Error: no memory slots available.\r\n");
                         tmpAction->release();
                         return NULL;
                     } else {
-                        tmpOp2->set(highVal, multiplier.data(), tmpVar2);
+                        tmpOp2->set(highVal, multiplier.data(), tmpVar2);                       
+                    }
+                    tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS);                  
+                    if (tmpOp == NULL) {
+                        pcPtr->printf("Error: no memory slots available.\r\n");
+                        tmpOp2->release();
+                        tmpAction->release();
+                        return NULL;
+                    } else {                       
                         tmpOp->set(tmpVar, tmpOp2);
                     }
                     tmpAction->set(tmpOp);