[Avida-SVN] r2435 - in development: Avida.xcodeproj source/script source/targets/avida-s

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Mar 7 14:57:42 PST 2008


Author: brysonda
Date: 2008-03-07 17:57:42 -0500 (Fri, 07 Mar 2008)
New Revision: 2435

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/script/cDirectInterpretASTVisitor.cc
   development/source/script/cSemanticASTVisitor.cc
   development/source/targets/avida-s/main.cc
Log:
AS:
Cleanup local string variables on function exit.
Add call to interpreter object.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2008-03-07 16:49:22 UTC (rev 2434)
+++ development/Avida.xcodeproj/project.pbxproj	2008-03-07 22:57:42 UTC (rev 2435)
@@ -218,23 +218,6 @@
 		};
 /* End PBXBuildRule section */
 
-/* Begin PBXBuildStyle section */
-		B51C949C0D6B3FD1004D5839 /* Development */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-			};
-			name = Development;
-		};
-		B51C949D0D6B3FD1004D5839 /* Deployment */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			name = Deployment;
-		};
-/* End PBXBuildStyle section */
-
 /* Begin PBXContainerItemProxy section */
 		56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1820,16 +1803,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
-			buildSettings = {
-			};
-			buildStyles = (
-				B51C949C0D6B3FD1004D5839 /* Development */,
-				B51C949D0D6B3FD1004D5839 /* Deployment */,
-			);
+			compatibilityVersion = "Xcode 2.4";
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
 			projectDirPath = "";
+			projectRoot = "";
 			targets = (
 				7023ED520C0A590200362B9C /* full-suite */,
 				DCC3164C07626CF3008F7A48 /* avida */,

Modified: development/source/script/cDirectInterpretASTVisitor.cc
===================================================================
--- development/source/script/cDirectInterpretASTVisitor.cc	2008-03-07 16:49:22 UTC (rev 2434)
+++ development/source/script/cDirectInterpretASTVisitor.cc	2008-03-07 22:57:42 UTC (rev 2435)
@@ -47,6 +47,7 @@
 cDirectInterpretASTVisitor::cDirectInterpretASTVisitor(cSymbolTable* global_symtbl)
   : m_global_symtbl(global_symtbl), m_cur_symtbl(global_symtbl), m_call_stack(0, 2048), m_sp(0), m_has_returned(false)
 {
+  m_call_stack.Resize(m_global_symtbl->GetNumVariables());
   for (int i = 0; i < m_global_symtbl->GetNumVariables(); i++) m_call_stack[i].as_string = NULL;
 }
 
@@ -560,9 +561,11 @@
   // Set current scope to the function symbol table
   m_cur_symtbl = func_symtbl->GetFunctionSymbolTable(fun_id);
   m_sp += prev_symtbl->GetNumVariables();
+  m_call_stack.Resize(m_call_stack.GetSize() + m_cur_symtbl->GetNumVariables());
   for (int i = 0; i < m_cur_symtbl->GetNumVariables(); i++) m_call_stack[m_sp + i].as_string = NULL;
   
   // Process the arguments to the function
+  tSmartArray<int> str_var_idxs;
   tListIterator<cASTVariableDefinition> sit = func_symtbl->GetFunctionSignature(fun_id)->Iterator();
   tListIterator<cASTNode> cit = node.GetArguments()->Iterator();
   cASTVariableDefinition* arg_def = NULL;
@@ -581,7 +584,12 @@
       case TYPE(INT):         m_call_stack[m_sp + var_id].as_int = asInt(m_rtype, m_rvalue, node); break;
       case TYPE(OBJECT_REF):  INTERPRET_ERROR(INTERNAL); // @TODO - assignment
       case TYPE(MATRIX):      INTERPRET_ERROR(INTERNAL); // @TODO - assignment
-      case TYPE(STRING):      m_call_stack[m_sp + var_id].as_string = asString(m_rtype, m_rvalue, node); break;
+      case TYPE(STRING):
+        {
+          m_call_stack[m_sp + var_id].as_string = asString(m_rtype, m_rvalue, node);
+          str_var_idxs.Push(var_id);
+        }
+        break;
         
       default:
         INTERPRET_ERROR(INTERNAL);
@@ -608,11 +616,13 @@
       INTERPRET_ERROR(INTERNAL);
   }
   m_rtype = node.GetType();
+
+  // Clean up string variables in the current scope
+  for (int i = 0; i < str_var_idxs.GetSize(); i++) delete m_call_stack[m_sp + str_var_idxs[i]].as_string;
   
-  // @TODO - cleanup scope (delete local string objects on the stack)
-  
   // Restore previous scope
   m_has_returned = false;
+  m_call_stack.Resize(m_call_stack.GetSize() - m_cur_symtbl->GetNumVariables());
   m_sp -= prev_symtbl->GetNumVariables();
   m_cur_symtbl = prev_symtbl;
 }

Modified: development/source/script/cSemanticASTVisitor.cc
===================================================================
--- development/source/script/cSemanticASTVisitor.cc	2008-03-07 16:49:22 UTC (rev 2434)
+++ development/source/script/cSemanticASTVisitor.cc	2008-03-07 22:57:42 UTC (rev 2435)
@@ -88,6 +88,7 @@
   bool global = false;
   if (lookupVariable(node.GetVariable(), var_id, global)) {
     checkCast(node.GetExpression()->GetType(), (global ? m_global_symtbl : m_cur_symtbl)->GetVariableType(var_id));
+    node.SetVar(var_id, global);
   } else {
     SEMANTIC_ERROR(VARIABLE_UNDEFINED, (const char*)node.GetVariable());
   }
@@ -543,7 +544,7 @@
     }
     
     node.SetFunc(fun_id, global);
-    node.SetType(m_cur_symtbl->GetFunctionRType(fun_id));
+    node.SetType((global ? m_global_symtbl : m_cur_symtbl)->GetFunctionRType(fun_id));
   } else {
     SEMANTIC_ERROR(FUNCTION_UNDECLARED, (const char*)node.GetName());
   }

Modified: development/source/targets/avida-s/main.cc
===================================================================
--- development/source/targets/avida-s/main.cc	2008-03-07 16:49:22 UTC (rev 2434)
+++ development/source/targets/avida-s/main.cc	2008-03-07 22:57:42 UTC (rev 2435)
@@ -26,6 +26,7 @@
 #include "PlatformExpert.h"
 
 #include "cASLibrary.h"
+#include "cDirectInterpretASTVisitor.h"
 #include "cDumpASTVisitor.h"
 #include "cFile.h"
 #include "cParser.h"
@@ -61,7 +62,10 @@
         Avida::Exit(AS_EXIT_FAIL_SEMANTIC);
       }
       
-      Avida::Exit(AS_EXIT_OK);
+      cDirectInterpretASTVisitor interpeter(&global_symtbl);
+      int exit_code = interpeter.Interpret(tree);
+      
+      Avida::Exit(exit_code);
     } else {
       std::cerr << "error: parse failed" << std::endl;
       Avida::Exit(AS_EXIT_FAIL_PARSE);




More information about the Avida-cvs mailing list