[Avida-SVN] r2787 - in development: Avida.xcodeproj source/script
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sun Sep 14 19:26:54 PDT 2008
Author: brysonda
Date: 2008-09-14 22:26:53 -0400 (Sun, 14 Sep 2008)
New Revision: 2787
Added:
development/source/script/cASCPPParameter.h
development/source/script/cASNativeObject.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/script/AvidaScript.h
development/source/script/cASFunction.h
development/source/script/cDirectInterpretASTVisitor.cc
development/source/script/cDirectInterpretASTVisitor.h
Log:
AS (#1): Some groundwork for native object handling.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2008-09-15 00:34:42 UTC (rev 2786)
+++ development/Avida.xcodeproj/project.pbxproj 2008-09-15 02:26:53 UTC (rev 2787)
@@ -591,6 +591,8 @@
70A778370D69D5C200735F1E /* cDemeProbSchedule.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cDemeProbSchedule.cc; sourceTree = "<group>"; };
70A778380D69D5C200735F1E /* cDemeProbSchedule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDemeProbSchedule.h; sourceTree = "<group>"; };
70AA941909D486AE006A24C8 /* libtcmalloc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libtcmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 70AE2D360E7DCAA100A520B5 /* cASNativeObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASNativeObject.h; sourceTree = "<group>"; };
+ 70AE2D3B0E7DF6C500A520B5 /* cASCPPParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASCPPParameter.h; sourceTree = "<group>"; };
70B0864808F4972600FC65FE /* cLandscape.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLandscape.h; sourceTree = "<group>"; };
70B0864B08F4972600FC65FE /* cLocalMutations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLocalMutations.h; sourceTree = "<group>"; };
70B0864C08F4972600FC65FE /* cMutation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMutation.h; sourceTree = "<group>"; };
@@ -1243,6 +1245,8 @@
70A33CE80D8DBD1E008EF976 /* cASFunction.h */,
70A33CF40D8DCBB4008EF976 /* ASCoreLib.h */,
70A33CF50D8DCBB4008EF976 /* ASCoreLib.cc */,
+ 70AE2D360E7DCAA100A520B5 /* cASNativeObject.h */,
+ 70AE2D3B0E7DF6C500A520B5 /* cASCPPParameter.h */,
);
path = script;
sourceTree = "<group>";
Modified: development/source/script/AvidaScript.h
===================================================================
--- development/source/script/AvidaScript.h 2008-09-15 00:34:42 UTC (rev 2786)
+++ development/source/script/AvidaScript.h 2008-09-15 02:26:53 UTC (rev 2787)
@@ -242,7 +242,11 @@
bool operator!=(const sASTypeInfo& ot) const { return (type != ot.type || info != ot.info); }
};
+enum eASMethodReturnValues {
+ AS_NOT_FOUND = -1
+};
+
namespace AvidaScript {
const char* mapBuiltIn(ASBuiltIn_t builtin);
const char* mapToken(ASToken_t token);
Added: development/source/script/cASCPPParameter.h
===================================================================
--- development/source/script/cASCPPParameter.h (rev 0)
+++ development/source/script/cASCPPParameter.h 2008-09-15 02:26:53 UTC (rev 2787)
@@ -0,0 +1,66 @@
+/*
+ * cASCPPParameter.h
+ * Avida
+ *
+ * Created by David Bryson on 9/14/08.
+ * Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cASCPPParameter_h
+#define cASCPPParameter_h
+
+#include "avida.h"
+#include "AvidaScript.h"
+
+#include "cString.h"
+
+
+class cASCPPParameter
+{
+private:
+ union {
+ bool m_bool;
+ char m_char;
+ int m_int;
+ double m_float;
+ cString* m_string;
+ };
+
+public:
+ cASCPPParameter() { ; }
+
+ void Set(bool val) { m_bool = val; }
+ void Set(char val) { m_char = val; }
+ void Set(int val) { m_int = val; }
+ void Set(double val) { m_float = val; }
+ void Set(cString* val) { m_string = val; }
+ void Set(const cString& val) { m_string = new cString(val); }
+
+ template<typename T> inline T Get() const { Avida::Exit(AS_EXIT_INTERNAL_ERROR); return m_int; }
+};
+
+template<> inline bool cASCPPParameter::Get<bool>() const { return m_bool; }
+template<> inline char cASCPPParameter::Get<char>() const { return m_char; }
+template<> inline int cASCPPParameter::Get<int>() const { return m_int; }
+template<> inline double cASCPPParameter::Get<double>() const { return m_float; }
+template<> inline const cString& cASCPPParameter::Get<const cString&>() const { return *m_string; }
+template<> inline const cString* cASCPPParameter::Get<const cString*>() const { return m_string; }
+template<> inline cString* cASCPPParameter::Get<cString*>() const { return m_string; }
+
+#endif
Modified: development/source/script/cASFunction.h
===================================================================
--- development/source/script/cASFunction.h 2008-09-15 00:34:42 UTC (rev 2786)
+++ development/source/script/cASFunction.h 2008-09-15 02:26:53 UTC (rev 2787)
@@ -25,40 +25,14 @@
#ifndef cASFunction_h
#define cASFunction_h
-#include "avida.h"
#include "AvidaScript.h"
+#include "cASCPPParameter.h"
#include "cString.h"
class cASFunction
{
-public:
- class cParameter
- {
- private:
- union {
- bool m_bool;
- char m_char;
- int m_int;
- double m_float;
- cString* m_string;
- };
-
- public:
- cParameter() { ; }
-
- void Set(bool val) { m_bool = val; }
- void Set(char val) { m_char = val; }
- void Set(int val) { m_int = val; }
- void Set(double val) { m_float = val; }
- void Set(cString* val) { m_string = val; }
- void Set(const cString& val) { m_string = new cString(val); }
-
- template<typename T> inline T Get() const { Avida::Exit(AS_EXIT_INTERNAL_ERROR); return m_int; }
- };
-
-
protected:
cString m_name;
sASTypeInfo m_rtype;
@@ -74,19 +48,10 @@
const sASTypeInfo& GetReturnType() const { return m_rtype; }
virtual const sASTypeInfo& GetArgumentType(int arg) const = 0;
- virtual cParameter Call(cParameter args[]) const = 0;
+ virtual cASCPPParameter Call(cASCPPParameter args[]) const = 0;
};
-template<> inline bool cASFunction::cParameter::Get<bool>() const { return m_bool; }
-template<> inline char cASFunction::cParameter::Get<char>() const { return m_char; }
-template<> inline int cASFunction::cParameter::Get<int>() const { return m_int; }
-template<> inline double cASFunction::cParameter::Get<double>() const { return m_float; }
-template<> inline const cString& cASFunction::cParameter::Get<const cString&>() const { return *m_string; }
-template<> inline const cString* cASFunction::cParameter::Get<const cString*>() const { return m_string; }
-template<> inline cString* cASFunction::cParameter::Get<cString*>() const { return m_string; }
-
-
template<typename FunctionType> class tASFunction;
@@ -110,9 +75,9 @@
int GetArity() const { return 1; }
const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
- cParameter Call(cParameter args[]) const
+ cASCPPParameter Call(cASCPPParameter args[]) const
{
- cParameter rvalue;
+ cASCPPParameter rvalue;
rvalue.Set((*m_func)(args[0].Get<Arg1Type>()));
return rvalue;
}
@@ -139,11 +104,11 @@
int GetArity() const { return 1; }
const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
- cParameter Call(cParameter args[]) const
+ cASCPPParameter Call(cASCPPParameter args[]) const
{
(*m_func)(args[0].Get<Arg1Type>());
- return cParameter();
+ return cASCPPParameter();
}
};
Added: development/source/script/cASNativeObject.h
===================================================================
--- development/source/script/cASNativeObject.h (rev 0)
+++ development/source/script/cASNativeObject.h 2008-09-15 02:26:53 UTC (rev 2787)
@@ -0,0 +1,49 @@
+/*
+ * cASNativeObject.h
+ * Avida
+ *
+ * Created by David Bryson on 9/14/08.
+ * Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cASNativeObject_h
+#define cASNativeObject_h
+
+#include "AvidaScript.h"
+
+#include "cASCPPParameter.h"
+
+class cString;
+
+class cASNativeObject
+{
+
+public:
+ cASNativeObject() { ; }
+ virtual ~cASNativeObject() { ; }
+
+ bool CallMethod(int mid, int argc, cASCPPParameter args[]) { return false; } // @TODO
+
+ int LookupValue(const cString& val_name) { return AS_NOT_FOUND; } // @TODO
+ int LookupMethod(const cString& meth_name) { return AS_NOT_FOUND; } // @TODO
+
+ void Release() { ; }
+};
+
+#endif
Modified: development/source/script/cDirectInterpretASTVisitor.cc
===================================================================
--- development/source/script/cDirectInterpretASTVisitor.cc 2008-09-15 00:34:42 UTC (rev 2786)
+++ development/source/script/cDirectInterpretASTVisitor.cc 2008-09-15 02:26:53 UTC (rev 2787)
@@ -1145,7 +1145,7 @@
const cASFunction* func = node.GetASFunction();
// Setup arguments
- cASFunction::cParameter* args = new cASFunction::cParameter[func->GetArity()];
+ cASCPPParameter* args = new cASCPPParameter[func->GetArity()];
tListIterator<cASTNode> cit = node.GetArguments()->Iterator();
cASTNode* an = NULL;
for (int i = 0; i < func->GetArity(); i++) {
@@ -1165,7 +1165,7 @@
}
// Call the function
- cASFunction::cParameter rvalue = func->Call(args);
+ cASCPPParameter rvalue = func->Call(args);
// Handle the return value
switch (node.GetType().type) {
Modified: development/source/script/cDirectInterpretASTVisitor.h
===================================================================
--- development/source/script/cDirectInterpretASTVisitor.h 2008-09-15 00:34:42 UTC (rev 2786)
+++ development/source/script/cDirectInterpretASTVisitor.h 2008-09-15 02:26:53 UTC (rev 2787)
@@ -25,6 +25,7 @@
#ifndef cDirectInterpretASTVisitor_h
#define cDirectInterpretASTVisitor_h
+#include "cASNativeObject.h"
#include "cASTVisitor.h"
#include "tHashTable.h"
@@ -306,6 +307,22 @@
bool Set(sAggregateValue& idx, sAggregateValue& val);
};
+ class cNativeObjectRef : public cObjectRef
+ {
+ private:
+ cASNativeObject* m_no;
+
+ public:
+ cNativeObjectRef();
+ ~cNativeObjectRef() { m_no->Release(); }
+
+ bool IsWritable() { return false; }
+ bool Get(sAggregateValue& val) { return false; }
+ bool Get(const sAggregateValue& idx, sAggregateValue& val) { return false; }
+ bool Set(sAggregateValue& val) { return false; }
+ bool Set(sAggregateValue& idx, sAggregateValue& val) { return false; }
+ };
+
class cObjectIndexRef : public cObjectRef
{
private:
More information about the Avida-cvs
mailing list