[Avida-SVN] r2857 - in development: Avida.xcodeproj source/script source/targets/avida-s
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Oct 20 16:45:24 PDT 2008
Author: brysonda
Date: 2008-10-20 19:45:24 -0400 (Mon, 20 Oct 2008)
New Revision: 2857
Added:
development/source/script/ASAnalyzeLib.cc
development/source/script/ASAnalyzeLib.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/script/cASFunction.h
development/source/script/cASNativeObjectMethod.h
development/source/targets/avida-s/main.cc
Log:
AS: Add support for binding native support functions to native objects as exposed via AS. For example, adding "LoadSequence" as a method on the 'World' object, even though it is not in fact a method in the actual cWorld c++ class.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2008-10-20 16:55:35 UTC (rev 2856)
+++ development/Avida.xcodeproj/project.pbxproj 2008-10-20 23:45:24 UTC (rev 2857)
@@ -168,6 +168,7 @@
7023ECDE0C0A44D800362B9C /* libavida-core.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7023EC330C0A426900362B9C /* libavida-core.a */; };
7023ECDF0C0A44D900362B9C /* libtcmalloc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 70AA941909D486AE006A24C8 /* libtcmalloc.a */; };
702F532F0993060A00B2B507 /* avida-s in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70DCAD1C097AF7CC002F8733 /* avida-s */; };
+ 70381F810EAD0BD000A97DFD /* ASAnalyzeLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70381F800EAD0BD000A97DFD /* ASAnalyzeLib.cc */; };
7039884D09F00D020052ACE7 /* analyze.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D309EE8501001AEA89 /* analyze.cfg */; };
7039884E09F00D030052ACE7 /* avida.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D509EE8501001AEA89 /* avida.cfg */; };
7039884F09F00D060052ACE7 /* environment.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D709EE8501001AEA89 /* environment.cfg */; };
@@ -417,6 +418,8 @@
702F52A80992F8F600B2B507 /* cSymbolTable.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cSymbolTable.cc; sourceTree = "<group>"; };
702F52DE0992FD8000B2B507 /* cScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cScriptObject.h; sourceTree = "<group>"; };
702F52DF0992FD8000B2B507 /* cScriptObject.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cScriptObject.cc; sourceTree = "<group>"; };
+ 70381F7F0EAD0BD000A97DFD /* ASAnalyzeLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASAnalyzeLib.h; sourceTree = "<group>"; };
+ 70381F800EAD0BD000A97DFD /* ASAnalyzeLib.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ASAnalyzeLib.cc; sourceTree = "<group>"; };
703D4D6D0ABA374A0032C8A0 /* cArgSchema.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cArgSchema.cc; sourceTree = "<group>"; };
70422A1C091B141000A5E67F /* cAnalyze.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyze.cc; sourceTree = "<group>"; };
70422A1D091B141000A5E67F /* cAnalyze.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyze.h; sourceTree = "<group>"; };
@@ -1262,6 +1265,8 @@
70BB2A2A0E9FA12F008269D2 /* ASAvidaLib.cc */,
7048A95E0EA417CD0087B7BD /* cASNativeObjectMethod.h */,
7048A9A40EA431140087B7BD /* cASCPPParameter_NativeObjectSupport.h */,
+ 70381F7F0EAD0BD000A97DFD /* ASAnalyzeLib.h */,
+ 70381F800EAD0BD000A97DFD /* ASAnalyzeLib.cc */,
);
path = script;
sourceTree = "<group>";
@@ -2079,6 +2084,7 @@
7050E7D70D7DC979008B3CA0 /* cDirectInterpretASTVisitor.cc in Sources */,
70A33CF60D8DCBB4008EF976 /* ASCoreLib.cc in Sources */,
70BB2A2B0E9FA12F008269D2 /* ASAvidaLib.cc in Sources */,
+ 70381F810EAD0BD000A97DFD /* ASAnalyzeLib.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: development/source/script/ASAnalyzeLib.cc
===================================================================
--- development/source/script/ASAnalyzeLib.cc (rev 0)
+++ development/source/script/ASAnalyzeLib.cc 2008-10-20 23:45:24 UTC (rev 2857)
@@ -0,0 +1,103 @@
+/*
+ * ASAnalyzeLib.cc
+ * Avida
+ *
+ * Created by David Bryson on 10/20/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.
+ *
+ */
+
+#include "ASAnalyzeLib.h"
+
+#include "cASCPPParameter_NativeObjectSupport.h"
+#include "cASFunction.h"
+#include "cASLibrary.h"
+#include "cASNativeObject.h"
+
+#include "cAnalyzeGenotype.h"
+#include "cDriverManager.h"
+#include "cDriverStatusConduit.h"
+#include "cGenome.h"
+#include "cGenomeUtil.h"
+#include "cHardwareManager.h"
+#include "cWorld.h"
+
+
+class cWorld;
+
+
+namespace ASAnalyzeLib {
+
+ cAnalyzeGenotype* LoadOrganismWithInstSet(cWorld* world, const cString& filename, cInstSet* inst_set)
+ {
+ cDriverManager::Status().NotifyComment(cString("Loading: ") + filename);
+
+ cGenome genome(cGenomeUtil::LoadGenome(filename, *inst_set));
+
+ // Construct the new genotype..
+ cAnalyzeGenotype* genotype = new cAnalyzeGenotype(world, genome, *inst_set);
+
+ cString genomename(filename);
+ // Determine the organism's original name -- strip off directory...
+ while (genomename.Find('/') != -1) genomename.Pop('/');
+ while (genomename.Find('\\') != -1) genomename.Pop('\\');
+ genomename.Replace(".gen", ""); // Remove the .gen from the filename.
+ genotype->SetName(genomename);
+
+ return genotype;
+ }
+
+
+ cAnalyzeGenotype* LoadOrganism(cWorld* world, const cString& filename)
+ {
+ return LoadOrganismWithInstSet(world, filename, &world->GetHardwareManager().GetInstSet());
+ }
+
+
+
+ cAnalyzeGenotype* LoadSequenceWithInstSet(cWorld* world, const cString& seq, cInstSet* inst_set)
+ {
+ cDriverManager::Status().NotifyComment(cString("Loading: ") + seq);
+ return new cAnalyzeGenotype(world, seq, *inst_set);
+ }
+
+
+ cAnalyzeGenotype* LoadSequence(cWorld* world, const cString& seq)
+ {
+ cDriverManager::Status().NotifyComment(cString("Loading: ") + seq);
+ return new cAnalyzeGenotype(world, seq, world->GetHardwareManager().GetInstSet());
+ }
+
+
+};
+
+
+void RegisterASAnalyzeLib(cASLibrary* lib)
+{
+#define BIND_FUNCTION(CLASS, NAME, METHOD, SIGNATURE) \
+ tASNativeObject<CLASS>::RegisterMethod(new tASNativeObjectBoundFunction<CLASS, SIGNATURE>(&ASAnalyzeLib::METHOD), NAME);
+#define REGISTER_FUNCTION(NAME, SIGNATURE) lib->RegisterFunction(new tASFunction<SIGNATURE>(&ASAnalyzeLib::NAME, #NAME));
+
+
+ BIND_FUNCTION(cWorld, "LoadOrganism", LoadOrganism, cAnalyzeGenotype* (const cString&));
+ BIND_FUNCTION(cWorld, "LoadOrgnaismWithInstSet", LoadOrganismWithInstSet, cAnalyzeGenotype* (const cString&, cInstSet*));
+
+
+#undef BIND_FUNCTION
+#undef REGISTER_FUNCTION
+}
Added: development/source/script/ASAnalyzeLib.h
===================================================================
--- development/source/script/ASAnalyzeLib.h (rev 0)
+++ development/source/script/ASAnalyzeLib.h 2008-10-20 23:45:24 UTC (rev 2857)
@@ -0,0 +1,32 @@
+/*
+ * ASAnalyzeLib.h
+ * Avida
+ *
+ * Created by David Bryson on 10/20/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 ASAnalyzeLib_h
+#define ASAnalyzeLib_h
+
+class cASLibrary;
+
+void RegisterASAnalyzeLib(cASLibrary* lib);
+
+#endif
Modified: development/source/script/cASFunction.h
===================================================================
--- development/source/script/cASFunction.h 2008-10-20 16:55:35 UTC (rev 2856)
+++ development/source/script/cASFunction.h 2008-10-20 23:45:24 UTC (rev 2857)
@@ -83,7 +83,7 @@
}
};
-
+
template<typename Arg1Type>
class tASFunction<void (Arg1Type)> : public cASFunction
{
@@ -114,4 +114,130 @@
+
+template<typename ReturnType, typename Arg1Type, typename Arg2Type>
+class tASFunction<ReturnType (Arg1Type, Arg2Type)> : public cASFunction
+{
+private:
+ typedef ReturnType (*TrgtFunType)(Arg1Type, Arg2Type);
+
+ sASTypeInfo m_signature[2];
+ TrgtFunType m_func;
+
+
+public:
+ tASFunction(TrgtFunType func, const cString& name) : cASFunction(name), m_func(func)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+
+ cASCPPParameter Call(cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_func)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>()));
+ return rvalue;
+ }
+};
+
+
+template<typename Arg1Type, typename Arg2Type>
+class tASFunction<void (Arg1Type, Arg2Type)> : public cASFunction
+{
+private:
+ typedef void (*TrgtFunType)(Arg1Type, Arg2Type);
+
+ sASTypeInfo m_signature[2];
+ TrgtFunType m_func;
+
+
+public:
+ tASFunction(TrgtFunType func, const cString& name) : cASFunction(name), m_func(func)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+
+ cASCPPParameter Call(cASCPPParameter args[]) const
+ {
+ (*m_func)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>());
+
+ return cASCPPParameter();
+ }
+};
+
+
+
+
+template<typename ReturnType, typename Arg1Type, typename Arg2Type, typename Arg3Type>
+class tASFunction<ReturnType (Arg1Type, Arg2Type, Arg3Type)> : public cASFunction
+{
+private:
+ typedef ReturnType (*TrgtFunType)(Arg1Type, Arg2Type, Arg3Type);
+
+ sASTypeInfo m_signature[3];
+ TrgtFunType m_func;
+
+
+public:
+ tASFunction(TrgtFunType func, const cString& name) : cASFunction(name), m_func(func)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+
+ cASCPPParameter Call(cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_func)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>()));
+ return rvalue;
+ }
+};
+
+
+template<typename Arg1Type, typename Arg2Type, typename Arg3Type>
+class tASFunction<void (Arg1Type, Arg2Type, Arg3Type)> : public cASFunction
+{
+private:
+ typedef void (*TrgtFunType)(Arg1Type, Arg2Type, Arg3Type);
+
+ sASTypeInfo m_signature[3];
+ TrgtFunType m_func;
+
+
+public:
+ tASFunction(TrgtFunType func, const cString& name) : cASFunction(name), m_func(func)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+
+ cASCPPParameter Call(cASCPPParameter args[]) const
+ {
+ (*m_func)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>());
+
+ return cASCPPParameter();
+ }
+};
+
+
+
#endif
Modified: development/source/script/cASNativeObjectMethod.h
===================================================================
--- development/source/script/cASNativeObjectMethod.h 2008-10-20 16:55:35 UTC (rev 2856)
+++ development/source/script/cASNativeObjectMethod.h 2008-10-20 23:45:24 UTC (rev 2857)
@@ -49,8 +49,11 @@
template<class NativeClass, class FunctionType> class tASNativeObjectMethod;
template<class NativeClass, class FunctionType> class tASNativeObjectMethodConst;
+template<class NativeClass, class FunctionType> class tASNativeObjectBoundFunction;
+// ---------- void (void) -----------
+
template<class NativeClass>
class tASNativeObjectMethod<NativeClass, void ()> : public cASNativeObjectMethod<NativeClass>
{
@@ -105,6 +108,121 @@
};
+template<class NativeClass>
+class tASNativeObjectBoundFunction<NativeClass, void ()> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ void (*m_method)(NativeClass*);
+
+public:
+ tASNativeObjectBoundFunction(void (*method)(NativeClass*)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature = AvidaScript::TypeOf<void>();
+ }
+
+ int GetArity() const { return 0; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (*m_method)(object);
+ return cASCPPParameter(); // @TODO - return actual void value?
+ }
+};
+
+
+// ---------- ReturnType (void) -----------
+
+template<class NativeClass, class ReturnType>
+class tASNativeObjectMethod<NativeClass, ReturnType ()> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ ReturnType (NativeClass::*m_method)();
+
+public:
+ tASNativeObjectMethod(ReturnType (NativeClass::*method)()) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature = AvidaScript::TypeOf<void>();
+ }
+
+ int GetArity() const { return 0; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((object->*m_method)());
+ return rvalue;
+ }
+};
+
+
+template<class NativeClass, class ReturnType>
+class tASNativeObjectMethodConst<NativeClass, ReturnType ()> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ ReturnType (NativeClass::*m_method)() const;
+
+public:
+ tASNativeObjectMethodConst(ReturnType (NativeClass::*method)() const) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature = AvidaScript::TypeOf<void>();
+ }
+
+ int GetArity() const { return 0; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((object->*m_method)());
+ return rvalue;
+ }
+};
+
+
+template<class NativeClass, class ReturnType>
+class tASNativeObjectBoundFunction<NativeClass, ReturnType ()> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ ReturnType (*m_method)(NativeClass*);
+
+public:
+ tASNativeObjectBoundFunction(ReturnType (*method)(NativeClass*)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature = AvidaScript::TypeOf<void>();
+ }
+
+ int GetArity() const { return 0; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_method)(object));
+ return rvalue;
+ }
+};
+
+
+// ---------- void (Arg1Type) -----------
+
template<class NativeClass, class Arg1Type>
class tASNativeObjectMethod<NativeClass, void (Arg1Type)> : public cASNativeObjectMethod<NativeClass>
{
@@ -159,6 +277,212 @@
};
+template<class NativeClass, class Arg1Type>
+class tASNativeObjectBoundFunction<NativeClass, void (Arg1Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ void (*m_method)(NativeClass*, Arg1Type);
+
+public:
+ tASNativeObjectBoundFunction(void (*method)(NativeClass*, Arg1Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature = AvidaScript::TypeOf<Arg1Type>();
+ }
+
+ int GetArity() const { return 1; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (*m_method)(object, args[0].Get<Arg1Type>());
+ return cASCPPParameter(); // @TODO - return actual void value?
+ }
+};
+
+
+// ---------- void (Arg1Type, Arg2Type) -----------
+
+template<class NativeClass, class Arg1Type, class Arg2Type>
+class tASNativeObjectMethod<NativeClass, void (Arg1Type, Arg2Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ void (NativeClass::*m_method)(Arg1Type, Arg2Type);
+
+public:
+ tASNativeObjectMethod(void (NativeClass::*method)(Arg1Type, Arg2Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+template<class NativeClass, class Arg1Type, class Arg2Type>
+class tASNativeObjectMethodConst<NativeClass, void (Arg1Type, Arg2Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ void (NativeClass::*m_method)(Arg1Type, Arg2Type) const;
+
+public:
+ tASNativeObjectMethodConst(void (NativeClass::*method)(Arg1Type, Arg2Type) const) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+template<class NativeClass, class Arg1Type, class Arg2Type>
+class tASNativeObjectBoundFunction<NativeClass, void (Arg1Type, Arg2Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ void (*m_method)(NativeClass*, Arg1Type, Arg2Type);
+
+public:
+ tASNativeObjectBoundFunction(void (*method)(NativeClass*, Arg1Type, Arg2Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (*m_method)(object, args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+// ---------- void (Arg1Type, Arg2Type, Arg3Type) -----------
+
+template<class NativeClass, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectMethod<NativeClass, void (Arg1Type, Arg2Type, Arg3Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[3];
+ void (NativeClass::*m_method)(Arg1Type, Arg2Type, Arg3Type);
+
+public:
+ tASNativeObjectMethod(void (NativeClass::*method)(Arg1Type, Arg2Type, Arg3Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+template<class NativeClass, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectMethodConst<NativeClass, void (Arg1Type, Arg2Type, Arg3Type)>
+ : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ void (NativeClass::*m_method)(Arg1Type, Arg2Type, Arg3Type) const;
+
+public:
+ tASNativeObjectMethodConst(void (NativeClass::*method)(Arg1Type, Arg2Type, Arg3Type) const) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+template<class NativeClass, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectBoundFunction<NativeClass, void (Arg1Type, Arg2Type, Arg3Type)>
+ : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ void (*m_method)(NativeClass*, Arg1Type, Arg2Type, Arg3Type);
+
+public:
+ tASNativeObjectBoundFunction(void (*method)(NativeClass*, Arg1Type, Arg2Type, Arg3Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<void>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ (*m_method)(object, args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>());
+ return cASCPPParameter();
+ }
+};
+
+
+// ---------- ReturnType (Arg1Type) -----------
+
template<class NativeClass, class ReturnType, class Arg1Type>
class tASNativeObjectMethod<NativeClass, ReturnType (Arg1Type)> : public cASNativeObjectMethod<NativeClass>
{
@@ -215,7 +539,36 @@
};
+template<class NativeClass, class ReturnType, class Arg1Type>
+class tASNativeObjectBoundFunction<NativeClass, ReturnType (Arg1Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature;
+ ReturnType (*m_method)(NativeClass*, Arg1Type);
+
+public:
+ tASNativeObjectBoundFunction(ReturnType (*method)(NativeClass*, Arg1Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature = AvidaScript::TypeOf<Arg1Type>();
+ }
+
+ int GetArity() const { return 1; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_method)(object, args[0].Get<Arg1Type>()));
+ return rvalue;
+ }
+};
+
+// ---------- ReturnType (Arg1Type, Arg2Type) -----------
+
template<class NativeClass, class ReturnType, class Arg1Type, class Arg2Type>
class tASNativeObjectMethod<NativeClass, ReturnType (Arg1Type, Arg2Type)> : public cASNativeObjectMethod<NativeClass>
{
@@ -274,4 +627,128 @@
};
+template<class NativeClass, class ReturnType, class Arg1Type, class Arg2Type>
+class tASNativeObjectBoundFunction<NativeClass, ReturnType (Arg1Type, Arg2Type)> : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ ReturnType (*m_method)(NativeClass*, Arg1Type, Arg2Type);
+
+public:
+ tASNativeObjectBoundFunction(ReturnType (*method)(NativeClass*, Arg1Type, Arg2Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ }
+
+ int GetArity() const { return 2; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_method)(object, args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>()));
+ return rvalue;
+ }
+};
+
+
+// ---------- ReturnType (Arg1Type, Arg2Type, Arg3Type) -----------
+
+template<class NativeClass, class ReturnType, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectMethod<NativeClass, ReturnType (Arg1Type, Arg2Type, Arg3Type)>
+ : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[3];
+ ReturnType (NativeClass::*m_method)(Arg1Type, Arg2Type, Arg3Type);
+
+public:
+ tASNativeObjectMethod(ReturnType (NativeClass::*method)(Arg1Type, Arg2Type, Arg3Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>()));
+ return rvalue;
+ }
+};
+
+
+template<class NativeClass, class ReturnType, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectMethodConst<NativeClass, ReturnType (Arg1Type, Arg2Type, Arg3Type)>
+ : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ ReturnType (NativeClass::*m_method)(Arg1Type, Arg2Type, Arg3Type) const;
+
+public:
+ tASNativeObjectMethodConst(ReturnType (NativeClass::*method)(Arg1Type, Arg2Type, Arg3Type) const) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((object->*m_method)(args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>()));
+ return rvalue;
+ }
+};
+
+
+template<class NativeClass, class ReturnType, class Arg1Type, class Arg2Type, class Arg3Type>
+class tASNativeObjectBoundFunction<NativeClass, ReturnType (Arg1Type, Arg2Type, Arg3Type)>
+ : public cASNativeObjectMethod<NativeClass>
+{
+private:
+ sASTypeInfo m_rtype;
+ sASTypeInfo m_signature[2];
+ ReturnType (*m_method)(NativeClass*, Arg1Type, Arg2Type, Arg3Type);
+
+public:
+ tASNativeObjectBoundFunction(ReturnType (*method)(NativeClass*, Arg1Type, Arg2Type, Arg3Type)) : m_method(method)
+ {
+ m_rtype = AvidaScript::TypeOf<ReturnType>();
+ m_signature[0] = AvidaScript::TypeOf<Arg1Type>();
+ m_signature[1] = AvidaScript::TypeOf<Arg2Type>();
+ m_signature[2] = AvidaScript::TypeOf<Arg3Type>();
+ }
+
+ int GetArity() const { return 3; }
+ const sASTypeInfo& GetArgumentType(int arg) const { return m_signature[arg]; }
+ const sASTypeInfo& GetReturnType() const { return m_rtype; }
+
+ cASCPPParameter Call(NativeClass* object, cASCPPParameter args[]) const
+ {
+ cASCPPParameter rvalue;
+ rvalue.Set((*m_method)(object, args[0].Get<Arg1Type>(), args[1].Get<Arg2Type>(), args[2].Get<Arg3Type>()));
+ return rvalue;
+ }
+};
+
+
#endif
Modified: development/source/targets/avida-s/main.cc
===================================================================
--- development/source/targets/avida-s/main.cc 2008-10-20 16:55:35 UTC (rev 2856)
+++ development/source/targets/avida-s/main.cc 2008-10-20 23:45:24 UTC (rev 2857)
@@ -27,6 +27,7 @@
#include "ASCoreLib.h"
#include "ASAvidaLib.h"
+#include "ASAnalyzeLib.h"
#include "cASLibrary.h"
#include "cDirectInterpretASTVisitor.h"
@@ -48,6 +49,7 @@
cASLibrary* lib = new cASLibrary;
RegisterASCoreLib(lib);
RegisterASAvidaLib(lib);
+ RegisterASAnalyzeLib(lib);
cParser* parser = new cParser;
More information about the Avida-cvs
mailing list