[Avida-cvs] [Avida2-svn] r179 - in branches/brysonda: Avida2.xcode
source source/bindings/Boost.Python
source/bindings/Boost.Python/AvidaGui source/cpu source/main
source/testsuites/unit_testsuites source/viewers
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Jun 6 07:59:30 PDT 2005
Author: brysonda
Date: 2005-06-06 10:59:29 -0400 (Mon, 06 Jun 2005)
New Revision: 179
Added:
branches/brysonda/source/cpu/hardware_smt_constants.h
branches/brysonda/source/cpu/head_cpu.cc
branches/brysonda/source/cpu/head_cpu.hh
branches/brysonda/source/cpu/head_multi_mem.cc
branches/brysonda/source/cpu/head_multi_mem.hh
Removed:
branches/brysonda/source/cpu/4stack_head.cc
branches/brysonda/source/cpu/4stack_head.hh
branches/brysonda/source/cpu/cpu_head.cc
branches/brysonda/source/cpu/cpu_head.hh
Modified:
branches/brysonda/Avida2.xcode/project.pbxproj
branches/brysonda/source/bindings/Boost.Python/4stack_head.pyste
branches/brysonda/source/bindings/Boost.Python/AvidaGui/py_avida_core_data.py
branches/brysonda/source/bindings/Boost.Python/cpu_head.pyste
branches/brysonda/source/bindings/Boost.Python/generatePysteFiles.py
branches/brysonda/source/cpu/cpu_stack.hh
branches/brysonda/source/cpu/hardware_4stack.cc
branches/brysonda/source/cpu/hardware_4stack.hh
branches/brysonda/source/cpu/hardware_4stack_thread.hh
branches/brysonda/source/cpu/hardware_cpu.cc
branches/brysonda/source/cpu/hardware_cpu.hh
branches/brysonda/source/cpu/hardware_cpu_thread.hh
branches/brysonda/source/cpu/hardware_smt.cc
branches/brysonda/source/cpu/hardware_smt.h
branches/brysonda/source/cpu/hardware_smt_thread.cc
branches/brysonda/source/cpu/hardware_smt_thread.h
branches/brysonda/source/cpu/hardware_status_printer.cc
branches/brysonda/source/cpu/hardware_util.cc
branches/brysonda/source/cpu/hardware_util.hh
branches/brysonda/source/cpu/tInstLib.h
branches/brysonda/source/defs.hh
branches/brysonda/source/main/avida.cc
branches/brysonda/source/testsuites/unit_testsuites/4stack_head.t.cc
branches/brysonda/source/testsuites/unit_testsuites/cpu_head.t.cc
branches/brysonda/source/viewers/zoom_screen.cc
Log:
New hardware successfully(?) added. Reworked CPU instruction library initialization.
Modified: branches/brysonda/Avida2.xcode/project.pbxproj
===================================================================
--- branches/brysonda/Avida2.xcode/project.pbxproj 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/Avida2.xcode/project.pbxproj 2005-06-06 14:59:29 UTC (rev 179)
@@ -25,7 +25,6 @@
dstPath = work;
dstSubfolderSpec = 16;
files = (
- 70486BB708267635009328F0,
70486BA00826722F009328F0,
70486BA10826722F009328F0,
70486BA20826722F009328F0,
@@ -34,9 +33,7 @@
70486BA50826722F009328F0,
70486BA60826722F009328F0,
70486BA70826722F009328F0,
- 706D30CD0852328F00D7DC8F,
- 706D30FD0852363400D7DC8F,
- 706D31010852366400D7DC8F,
+ 706D3158085243CD00D7DC8F,
);
isa = PBXCopyFilesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@@ -89,12 +86,6 @@
settings = {
};
};
- 70486BB708267635009328F0 = {
- fileRef = DCC3164D07626CF3008F7A48;
- isa = PBXBuildFile;
- settings = {
- };
- };
706D30CC0852328F00D7DC8F = {
fileEncoding = 4;
isa = PBXFileReference;
@@ -103,12 +94,6 @@
refType = 4;
sourceTree = "<group>";
};
- 706D30CD0852328F00D7DC8F = {
- fileRef = 706D30CC0852328F00D7DC8F;
- isa = PBXBuildFile;
- settings = {
- };
- };
706D30FB0852363400D7DC8F = {
fileEncoding = 4;
isa = PBXFileReference;
@@ -125,18 +110,6 @@
refType = 4;
sourceTree = "<group>";
};
- 706D30FD0852363400D7DC8F = {
- fileRef = 706D30FB0852363400D7DC8F;
- isa = PBXBuildFile;
- settings = {
- };
- };
- 706D30FE0852363400D7DC8F = {
- fileRef = 706D30FC0852363400D7DC8F;
- isa = PBXBuildFile;
- settings = {
- };
- };
706D30FF0852366400D7DC8F = {
fileEncoding = 4;
isa = PBXFileReference;
@@ -153,18 +126,54 @@
refType = 4;
sourceTree = "<group>";
};
- 706D31010852366400D7DC8F = {
- fileRef = 706D30FF0852366400D7DC8F;
+ 706D3155085243CD00D7DC8F = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.cpp;
+ path = head_cpu.cc;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 706D3156085243CD00D7DC8F = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.cpp.h;
+ path = head_cpu.hh;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 706D3157085243CD00D7DC8F = {
+ fileRef = 706D3155085243CD00D7DC8F;
isa = PBXBuildFile;
settings = {
};
};
- 706D31020852366400D7DC8F = {
+ 706D3158085243CD00D7DC8F = {
+ fileRef = 706D3156085243CD00D7DC8F;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 706D31650852475D00D7DC8F = {
fileRef = 706D31000852366400D7DC8F;
isa = PBXBuildFile;
settings = {
};
};
+ 706D31660852475E00D7DC8F = {
+ fileRef = 706D30FC0852363400D7DC8F;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
+ 706D3170085248F800D7DC8F = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ path = hardware_smt_constants.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
70CBFCE80815E7FE0078D8CC = {
fileEncoding = 30;
isa = PBXFileReference;
@@ -2274,21 +2283,11 @@
};
DCC30F7C0762539D008F7A48 = {
children = (
- 70CBFCE80815E7FE0078D8CC,
- 70CBFCE90815E7FE0078D8CC,
- 70CBFCEA0815E7FE0078D8CC,
- 70CBFCEB0815E7FE0078D8CC,
- 70CBFCEC0815E7FE0078D8CC,
- 70CBFCED0815E7FE0078D8CC,
- DCC30FA70762539D008F7A48,
- DCC30FA80762539D008F7A48,
DCC30FA90762539D008F7A48,
DCC30FAA0762539D008F7A48,
DCC30FAB0762539D008F7A48,
DCC30FAC0762539D008F7A48,
DCC30FAD0762539D008F7A48,
- DCC30FAE0762539D008F7A48,
- DCC30FAF0762539D008F7A48,
DCC30FB00762539D008F7A48,
DCC30FB10762539D008F7A48,
DCC30FB20762539D008F7A48,
@@ -2309,8 +2308,23 @@
DCC30FC10762539D008F7A48,
DCC30FC20762539D008F7A48,
DCC30FC30762539D008F7A48,
+ 706D30FB0852363400D7DC8F,
+ 706D30FC0852363400D7DC8F,
+ 706D3170085248F800D7DC8F,
+ 706D30FF0852366400D7DC8F,
+ 706D31000852366400D7DC8F,
+ 70CBFCE80815E7FE0078D8CC,
+ 70CBFCE90815E7FE0078D8CC,
+ 70CBFCEA0815E7FE0078D8CC,
+ 70CBFCEB0815E7FE0078D8CC,
+ 70CBFCEC0815E7FE0078D8CC,
+ 70CBFCED0815E7FE0078D8CC,
DCC30FC40762539D008F7A48,
DCC30FC50762539D008F7A48,
+ 706D3155085243CD00D7DC8F,
+ 706D3156085243CD00D7DC8F,
+ DCC30FA70762539D008F7A48,
+ DCC30FA80762539D008F7A48,
DCC30FC60762539D008F7A48,
DCC30FC80762539D008F7A48,
DCC30FC90762539D008F7A48,
@@ -2319,10 +2333,6 @@
DCC30FCC0762539D008F7A48,
DCC30FCD0762539D008F7A48,
706D30CC0852328F00D7DC8F,
- 706D30FB0852363400D7DC8F,
- 706D30FC0852363400D7DC8F,
- 706D30FF0852366400D7DC8F,
- 706D31000852366400D7DC8F,
);
isa = PBXGroup;
path = cpu;
@@ -2333,7 +2343,7 @@
fileEncoding = 30;
isa = PBXFileReference;
lastKnownFileType = sourcecode.cpp.cpp;
- path = 4stack_head.cc;
+ path = head_multi_mem.cc;
refType = 4;
sourceTree = "<group>";
};
@@ -2341,7 +2351,7 @@
fileEncoding = 30;
isa = PBXFileReference;
lastKnownFileType = sourcecode.cpp.h;
- path = 4stack_head.hh;
+ path = head_multi_mem.hh;
refType = 4;
sourceTree = "<group>";
};
@@ -2385,22 +2395,6 @@
refType = 4;
sourceTree = "<group>";
};
- DCC30FAE0762539D008F7A48 = {
- fileEncoding = 30;
- isa = PBXFileReference;
- lastKnownFileType = sourcecode.cpp.cpp;
- path = cpu_head.cc;
- refType = 4;
- sourceTree = "<group>";
- };
- DCC30FAF0762539D008F7A48 = {
- fileEncoding = 30;
- isa = PBXFileReference;
- lastKnownFileType = sourcecode.cpp.h;
- path = cpu_head.hh;
- refType = 4;
- sourceTree = "<group>";
- };
DCC30FB00762539D008F7A48 = {
fileEncoding = 30;
isa = PBXFileReference;
@@ -9497,7 +9491,6 @@
DCC316A1076285C8008F7A48,
DCC316A2076285D1008F7A48,
DCC316A3076285D2008F7A48,
- DCC316A4076285D3008F7A48,
DCC316A5076285D5008F7A48,
DCC316A6076285D5008F7A48,
DCC316A7076285D6008F7A48,
@@ -9552,8 +9545,9 @@
DCC316DB0762876F008F7A48,
70CBFCEE0815E7FE0078D8CC,
70CBFCF10815E8370078D8CC,
- 706D30FE0852363400D7DC8F,
- 706D31020852366400D7DC8F,
+ 706D3157085243CD00D7DC8F,
+ 706D31650852475D00D7DC8F,
+ 706D31660852475E00D7DC8F,
);
isa = PBXSourcesBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
@@ -10030,12 +10024,6 @@
settings = {
};
};
- DCC316A4076285D3008F7A48 = {
- fileRef = DCC30FAE0762539D008F7A48;
- isa = PBXBuildFile;
- settings = {
- };
- };
DCC316A5076285D5008F7A48 = {
fileRef = DCC30FB00762539D008F7A48;
isa = PBXBuildFile;
Modified: branches/brysonda/source/bindings/Boost.Python/4stack_head.pyste
===================================================================
--- branches/brysonda/source/bindings/Boost.Python/4stack_head.pyste 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/bindings/Boost.Python/4stack_head.pyste 2005-06-06 14:59:29 UTC (rev 179)
@@ -5,12 +5,12 @@
Include("instruction.hh")
Include("hardware_base.hh")
-c4StackHead = Class("c4StackHead", "4stack_head.hh")
-set_policy(c4StackHead.FlagCopied, return_internal_reference())
-set_policy(c4StackHead.FlagMutated, return_internal_reference())
-set_policy(c4StackHead.FlagExecuted, return_internal_reference())
-set_policy(c4StackHead.FlagPointMut, return_internal_reference())
-set_policy(c4StackHead.FlagCopyMut, return_internal_reference())
-set_policy(c4StackHead.FlagBreakpoint, return_internal_reference())
+cHeadMultiMem = Class("cHeadMultiMem", "head_multi_mem.hh")
+set_policy(cHeadMultiMem.FlagCopied, return_internal_reference())
+set_policy(cHeadMultiMem.FlagMutated, return_internal_reference())
+set_policy(cHeadMultiMem.FlagExecuted, return_internal_reference())
+set_policy(cHeadMultiMem.FlagPointMut, return_internal_reference())
+set_policy(cHeadMultiMem.FlagCopyMut, return_internal_reference())
+set_policy(cHeadMultiMem.FlagBreakpoint, return_internal_reference())
# vim: set ft=python:
Modified: branches/brysonda/source/bindings/Boost.Python/AvidaGui/py_avida_core_data.py
===================================================================
--- branches/brysonda/source/bindings/Boost.Python/AvidaGui/py_avida_core_data.py 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/bindings/Boost.Python/AvidaGui/py_avida_core_data.py 2005-06-06 14:59:29 UTC (rev 179)
@@ -21,7 +21,7 @@
import sys
sys.exit()
self.environment.GetInstSet().SetInstLib(cHardwareCPU.GetInstLib())
- cHardwareUtil.LoadInstSet_CPUOriginal(cConfig.GetInstFilename(), self.environment.GetInstSet())
+ cHardwareUtil.LoadInstSet(cConfig.GetInstFilename(), self.environment.GetInstSet())
cConfig.SetNumInstructions(self.environment.GetInstSet().GetSize())
cConfig.SetNumTasks(self.environment.GetTaskLib().GetSize())
cConfig.SetNumReactions(self.environment.GetReactionLib().GetSize())
Modified: branches/brysonda/source/bindings/Boost.Python/cpu_head.pyste
===================================================================
--- branches/brysonda/source/bindings/Boost.Python/cpu_head.pyste 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/bindings/Boost.Python/cpu_head.pyste 2005-06-06 14:59:29 UTC (rev 179)
@@ -4,44 +4,44 @@
Include("hardware_base.hh")
Include("code_label.hh")
-cCPUHead = Class("cCPUHead", "cpu_head-fixups.hh")
-set_policy(cCPUHead.GetCurHardware, return_internal_reference())
-set_policy(cCPUHead.GetMainHardware, return_internal_reference())
+cHeadCPU = Class("cHeadCPU", "cpu_head-fixups.hh")
+set_policy(cHeadCPU.GetCurHardware, return_internal_reference())
+set_policy(cHeadCPU.GetMainHardware, return_internal_reference())
-exclude(cCPUHead.FlagCopied)
-exclude(cCPUHead.FlagMutated)
-exclude(cCPUHead.FlagExecuted)
-exclude(cCPUHead.FlagPointMut)
-exclude(cCPUHead.FlagCopyMut)
-exclude(cCPUHead.FlagBreakpoint)
+exclude(cHeadCPU.FlagCopied)
+exclude(cHeadCPU.FlagMutated)
+exclude(cHeadCPU.FlagExecuted)
+exclude(cHeadCPU.FlagPointMut)
+exclude(cHeadCPU.FlagCopyMut)
+exclude(cHeadCPU.FlagBreakpoint)
-add_method(cCPUHead, "cCPUHead_GetFlagCopied")
-add_method(cCPUHead, "cCPUHead_GetFlagMutated")
-add_method(cCPUHead, "cCPUHead_GetFlagExecuted")
-add_method(cCPUHead, "cCPUHead_GetFlagPointMut")
-add_method(cCPUHead, "cCPUHead_GetFlagCopyMut")
-add_method(cCPUHead, "cCPUHead_GetFlagBreakpoint")
+add_method(cHeadCPU, "cHeadCPU_GetFlagCopied")
+add_method(cHeadCPU, "cHeadCPU_GetFlagMutated")
+add_method(cHeadCPU, "cHeadCPU_GetFlagExecuted")
+add_method(cHeadCPU, "cHeadCPU_GetFlagPointMut")
+add_method(cHeadCPU, "cHeadCPU_GetFlagCopyMut")
+add_method(cHeadCPU, "cHeadCPU_GetFlagBreakpoint")
-add_method(cCPUHead, "cCPUHead_SetFlagCopied")
-add_method(cCPUHead, "cCPUHead_SetFlagMutated")
-add_method(cCPUHead, "cCPUHead_SetFlagExecuted")
-add_method(cCPUHead, "cCPUHead_SetFlagPointMut")
-add_method(cCPUHead, "cCPUHead_SetFlagCopyMut")
-add_method(cCPUHead, "cCPUHead_SetFlagBreakpoint")
+add_method(cHeadCPU, "cHeadCPU_SetFlagCopied")
+add_method(cHeadCPU, "cHeadCPU_SetFlagMutated")
+add_method(cHeadCPU, "cHeadCPU_SetFlagExecuted")
+add_method(cHeadCPU, "cHeadCPU_SetFlagPointMut")
+add_method(cHeadCPU, "cHeadCPU_SetFlagCopyMut")
+add_method(cHeadCPU, "cHeadCPU_SetFlagBreakpoint")
-rename(cCPUHead.cCPUHead_GetFlagCopied, "GetFlagCopied");
-rename(cCPUHead.cCPUHead_GetFlagMutated, "GetFlagMutated");
-rename(cCPUHead.cCPUHead_GetFlagExecuted, "GetFlagExecuted");
-rename(cCPUHead.cCPUHead_GetFlagPointMut, "GetFlagPointMut");
-rename(cCPUHead.cCPUHead_GetFlagCopyMut, "GetFlagCopyMut");
-rename(cCPUHead.cCPUHead_GetFlagBreakpoint, "GetFlagBreakpoint");
+rename(cHeadCPU.cHeadCPU_GetFlagCopied, "GetFlagCopied");
+rename(cHeadCPU.cHeadCPU_GetFlagMutated, "GetFlagMutated");
+rename(cHeadCPU.cHeadCPU_GetFlagExecuted, "GetFlagExecuted");
+rename(cHeadCPU.cHeadCPU_GetFlagPointMut, "GetFlagPointMut");
+rename(cHeadCPU.cHeadCPU_GetFlagCopyMut, "GetFlagCopyMut");
+rename(cHeadCPU.cHeadCPU_GetFlagBreakpoint, "GetFlagBreakpoint");
-rename(cCPUHead.cCPUHead_SetFlagCopied, "SetFlagCopied");
-rename(cCPUHead.cCPUHead_SetFlagMutated, "SetFlagMutated");
-rename(cCPUHead.cCPUHead_SetFlagExecuted, "SetFlagExecuted");
-rename(cCPUHead.cCPUHead_SetFlagPointMut, "SetFlagPointMut");
-rename(cCPUHead.cCPUHead_SetFlagCopyMut, "SetFlagCopyMut");
-rename(cCPUHead.cCPUHead_SetFlagBreakpoint, "SetFlagBreakpoint");
+rename(cHeadCPU.cHeadCPU_SetFlagCopied, "SetFlagCopied");
+rename(cHeadCPU.cHeadCPU_SetFlagMutated, "SetFlagMutated");
+rename(cHeadCPU.cHeadCPU_SetFlagExecuted, "SetFlagExecuted");
+rename(cHeadCPU.cHeadCPU_SetFlagPointMut, "SetFlagPointMut");
+rename(cHeadCPU.cHeadCPU_SetFlagCopyMut, "SetFlagCopyMut");
+rename(cHeadCPU.cHeadCPU_SetFlagBreakpoint, "SetFlagBreakpoint");
# vim: set ft=python:
Modified: branches/brysonda/source/bindings/Boost.Python/generatePysteFiles.py
===================================================================
--- branches/brysonda/source/bindings/Boost.Python/generatePysteFiles.py 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/bindings/Boost.Python/generatePysteFiles.py 2005-06-06 14:59:29 UTC (rev 179)
@@ -4,10 +4,10 @@
classes_table = [
#["cCLASSNAMEBLAHBLAHBLAHBLAHBLAH", "defs", [],],
# cpu/
- ["c4StackHead", "4stack_head", ["cpu_head"],],
+ ["cHeadMultiMem", "4stack_head", ["cpu_head"],],
["cCodeLabel", "code_label", [],],
#["cCLASSNAMEBLAHBLAHBLAHBLAHBLAH", "cpu_defs", [],],
- ["cCPUHead", "cpu_head", [],],
+ ["cHeadCPU", "cpu_head", [],],
["cCPUMemory", "cpu_memory", ["genome"],],
["cCPUStack", "cpu_stack", [],],
["sCPUStats", "cpu_stats", [],],
Deleted: branches/brysonda/source/cpu/4stack_head.cc
===================================================================
--- branches/brysonda/source/cpu/4stack_head.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/4stack_head.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,224 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology //
-// //
-// Read the COPYING and README files, or contact 'avida at alife.org', //
-// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
-#endif
-
-#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
-#include "hardware_base.hh"
-#endif
-#ifndef INST_SET_HH
-#include "inst_set.hh"
-#endif
-#ifndef INSTRUCTION_HH
-#include "instruction.hh"
-#endif
-
-#include <assert.h>
-
-c4StackHead::c4StackHead() : cCPUHead() { mem_space=0; }
-
-c4StackHead::c4StackHead(cHardwareBase * in_hardware, int in_pos, int in_mem_space)
- : cCPUHead(in_hardware, in_pos) { mem_space = in_mem_space; }
-
-c4StackHead::c4StackHead(const c4StackHead & in_head) : cCPUHead(in_head)
-{
- mem_space = in_head.mem_space;
-}
-
-void c4StackHead::Adjust()
-{
- assert(cur_hardware != NULL);
- assert(main_hardware != NULL);
-
- const int mem_size = GetMemory().GetSize();
-
- // If we are still in range, stop here!
- if (position >= 0 && position < mem_size) return;
-
- // If the memory is gone, just stick it at the begining of its parent.
- if (mem_size == 0) {
- cur_hardware = main_hardware;
- position = 0;
- }
- else if (position <= 0) { position = 0; }
- else if (position >= mem_size) {
- // Always loop into the begining of the owner hardware.
- cur_hardware = main_hardware;
- position -= mem_size;
- while (position >= GetMemory().GetSize()) {
- // position back at the begining of the creature.
- position %= GetMemory().GetSize();
- }
- }
-}
-
-void c4StackHead::Reset(int in_mem_space, cHardwareBase * new_hardware)
-{
- if (new_hardware) main_hardware = new_hardware;
- cur_hardware = new_hardware;
- position = 0;
- mem_space = in_mem_space;
-}
-
-void c4StackHead::Set(int new_pos, int in_mem_space, cHardwareBase * in_hardware)
-{
- position = new_pos;
- if (in_hardware) cur_hardware = in_hardware;
- mem_space = in_mem_space;
- Adjust();
-}
-
-void c4StackHead::Set(const c4StackHead & in_head)
-{
- position = in_head.position;
- cur_hardware = in_head.cur_hardware;
- mem_space = in_head.mem_space;
- Adjust();
-}
-
-void c4StackHead::LoopJump(int jump)
-{
- position += jump;
-
- // If we are out of range, bring back in.
- if (position < 0 || position >= GetMemory().GetSize()) {
- position %= GetMemory().GetSize();
- if (position <= 0) position += GetMemory().GetSize();
- }
-}
-
-const cCPUMemory & c4StackHead::GetMemory() const
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory(mem_space);
-}
-
-cCPUMemory & c4StackHead::GetMemory()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory(mem_space);
-}
-
-const cInstruction & c4StackHead::GetInst() const
-{
- assert(position >= 0);
- assert(position < GetMemory().GetSize());
- return GetMemory()[position];
-}
-
-const cInstruction & c4StackHead::GetInst(int offset) const
-{
- int new_pos = position + offset;
- return GetMemory()[new_pos];
-}
-
-
-void c4StackHead::SetInst(const cInstruction & value)
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) GetMemory()[position] = value;
-#else
- GetMemory()[position] = value;
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-void c4StackHead::InsertInst(const cInstruction & value)
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) GetMemory().Insert(position, value);
-#else
- GetMemory().Insert(position, value);
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-void c4StackHead::RemoveInst()
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) GetMemory().Remove(position);
-#else
- GetMemory().Remove(position);
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-const cInstruction & c4StackHead::GetNextInst()
-{
- return (AtEnd()) ? cInstSet::GetInstError() : GetMemory()[position+1];
-}
-
-bool & c4StackHead::FlagCopied()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagCopied(position);
-}
-
-bool & c4StackHead::FlagMutated()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagMutated(position);
-}
-
-bool & c4StackHead::FlagExecuted()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagExecuted(position);
-}
-
-bool & c4StackHead::FlagBreakpoint()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagBreakpoint(position);
-}
-
-bool & c4StackHead::FlagPointMut()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagPointMut(position);
-}
-
-bool & c4StackHead::FlagCopyMut()
-{
- assert(cur_hardware != NULL);
- return GetMemory().FlagCopyMut(position);
-}
-
-c4StackHead & c4StackHead::operator=(const c4StackHead & in_cpu_head)
-{
- main_hardware = in_cpu_head.main_hardware;
- cur_hardware = in_cpu_head.cur_hardware;
- position = in_cpu_head.position;
- mem_space = in_cpu_head.mem_space;
- return *this;
-}
-
-bool c4StackHead::operator==(const c4StackHead & in_cpu_head) const
-{
- return (cur_hardware == in_cpu_head.cur_hardware) &&
- (position == in_cpu_head.position) &&
- (mem_space == in_cpu_head.mem_space);
-}
-
-bool c4StackHead::AtEnd() const
-{
- return (position + 1 == GetMemory().GetSize());
-}
-
-bool c4StackHead::InMemory() const
-{
- return (position >= 0 && position < GetMemory().GetSize());
-}
-
Deleted: branches/brysonda/source/cpu/4stack_head.hh
===================================================================
--- branches/brysonda/source/cpu/4stack_head.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/4stack_head.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,65 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology //
-// //
-// Read the COPYING and README files, or contact 'avida at alife.org', //
-// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef FOURSTACK_HEAD_HH
-#define FOURSTACK_HEAD_HH
-
-#ifndef CPU_HEAD_HH
-#include "cpu_head.hh"
-#endif
-#ifndef DEFS_HH
-#include "defs.hh"
-#endif
-
-class cCodeLabel;
-class cCPUMemory;
-class cGenome;
-class cHardwareBase;
-class cInstruction;
-
-class c4StackHead : public cCPUHead {
-private:
- int mem_space;
-
-public:
-
- c4StackHead();
- c4StackHead(cHardwareBase * in_hardware, int in_pos = 0, int mem_space = 0);
- c4StackHead(const c4StackHead & in_cpu_head);
-
- void Adjust();
- void Reset(int in_mem_space=0, cHardwareBase * new_hardware = NULL);
- void Set(int new_pos, int in_mem_space = 0, cHardwareBase * in_hardware = NULL);
- void Set(const c4StackHead & in_head);
- void LoopJump(int jump);
- const cCPUMemory & GetMemory() const;
- cCPUMemory & GetMemory();
- const cInstruction & GetInst() const;
- const cInstruction & GetInst(int offset) const;
-
- int GetMemSpace() const { return mem_space; }
-
- void SetInst(const cInstruction & value);
- void InsertInst(const cInstruction & in_char);
- void RemoveInst();
- const cInstruction & GetNextInst();
-
- bool & FlagCopied();
- bool & FlagMutated();
- bool & FlagExecuted();
- bool & FlagBreakpoint();
- bool & FlagPointMut();
- bool & FlagCopyMut();
-
- // Operator Overloading...
- c4StackHead & operator=(const c4StackHead & in_cpu_head);
- bool operator==(const c4StackHead & in_cpu_head) const;
- bool AtEnd() const;
- bool InMemory() const;
-};
-
-#endif
Deleted: branches/brysonda/source/cpu/cpu_head.cc
===================================================================
--- branches/brysonda/source/cpu/cpu_head.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/cpu_head.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,489 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology //
-// //
-// Read the COPYING and README files, or contact 'avida at alife.org', //
-// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef CPU_HEAD_HH
-#include "cpu_head.hh"
-#endif
-
-#ifndef CPU_MEMORY_HH
-#include "cpu_memory.hh"
-#endif
-#ifndef CODE_LABEL_HH
-#include "code_label.hh"
-#endif
-#ifndef GENOME_HH
-#include "genome.hh"
-#endif
-#ifndef HARDWARE_BASE_HH
-#include "hardware_base.hh"
-#endif
-#ifndef INST_SET_HH
-#include "inst_set.hh"
-#endif
-#ifndef INSTRUCTION_HH
-#include "instruction.hh"
-#endif
-
-#include <assert.h>
-
-class cHardwareBase; // access
-class cCPUMemory; // access
-class cCodeLabel; // access
-class cInstSet; // access
-
-cCPUHead::cCPUHead() {
- main_hardware = NULL;
- cur_hardware = NULL;
- position = 0;
-}
-
-cCPUHead::cCPUHead(cHardwareBase * in_hardware, int in_pos) {
- main_hardware = in_hardware;
- cur_hardware = in_hardware;
-
- position = in_pos;
- if (in_pos) Adjust();
-}
-
-cCPUHead::cCPUHead(const cCPUHead & in_cpu_head) {
- main_hardware = in_cpu_head.main_hardware;
- cur_hardware = in_cpu_head.cur_hardware;
- position = in_cpu_head.position;
-}
-
-
-
-void cCPUHead::Adjust()
-{
- assert(cur_hardware != NULL);
- assert(main_hardware != NULL);
-
- const int mem_size = cur_hardware->GetMemory().GetSize();
-
- // If we are still in range, stop here!
- if (position >= 0 && position < mem_size) return;
-
- // If the memory is gone, just stick it at the begining of its parent.
- if (mem_size == 0) {
- cur_hardware = main_hardware;
- position = 0;
- }
- else if (position <= 0) { position = 0; }
- else if (position >= mem_size) {
- // Always loop into the begining of the owner hardware.
- cur_hardware = main_hardware;
- position -= mem_size;
- while (position >= GetMemory().GetSize()) {
- // position back at the begining of the creature.
- position %= GetMemory().GetSize();
- }
- }
-
-}
-
-
-
-/////////////////////////////////////////////////////////////////////////
-// Method: cCPUHead::FindLabel(direction)
-//
-// Search in 'direction' (+ or - 1) from this head for the compliment of
-// the label in 'next_label' and return a head to the resulting pos.
-//
-/////////////////////////////////////////////////////////////////////////
-
-cCPUHead cCPUHead::FindLabel(const cCodeLabel & label, int direction)
-{
- // Make sure the label is of size > 0.
- if (label.GetSize() == 0) {
- return *this;
- }
-
- int found_pos = -1;
-
- // Call special functions depending on if jump is forwards or backwards.
- if( direction < 0 ) {
- found_pos =
- FindLabel_Backward(label, GetMemory(), GetPosition() - label.GetSize());
- }
-
- // Jump forwards.
- else {
- found_pos = FindLabel_Forward(label, GetMemory(), GetPosition());
- }
-
- if (found_pos >= 0) {
- // Return the last line of the found label, or the starting point.
- cCPUHead search_head(*this);
- search_head.Set(found_pos - 1);
- return search_head;
- }
-
- // It wasn't found; return the starting position of the instruction pointer.
- return *this;
-}
-
-void cCPUHead::Reset(cHardwareBase * new_hardware) {
- if (new_hardware) main_hardware = new_hardware;
- cur_hardware = new_hardware;
- position = 0;
-}
-
-void cCPUHead::Set(int new_pos, cHardwareBase * in_hardware)
-{
- position = new_pos;
- if (in_hardware) cur_hardware = in_hardware;
- Adjust();
-}
-
-
-void cCPUHead::Jump(int jump)
-{
- position += jump;
- Adjust();
-}
-
-void cCPUHead::LoopJump(int jump)
-{
- position += jump;
-
- // If we are out of range, bring back in.
- if (position < 0 || position >= GetMemory().GetSize()) {
- position %= GetMemory().GetSize();
- if (position <= 0) position += GetMemory().GetSize();
- }
-}
-
-void cCPUHead::AbsJump(int jump)
-{
- position += jump;
-}
-
-void cCPUHead::Advance()
-{
- position++;
- Adjust();
-}
-
-void cCPUHead::Retreat()
-{
- position--;
- Adjust();
-}
-
-
-const cCPUMemory & cCPUHead::GetMemory() const
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory();
-}
-
-
-const cInstruction & cCPUHead::GetInst() const
-{
- assert(position >= 0);
- assert(position < GetMemory().GetSize());
- return GetMemory()[position];
-}
-
-const cInstruction & cCPUHead::GetInst(int offset) const {
- int new_pos = position + offset;
-
- return GetMemory()[new_pos];
-}
-
-
-void cCPUHead::SetInst(const cInstruction & value)
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) cur_hardware->GetMemory()[position] = value;
-#else
- cur_hardware->GetMemory()[position] = value;
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-
-void cCPUHead::InsertInst(const cInstruction & value)
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) cur_hardware->GetMemory().Insert(position, value);
-#else
- cur_hardware->GetMemory().Insert(position, value);
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-void cCPUHead::RemoveInst()
-{
- assert(cur_hardware != NULL);
-#ifdef WRITE_PROTECTION
- if (main_hardware == cur_hardware) cur_hardware->GetMemory().Remove(position);
-#else
- cur_hardware->GetMemory().Remove(position);
- if (main_hardware != cur_hardware) cur_hardware->SetModified();
-#endif
-}
-
-const cInstruction & cCPUHead::GetNextInst()
-{
- return (AtEnd()) ? cInstSet::GetInstError() : GetMemory()[position+1];
-}
-
-
-
-bool & cCPUHead::FlagCopied()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagCopied(position);
-}
-
-bool & cCPUHead::FlagMutated()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagMutated(position);
-}
-
-bool & cCPUHead::FlagExecuted()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagExecuted(position);
-}
-
-bool & cCPUHead::FlagBreakpoint()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagBreakpoint(position);
-}
-
-bool & cCPUHead::FlagPointMut()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagPointMut(position);
-}
-
-bool & cCPUHead::FlagCopyMut()
-{
- assert(cur_hardware != NULL);
- return cur_hardware->GetMemory().FlagCopyMut(position);
-}
-
-cCPUHead & cCPUHead::operator=(const cCPUHead & in_cpu_head)
-{
- main_hardware = in_cpu_head.main_hardware;
- cur_hardware = in_cpu_head.cur_hardware;
- position = in_cpu_head.position;
- return *this;
-}
-
-
-cCPUHead & cCPUHead::operator++()
-{
- position++;
- Adjust();
- return *this;
-}
-
-cCPUHead & cCPUHead::operator--()
-{
- position--;
- Adjust();
- return *this;
-}
-
-cCPUHead & cCPUHead::operator++(int)
-{
- return operator++();
-}
-
-cCPUHead & cCPUHead::operator--(int)
-{
- return operator--();
-}
-
-
-// Search forwards for search_label from _after_ position pos in the
-// memory. Return the first line _after_ the the found label. It is okay
-// to find search label's match inside another label.
-
-int cCPUHead::FindLabel_Forward(const cCodeLabel & search_label,
- const cGenome & search_mem, int pos)
-{
- assert (pos < search_mem.GetSize() && pos >= 0);
-
- int search_start = pos;
- int label_size = search_label.GetSize();
- bool found_label = false;
- const cInstSet & inst_set = main_hardware->GetInstSet();
-
- // Move off the template we are on.
- pos += label_size;
-
- // Search until we find the complement or exit the memory.
- while (pos < search_mem.GetSize()) {
-
- // If we are within a label, rewind to the beginning of it and see if
- // it has the proper sub-label that we're looking for.
-
- if (inst_set.IsNop(search_mem[pos])) {
- // Find the start and end of the label we're in the middle of.
-
- int start_pos = pos;
- int end_pos = pos + 1;
- while (start_pos > search_start &&
- inst_set.IsNop( search_mem[start_pos - 1] )) {
- start_pos--;
- }
- while (end_pos < search_mem.GetSize() &&
- inst_set.IsNop( search_mem[end_pos] )) {
- end_pos++;
- }
- int test_size = end_pos - start_pos;
-
- // See if this label has the proper sub-label within it.
- int max_offset = test_size - label_size + 1;
- for (int offset = start_pos; offset < start_pos + max_offset; offset++) {
-
- // Test the number of matches for this offset.
- int matches;
- for (matches = 0; matches < label_size; matches++) {
- if (search_label[matches] !=
- inst_set.GetNopMod( search_mem[offset + matches] )) {
- break;
- }
- }
-
- // If we have found it, break out of this loop!
- if (matches == label_size) {
- found_label = true;
- break;
- }
- }
-
- // If we've found the complement label, set the position to the end of
- // the label we found it in, and break out.
-
- if (found_label == true) {
- pos = end_pos;
- break;
- }
-
- // We haven't found it; jump pos to just after the current label being
- // checked.
- pos = end_pos;
- }
-
- // Jump up a block to the next possible point to find a label,
- pos += label_size;
- }
-
- // If the label was not found return a -1.
- if (found_label == false) pos = -1;
-
- return pos;
-}
-
-// Search backwards for search_label from _before_ position pos in the
-// memory. Return the first line _after_ the the found label. It is okay
-// to find search label's match inside another label.
-
-int cCPUHead::FindLabel_Backward(const cCodeLabel & search_label,
- const cGenome & search_mem, int pos)
-{
- assert (pos < search_mem.GetSize());
-
- int search_start = pos;
- int label_size = search_label.GetSize();
- bool found_label = false;
- const cInstSet & inst_set = main_hardware->GetInstSet();
-
- // Move off the template we are on.
- pos -= label_size;
-
- // Search until we find the complement or exit the memory.
- while (pos >= 0) {
- // If we are within a label, rewind to the beginning of it and see if
- // it has the proper sub-label that we're looking for.
-
- if (inst_set.IsNop( search_mem[pos] )) {
- // Find the start and end of the label we're in the middle of.
-
- int start_pos = pos;
- int end_pos = pos + 1;
- while (start_pos > 0 && inst_set.IsNop(search_mem[start_pos - 1])) {
- start_pos--;
- }
- while (end_pos < search_start &&
- inst_set.IsNop( search_mem[end_pos] )) {
- end_pos++;
- }
- int test_size = end_pos - start_pos;
-
- // See if this label has the proper sub-label within it.
- int max_offset = test_size - label_size + 1;
- for (int offset = start_pos; offset < start_pos + max_offset; offset++) {
-
- // Test the number of matches for this offset.
- int matches;
- for (matches = 0; matches < label_size; matches++) {
- if (search_label[matches] !=
- inst_set.GetNopMod( search_mem[offset + matches] )) {
- break;
- }
- }
-
- // If we have found it, break out of this loop!
- if (matches == label_size) {
- found_label = true;
- break;
- }
- }
-
- // If we've found the complement label, set the position to the end of
- // the label we found it in, and break out.
-
- if (found_label == true) {
- pos = end_pos;
- break;
- }
-
- // We haven't found it; jump pos to just before the current label
- // being checked.
- pos = start_pos - 1;
- }
-
- // Jump up a block to the next possible point to find a label,
- pos -= label_size;
- }
-
- // If the label was not found return a -1.
- if (found_label == false) pos = -1;
-
- return pos;
-}
-
-bool cCPUHead::operator==(const cCPUHead & in_cpu_head) const {
- return (cur_hardware == in_cpu_head.cur_hardware) &&
- (position == in_cpu_head.position);
-}
-
-bool cCPUHead::AtEnd() const
-{
- return (position + 1 == GetMemory().GetSize());
-}
-
-bool cCPUHead::InMemory() const
-{
- return (position >= 0 && position < GetMemory().GetSize());
-}
-
-int cCPUHead::TestParasite() const
-{
- // If CPU has a head in another creature, mark it as a parasite.
- return (cur_hardware != main_hardware);
-}
Deleted: branches/brysonda/source/cpu/cpu_head.hh
===================================================================
--- branches/brysonda/source/cpu/cpu_head.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/cpu_head.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,121 +0,0 @@
-/////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology //
-// //
-// Read the COPYING and README files, or contact 'avida at alife.org', //
-// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef CPU_HEAD_HH
-#define CPU_HEAD_HH
-
-#ifndef DEFS_HH
-#include "defs.hh"
-#endif
-
-class cHardwareBase;
-class cCodeLabel;
-class cGenome;
-class cCPUMemory;
-
-/**
- * The cCPUHead class contains a pointer to locations in memory for a CPU.
- **/
-
-class cHardwareBase;
-class cCodeLabel;
-class cGenome;
-class cInstruction;
-
-class cCPUHead {
-protected:
- cHardwareBase * main_hardware;
- cHardwareBase * cur_hardware;
- int position;
-
- int FindLabel_Forward(const cCodeLabel & search_label,
- const cGenome & search_mem, int pos);
- int FindLabel_Backward(const cCodeLabel & search_label,
- const cGenome & search_mem, int pos);
-public:
- cCPUHead();
- cCPUHead(cHardwareBase * in_hardware, int in_pos = 0);
- cCPUHead(const cCPUHead & in_cpu_head);
- virtual ~cCPUHead() { ; }
-
- /**
- * This function keeps the position within the range of the current memory.
- **/
- virtual void Adjust();
-
- virtual void Reset(cHardwareBase * new_hardware = NULL);
-
- /**
- * Set the new position of the head (and adjust it into range in Set()).
- **/
-
- virtual void Set(int new_pos, cHardwareBase * in_hardware = NULL);
-
- void AbsSet(int new_pos) { position = new_pos; }
-
- virtual void Set(const cCPUHead & in_head) {
- position = in_head.position;
- cur_hardware = in_head.cur_hardware;
- }
-
- /**
- * Increment the new position of the head by 'jump'.
- **/
-
- void Jump(int jump);
- virtual void LoopJump(int jump);
- void AbsJump(int jump);
-
- // Other manipulation functions.
- void Advance();
- void Retreat();
- cCPUHead FindLabel(const cCodeLabel & label, int direction=1);
-
- // Accessors.
- int GetPosition() const { return position; }
- virtual const cCPUMemory & GetMemory() const;
- cHardwareBase * GetCurHardware() const { return cur_hardware; }
- cHardwareBase * GetMainHardware() const { return main_hardware; }
- virtual const cInstruction & GetInst() const;
- virtual const cInstruction & GetInst(int offset) const;
- // int GetFlag(int id) const;
-
- virtual void SetInst(const cInstruction & value);
- virtual void InsertInst(const cInstruction & in_char);
- virtual void RemoveInst();
- virtual const cInstruction & GetNextInst();
-
- virtual bool & FlagCopied();
- virtual bool & FlagMutated();
- virtual bool & FlagExecuted();
- virtual bool & FlagBreakpoint();
- virtual bool & FlagPointMut();
- virtual bool & FlagCopyMut();
-
- // Operator Overloading...
- virtual cCPUHead & operator=(const cCPUHead & in_cpu_head);
- cCPUHead & operator++();
- cCPUHead & operator--();
- cCPUHead & operator++(int);
- cCPUHead & operator--(int);
-
- inline int operator-(const cCPUHead & in_cpu_head) {
- if (cur_hardware != in_cpu_head.cur_hardware) return 0;
- else return position - in_cpu_head.position;
- }
- virtual bool operator==(const cCPUHead & in_cpu_head) const;
-
- // Bool Tests...
- inline bool AtFront() const { return (position == 0); }
- virtual bool AtEnd() const;
- virtual bool InMemory() const;
-
- // Test functions...
- int TestParasite() const;
-};
-
-#endif
Modified: branches/brysonda/source/cpu/cpu_stack.hh
===================================================================
--- branches/brysonda/source/cpu/cpu_stack.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/cpu_stack.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -17,7 +17,7 @@
/**
* A CPU stack, used by various hardware components.
*
- * @see cCPUThread, cCPUHead, cHardware
+ * @see cCPUThread, cHeadCPU, cHardware
**/
class cCPUStack {
Modified: branches/brysonda/source/cpu/hardware_4stack.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_4stack.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_4stack.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -203,8 +203,6 @@
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry4Stack);
- cout << "Instruction Library has " << n_size << " instructions." << endl;
-
static cString n_names[n_size];
static int nop_mods[n_size];
for (int i = 0; i < n_size; i++){
@@ -583,12 +581,12 @@
//
/////////////////////////////////////////////////////////////////////////
-c4StackHead cHardware4Stack::FindLabel(int direction)
+cHeadMultiMem cHardware4Stack::FindLabel(int direction)
{
- c4StackHead & inst_ptr = IP();
+ cHeadMultiMem & inst_ptr = IP();
// Start up a search head at the position of the instruction pointer.
- c4StackHead search_head(inst_ptr);
+ cHeadMultiMem search_head(inst_ptr);
cCodeLabel & search_label = GetLabel();
// Make sure the label is of size > 0.
@@ -785,7 +783,7 @@
}
// Search for 'in_label' anywhere in the hardware.
-c4StackHead cHardware4Stack::FindLabel(const cCodeLabel & in_label, int direction)
+cHeadMultiMem cHardware4Stack::FindLabel(const cCodeLabel & in_label, int direction)
{
assert (in_label.GetSize() > 0);
@@ -796,7 +794,7 @@
// FOR NOW:
// Get something which works, no matter how inefficient!!!
- c4StackHead temp_head(this);
+ cHeadMultiMem temp_head(this);
while (temp_head.InMemory()) {
// IDEALY: Analyze the label we are in; see if the one we are looking
@@ -823,14 +821,14 @@
// @CAO: direction is not currently used; should be used to indicate the
// direction which the heads[HEAD_IP] should progress through a creature.
-c4StackHead cHardware4Stack::FindFullLabel(const cCodeLabel & in_label)
+cHeadMultiMem cHardware4Stack::FindFullLabel(const cCodeLabel & in_label)
{
// cout << "Running FindFullLabel with " << in_label.AsString() <<
// endl;
assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
- c4StackHead temp_head(this);
+ cHeadMultiMem temp_head(this);
while (temp_head.InMemory()) {
// If we are not in a label, jump to the next checkpoint...
@@ -1057,7 +1055,7 @@
return TriggerMutations(trigger, IP());
}
-bool cHardware4Stack::TriggerMutations(int trigger, c4StackHead & cur_head)
+bool cHardware4Stack::TriggerMutations(int trigger, cHeadMultiMem & cur_head)
{
// Collect information about mutations from the organism.
cLocalMutations & mut_info = organism->GetLocalMutations();
@@ -1110,7 +1108,7 @@
}
bool cHardware4Stack::TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
@@ -1118,7 +1116,7 @@
if (g_random.P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
- c4StackHead tmp_head(cur_head);
+ cHeadMultiMem tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
@@ -1127,7 +1125,7 @@
}
bool cHardware4Stack::TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
@@ -1140,7 +1138,7 @@
}
int cHardware4Stack::TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The probability we have stored is per-site, so we can pull a random
// number from a binomial distribution to determine the number of mutations
@@ -1151,7 +1149,7 @@
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
- c4StackHead tmp_head(cur_head);
+ cHeadMultiMem tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
@@ -1161,7 +1159,7 @@
}
void cHardware4Stack::TriggerMutations_Body(int type, cCPUMemory & target_memory,
- c4StackHead & cur_head)
+ cHeadMultiMem & cur_head)
{
const int pos = cur_head.GetPosition();
@@ -1210,7 +1208,7 @@
void cHardware4Stack::ReadLabel(int max_size)
{
int count = 0;
- c4StackHead * inst_ptr = &( IP() );
+ cHeadMultiMem * inst_ptr = &( IP() );
GetLabel().Clear();
@@ -1969,7 +1967,7 @@
bool cHardware4Stack::Inst_HeadWrite()
{
const int head_id = FindModifiedHead(HEAD_WRITE);
- c4StackHead & active_head = GetHead(head_id);
+ cHeadMultiMem & active_head = GetHead(head_id);
int mem_space_used = active_head.GetMemSpace();
//commented out for right now...
@@ -1996,8 +1994,8 @@
bool cHardware4Stack::Inst_HeadCopy()
{
// For the moment, this cannot be nop-modified.
- c4StackHead & read_head = GetHead(HEAD_READ);
- c4StackHead & write_head = GetHead(HEAD_WRITE);
+ cHeadMultiMem & read_head = GetHead(HEAD_READ);
+ cHeadMultiMem & write_head = GetHead(HEAD_WRITE);
sCPUStats & cpu_stats = organism->CPUStats();
read_head.Adjust();
@@ -2106,7 +2104,7 @@
{
ReadLabel();
GetLabel().Rotate(2, NUM_NOPS_4STACK);
- c4StackHead found_pos = FindLabel(0);
+ cHeadMultiMem found_pos = FindLabel(0);
if(found_pos.GetPosition()-IP().GetPosition()==0)
{
GetHead(HEAD_FLOW).Set(IP().GetPosition()+1, IP().GetMemSpace(), this);
Modified: branches/brysonda/source/cpu/hardware_4stack.hh
===================================================================
--- branches/brysonda/source/cpu/hardware_4stack.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_4stack.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -19,8 +19,8 @@
#ifndef DEFS_HH
#include "defs.hh"
#endif
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
#endif
#ifndef HARDWARE_BASE_HH
#include "hardware_base.hh"
@@ -60,7 +60,7 @@
class cCodeLabel;
class cCPUMemory;
class cCPUStack; // aggregate
-class c4StackHead; // access
+class cHeadMultiMem; // access
class cGenome;
class cHardware4Stack_Thread; // access
class cInjectGenotype;
@@ -149,28 +149,28 @@
int GetCurHead() const { return threads[cur_thread].cur_head; }
- const c4StackHead & GetHead(int head_id) const
+ const cHeadMultiMem & GetHead(int head_id) const
{ return threads[cur_thread].heads[head_id]; }
- c4StackHead & GetHead(int head_id)
+ cHeadMultiMem & GetHead(int head_id)
{ return threads[cur_thread].heads[head_id];}
- const c4StackHead & GetHead(int head_id, int thread) const
+ const cHeadMultiMem & GetHead(int head_id, int thread) const
{ return threads[thread].heads[head_id]; }
- c4StackHead & GetHead(int head_id, int thread)
+ cHeadMultiMem & GetHead(int head_id, int thread)
{ return threads[thread].heads[head_id];}
- const c4StackHead & GetActiveHead() const { return GetHead(GetCurHead()); }
- c4StackHead & GetActiveHead() { return GetHead(GetCurHead()); }
+ const cHeadMultiMem & GetActiveHead() const { return GetHead(GetCurHead()); }
+ cHeadMultiMem & GetActiveHead() { return GetHead(GetCurHead()); }
void AdjustHeads();
- inline const c4StackHead & IP() const
+ inline const cHeadMultiMem & IP() const
{ return threads[cur_thread].heads[HEAD_IP]; }
- inline c4StackHead & IP() { return threads[cur_thread].heads[HEAD_IP]; }
+ inline cHeadMultiMem & IP() { return threads[cur_thread].heads[HEAD_IP]; }
- inline const c4StackHead & IP(int thread) const
+ inline const cHeadMultiMem & IP(int thread) const
{ return threads[thread].heads[HEAD_IP]; }
- inline c4StackHead & IP(int thread)
+ inline cHeadMultiMem & IP(int thread)
{ return threads[thread].heads[HEAD_IP]; }
@@ -225,13 +225,13 @@
}
// Complex label manipulation...
- c4StackHead FindLabel(int direction);
+ cHeadMultiMem FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
int FindLabel_Backward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
- c4StackHead FindLabel(const cCodeLabel & in_label, int direction);
- c4StackHead FindFullLabel(const cCodeLabel & in_label);
+ cHeadMultiMem FindLabel(const cCodeLabel & in_label, int direction);
+ cHeadMultiMem FindFullLabel(const cCodeLabel & in_label);
int GetType() const { return HARDWARE_TYPE_CPU_4STACK; }
bool InjectParasite(double mut_multiplier);
@@ -243,15 +243,15 @@
bool isEmpty(int mem_space_used);
bool TriggerMutations(int trigger);
- bool TriggerMutations(int trigger, c4StackHead & cur_head);
+ bool TriggerMutations(int trigger, cHeadMultiMem & cur_head);
bool TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
bool TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
int TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
void TriggerMutations_Body(int type, cCPUMemory & target_memory,
- c4StackHead & cur_head);
+ cHeadMultiMem & cur_head);
void ReadInst(const int in_inst);
Modified: branches/brysonda/source/cpu/hardware_4stack_thread.hh
===================================================================
--- branches/brysonda/source/cpu/hardware_4stack_thread.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_4stack_thread.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -16,8 +16,8 @@
#ifndef CPU_STACK_HH
#include "cpu_stack.hh"
#endif
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
#endif
#ifndef HARDWARE_4STACK_CONSTANTS_HH
#include "hardware_4stack_constants.hh"
@@ -29,10 +29,10 @@
/**
* This class is needed to run several threads on a single genome.
*
- * @see cCPUStack, c4StackHead, cHardware4Stack
+ * @see cCPUStack, cHeadMultiMem, cHardware4Stack
**/
-class c4StackHead; // aggregate
+class cHeadMultiMem; // aggregate
class cCodeLabel; // aggregate
class cCPUStack; // aggregate
class cHardwareBase;
@@ -43,7 +43,7 @@
private:
int id;
public:
- c4StackHead heads[NUM_HEADS];
+ cHeadMultiMem heads[NUM_HEADS];
UCHAR cur_head;
cCPUStack local_stacks[NUM_LOCAL_STACKS];
Modified: branches/brysonda/source/cpu/hardware_cpu.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_cpu.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_cpu.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -332,10 +332,6 @@
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
- cout << "<cHardwareCPU::initInstLib> Instruction Library has "
- << n_size << " instructions." << endl;
-
-
static cString n_names[n_size];
static int nop_mods[n_size];
for (int i = 0; i < n_size; i++){
@@ -664,12 +660,12 @@
//
/////////////////////////////////////////////////////////////////////////
-cCPUHead cHardwareCPU::FindLabel(int direction)
+cHeadCPU cHardwareCPU::FindLabel(int direction)
{
- cCPUHead & inst_ptr = IP();
+ cHeadCPU & inst_ptr = IP();
// Start up a search head at the position of the instruction pointer.
- cCPUHead search_head(inst_ptr);
+ cHeadCPU search_head(inst_ptr);
cCodeLabel & search_label = GetLabel();
// Make sure the label is of size > 0.
@@ -865,7 +861,7 @@
}
// Search for 'in_label' anywhere in the hardware.
-cCPUHead cHardwareCPU::FindLabel(const cCodeLabel & in_label, int direction)
+cHeadCPU cHardwareCPU::FindLabel(const cCodeLabel & in_label, int direction)
{
assert (in_label.GetSize() > 0);
@@ -876,7 +872,7 @@
// FOR NOW:
// Get something which works, no matter how inefficient!!!
- cCPUHead temp_head(this);
+ cHeadCPU temp_head(this);
while (temp_head.InMemory()) {
// IDEALY: Analyze the label we are in; see if the one we are looking
@@ -903,14 +899,14 @@
// @CAO: direction is not currently used; should be used to indicate the
// direction which the heads[HEAD_IP] should progress through a creature.
-cCPUHead cHardwareCPU::FindFullLabel(const cCodeLabel & in_label)
+cHeadCPU cHardwareCPU::FindFullLabel(const cCodeLabel & in_label)
{
// cout << "Running FindFullLabel with " << in_label.AsString() <<
// endl;
assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
- cCPUHead temp_head(this);
+ cHeadCPU temp_head(this);
while (temp_head.InMemory()) {
// If we are not in a label, jump to the next checkpoint...
@@ -1113,7 +1109,7 @@
return TriggerMutations(trigger, IP());
}
-bool cHardwareCPU::TriggerMutations(int trigger, cCPUHead & cur_head)
+bool cHardwareCPU::TriggerMutations(int trigger, cHeadCPU & cur_head)
{
// Collect information about mutations from the organism.
cLocalMutations & mut_info = organism->GetLocalMutations();
@@ -1166,7 +1162,7 @@
}
bool cHardwareCPU::TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate)
{
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
@@ -1174,7 +1170,7 @@
if (g_random.P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
- cCPUHead tmp_head(cur_head);
+ cHeadCPU tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
@@ -1183,7 +1179,7 @@
}
bool cHardwareCPU::TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate)
{
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
@@ -1196,7 +1192,7 @@
}
int cHardwareCPU::TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate)
{
// The probability we have stored is per-site, so we can pull a random
// number from a binomial distribution to determine the number of mutations
@@ -1207,7 +1203,7 @@
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
- cCPUHead tmp_head(cur_head);
+ cHeadCPU tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
@@ -1217,7 +1213,7 @@
}
void cHardwareCPU::TriggerMutations_Body(int type, cCPUMemory & target_memory,
- cCPUHead & cur_head)
+ cHeadCPU & cur_head)
{
const int pos = cur_head.GetPosition();
@@ -1266,7 +1262,7 @@
void cHardwareCPU::ReadLabel(int max_size)
{
int count = 0;
- cCPUHead * inst_ptr = &( IP() );
+ cHeadCPU * inst_ptr = &( IP() );
GetLabel().Clear();
@@ -1971,7 +1967,7 @@
}
// Otherwise, try to jump to the complement label.
- const cCPUHead jump_location(FindLabel(1));
+ const cHeadCPU jump_location(FindLabel(1));
if ( jump_location.GetPosition() != -1 ) {
GetActiveHead().Set(jump_location);
return true;
@@ -1996,7 +1992,7 @@
}
// otherwise jump to the complement label.
- const cCPUHead jump_location(FindLabel(-1));
+ const cHeadCPU jump_location(FindLabel(-1));
if ( jump_location.GetPosition() != -1 ) {
GetActiveHead().Set(jump_location);
return true;
@@ -2038,7 +2034,7 @@
}
// otherwise jump to the complement label.
- const cCPUHead jump_location(other_hardware.FindFullLabel(GetLabel()));
+ const cHeadCPU jump_location(other_hardware.FindFullLabel(GetLabel()));
if (jump_location.GetPosition() != -1) {
IP().Set(jump_location);
organism->GetPhenotype().IsParasite() = true;
@@ -2065,7 +2061,7 @@
}
// otherwise jump to the complement label.
- const cCPUHead jump_location( FindFullLabel(GetLabel()) );
+ const cHeadCPU jump_location( FindFullLabel(GetLabel()) );
if ( jump_location.GetPosition() != -1 ) {
IP().Set(jump_location);
return true;
@@ -2092,7 +2088,7 @@
return true;
}
- const cCPUHead jump_location(FindLabel(1));
+ const cHeadCPU jump_location(FindLabel(1));
if (jump_location.GetPosition() != -1) {
IP().Set(jump_location);
return true;
@@ -2432,8 +2428,8 @@
bool cHardwareCPU::Inst_Copy()
{
- const cCPUHead from(this, Register(REG_BX));
- cCPUHead to(this, Register(REG_AX) + Register(REG_BX));
+ const cHeadCPU from(this, Register(REG_BX));
+ cHeadCPU to(this, Register(REG_AX) + Register(REG_BX));
sCPUStats & cpu_stats = organism->CPUStats();
if (organism->TestCopyMut()) {
@@ -2456,7 +2452,7 @@
bool cHardwareCPU::Inst_ReadInst()
{
const int reg_used = FindModifiedRegister(REG_CX);
- const cCPUHead from(this, Register(REG_BX));
+ const cHeadCPU from(this, Register(REG_BX));
// Dis-allowing mutations on read, for the moment (write only...)
// @CAO This allows perfect error-correction...
@@ -2466,7 +2462,7 @@
bool cHardwareCPU::Inst_WriteInst()
{
- cCPUHead to(this, Register(REG_AX) + Register(REG_BX));
+ cHeadCPU to(this, Register(REG_AX) + Register(REG_BX));
const int reg_used = FindModifiedRegister(REG_CX);
const int value = Mod(Register(reg_used), GetNumInst());
sCPUStats & cpu_stats = organism->CPUStats();
@@ -2492,7 +2488,7 @@
bool cHardwareCPU::Inst_StackReadInst()
{
const int reg_used = FindModifiedRegister(REG_CX);
- cCPUHead from(this, Register(reg_used));
+ cHeadCPU from(this, Register(reg_used));
StackPush(from.GetInst().GetOp());
return true;
}
@@ -2500,7 +2496,7 @@
bool cHardwareCPU::Inst_StackWriteInst()
{
const int reg_used = FindModifiedRegister(REG_BX);
- cCPUHead to(this, Register(REG_AX) + Register(reg_used));
+ cHeadCPU to(this, Register(REG_AX) + Register(reg_used));
const int value = Mod(StackPop(), GetNumInst());
sCPUStats & cpu_stats = organism->CPUStats();
@@ -2525,8 +2521,8 @@
bool cHardwareCPU::Inst_Compare()
{
const int reg_used = FindModifiedRegister(REG_CX);
- cCPUHead from(this, Register(REG_BX));
- cCPUHead to(this, Register(REG_AX) + Register(REG_BX));
+ cHeadCPU from(this, Register(REG_BX));
+ cHeadCPU to(this, Register(REG_AX) + Register(REG_BX));
// Compare is dangerous -- it can cause mutations!
if (organism->TestCopyMut()) {
@@ -2543,8 +2539,8 @@
bool cHardwareCPU::Inst_IfNCpy()
{
- const cCPUHead from(this, Register(REG_BX));
- const cCPUHead to(this, Register(REG_AX) + Register(REG_BX));
+ const cHeadCPU from(this, Register(REG_BX));
+ const cHeadCPU to(this, Register(REG_AX) + Register(REG_BX));
// Allow for errors in this test...
if (organism->TestCopyMut()) {
@@ -3287,7 +3283,7 @@
bool cHardwareCPU::Inst_HeadWrite()
{
const int head_id = FindModifiedHead(HEAD_WRITE);
- cCPUHead & active_head = GetHead(head_id);
+ cHeadCPU & active_head = GetHead(head_id);
active_head.Adjust();
@@ -3305,8 +3301,8 @@
bool cHardwareCPU::Inst_HeadCopy()
{
// For the moment, this cannot be nop-modified.
- cCPUHead & read_head = GetHead(HEAD_READ);
- cCPUHead & write_head = GetHead(HEAD_WRITE);
+ cHeadCPU & read_head = GetHead(HEAD_READ);
+ cHeadCPU & write_head = GetHead(HEAD_WRITE);
sCPUStats & cpu_stats = organism->CPUStats();
read_head.Adjust();
@@ -3340,8 +3336,8 @@
bool cHardwareCPU::HeadCopy_ErrorCorrect(double reduction)
{
// For the moment, this cannot be nop-modified.
- cCPUHead & read_head = GetHead(HEAD_READ);
- cCPUHead & write_head = GetHead(HEAD_WRITE);
+ cHeadCPU & read_head = GetHead(HEAD_READ);
+ cHeadCPU & write_head = GetHead(HEAD_WRITE);
sCPUStats & cpu_stats = organism->CPUStats();
read_head.Adjust();
@@ -3382,7 +3378,7 @@
{
ReadLabel();
GetLabel().Rotate(1, NUM_NOPS);
- cCPUHead found_pos = FindLabel(0);
+ cHeadCPU found_pos = FindLabel(0);
const int search_size = found_pos.GetPosition() - IP().GetPosition();
Register(REG_BX) = search_size;
Register(REG_CX) = GetLabel().GetSize();
@@ -3411,7 +3407,7 @@
}
// Otherwise, jump to the label.
- cCPUHead jump_location(FindLabel(1));
+ cHeadCPU jump_location(FindLabel(1));
if (jump_location.GetPosition() != -1) {
IP().Set(jump_location);
return true;
Modified: branches/brysonda/source/cpu/hardware_cpu.hh
===================================================================
--- branches/brysonda/source/cpu/hardware_cpu.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_cpu.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -20,8 +20,8 @@
#ifndef CPU_DEFS_HH
#include "cpu_defs.hh"
#endif
-#ifndef CPU_HEAD_HH
-#include "cpu_head.hh"
+#ifndef HEAD_CPU_HH
+#include "head_cpu.hh"
#endif
#ifndef CPU_MEMORY_HH
#include "cpu_memory.hh"
@@ -62,7 +62,7 @@
**/
class cCodeLabel; // access
-class cCPUHead; // access
+class cHeadCPU; // access
class cCPUMemory; // aggregate
class cCPUStack; // aggregate
class cGenome;
@@ -142,18 +142,18 @@
{ threads[cur_thread].cur_head = (UCHAR) new_head; }
int GetCurHead() const { return threads[cur_thread].cur_head; }
- const cCPUHead & GetHead(int head_id) const
+ const cHeadCPU & GetHead(int head_id) const
{ return threads[cur_thread].heads[head_id]; }
- cCPUHead & GetHead(int head_id) { return threads[cur_thread].heads[head_id];}
+ cHeadCPU & GetHead(int head_id) { return threads[cur_thread].heads[head_id];}
- const cCPUHead & GetActiveHead() const { return GetHead(GetCurHead()); }
- cCPUHead & GetActiveHead() { return GetHead(GetCurHead()); }
+ const cHeadCPU & GetActiveHead() const { return GetHead(GetCurHead()); }
+ cHeadCPU & GetActiveHead() { return GetHead(GetCurHead()); }
void AdjustHeads();
- inline const cCPUHead & IP() const
+ inline const cHeadCPU & IP() const
{ return threads[cur_thread].heads[HEAD_IP]; }
- inline cCPUHead & IP() { return threads[cur_thread].heads[HEAD_IP]; }
+ inline cHeadCPU & IP() { return threads[cur_thread].heads[HEAD_IP]; }
// -------- Label Manipulation -------
@@ -203,13 +203,13 @@
}
// Complex label manipulation...
- cCPUHead FindLabel(int direction);
+ cHeadCPU FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
int FindLabel_Backward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
- cCPUHead FindLabel(const cCodeLabel & in_label, int direction);
- cCPUHead FindFullLabel(const cCodeLabel & in_label);
+ cHeadCPU FindLabel(const cCodeLabel & in_label, int direction);
+ cHeadCPU FindFullLabel(const cCodeLabel & in_label);
int GetType() const { return HARDWARE_TYPE_CPU_ORIGINAL; }
bool InjectHost(const cCodeLabel & in_label, const cGenome & injection);
@@ -220,15 +220,15 @@
int PointMutate(const double mut_rate);
bool TriggerMutations(int trigger);
- bool TriggerMutations(int trigger, cCPUHead & cur_head);
+ bool TriggerMutations(int trigger, cHeadCPU & cur_head);
bool TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate);
bool TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate);
int TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, cCPUHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadCPU & cur_head, const double rate);
void TriggerMutations_Body(int type, cCPUMemory & target_memory,
- cCPUHead & cur_head);
+ cHeadCPU & cur_head);
void ReadInst(const int in_inst);
Modified: branches/brysonda/source/cpu/hardware_cpu_thread.hh
===================================================================
--- branches/brysonda/source/cpu/hardware_cpu_thread.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_cpu_thread.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -16,8 +16,8 @@
#ifndef CPU_DEFS_HH
#include "cpu_defs.hh"
#endif
-#ifndef CPU_HEAD_HH
-#include "cpu_head.hh"
+#ifndef HEAD_CPU_HH
+#include "head_cpu.hh"
#endif
#ifndef CPU_STACK_HH
#include "cpu_stack.hh"
@@ -29,11 +29,11 @@
/**
* This class is needed to run several threads on a single genome.
*
- * @see cCPUStack, cCPUHead, cHardwareCPU
+ * @see cCPUStack, cHeadCPU, cHardwareCPU
**/
class cCodeLabel; // aggregate;
-class cCPUHead; // aggregate
+class cHeadCPU; // aggregate
class cCPUStack; // aggregate
class cHardwareBase;
template <class T> class tBuffer; // aggregate
@@ -43,7 +43,7 @@
int id;
public:
int reg[NUM_REGISTERS];
- cCPUHead heads[NUM_HEADS];
+ cHeadCPU heads[NUM_HEADS];
cCPUStack stack;
UCHAR cur_stack; // 0 = local stack, 1 = global stack.
UCHAR cur_head;
Modified: branches/brysonda/source/cpu/hardware_smt.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_smt.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_smt.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -16,7 +16,7 @@
#include "inst_lib_base.hh"
#include "inst_set.hh"
#include "hardware_tracer.hh"
-#include "hardware_tracer_4stack.hh"
+//#include "hardware_tracer_4stack.hh"
#include "mutation.hh"
#include "mutation_lib.hh"
#include "mutation_macros.hh"
@@ -36,8 +36,6 @@
// cHardwareSMT
///////////////
-const cInstruction tInstLib<cHardwareSMT::tMethod>::inst_error(255);
-const cInstruction tInstLib<cHardwareSMT::tMethod>::inst_default(0);
cInstLibBase* cHardwareSMT::GetInstLib(){ return s_inst_slib; }
tInstLib<cHardwareSMT::tMethod> *cHardwareSMT::s_inst_slib = cHardwareSMT::initInstLib();
@@ -48,18 +46,18 @@
int nop_mod;
};
static const cNOPEntry4Stack s_n_array[] = {
- cNOPEntry4Stack("Nop-A", STACK_AX),
- cNOPEntry4Stack("Nop-B", STACK_BX),
- cNOPEntry4Stack("Nop-C", STACK_CX),
- cNOPEntry4Stack("Nop-D", STACK_DX),
- cNOPEntry4Stack("Nop-E", STACK_EX),
- cNOPEntry4Stack("Nop-F", STACK_FX)
+ cNOPEntry4Stack("Nop-A", nHardwareSMT::STACK_AX),
+ cNOPEntry4Stack("Nop-B", nHardwareSMT::STACK_BX),
+ cNOPEntry4Stack("Nop-C", nHardwareSMT::STACK_CX),
+ cNOPEntry4Stack("Nop-D", nHardwareSMT::STACK_DX),
+ cNOPEntry4Stack("Nop-E", nHardwareSMT::STACK_EX),
+ cNOPEntry4Stack("Nop-F", nHardwareSMT::STACK_FX)
};
struct cInstEntry4Stack {
- cInstEntry4Stack(const cString &name, tHardware4StackMethod function):name(name), function(function){}
+ cInstEntry4Stack(const cString &name, tMethod function):name(name), function(function){}
cString name;
- tHardware4StackMethod function;
+ tMethod function;
};
static const cInstEntry4Stack s_f_array[] = {
//1
@@ -146,8 +144,6 @@
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry4Stack);
- cout << "Instruction Library has " << n_size << " instructions." << endl;
-
static cString n_names[n_size];
static int nop_mods[n_size];
for (int i = 0; i < n_size; i++){
@@ -157,20 +153,25 @@
const int f_size = sizeof(s_f_array)/sizeof(cInstEntry4Stack);
static cString f_names[f_size];
- static tHardware4StackMethod functions[f_size];
+ static tMethod functions[f_size];
for (int i = 0; i < f_size; i++){
f_names[i] = s_f_array[i].name;
functions[i] = s_f_array[i].function;
}
+ const cInstruction error(255);
+ const cInstruction def(0);
+
tInstLib<cHardwareSMT::tMethod> *inst_lib = new tInstLib<cHardwareSMT::tMethod>(
- n_size,
- f_size,
- n_names,
- f_names,
- nop_mods,
- functions
- );
+ n_size,
+ f_size,
+ n_names,
+ f_names,
+ nop_mods,
+ functions,
+ error,
+ def
+ );
cout <<
"<cHardwareSMT::initInstLib> debug: important post-init values:" <<endl<<
@@ -185,7 +186,7 @@
cHardwareSMT::cHardwareSMT(cOrganism * in_organism, cInstSet * in_inst_set)
: cHardwareBase(in_organism, in_inst_set)
-, memory_array(NUM_MEMORY_SPACES)
+, memory_array(nHardwareSMT::NUM_MEMORY_SPACES)
{
/* FIXME: reorganize storage of m_functions. -- kgn */
m_functions = s_inst_slib->GetFunctions();
@@ -218,7 +219,7 @@
, inst_remainder(hardware_4stack.inst_remainder)
#endif
{
- for(int i = 0; i < NUM_GLOBAL_STACKS; i++){
+ for(int i = 0; i < nHardwareSMT::NUM_GLOBAL_STACKS; i++){
global_stacks[i] = hardware_4stack.global_stacks[i];
}
for(int i = 0; i < sizeof(slice_array)/sizeof(float); i++){
@@ -243,7 +244,7 @@
//thread_time_used = 0;
// Setup the memory...
- for (int i = 1; i < NUM_MEMORY_SPACES; i++) {
+ for (int i = 1; i < nHardwareSMT::NUM_MEMORY_SPACES; i++) {
memory_array[i].Resize(1);
//GetMemory(i).Replace(0, 1, cGenome(ConvertToInstruction(i)));
GetMemory(i)=cGenome(ConvertToInstruction(i));
@@ -260,7 +261,7 @@
mal_active = false;
// Reset all stacks (local and global)
- for(int i=0; i<NUM_STACKS; i++)
+ for(int i = 0; i < nHardwareSMT::NUM_STACKS; i++)
{
Stack(i).Clear();
}
@@ -318,14 +319,15 @@
}
#endif
+ // XXX - Tracer
// Print the status of this CPU at each step...
- if (m_tracer != NULL) {
- if (cHardwareTracer_4Stack * tracer
- = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
- ){
- tracer->TraceHardware_4Stack(*this);
- }
- }
+ //if (m_tracer != NULL) {
+ // if (cHardwareTracer_4Stack * tracer
+ // = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+ // ){
+ // tracer->TraceHardware_4Stack(*this);
+ // }
+ //}
// Find the instruction to be executed
const cInstruction & cur_inst = IP().GetInst();
@@ -343,17 +345,17 @@
} // if exec
} // Previous was executed once for each thread...
-
- // Kill creatures who have reached their max num of instructions executed
- const int max_executed = organism->GetMaxExecuted();
- if ((max_executed > 0 && phenotype.GetTimeUsed() >= max_executed)
- || phenotype.GetToDie()) {
- organism->Die();
- }
-
- organism->SetRunning(false);
+
+// Kill creatures who have reached their max num of instructions executed
+const int max_executed = organism->GetMaxExecuted();
+if ((max_executed > 0 && phenotype.GetTimeUsed() >= max_executed)
+ || phenotype.GetToDie()) {
+ organism->Die();
}
+organism->SetRunning(false);
+}
+
// This method will test to see if all costs have been paid associated
// with executing an instruction and only return true when that instruction
// should proceed.
@@ -432,17 +434,18 @@
// @CAO FIX PRINTING TO INDICATE THIS IS A BONUS
// Print the status of this CPU at each step...
- if (m_tracer != NULL) {
- if (cHardwareTracer_4Stack * tracer
- = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
- ){
- tracer->TraceHardware_4StackBonus(*this);
- }
- }
+ // XXX - tracer
+ //if (m_tracer != NULL) {
+ // if (cHardwareTracer_4Stack * tracer
+ // = dynamic_cast<cHardwareTracer_4Stack *>(m_tracer)
+ // ){
+ // tracer->TraceHardware_4StackBonus(*this);
+ // }
+ //}
- SingleProcess_ExecuteInst(inst);
-
- organism->SetRunning(prev_run_state);
+SingleProcess_ExecuteInst(inst);
+
+organism->SetRunning(prev_run_state);
}
@@ -456,12 +459,12 @@
{
bool result = true;
- for(int i = 0 ; i < NUM_MEMORY_SPACES; i++) {
+ for(int i = 0 ; i < nHardwareSMT::NUM_MEMORY_SPACES; i++) {
if (!memory_array[i].OK()) result = false;
}
for (int i = 0; i < GetNumThreads(); i++) {
- for(int j=0; j<NUM_LOCAL_STACKS; j++)
+ for(int j=0; j < nHardwareSMT::NUM_LOCAL_STACKS; j++)
if (threads[i].local_stacks[j].OK() == false) result = false;
if (threads[i].next_label.OK() == false) result = false;
}
@@ -474,17 +477,17 @@
fp << organism->GetPhenotype().GetTimeUsed() << " "
<< "IP:(" << IP().GetMemSpace() << ", " << IP().GetPosition() << ") "
- << "AX:" << Stack(STACK_AX).Top() << " "
- << setbase(16) << "[0x" << Stack(STACK_AX).Top() << "] " << setbase(10)
+ << "AX:" << Stack(nHardwareSMT::STACK_AX).Top() << " "
+ << setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_AX).Top() << "] " << setbase(10)
- << "BX:" << Stack(STACK_BX).Top() << " "
- << setbase(16) << "[0x" << Stack(STACK_BX).Top() << "] " << setbase(10)
+ << "BX:" << Stack(nHardwareSMT::STACK_BX).Top() << " "
+ << setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_BX).Top() << "] " << setbase(10)
- << "CX:" << Stack(STACK_CX).Top() << " "
- << setbase(16) << "[0x" << Stack(STACK_CX).Top() << "] " << setbase(10)
+ << "CX:" << Stack(nHardwareSMT::STACK_CX).Top() << " "
+ << setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_CX).Top() << "] " << setbase(10)
- << "DX:" << Stack(STACK_DX).Top() << " "
- << setbase(16) << "[0x" << Stack(STACK_DX).Top() << "] " << setbase(10)
+ << "DX:" << Stack(nHardwareSMT::STACK_DX).Top() << " "
+ << setbase(16) << "[0x" << Stack(nHardwareSMT::STACK_DX).Top() << "] " << setbase(10)
<< endl;
@@ -526,12 +529,12 @@
//
/////////////////////////////////////////////////////////////////////////
-c4StackHead cHardwareSMT::FindLabel(int direction)
+cHeadMultiMem cHardwareSMT::FindLabel(int direction)
{
- c4StackHead & inst_ptr = IP();
+ cHeadMultiMem & inst_ptr = IP();
// Start up a search head at the position of the instruction pointer.
- c4StackHead search_head(inst_ptr);
+ cHeadMultiMem search_head(inst_ptr);
cCodeLabel & search_label = GetLabel();
// Make sure the label is of size > 0.
@@ -572,7 +575,7 @@
// to find search label's match inside another label.
int cHardwareSMT::FindLabel_Forward(const cCodeLabel & search_label,
- const cGenome & search_genome, int pos)
+ const cGenome & search_genome, int pos)
{
assert (pos < search_genome.GetSize() && pos >= 0);
@@ -654,7 +657,7 @@
// to find search label's match inside another label.
int cHardwareSMT::FindLabel_Backward(const cCodeLabel & search_label,
- const cGenome & search_genome, int pos)
+ const cGenome & search_genome, int pos)
{
assert (pos < search_genome.GetSize());
@@ -728,7 +731,7 @@
}
// Search for 'in_label' anywhere in the hardware.
-c4StackHead cHardwareSMT::FindLabel(const cCodeLabel & in_label, int direction)
+cHeadMultiMem cHardwareSMT::FindLabel(const cCodeLabel & in_label, int direction)
{
assert (in_label.GetSize() > 0);
@@ -739,7 +742,7 @@
// FOR NOW:
// Get something which works, no matter how inefficient!!!
- c4StackHead temp_head(this);
+ cHeadMultiMem temp_head(this);
while (temp_head.InMemory()) {
// IDEALY: Analyze the label we are in; see if the one we are looking
@@ -766,14 +769,14 @@
// @CAO: direction is not currently used; should be used to indicate the
// direction which the heads[HEAD_IP] should progress through a creature.
-c4StackHead cHardwareSMT::FindFullLabel(const cCodeLabel & in_label)
+cHeadMultiMem cHardwareSMT::FindFullLabel(const cCodeLabel & in_label)
{
// cout << "Running FindFullLabel with " << in_label.AsString() <<
// endl;
assert(in_label.GetSize() > 0); // Trying to find label of 0 size!
- c4StackHead temp_head(this);
+ cHeadMultiMem temp_head(this);
while (temp_head.InMemory()) {
// If we are not in a label, jump to the next checkpoint...
@@ -887,7 +890,7 @@
GetHead(x).Reset(IP().GetMemSpace(), this);
}
- for(int x=0; x<NUM_LOCAL_STACKS; x++)
+ for(int x=0; x < nHardwareSMT::NUM_LOCAL_STACKS; x++)
{
Stack(x).Clear();
}
@@ -906,7 +909,7 @@
// FIND THE FIRST EMPTY MEMORY SPACE
int target_mem_space;
- for (target_mem_space = 0; target_mem_space < NUM_MEMORY_SPACES; target_mem_space++)
+ for (target_mem_space = 0; target_mem_space < nHardwareSMT::NUM_MEMORY_SPACES; target_mem_space++)
{
if(isEmpty(target_mem_space))
{
@@ -914,12 +917,12 @@
}
}
- if (target_mem_space == NUM_MEMORY_SPACES)
+ if (target_mem_space == nHardwareSMT::NUM_MEMORY_SPACES)
{
return false;
}
- assert(target_mem_space >=0 && target_mem_space < NUM_MEMORY_SPACES);
+ assert(target_mem_space >=0 && target_mem_space < nHardwareSMT::NUM_MEMORY_SPACES);
if(ForkThread()) {
// Inject the new code
@@ -943,7 +946,7 @@
cur_thread=GetNumThreads()-1;
for(int i=0; i<cur_thread; i++) {
- for(int j=0; j<NUM_HEADS; j++) {
+ for(int j=0; j < NUM_HEADS; j++) {
if(threads[i].heads[j].GetMemSpace()==target_mem_space)
threads[i].heads[j].Jump(inject_code.GetSize());
}
@@ -952,7 +955,7 @@
for (int i=0; i < NUM_HEADS; i++) {
GetHead(i).Reset(target_mem_space, this);
}
- for (int i=0; i < NUM_LOCAL_STACKS; i++) {
+ for (int i=0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) {
Stack(i).Clear();
}
}
@@ -1000,7 +1003,7 @@
return TriggerMutations(trigger, IP());
}
-bool cHardwareSMT::TriggerMutations(int trigger, c4StackHead & cur_head)
+bool cHardwareSMT::TriggerMutations(int trigger, cHeadMultiMem & cur_head)
{
// Collect information about mutations from the organism.
cLocalMutations & mut_info = organism->GetLocalMutations();
@@ -1053,7 +1056,7 @@
}
bool cHardwareSMT::TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The rate we have stored indicates the probability that a single
// mutation will occur anywhere in the genome.
@@ -1061,7 +1064,7 @@
if (g_random.P(rate) == true) {
// We must create a temporary head and use it to randomly determine the
// position in the genome to be mutated.
- c4StackHead tmp_head(cur_head);
+ cHeadMultiMem tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
return true;
@@ -1070,7 +1073,7 @@
}
bool cHardwareSMT::TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The rate we have stored is the probability for a mutation at this single
// position in the genome.
@@ -1083,7 +1086,7 @@
}
int cHardwareSMT::TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate)
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate)
{
// The probability we have stored is per-site, so we can pull a random
// number from a binomial distribution to determine the number of mutations
@@ -1094,7 +1097,7 @@
if (num_mut > 0) {
for (int i = 0; i < num_mut; i++) {
- c4StackHead tmp_head(cur_head);
+ cHeadMultiMem tmp_head(cur_head);
tmp_head.AbsSet(g_random.GetUInt(target_memory.GetSize()));
TriggerMutations_Body(cur_mut->GetType(), target_memory, tmp_head);
}
@@ -1104,7 +1107,7 @@
}
void cHardwareSMT::TriggerMutations_Body(int type, cCPUMemory & target_memory,
- c4StackHead & cur_head)
+ cHeadMultiMem & cur_head)
{
const int pos = cur_head.GetPosition();
@@ -1153,7 +1156,7 @@
void cHardwareSMT::ReadLabel(int max_size)
{
int count = 0;
- c4StackHead * inst_ptr = &( IP() );
+ cHeadMultiMem * inst_ptr = &( IP() );
GetLabel().Clear();
@@ -1236,7 +1239,7 @@
fp<<"cHardwareSMT"<<endl;
// global_stack (in inverse order so load can just push)
- for(int i=NUM_LOCAL_STACKS; i<NUM_STACKS; i++)
+ for(int i = nHardwareSMT::NUM_LOCAL_STACKS; i < nHardwareSMT::NUM_STACKS; i++)
Stack(i).SaveState(fp);
//fp << thread_time_used << endl;
@@ -1260,7 +1263,7 @@
assert( foo == "cHardwareSMT" );
// global_stack
- for(int i=NUM_LOCAL_STACKS; i<NUM_STACKS; i++)
+ for(int i = nHardwareSMT::NUM_LOCAL_STACKS; i < nHardwareSMT::NUM_STACKS; i++)
Stack(i).LoadState(fp);
int num_threads;
@@ -1281,7 +1284,7 @@
inline int cHardwareSMT::FindModifiedStack(int default_stack)
{
- assert(default_stack < NUM_STACKS); // Stack ID too high.
+ assert(default_stack < nHardwareSMT::NUM_STACKS); // Stack ID too high.
if (GetInstSet().IsNop(IP().GetNextInst())) {
IP().Advance();
@@ -1307,7 +1310,7 @@
inline int cHardwareSMT::FindComplementStack(int base_stack)
{
const int comp_stack = base_stack + 2;
- return comp_stack%NUM_STACKS;
+ return comp_stack % nHardwareSMT::NUM_STACKS;
}
inline void cHardwareSMT::Fault(int fault_loc, int fault_type, cString fault_desc)
@@ -1316,7 +1319,7 @@
}
bool cHardwareSMT::Divide_CheckViable(const int parent_size,
- const int child_size, const int mem_space)
+ const int child_size, const int mem_space)
{
// Make sure the organism is okay with dividing now...
if (organism->Divide_CheckViable() == false) return false; // (divide fails)
@@ -1727,11 +1730,11 @@
//not touch any other threads or memory spaces (ie: parasites)
else
{
- for(int x=0; x<NUM_HEADS; x++)
+ for(int x = 0; x < NUM_HEADS; x++)
{
GetHead(x).Reset(0, this);
}
- for(int x=0; x<NUM_LOCAL_STACKS; x++)
+ for(int x = 0; x < nHardwareSMT::NUM_LOCAL_STACKS; x++)
{
Stack(x).Clear();
}
@@ -1753,13 +1756,13 @@
cString cHardwareSMT::GetActiveStackID(int stackID) const
{
- if(stackID==STACK_AX)
+ if(stackID == nHardwareSMT::STACK_AX)
return "AX";
- else if(stackID==STACK_BX)
+ else if(stackID == nHardwareSMT::STACK_BX)
return "BX";
- else if(stackID==STACK_CX)
+ else if(stackID == nHardwareSMT::STACK_CX)
return "CX";
- else if(stackID==STACK_DX)
+ else if(stackID == nHardwareSMT::STACK_DX)
return "DX";
else
return "";
@@ -1773,7 +1776,7 @@
//6
bool cHardwareSMT::Inst_ShiftR()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
int value = Stack(stack_used).Pop();
value >>= 1;
Stack(stack_used).Push(value);
@@ -1783,7 +1786,7 @@
//7
bool cHardwareSMT::Inst_ShiftL()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
int value = Stack(stack_used).Pop();
value <<= 1;
Stack(stack_used).Push(value);
@@ -1793,44 +1796,44 @@
//8
bool cHardwareSMT::Inst_Val_Nand()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- Stack(stack_used).Push(~(Stack(STACK_BX).Top() & Stack(STACK_CX).Top()));
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ Stack(stack_used).Push(~(Stack(nHardwareSMT::STACK_BX).Top() & Stack(nHardwareSMT::STACK_CX).Top()));
return true;
}
//9
bool cHardwareSMT::Inst_Val_Add()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- Stack(stack_used).Push(Stack(STACK_BX).Top() + Stack(STACK_CX).Top());
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ Stack(stack_used).Push(Stack(nHardwareSMT::STACK_BX).Top() + Stack(nHardwareSMT::STACK_CX).Top());
return true;
}
//10
bool cHardwareSMT::Inst_Val_Sub()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- Stack(stack_used).Push(Stack(STACK_BX).Top() - Stack(STACK_CX).Top());
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ Stack(stack_used).Push(Stack(nHardwareSMT::STACK_BX).Top() - Stack(nHardwareSMT::STACK_CX).Top());
return true;
}
//11
bool cHardwareSMT::Inst_Val_Mult()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- Stack(stack_used).Push(Stack(STACK_BX).Top() * Stack(STACK_CX).Top());
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ Stack(stack_used).Push(Stack(nHardwareSMT::STACK_BX).Top() * Stack(nHardwareSMT::STACK_CX).Top());
return true;
}
//12
bool cHardwareSMT::Inst_Val_Div()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- if (Stack(STACK_CX).Top() != 0) {
- if (0-INT_MAX > Stack(STACK_BX).Top() && Stack(STACK_CX).Top() == -1)
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ if (Stack(nHardwareSMT::STACK_CX).Top() != 0) {
+ if (0-INT_MAX > Stack(nHardwareSMT::STACK_BX).Top() && Stack(nHardwareSMT::STACK_CX).Top() == -1)
Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: Float exception");
else
- Stack(stack_used).Push(Stack(STACK_BX).Top() / Stack(STACK_CX).Top());
+ Stack(stack_used).Push(Stack(nHardwareSMT::STACK_BX).Top() / Stack(nHardwareSMT::STACK_CX).Top());
} else {
Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "div: dividing by 0");
return false;
@@ -1900,7 +1903,7 @@
} else {
read_inst = GetHead(head_id).GetInst().GetOp();
}
- Stack(STACK_AX).Push(read_inst);
+ Stack(nHardwareSMT::STACK_AX).Push(read_inst);
ReadInst(read_inst);
cpu_stats.mut_stats.copies_exec++; // @CAO, this too..
@@ -1912,7 +1915,7 @@
bool cHardwareSMT::Inst_HeadWrite()
{
const int head_id = FindModifiedHead(HEAD_WRITE);
- c4StackHead & active_head = GetHead(head_id);
+ cHeadMultiMem & active_head = GetHead(head_id);
int mem_space_used = active_head.GetMemSpace();
//commented out for right now...
@@ -1924,7 +1927,7 @@
active_head.Adjust();
- int value = Stack(STACK_AX).Pop();
+ int value = Stack(nHardwareSMT::STACK_AX).Pop();
if (value < 0 || value >= GetNumInst()) value = 0;
active_head.SetInst(cInstruction(value));
@@ -1939,8 +1942,8 @@
bool cHardwareSMT::Inst_HeadCopy()
{
// For the moment, this cannot be nop-modified.
- c4StackHead & read_head = GetHead(HEAD_READ);
- c4StackHead & write_head = GetHead(HEAD_WRITE);
+ cHeadMultiMem & read_head = GetHead(HEAD_READ);
+ cHeadMultiMem & write_head = GetHead(HEAD_WRITE);
sCPUStats & cpu_stats = organism->CPUStats();
read_head.Adjust();
@@ -1974,8 +1977,8 @@
//17
bool cHardwareSMT::Inst_IfEqual() // Execute next if bx == ?cx?
{
- const int stack_used = FindModifiedStack(STACK_AX);
- const int stack_used2 = (stack_used+1)%NUM_STACKS;
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_AX);
+ const int stack_used2 = (stack_used+1) % nHardwareSMT::NUM_STACKS;
if (Stack(stack_used).Top() != Stack(stack_used2).Top()) IP().Advance();
return true;
}
@@ -1983,8 +1986,8 @@
//18
bool cHardwareSMT::Inst_IfNotEqual() // Execute next if bx != ?cx?
{
- const int stack_used = FindModifiedStack(STACK_AX);
- const int stack_used2 = (stack_used+1)%NUM_STACKS;
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_AX);
+ const int stack_used2 = (stack_used+1) % nHardwareSMT::NUM_STACKS;
if (Stack(stack_used).Top() == Stack(stack_used2).Top()) IP().Advance();
return true;
}
@@ -1992,8 +1995,8 @@
//19
bool cHardwareSMT::Inst_IfLess() // Execute next if ?bx? < ?cx?
{
- const int stack_used = FindModifiedStack(STACK_AX);
- const int stack_used2 = (stack_used+1)%NUM_STACKS;
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_AX);
+ const int stack_used2 = (stack_used+1) % nHardwareSMT::NUM_STACKS;
if (Stack(stack_used).Top() >= Stack(stack_used2).Top()) IP().Advance();
return true;
}
@@ -2001,8 +2004,8 @@
//20
bool cHardwareSMT::Inst_IfGreater() // Execute next if bx > ?cx?
{
- const int stack_used = FindModifiedStack(STACK_AX);
- const int stack_used2 = (stack_used+1)%NUM_STACKS;
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_AX);
+ const int stack_used2 = (stack_used+1) % nHardwareSMT::NUM_STACKS;
if (Stack(stack_used).Top() <= Stack(stack_used2).Top()) IP().Advance();
return true;
}
@@ -2011,7 +2014,7 @@
bool cHardwareSMT::Inst_HeadPush()
{
const int head_used = FindModifiedHead(HEAD_IP);
- Stack(STACK_BX).Push(GetHead(head_used).GetPosition());
+ Stack(nHardwareSMT::STACK_BX).Push(GetHead(head_used).GetPosition());
//if (head_used == HEAD_IP) {
// GetHead(head_used).Set(GetHead(HEAD_FLOW));
// AdvanceIP() = false;
@@ -2023,7 +2026,7 @@
bool cHardwareSMT::Inst_HeadPop()
{
const int head_used = FindModifiedHead(HEAD_IP);
- GetHead(head_used).Set(Stack(STACK_BX).Pop(),
+ GetHead(head_used).Set(Stack(nHardwareSMT::STACK_BX).Pop(),
GetHead(head_used).GetMemSpace(), this);
return true;
}
@@ -2048,21 +2051,21 @@
bool cHardwareSMT::Inst_Search()
{
ReadLabel();
- GetLabel().Rotate(2, NUM_NOPS_4STACK);
- c4StackHead found_pos = FindLabel(0);
+ GetLabel().Rotate(2, nHardwareSMT::NUM_NOPS);
+ cHeadMultiMem found_pos = FindLabel(0);
if(found_pos.GetPosition()-IP().GetPosition()==0)
{
GetHead(HEAD_FLOW).Set(IP().GetPosition()+1, IP().GetMemSpace(), this);
// pushing zero into STACK_AX on a missed search makes it difficult to create
// a self-replicating organism. -law
//Stack(STACK_AX).Push(0);
- Stack(STACK_BX).Push(0);
+ Stack(nHardwareSMT::STACK_BX).Push(0);
}
else
{
int search_size = found_pos.GetPosition() - IP().GetPosition() + GetLabel().GetSize() + 1;
- Stack(STACK_BX).Push(search_size);
- Stack(STACK_AX).Push(GetLabel().GetSize());
+ Stack(nHardwareSMT::STACK_BX).Push(search_size);
+ Stack(nHardwareSMT::STACK_AX).Push(GetLabel().GetSize());
GetHead(HEAD_FLOW).Set(found_pos);
}
@@ -2072,8 +2075,8 @@
//25
bool cHardwareSMT::Inst_PushNext()
{
- int stack_used = FindModifiedStack(STACK_AX);
- int successor = (stack_used+1)%NUM_STACKS;
+ int stack_used = FindModifiedStack(nHardwareSMT::STACK_AX);
+ int successor = (stack_used+1) % nHardwareSMT::NUM_STACKS;
Stack(successor).Push(Stack(stack_used).Pop());
return true;
}
@@ -2081,8 +2084,8 @@
//26
bool cHardwareSMT::Inst_PushPrevious()
{
- int stack_used = FindModifiedStack(STACK_BX);
- int predecessor = (stack_used+NUM_STACKS-1)%NUM_STACKS;
+ int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ int predecessor = (stack_used + nHardwareSMT::NUM_STACKS - 1) % nHardwareSMT::NUM_STACKS;
Stack(predecessor).Push(Stack(stack_used).Pop());
return true;
}
@@ -2090,7 +2093,7 @@
//27
bool cHardwareSMT::Inst_PushComplement()
{
- int stack_used = FindModifiedStack(STACK_BX);
+ int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
int complement = FindComplementStack(stack_used);
Stack(complement).Push(Stack(stack_used).Pop());
return true;
@@ -2099,7 +2102,7 @@
//28
bool cHardwareSMT::Inst_ValDelete()
{
- int stack_used = FindModifiedStack(STACK_BX);
+ int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
Stack(stack_used).Pop();
return true;
}
@@ -2107,7 +2110,7 @@
//29
bool cHardwareSMT::Inst_ValCopy()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
Stack(stack_used).Push(Stack(stack_used).Top());
return true;
}
@@ -2126,7 +2129,7 @@
bool cHardwareSMT::Inst_IfLabel()
{
ReadLabel();
- GetLabel().Rotate(2, NUM_NOPS_4STACK);
+ GetLabel().Rotate(2, nHardwareSMT::NUM_NOPS);
if (GetLabel() != GetReadLabel()) IP().Advance();
return true;
}
@@ -2134,7 +2137,7 @@
//32
bool cHardwareSMT::Inst_Increment()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
int value = Stack(stack_used).Pop();
Stack(stack_used).Push(++value);
return true;
@@ -2143,7 +2146,7 @@
//33
bool cHardwareSMT::Inst_Decrement()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
int value = Stack(stack_used).Pop();
Stack(stack_used).Push(--value);
return true;
@@ -2152,12 +2155,12 @@
//34
bool cHardwareSMT::Inst_Mod()
{
- const int stack_used = FindModifiedStack(STACK_BX);
- if (Stack(STACK_CX).Top() != 0) {
- if(Stack(STACK_CX).Top() == -1)
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
+ if (Stack(nHardwareSMT::STACK_CX).Top() != 0) {
+ if(Stack(nHardwareSMT::STACK_CX).Top() == -1)
Stack(stack_used).Push(0);
else
- Stack(stack_used).Push(Stack(STACK_BX).Top() % Stack(STACK_CX).Top());
+ Stack(stack_used).Push(Stack(nHardwareSMT::STACK_BX).Top() % Stack(nHardwareSMT::STACK_CX).Top());
} else {
Fault(FAULT_LOC_MATH, FAULT_TYPE_ERROR, "mod: modding by 0");
return false;
@@ -2176,7 +2179,7 @@
//36
bool cHardwareSMT::Inst_IO()
{
- const int stack_used = FindModifiedStack(STACK_BX);
+ const int stack_used = FindModifiedStack(nHardwareSMT::STACK_BX);
// Do the "put" component
const int value_out = Stack(stack_used).Top();
@@ -2194,15 +2197,15 @@
bool OK=true;
const int current_mem_space = IP().GetMemSpace();
- for(int x=1; x<NUM_MEMORY_SPACES; x++)
+ for(int x = 1; x < nHardwareSMT::NUM_MEMORY_SPACES; x++)
{
OK=true;
- int index = (current_mem_space+x) % NUM_MEMORY_SPACES;
+ int index = (current_mem_space+x) % nHardwareSMT::NUM_MEMORY_SPACES;
for(int y=0; y<GetMemory(index).GetSize() && OK; y++)
{
- if(GetMemory(index)[y].GetOp() >= NUM_NOPS_4STACK)
+ if(GetMemory(index)[y].GetOp() >= nHardwareSMT::NUM_NOPS)
OK=false;
}
for(int y=0; y<GetNumThreads() && OK; y++)
@@ -2223,7 +2226,7 @@
{
for(int x=0; x<GetMemory(mem_space_used).GetSize(); x++)
{
- if(GetMemory(mem_space_used)[x].GetOp() >= NUM_NOPS_4STACK)
+ if(GetMemory(mem_space_used)[x].GetOp() >= nHardwareSMT::NUM_NOPS)
return false;
}
return true;
Modified: branches/brysonda/source/cpu/hardware_smt.h
===================================================================
--- branches/brysonda/source/cpu/hardware_smt.h 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_smt.h 2005-06-06 14:59:29 UTC (rev 179)
@@ -7,8 +7,8 @@
*
*/
-#ifndef HARDWARE_SMT_HH
-#define HARDWARE_SMT_HH
+#ifndef HARDWARE_SMT_H
+#define HARDWARE_SMT_H
#include <iomanip>
@@ -21,17 +21,17 @@
#ifndef DEFS_HH
#include "defs.hh"
#endif
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
#endif
#ifndef HARDWARE_BASE_HH
#include "hardware_base.hh"
#endif
-#ifndef HARDWARE_4STACK_CONSTANTS_HH
-#include "hardware_4stack_constants.hh"
+#ifndef HARDWARE_SMT_CONSTANTS_H
+#include "hardware_smt_constants.h"
#endif
-#ifndef HARDWARE_4STACK_THREAD_HH
-#include "hardware_4stack_thread.hh"
+#ifndef HARDWARE_SMT_THREAD_H
+#include "hardware_smt_thread.h"
#endif
#ifndef STRING_HH
#include "string.hh"
@@ -39,6 +39,9 @@
#ifndef TARRAY_HH
#include "tArray.hh"
#endif
+#ifndef TINSTLIB_H
+#include "tInstLib.h"
+#endif
class cInstSet;
class cInstLibBase;
@@ -62,7 +65,7 @@
class cCodeLabel;
class cCPUMemory;
class cCPUStack; // aggregate
-class c4StackHead; // access
+class cHeadMultiMem; // access
class cGenome;
class cHardwareSMT_Thread; // access
class cInjectGenotype;
@@ -77,14 +80,12 @@
public:
typedef bool (cHardwareSMT::*tMethod)();
private:
- static cInstLib4Stack *s_inst_slib;
- static cInstLib4Stack *initInstLib(void);
- tHardware4StackMethod *m_functions;
+ static tInstLib<cHardwareSMT::tMethod>* s_inst_slib;
+ static tInstLib<cHardwareSMT::tMethod>* initInstLib(void);
+ tMethod* m_functions;
private:
- tArray<cCPUMemory> memory_array; // Memory...
- //cCPUStack global_stack; // A stack that all threads share.
- cCPUStack global_stacks[NUM_GLOBAL_STACKS];
- //int thread_time_used;
+ tArray<cCPUMemory> memory_array; // Memory...
+ cCPUStack global_stacks[nHardwareSMT::NUM_GLOBAL_STACKS];
tArray<cHardwareSMT_Thread> threads;
int thread_id_chart;
@@ -151,28 +152,28 @@
int GetCurHead() const { return threads[cur_thread].cur_head; }
- const c4StackHead & GetHead(int head_id) const
+ const cHeadMultiMem & GetHead(int head_id) const
{ return threads[cur_thread].heads[head_id]; }
- c4StackHead & GetHead(int head_id)
+ cHeadMultiMem & GetHead(int head_id)
{ return threads[cur_thread].heads[head_id];}
- const c4StackHead & GetHead(int head_id, int thread) const
+ const cHeadMultiMem & GetHead(int head_id, int thread) const
{ return threads[thread].heads[head_id]; }
- c4StackHead & GetHead(int head_id, int thread)
+ cHeadMultiMem & GetHead(int head_id, int thread)
{ return threads[thread].heads[head_id];}
- const c4StackHead & GetActiveHead() const { return GetHead(GetCurHead()); }
- c4StackHead & GetActiveHead() { return GetHead(GetCurHead()); }
+ const cHeadMultiMem & GetActiveHead() const { return GetHead(GetCurHead()); }
+ cHeadMultiMem & GetActiveHead() { return GetHead(GetCurHead()); }
void AdjustHeads();
- inline const c4StackHead & IP() const
+ inline const cHeadMultiMem & IP() const
{ return threads[cur_thread].heads[HEAD_IP]; }
- inline c4StackHead & IP() { return threads[cur_thread].heads[HEAD_IP]; }
+ inline cHeadMultiMem & IP() { return threads[cur_thread].heads[HEAD_IP]; }
- inline const c4StackHead & IP(int thread) const
+ inline const cHeadMultiMem & IP(int thread) const
{ return threads[thread].heads[HEAD_IP]; }
- inline c4StackHead & IP(int thread)
+ inline cHeadMultiMem & IP(int thread)
{ return threads[thread].heads[HEAD_IP]; }
@@ -227,13 +228,13 @@
}
// Complex label manipulation...
- c4StackHead FindLabel(int direction);
+ cHeadMultiMem FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
int FindLabel_Backward(const cCodeLabel & search_label,
const cGenome & search_genome, int pos);
- c4StackHead FindLabel(const cCodeLabel & in_label, int direction);
- c4StackHead FindFullLabel(const cCodeLabel & in_label);
+ cHeadMultiMem FindLabel(const cCodeLabel & in_label, int direction);
+ cHeadMultiMem FindFullLabel(const cCodeLabel & in_label);
int GetType() const { return HARDWARE_TYPE_CPU_4STACK; }
bool InjectParasite(double mut_multiplier);
@@ -245,15 +246,15 @@
bool isEmpty(int mem_space_used);
bool TriggerMutations(int trigger);
- bool TriggerMutations(int trigger, c4StackHead & cur_head);
+ bool TriggerMutations(int trigger, cHeadMultiMem & cur_head);
bool TriggerMutations_ScopeGenome(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
bool TriggerMutations_ScopeLocal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
int TriggerMutations_ScopeGlobal(const cMutation * cur_mut,
- cCPUMemory & target_memory, c4StackHead & cur_head, const double rate);
+ cCPUMemory & target_memory, cHeadMultiMem & cur_head, const double rate);
void TriggerMutations_Body(int type, cCPUMemory & target_memory,
- c4StackHead & cur_head);
+ cHeadMultiMem & cur_head);
void ReadInst(const int in_inst);
@@ -384,15 +385,15 @@
inline const cCPUMemory & cHardwareSMT::GetMemory(int mem_space) const
{
- if(mem_space >= NUM_MEMORY_SPACES)
- mem_space %= NUM_MEMORY_SPACES;
+ if(mem_space >= nHardwareSMT::NUM_MEMORY_SPACES)
+ mem_space %= nHardwareSMT::NUM_MEMORY_SPACES;
return memory_array[mem_space];
}
inline cCPUMemory & cHardwareSMT::GetMemory(int mem_space)
{
- if(mem_space >= NUM_MEMORY_SPACES)
- mem_space %= NUM_MEMORY_SPACES;
+ if(mem_space >= nHardwareSMT::NUM_MEMORY_SPACES)
+ mem_space %= nHardwareSMT::NUM_MEMORY_SPACES;
return memory_array[mem_space];
}
@@ -440,7 +441,7 @@
inline int cHardwareSMT::GetStack(int depth, int stack_id, int in_thread) const
{
- if(stack_id<0 || stack_id>NUM_STACKS) stack_id=0;
+ if(stack_id<0 || stack_id > nHardwareSMT::NUM_STACKS) stack_id=0;
if(in_thread==-1)
in_thread=cur_thread;
@@ -466,52 +467,52 @@
inline cCPUStack& cHardwareSMT::Stack(int stack_id)
{
- if(stack_id >= NUM_STACKS)
+ if(stack_id >= nHardwareSMT::NUM_STACKS)
{
stack_id=0;
}
- if(stack_id < NUM_LOCAL_STACKS)
+ if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
return threads[cur_thread].local_stacks[stack_id];
else
- return global_stacks[stack_id % NUM_LOCAL_STACKS];
+ return global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
}
inline const cCPUStack& cHardwareSMT::Stack(int stack_id) const
{
- if(stack_id >= NUM_STACKS)
+ if(stack_id >= nHardwareSMT::NUM_STACKS)
{
stack_id=0;
}
- if(stack_id < NUM_LOCAL_STACKS)
+ if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
return threads[cur_thread].local_stacks[stack_id];
else
- return global_stacks[stack_id % NUM_LOCAL_STACKS];
+ return global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
}
inline cCPUStack& cHardwareSMT::Stack(int stack_id, int in_thread)
{
- if(stack_id >= NUM_STACKS)
+ if(stack_id >= nHardwareSMT::NUM_STACKS)
stack_id=0;
if(in_thread >= threads.GetSize())
in_thread=cur_thread;
- if(stack_id < NUM_LOCAL_STACKS)
+ if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
return threads[in_thread].local_stacks[stack_id];
else
- return global_stacks[stack_id % NUM_LOCAL_STACKS];
+ return global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
}
inline const cCPUStack& cHardwareSMT::Stack(int stack_id, int in_thread) const
{
- if(stack_id >= NUM_STACKS)
+ if(stack_id >= nHardwareSMT::NUM_STACKS)
stack_id=0;
if(in_thread >= threads.GetSize())
in_thread=cur_thread;
- if(stack_id < NUM_LOCAL_STACKS)
+ if(stack_id < nHardwareSMT::NUM_LOCAL_STACKS)
return threads[in_thread].local_stacks[stack_id];
else
- return global_stacks[stack_id % NUM_LOCAL_STACKS];
+ return global_stacks[stack_id % nHardwareSMT::NUM_LOCAL_STACKS];
}
#endif
Copied: branches/brysonda/source/cpu/hardware_smt_constants.h (from rev 177, branches/brysonda/source/cpu/hardware_4stack_constants.hh)
===================================================================
--- branches/brysonda/source/cpu/hardware_4stack_constants.hh 2005-06-04 19:16:19 UTC (rev 177)
+++ branches/brysonda/source/cpu/hardware_smt_constants.h 2005-06-06 14:59:29 UTC (rev 179)
@@ -0,0 +1,26 @@
+/*
+ * hardware_smt_constants.h
+ * Avida2
+ *
+ * Created by David on 6/4/05.
+ * Copyright 2005 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef HARDWARE_SMT_CONSTANTS_H
+#define HARDWARE_SMT_CONSTANTS_H
+
+// Constants can be used across different cpu models, wrap in namespace @DMB
+namespace nHardwareSMT
+{
+ static const int NUM_LOCAL_STACKS = 5;
+ static const int NUM_GLOBAL_STACKS = 1;
+ static const int NUM_STACKS = NUM_LOCAL_STACKS + NUM_GLOBAL_STACKS;
+
+ enum tStacks { STACK_AX = 0, STACK_BX, STACK_CX, STACK_DX, STACK_EX, STACK_FX };
+
+ static const int NUM_NOPS = 6;
+ static const int NUM_MEMORY_SPACES = 6;
+}
+
+#endif
Modified: branches/brysonda/source/cpu/hardware_smt_thread.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_smt_thread.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_smt_thread.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -24,7 +24,7 @@
{
id = _id;
if (id == -1) id = in_thread.id;
- for (int i = 0; i < NUM_LOCAL_STACKS; i++) {
+ for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) {
local_stacks[i] = in_thread.local_stacks[i];
}
for (int i = 0; i < NUM_HEADS; i++) {
@@ -38,7 +38,7 @@
void cHardwareSMT_Thread::operator=(const cHardwareSMT_Thread & in_thread)
{
id = in_thread.id;
- for (int i = 0; i < NUM_LOCAL_STACKS; i++) {
+ for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) {
local_stacks[i] = in_thread.local_stacks[i];
}
for (int i = 0; i < NUM_HEADS; i++) {
@@ -51,7 +51,7 @@
{
id = _id;
- for (int i = 0; i < NUM_LOCAL_STACKS; i++) local_stacks[i].Clear();
+ for (int i = 0; i < nHardwareSMT::NUM_LOCAL_STACKS; i++) local_stacks[i].Clear();
for (int i = 0; i < NUM_HEADS; i++) heads[i].Reset(0, in_hardware);
cur_head = HEAD_IP;
@@ -65,12 +65,12 @@
fp << "cHardwareSMT_Thread" << endl;
// stacks (NOT WORKING! -law)
- for( int i=0; i<NUM_STACKS; ++i ){
+ for( int i = 0; i < nHardwareSMT::NUM_STACKS; ++i ){
local_stacks[i].SaveState(fp);
}
// heads (@TCC does not handle parasites!!!)
- for( int i=0; i<NUM_HEADS; ++i ){
+ for( int i = 0; i < NUM_HEADS; ++i ){
fp<<heads[i].GetPosition()<<endl;
}
@@ -90,18 +90,18 @@
assert( foo == "cHardwareSMT_Thread");
// stacks (NOT WORKING! -law)
- for( int i=0; i<NUM_STACKS; ++i ){
+ for( int i=0; i < nHardwareSMT::NUM_STACKS; ++i ){
local_stacks[i].LoadState(fp);
}
// heads (@TCC does not handle parasites!!!)
- for( int i=0; i<NUM_HEADS; ++i ){
+ for( int i = 0; i < NUM_HEADS; ++i ){
int pos;
fp>>pos;
heads[i].AbsSet(pos);
}
- char marker; fp>>marker; assert( marker == '|' );
+ char marker; fp >> marker; assert( marker == '|' );
/* YIKES! data loss below: */
char the_cur_head = cur_head;
Modified: branches/brysonda/source/cpu/hardware_smt_thread.h
===================================================================
--- branches/brysonda/source/cpu/hardware_smt_thread.h 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_smt_thread.h 2005-06-06 14:59:29 UTC (rev 179)
@@ -7,8 +7,8 @@
*
*/
-#ifndef HARDWARE_SMT_THREAD_HH
-#define HARDWARE_SMT_THREAD_HH
+#ifndef HARDWARE_SMT_THREAD_H
+#define HARDWARE_SMT_THREAD_H
#include <iostream>
@@ -18,11 +18,11 @@
#ifndef CPU_STACK_HH
#include "cpu_stack.hh"
#endif
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
#endif
-#ifndef HARDWARE_4STACK_CONSTANTS_HH
-#include "hardware_4stack_constants.hh"
+#ifndef HARDWARE_SMT_CONSTANTS_H
+#include "hardware_smt_constants.h"
#endif
#ifndef TBUFFER_HH
#include "tBuffer.hh"
@@ -31,10 +31,10 @@
/**
* This class is needed to run several threads on a single genome.
*
- * @see cCPUStack, c4StackHead, cHardwareSMT
+ * @see cCPUStack, cHeadMultiMem, cHardwareSMT
**/
-class c4StackHead; // aggregate
+class cHeadMultiMem; // aggregate
class cCodeLabel; // aggregate
class cCPUStack; // aggregate
class cHardwareBase;
@@ -45,9 +45,9 @@
private:
int id;
public:
- c4StackHead heads[NUM_HEADS];
+ cHeadMultiMem heads[NUM_HEADS];
UCHAR cur_head;
- cCPUStack local_stacks[NUM_LOCAL_STACKS];
+ cCPUStack local_stacks[nHardwareSMT::NUM_LOCAL_STACKS];
bool advance_ip; // Should the IP advance after this instruction?
cCodeLabel read_label;
@@ -56,13 +56,13 @@
// of the parasite running the thread. Otherwise, it will be NULL.
cInjectGenotype* owner;
public:
- cHardwareSMT_Thread(cHardwareBase * in_hardware=NULL, int _id=-1);
- cHardwareSMT_Thread(const cHardwareSMT_Thread & in_thread, int _id=-1);
+ cHardwareSMT_Thread(cHardwareBase* in_hardware = NULL, int _id = -1);
+ cHardwareSMT_Thread(const cHardwareSMT_Thread& in_thread, int _id = -1);
~cHardwareSMT_Thread();
- void operator=(const cHardwareSMT_Thread & in_thread);
+ void operator=(const cHardwareSMT_Thread& in_thread);
- void Reset(cHardwareBase * in_hardware, int _id);
+ void Reset(cHardwareBase* in_hardware, int _id);
int GetID() const { return id; }
void SetID(int _id) { id = _id; }
Modified: branches/brysonda/source/cpu/hardware_status_printer.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_status_printer.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_status_printer.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -5,7 +5,7 @@
// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
//////////////////////////////////////////////////////////////////////////////
-#include "cpu_head.hh"
+#include "head_cpu.hh"
#include "hardware_4stack.hh"
#include "hardware_base.hh"
#include "hardware_cpu.hh"
Modified: branches/brysonda/source/cpu/hardware_util.cc
===================================================================
--- branches/brysonda/source/cpu/hardware_util.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_util.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -21,6 +21,9 @@
#ifndef HARDWARE_4STACK_HH
#include "hardware_4stack.hh"
#endif
+#ifndef HARDWARE_SMT_H
+#include "hardware_smt.h"
+#endif
#ifndef INIT_FILE_HH
#include "init_file.hh"
#endif
@@ -30,55 +33,86 @@
#ifndef INST_SET_HH
#include "inst_set.hh"
#endif
+#ifndef TDICTIONARY_HH
+#include "tDictionary.hh"
+#endif
using namespace std;
-void cHardwareUtil::LoadInstSet(cString filename, cInstSet & inst_set,
- tDictionary<int> & nop_dict,
- tDictionary<int> & inst_dict
-){
- // If there is no filename, use the default for the appropriate hardware.
- cString default_filename = "unknown";
- if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
- default_filename = cHardwareCPU::GetDefaultInstFilename();
+void cHardwareUtil::LoadInstSet(cString filename, cInstSet & inst_set)
+{
+ // Setup the instruction library and collect the default filename
+ cString default_filename;
+ switch (cConfig::GetHardwareType())
+ {
+ case HARDWARE_TYPE_CPU_ORIGINAL:
+ inst_set.SetInstLib(cHardwareCPU::GetInstLib());
+ default_filename = cHardwareCPU::GetDefaultInstFilename();
+ break;
+ case HARDWARE_TYPE_CPU_4STACK:
+ inst_set.SetInstLib(cHardware4Stack::GetInstLib());
+ default_filename = cHardware4Stack::GetDefaultInstFilename();
+ break;
+ case HARDWARE_TYPE_CPU_SMT:
+ inst_set.SetInstLib(cHardwareSMT::GetInstLib());
+ default_filename = cHardwareSMT::GetDefaultInstFilename();
+ break;
+ default:
+ default_filename = "unknown";
}
- else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
- default_filename = cHardware4Stack::GetDefaultInstFilename();
- }
-
- if (filename == "") {
- cerr << "Warning: No instruction set specified; using default '"
- << filename << "'." << endl;
+
+ if (filename == "")
+ {
filename = default_filename;
+ cerr << "Warning: No instruction set specified; using default '"
+ << filename << "'." << endl;
}
-
+
cInitFile file(filename);
-
+
// If we could not open the instruction set what to do?
- if (file.IsOpen() == false) {
-
+ if (file.IsOpen() == false)
+ {
+
// If this is the default filename, write the file and try again.
- if (filename == default_filename) {
- if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
- cHardwareCPU::WriteDefaultInstSet();
- }
- else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
- cHardware4Stack::WriteDefaultInstSet();
- }
+ if (filename == default_filename)
+ {
+ switch (cConfig::GetHardwareType())
+ {
+ case HARDWARE_TYPE_CPU_ORIGINAL:
+ cHardwareCPU::WriteDefaultInstSet();
+ break;
+ case HARDWARE_TYPE_CPU_4STACK:
+ cHardware4Stack::WriteDefaultInstSet();
+ break;
+ case HARDWARE_TYPE_CPU_SMT:
+ cHardwareSMT::WriteDefaultInstSet();
+ }
}
-
// If this is not the default filename, give and error and stop.
- else {
+ else
+ {
cerr << "Error: Could not open instruction set '" << filename
- << "'. Halting." << endl;
+ << "'. Halting." << endl;
exit(1);
}
}
-
+
file.Load();
file.Compress();
-
+
+ tDictionary<int> nop_dict;
+ for(int i = 0; i < inst_set.GetInstLib()->GetNumNops(); i++)
+ nop_dict.Add(inst_set.GetInstLib()->GetNopName(i), i);
+
+ tDictionary<int> inst_dict;
+ for(int i = 0; i < inst_set.GetInstLib()->GetSize(); i++)
+ inst_dict.Add(inst_set.GetInstLib()->GetName(i), i);
+
+ cout << "Instruction Library has " << inst_dict.GetSize()
+ << " instructions and " << nop_dict.GetSize() << " nops." << endl;
+
for (int line_id = 0; line_id < file.GetNumLines(); line_id++) {
cString cur_line = file.GetLine(line_id);
cString inst_name = cur_line.PopWord();
@@ -86,12 +120,12 @@
int cost = cur_line.PopWord().AsInt();
int ft_cost = cur_line.PopWord().AsInt();
double prob_fail = cur_line.PopWord().AsDouble();
-
+
// If this instruction has 0 redundancy, we don't want it!
if (redundancy < 0) continue;
if (redundancy > 256) {
cerr << "Error: Max redundancy is 256. Resetting redundancy of \""
- << inst_name << "\" from " << redundancy << " to 256." << endl;
+ << inst_name << "\" from " << redundancy << " to 256." << endl;
redundancy = 256;
}
@@ -102,85 +136,33 @@
inst_set.AddNop2(nop_mod, redundancy, ft_cost, cost, prob_fail);
continue;
}
-
+
// Otherwise, it had better be in the main dictionary...
int fun_id = -1;
if(inst_dict.Find(inst_name, fun_id) == true){
inst_set.Add2(fun_id, redundancy, ft_cost, cost, prob_fail);
continue;
}
-
+
// Oh oh! Didn't find an instruction!
cerr << endl
- << "Error: Could not find instruction '" << inst_name << "'" << endl
- << " (Best match = '"
- << inst_dict.NearMatch(inst_name) << "')" << endl;
+ << "Error: Could not find instruction '" << inst_name << "'" << endl
+ << " (Best match = '"
+ << inst_dict.NearMatch(inst_name) << "')" << endl;
exit(1);
}
-
- cerr << "Loaded Instruction Library \"" << filename
- << "\" with " << inst_set.GetSize() << " instructions." << endl;
-}
-
-void cHardwareUtil::LoadInstSet_CPUOriginal(const cString & filename, cInstSet & inst_set)
-{
- // Nops (or other modifying-instructions...) Note: Nops must be the
- // first instructions added to the set.
-
- // Build a dictionary of instructions and their corresponding methods...
- tDictionary<int> nop_dict;
- for(int i=0; i<inst_set.GetInstLib()->GetNumNops(); i++)
- nop_dict.Add(inst_set.GetInstLib()->GetNopName(i), i);
-
- tDictionary<int> inst_dict;
- for(int i=0; i<inst_set.GetInstLib()->GetSize(); i++)
- inst_dict.Add(inst_set.GetInstLib()->GetName(i), i);
-
- // And load it on up!
- LoadInstSet(filename, inst_set, nop_dict, inst_dict);
+ cerr << "Loaded Instruction Set \"" << filename
+ << "\" with " << inst_set.GetSize() << " instructions." << endl;
}
-void cHardwareUtil::LoadInstSet_CPU4Stack(const cString & filename, cInstSet & inst_set)
-{
- // Nops (or other modifying-instructions...) Note: Nops must be the
- // first instructions added to the set.
-
- // Build a dictionary of instructions and their corresponding methods...
-
- tDictionary<int> nop_dict;
- for(int i=0; i<inst_set.GetInstLib()->GetNumNops(); i++)
- nop_dict.Add(inst_set.GetInstLib()->GetNopName(i), i);
-
- tDictionary<int> inst_dict;
- for(int i=0; i<inst_set.GetInstLib()->GetSize(); i++)
- inst_dict.Add(inst_set.GetInstLib()->GetName(i), i);
-
- cout << "Instruction Library in util has " << inst_dict.GetSize()
- << " instructions and " << nop_dict.GetSize() << " nops." << endl;
-
-
- // And load it on up!
- LoadInstSet(filename, inst_set, nop_dict, inst_dict);
-}
-
cInstSet & cHardwareUtil::DefaultInstSet(const cString & inst_filename)
{
static cInstSet inst_set;
+
+ // If we don't have an instruction set yet, set it up.
+ if (inst_set.GetSize() == 0) LoadInstSet(inst_filename, inst_set);
- // If we don't have an instruction set yet, and we've been given a filename,
- // set it up.
- if (inst_filename != "" && inst_set.GetSize() == 0) {
- if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
- inst_set.SetInstLib(cHardwareCPU::GetInstLib());
- LoadInstSet_CPUOriginal(inst_filename, inst_set);
- }
- else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
- inst_set.SetInstLib(cHardware4Stack::GetInstLib());
- LoadInstSet_CPU4Stack(inst_filename, inst_set);
- }
- }
-
return inst_set;
}
Modified: branches/brysonda/source/cpu/hardware_util.hh
===================================================================
--- branches/brysonda/source/cpu/hardware_util.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/hardware_util.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -11,23 +11,14 @@
#ifndef STRING_HH
#include "string.hh"
#endif
-#ifndef TDICTIONARY_HH
-#include "tDictionary.hh"
-#endif
class cString; // aggregate
class cInstSet;
-template <class T> class tDictionary;
class cHardwareUtil {
public:
- static void LoadInstSet( cString filename, cInstSet & inst_set,
- tDictionary<int> & nop_dict, tDictionary<int> & inst_dict );
- static void LoadInstSet_CPUOriginal(const cString & filename,
- cInstSet & inst_set);
- static void LoadInstSet_CPU4Stack(const cString & filename,
- cInstSet & inst_set);
- static cInstSet & DefaultInstSet(const cString & inst_filename);
+ static void LoadInstSet( cString filename, cInstSet& inst_set);
+ static cInstSet& DefaultInstSet(const cString & inst_filename);
};
#endif
Copied: branches/brysonda/source/cpu/head_cpu.cc (from rev 177, branches/brysonda/source/cpu/cpu_head.cc)
===================================================================
--- branches/brysonda/source/cpu/cpu_head.cc 2005-06-04 19:16:19 UTC (rev 177)
+++ branches/brysonda/source/cpu/head_cpu.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -0,0 +1,489 @@
+/////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology //
+// //
+// Read the COPYING and README files, or contact 'avida at alife.org', //
+// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef HEAD_CPU_HH
+#include "head_cpu.hh"
+#endif
+
+#ifndef CPU_MEMORY_HH
+#include "cpu_memory.hh"
+#endif
+#ifndef CODE_LABEL_HH
+#include "code_label.hh"
+#endif
+#ifndef GENOME_HH
+#include "genome.hh"
+#endif
+#ifndef HARDWARE_BASE_HH
+#include "hardware_base.hh"
+#endif
+#ifndef INST_SET_HH
+#include "inst_set.hh"
+#endif
+#ifndef INSTRUCTION_HH
+#include "instruction.hh"
+#endif
+
+#include <assert.h>
+
+class cHardwareBase; // access
+class cCPUMemory; // access
+class cCodeLabel; // access
+class cInstSet; // access
+
+cHeadCPU::cHeadCPU() {
+ main_hardware = NULL;
+ cur_hardware = NULL;
+ position = 0;
+}
+
+cHeadCPU::cHeadCPU(cHardwareBase * in_hardware, int in_pos) {
+ main_hardware = in_hardware;
+ cur_hardware = in_hardware;
+
+ position = in_pos;
+ if (in_pos) Adjust();
+}
+
+cHeadCPU::cHeadCPU(const cHeadCPU & in_cpu_head) {
+ main_hardware = in_cpu_head.main_hardware;
+ cur_hardware = in_cpu_head.cur_hardware;
+ position = in_cpu_head.position;
+}
+
+
+
+void cHeadCPU::Adjust()
+{
+ assert(cur_hardware != NULL);
+ assert(main_hardware != NULL);
+
+ const int mem_size = cur_hardware->GetMemory().GetSize();
+
+ // If we are still in range, stop here!
+ if (position >= 0 && position < mem_size) return;
+
+ // If the memory is gone, just stick it at the begining of its parent.
+ if (mem_size == 0) {
+ cur_hardware = main_hardware;
+ position = 0;
+ }
+ else if (position <= 0) { position = 0; }
+ else if (position >= mem_size) {
+ // Always loop into the begining of the owner hardware.
+ cur_hardware = main_hardware;
+ position -= mem_size;
+ while (position >= GetMemory().GetSize()) {
+ // position back at the begining of the creature.
+ position %= GetMemory().GetSize();
+ }
+ }
+
+}
+
+
+
+/////////////////////////////////////////////////////////////////////////
+// Method: cHeadCPU::FindLabel(direction)
+//
+// Search in 'direction' (+ or - 1) from this head for the compliment of
+// the label in 'next_label' and return a head to the resulting pos.
+//
+/////////////////////////////////////////////////////////////////////////
+
+cHeadCPU cHeadCPU::FindLabel(const cCodeLabel & label, int direction)
+{
+ // Make sure the label is of size > 0.
+ if (label.GetSize() == 0) {
+ return *this;
+ }
+
+ int found_pos = -1;
+
+ // Call special functions depending on if jump is forwards or backwards.
+ if( direction < 0 ) {
+ found_pos =
+ FindLabel_Backward(label, GetMemory(), GetPosition() - label.GetSize());
+ }
+
+ // Jump forwards.
+ else {
+ found_pos = FindLabel_Forward(label, GetMemory(), GetPosition());
+ }
+
+ if (found_pos >= 0) {
+ // Return the last line of the found label, or the starting point.
+ cHeadCPU search_head(*this);
+ search_head.Set(found_pos - 1);
+ return search_head;
+ }
+
+ // It wasn't found; return the starting position of the instruction pointer.
+ return *this;
+}
+
+void cHeadCPU::Reset(cHardwareBase * new_hardware) {
+ if (new_hardware) main_hardware = new_hardware;
+ cur_hardware = new_hardware;
+ position = 0;
+}
+
+void cHeadCPU::Set(int new_pos, cHardwareBase * in_hardware)
+{
+ position = new_pos;
+ if (in_hardware) cur_hardware = in_hardware;
+ Adjust();
+}
+
+
+void cHeadCPU::Jump(int jump)
+{
+ position += jump;
+ Adjust();
+}
+
+void cHeadCPU::LoopJump(int jump)
+{
+ position += jump;
+
+ // If we are out of range, bring back in.
+ if (position < 0 || position >= GetMemory().GetSize()) {
+ position %= GetMemory().GetSize();
+ if (position <= 0) position += GetMemory().GetSize();
+ }
+}
+
+void cHeadCPU::AbsJump(int jump)
+{
+ position += jump;
+}
+
+void cHeadCPU::Advance()
+{
+ position++;
+ Adjust();
+}
+
+void cHeadCPU::Retreat()
+{
+ position--;
+ Adjust();
+}
+
+
+const cCPUMemory & cHeadCPU::GetMemory() const
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory();
+}
+
+
+const cInstruction & cHeadCPU::GetInst() const
+{
+ assert(position >= 0);
+ assert(position < GetMemory().GetSize());
+ return GetMemory()[position];
+}
+
+const cInstruction & cHeadCPU::GetInst(int offset) const {
+ int new_pos = position + offset;
+
+ return GetMemory()[new_pos];
+}
+
+
+void cHeadCPU::SetInst(const cInstruction & value)
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) cur_hardware->GetMemory()[position] = value;
+#else
+ cur_hardware->GetMemory()[position] = value;
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+
+void cHeadCPU::InsertInst(const cInstruction & value)
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) cur_hardware->GetMemory().Insert(position, value);
+#else
+ cur_hardware->GetMemory().Insert(position, value);
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+void cHeadCPU::RemoveInst()
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) cur_hardware->GetMemory().Remove(position);
+#else
+ cur_hardware->GetMemory().Remove(position);
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+const cInstruction & cHeadCPU::GetNextInst()
+{
+ return (AtEnd()) ? cInstSet::GetInstError() : GetMemory()[position+1];
+}
+
+
+
+bool & cHeadCPU::FlagCopied()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagCopied(position);
+}
+
+bool & cHeadCPU::FlagMutated()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagMutated(position);
+}
+
+bool & cHeadCPU::FlagExecuted()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagExecuted(position);
+}
+
+bool & cHeadCPU::FlagBreakpoint()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagBreakpoint(position);
+}
+
+bool & cHeadCPU::FlagPointMut()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagPointMut(position);
+}
+
+bool & cHeadCPU::FlagCopyMut()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory().FlagCopyMut(position);
+}
+
+cHeadCPU & cHeadCPU::operator=(const cHeadCPU & in_cpu_head)
+{
+ main_hardware = in_cpu_head.main_hardware;
+ cur_hardware = in_cpu_head.cur_hardware;
+ position = in_cpu_head.position;
+ return *this;
+}
+
+
+cHeadCPU & cHeadCPU::operator++()
+{
+ position++;
+ Adjust();
+ return *this;
+}
+
+cHeadCPU & cHeadCPU::operator--()
+{
+ position--;
+ Adjust();
+ return *this;
+}
+
+cHeadCPU & cHeadCPU::operator++(int)
+{
+ return operator++();
+}
+
+cHeadCPU & cHeadCPU::operator--(int)
+{
+ return operator--();
+}
+
+
+// Search forwards for search_label from _after_ position pos in the
+// memory. Return the first line _after_ the the found label. It is okay
+// to find search label's match inside another label.
+
+int cHeadCPU::FindLabel_Forward(const cCodeLabel & search_label,
+ const cGenome & search_mem, int pos)
+{
+ assert (pos < search_mem.GetSize() && pos >= 0);
+
+ int search_start = pos;
+ int label_size = search_label.GetSize();
+ bool found_label = false;
+ const cInstSet & inst_set = main_hardware->GetInstSet();
+
+ // Move off the template we are on.
+ pos += label_size;
+
+ // Search until we find the complement or exit the memory.
+ while (pos < search_mem.GetSize()) {
+
+ // If we are within a label, rewind to the beginning of it and see if
+ // it has the proper sub-label that we're looking for.
+
+ if (inst_set.IsNop(search_mem[pos])) {
+ // Find the start and end of the label we're in the middle of.
+
+ int start_pos = pos;
+ int end_pos = pos + 1;
+ while (start_pos > search_start &&
+ inst_set.IsNop( search_mem[start_pos - 1] )) {
+ start_pos--;
+ }
+ while (end_pos < search_mem.GetSize() &&
+ inst_set.IsNop( search_mem[end_pos] )) {
+ end_pos++;
+ }
+ int test_size = end_pos - start_pos;
+
+ // See if this label has the proper sub-label within it.
+ int max_offset = test_size - label_size + 1;
+ for (int offset = start_pos; offset < start_pos + max_offset; offset++) {
+
+ // Test the number of matches for this offset.
+ int matches;
+ for (matches = 0; matches < label_size; matches++) {
+ if (search_label[matches] !=
+ inst_set.GetNopMod( search_mem[offset + matches] )) {
+ break;
+ }
+ }
+
+ // If we have found it, break out of this loop!
+ if (matches == label_size) {
+ found_label = true;
+ break;
+ }
+ }
+
+ // If we've found the complement label, set the position to the end of
+ // the label we found it in, and break out.
+
+ if (found_label == true) {
+ pos = end_pos;
+ break;
+ }
+
+ // We haven't found it; jump pos to just after the current label being
+ // checked.
+ pos = end_pos;
+ }
+
+ // Jump up a block to the next possible point to find a label,
+ pos += label_size;
+ }
+
+ // If the label was not found return a -1.
+ if (found_label == false) pos = -1;
+
+ return pos;
+}
+
+// Search backwards for search_label from _before_ position pos in the
+// memory. Return the first line _after_ the the found label. It is okay
+// to find search label's match inside another label.
+
+int cHeadCPU::FindLabel_Backward(const cCodeLabel & search_label,
+ const cGenome & search_mem, int pos)
+{
+ assert (pos < search_mem.GetSize());
+
+ int search_start = pos;
+ int label_size = search_label.GetSize();
+ bool found_label = false;
+ const cInstSet & inst_set = main_hardware->GetInstSet();
+
+ // Move off the template we are on.
+ pos -= label_size;
+
+ // Search until we find the complement or exit the memory.
+ while (pos >= 0) {
+ // If we are within a label, rewind to the beginning of it and see if
+ // it has the proper sub-label that we're looking for.
+
+ if (inst_set.IsNop( search_mem[pos] )) {
+ // Find the start and end of the label we're in the middle of.
+
+ int start_pos = pos;
+ int end_pos = pos + 1;
+ while (start_pos > 0 && inst_set.IsNop(search_mem[start_pos - 1])) {
+ start_pos--;
+ }
+ while (end_pos < search_start &&
+ inst_set.IsNop( search_mem[end_pos] )) {
+ end_pos++;
+ }
+ int test_size = end_pos - start_pos;
+
+ // See if this label has the proper sub-label within it.
+ int max_offset = test_size - label_size + 1;
+ for (int offset = start_pos; offset < start_pos + max_offset; offset++) {
+
+ // Test the number of matches for this offset.
+ int matches;
+ for (matches = 0; matches < label_size; matches++) {
+ if (search_label[matches] !=
+ inst_set.GetNopMod( search_mem[offset + matches] )) {
+ break;
+ }
+ }
+
+ // If we have found it, break out of this loop!
+ if (matches == label_size) {
+ found_label = true;
+ break;
+ }
+ }
+
+ // If we've found the complement label, set the position to the end of
+ // the label we found it in, and break out.
+
+ if (found_label == true) {
+ pos = end_pos;
+ break;
+ }
+
+ // We haven't found it; jump pos to just before the current label
+ // being checked.
+ pos = start_pos - 1;
+ }
+
+ // Jump up a block to the next possible point to find a label,
+ pos -= label_size;
+ }
+
+ // If the label was not found return a -1.
+ if (found_label == false) pos = -1;
+
+ return pos;
+}
+
+bool cHeadCPU::operator==(const cHeadCPU & in_cpu_head) const {
+ return (cur_hardware == in_cpu_head.cur_hardware) &&
+ (position == in_cpu_head.position);
+}
+
+bool cHeadCPU::AtEnd() const
+{
+ return (position + 1 == GetMemory().GetSize());
+}
+
+bool cHeadCPU::InMemory() const
+{
+ return (position >= 0 && position < GetMemory().GetSize());
+}
+
+int cHeadCPU::TestParasite() const
+{
+ // If CPU has a head in another creature, mark it as a parasite.
+ return (cur_hardware != main_hardware);
+}
Copied: branches/brysonda/source/cpu/head_cpu.hh (from rev 177, branches/brysonda/source/cpu/cpu_head.hh)
===================================================================
--- branches/brysonda/source/cpu/cpu_head.hh 2005-06-04 19:16:19 UTC (rev 177)
+++ branches/brysonda/source/cpu/head_cpu.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -0,0 +1,121 @@
+/////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology //
+// //
+// Read the COPYING and README files, or contact 'avida at alife.org', //
+// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef HEAD_CPU_HH
+#define HEAD_CPU_HH
+
+#ifndef DEFS_HH
+#include "defs.hh"
+#endif
+
+class cHardwareBase;
+class cCodeLabel;
+class cGenome;
+class cCPUMemory;
+
+/**
+ * The cHeadCPU class contains a pointer to locations in memory for a CPU.
+ **/
+
+class cHardwareBase;
+class cCodeLabel;
+class cGenome;
+class cInstruction;
+
+class cHeadCPU {
+protected:
+ cHardwareBase * main_hardware;
+ cHardwareBase * cur_hardware;
+ int position;
+
+ int FindLabel_Forward(const cCodeLabel & search_label,
+ const cGenome & search_mem, int pos);
+ int FindLabel_Backward(const cCodeLabel & search_label,
+ const cGenome & search_mem, int pos);
+public:
+ cHeadCPU();
+ cHeadCPU(cHardwareBase * in_hardware, int in_pos = 0);
+ cHeadCPU(const cHeadCPU & in_cpu_head);
+ virtual ~cHeadCPU() { ; }
+
+ /**
+ * This function keeps the position within the range of the current memory.
+ **/
+ virtual void Adjust();
+
+ virtual void Reset(cHardwareBase * new_hardware = NULL);
+
+ /**
+ * Set the new position of the head (and adjust it into range in Set()).
+ **/
+
+ virtual void Set(int new_pos, cHardwareBase * in_hardware = NULL);
+
+ void AbsSet(int new_pos) { position = new_pos; }
+
+ virtual void Set(const cHeadCPU & in_head) {
+ position = in_head.position;
+ cur_hardware = in_head.cur_hardware;
+ }
+
+ /**
+ * Increment the new position of the head by 'jump'.
+ **/
+
+ void Jump(int jump);
+ virtual void LoopJump(int jump);
+ void AbsJump(int jump);
+
+ // Other manipulation functions.
+ void Advance();
+ void Retreat();
+ cHeadCPU FindLabel(const cCodeLabel & label, int direction=1);
+
+ // Accessors.
+ int GetPosition() const { return position; }
+ virtual const cCPUMemory & GetMemory() const;
+ cHardwareBase * GetCurHardware() const { return cur_hardware; }
+ cHardwareBase * GetMainHardware() const { return main_hardware; }
+ virtual const cInstruction & GetInst() const;
+ virtual const cInstruction & GetInst(int offset) const;
+ // int GetFlag(int id) const;
+
+ virtual void SetInst(const cInstruction & value);
+ virtual void InsertInst(const cInstruction & in_char);
+ virtual void RemoveInst();
+ virtual const cInstruction & GetNextInst();
+
+ virtual bool & FlagCopied();
+ virtual bool & FlagMutated();
+ virtual bool & FlagExecuted();
+ virtual bool & FlagBreakpoint();
+ virtual bool & FlagPointMut();
+ virtual bool & FlagCopyMut();
+
+ // Operator Overloading...
+ virtual cHeadCPU & operator=(const cHeadCPU & in_cpu_head);
+ cHeadCPU & operator++();
+ cHeadCPU & operator--();
+ cHeadCPU & operator++(int);
+ cHeadCPU & operator--(int);
+
+ inline int operator-(const cHeadCPU & in_cpu_head) {
+ if (cur_hardware != in_cpu_head.cur_hardware) return 0;
+ else return position - in_cpu_head.position;
+ }
+ virtual bool operator==(const cHeadCPU & in_cpu_head) const;
+
+ // Bool Tests...
+ inline bool AtFront() const { return (position == 0); }
+ virtual bool AtEnd() const;
+ virtual bool InMemory() const;
+
+ // Test functions...
+ int TestParasite() const;
+};
+
+#endif
Copied: branches/brysonda/source/cpu/head_multi_mem.cc (from rev 177, branches/brysonda/source/cpu/4stack_head.cc)
===================================================================
--- branches/brysonda/source/cpu/4stack_head.cc 2005-06-04 19:16:19 UTC (rev 177)
+++ branches/brysonda/source/cpu/head_multi_mem.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -0,0 +1,224 @@
+/////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology //
+// //
+// Read the COPYING and README files, or contact 'avida at alife.org', //
+// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
+#endif
+
+#ifndef CPU_MEMORY_HH
+#include "cpu_memory.hh"
+#endif
+#ifndef HARDWARE_BASE_HH
+#include "hardware_base.hh"
+#endif
+#ifndef INST_SET_HH
+#include "inst_set.hh"
+#endif
+#ifndef INSTRUCTION_HH
+#include "instruction.hh"
+#endif
+
+#include <assert.h>
+
+cHeadMultiMem::cHeadMultiMem() : cHeadCPU() { mem_space=0; }
+
+cHeadMultiMem::cHeadMultiMem(cHardwareBase * in_hardware, int in_pos, int in_mem_space)
+ : cHeadCPU(in_hardware, in_pos) { mem_space = in_mem_space; }
+
+cHeadMultiMem::cHeadMultiMem(const cHeadMultiMem & in_head) : cHeadCPU(in_head)
+{
+ mem_space = in_head.mem_space;
+}
+
+void cHeadMultiMem::Adjust()
+{
+ assert(cur_hardware != NULL);
+ assert(main_hardware != NULL);
+
+ const int mem_size = GetMemory().GetSize();
+
+ // If we are still in range, stop here!
+ if (position >= 0 && position < mem_size) return;
+
+ // If the memory is gone, just stick it at the begining of its parent.
+ if (mem_size == 0) {
+ cur_hardware = main_hardware;
+ position = 0;
+ }
+ else if (position <= 0) { position = 0; }
+ else if (position >= mem_size) {
+ // Always loop into the begining of the owner hardware.
+ cur_hardware = main_hardware;
+ position -= mem_size;
+ while (position >= GetMemory().GetSize()) {
+ // position back at the begining of the creature.
+ position %= GetMemory().GetSize();
+ }
+ }
+}
+
+void cHeadMultiMem::Reset(int in_mem_space, cHardwareBase * new_hardware)
+{
+ if (new_hardware) main_hardware = new_hardware;
+ cur_hardware = new_hardware;
+ position = 0;
+ mem_space = in_mem_space;
+}
+
+void cHeadMultiMem::Set(int new_pos, int in_mem_space, cHardwareBase * in_hardware)
+{
+ position = new_pos;
+ if (in_hardware) cur_hardware = in_hardware;
+ mem_space = in_mem_space;
+ Adjust();
+}
+
+void cHeadMultiMem::Set(const cHeadMultiMem & in_head)
+{
+ position = in_head.position;
+ cur_hardware = in_head.cur_hardware;
+ mem_space = in_head.mem_space;
+ Adjust();
+}
+
+void cHeadMultiMem::LoopJump(int jump)
+{
+ position += jump;
+
+ // If we are out of range, bring back in.
+ if (position < 0 || position >= GetMemory().GetSize()) {
+ position %= GetMemory().GetSize();
+ if (position <= 0) position += GetMemory().GetSize();
+ }
+}
+
+const cCPUMemory & cHeadMultiMem::GetMemory() const
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory(mem_space);
+}
+
+cCPUMemory & cHeadMultiMem::GetMemory()
+{
+ assert(cur_hardware != NULL);
+ return cur_hardware->GetMemory(mem_space);
+}
+
+const cInstruction & cHeadMultiMem::GetInst() const
+{
+ assert(position >= 0);
+ assert(position < GetMemory().GetSize());
+ return GetMemory()[position];
+}
+
+const cInstruction & cHeadMultiMem::GetInst(int offset) const
+{
+ int new_pos = position + offset;
+ return GetMemory()[new_pos];
+}
+
+
+void cHeadMultiMem::SetInst(const cInstruction & value)
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) GetMemory()[position] = value;
+#else
+ GetMemory()[position] = value;
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+void cHeadMultiMem::InsertInst(const cInstruction & value)
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) GetMemory().Insert(position, value);
+#else
+ GetMemory().Insert(position, value);
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+void cHeadMultiMem::RemoveInst()
+{
+ assert(cur_hardware != NULL);
+#ifdef WRITE_PROTECTION
+ if (main_hardware == cur_hardware) GetMemory().Remove(position);
+#else
+ GetMemory().Remove(position);
+ if (main_hardware != cur_hardware) cur_hardware->SetModified();
+#endif
+}
+
+const cInstruction & cHeadMultiMem::GetNextInst()
+{
+ return (AtEnd()) ? cInstSet::GetInstError() : GetMemory()[position+1];
+}
+
+bool & cHeadMultiMem::FlagCopied()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagCopied(position);
+}
+
+bool & cHeadMultiMem::FlagMutated()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagMutated(position);
+}
+
+bool & cHeadMultiMem::FlagExecuted()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagExecuted(position);
+}
+
+bool & cHeadMultiMem::FlagBreakpoint()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagBreakpoint(position);
+}
+
+bool & cHeadMultiMem::FlagPointMut()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagPointMut(position);
+}
+
+bool & cHeadMultiMem::FlagCopyMut()
+{
+ assert(cur_hardware != NULL);
+ return GetMemory().FlagCopyMut(position);
+}
+
+cHeadMultiMem & cHeadMultiMem::operator=(const cHeadMultiMem & in_cpu_head)
+{
+ main_hardware = in_cpu_head.main_hardware;
+ cur_hardware = in_cpu_head.cur_hardware;
+ position = in_cpu_head.position;
+ mem_space = in_cpu_head.mem_space;
+ return *this;
+}
+
+bool cHeadMultiMem::operator==(const cHeadMultiMem & in_cpu_head) const
+{
+ return (cur_hardware == in_cpu_head.cur_hardware) &&
+ (position == in_cpu_head.position) &&
+ (mem_space == in_cpu_head.mem_space);
+}
+
+bool cHeadMultiMem::AtEnd() const
+{
+ return (position + 1 == GetMemory().GetSize());
+}
+
+bool cHeadMultiMem::InMemory() const
+{
+ return (position >= 0 && position < GetMemory().GetSize());
+}
+
Copied: branches/brysonda/source/cpu/head_multi_mem.hh (from rev 177, branches/brysonda/source/cpu/4stack_head.hh)
===================================================================
--- branches/brysonda/source/cpu/4stack_head.hh 2005-06-04 19:16:19 UTC (rev 177)
+++ branches/brysonda/source/cpu/head_multi_mem.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -0,0 +1,65 @@
+/////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology //
+// //
+// Read the COPYING and README files, or contact 'avida at alife.org', //
+// before continuing. SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE. //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef HEAD_MULTI_MEM_HH
+#define HEAD_MULTI_MEM_HH
+
+#ifndef HEAD_CPU_HH
+#include "head_cpu.hh"
+#endif
+#ifndef DEFS_HH
+#include "defs.hh"
+#endif
+
+class cCodeLabel;
+class cCPUMemory;
+class cGenome;
+class cHardwareBase;
+class cInstruction;
+
+class cHeadMultiMem : public cHeadCPU {
+private:
+ int mem_space;
+
+public:
+
+ cHeadMultiMem();
+ cHeadMultiMem(cHardwareBase * in_hardware, int in_pos = 0, int mem_space = 0);
+ cHeadMultiMem(const cHeadMultiMem & in_cpu_head);
+
+ void Adjust();
+ void Reset(int in_mem_space=0, cHardwareBase * new_hardware = NULL);
+ void Set(int new_pos, int in_mem_space = 0, cHardwareBase * in_hardware = NULL);
+ void Set(const cHeadMultiMem & in_head);
+ void LoopJump(int jump);
+ const cCPUMemory & GetMemory() const;
+ cCPUMemory & GetMemory();
+ const cInstruction & GetInst() const;
+ const cInstruction & GetInst(int offset) const;
+
+ int GetMemSpace() const { return mem_space; }
+
+ void SetInst(const cInstruction & value);
+ void InsertInst(const cInstruction & in_char);
+ void RemoveInst();
+ const cInstruction & GetNextInst();
+
+ bool & FlagCopied();
+ bool & FlagMutated();
+ bool & FlagExecuted();
+ bool & FlagBreakpoint();
+ bool & FlagPointMut();
+ bool & FlagCopyMut();
+
+ // Operator Overloading...
+ cHeadMultiMem & operator=(const cHeadMultiMem & in_cpu_head);
+ bool operator==(const cHeadMultiMem & in_cpu_head) const;
+ bool AtEnd() const;
+ bool InMemory() const;
+};
+
+#endif
Modified: branches/brysonda/source/cpu/tInstLib.h
===================================================================
--- branches/brysonda/source/cpu/tInstLib.h 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/cpu/tInstLib.h 2005-06-06 14:59:29 UTC (rev 179)
@@ -7,6 +7,9 @@
*
*/
+#ifndef TINSTLIB_H
+#define TINSTLIB_H
+
#ifndef STRING_HH
#include "string.hh"
#endif
@@ -23,22 +26,26 @@
cString *m_function_names;
const int *m_nopmods;
MethodType *m_functions;
- static const cInstruction inst_error;
- static const cInstruction inst_default;
+ const cInstruction inst_error;
+ const cInstruction inst_default;
public:
tInstLib(
- size_t nopmod_array_size,
- size_t function_array_size,
- cString *nopmod_names,
- cString *function_names,
- const int *nopmods,
- MethodType *functions
- ):m_nopmods_array_size(nopmod_array_size),
+ size_t nopmod_array_size,
+ size_t function_array_size,
+ cString *nopmod_names,
+ cString *function_names,
+ const int *nopmods,
+ MethodType *functions,
+ const cInstruction& error,
+ const cInstruction& def
+ ):m_nopmods_array_size(nopmod_array_size),
m_function_array_size(function_array_size),
m_nopmod_names(nopmod_names),
m_function_names(function_names),
m_nopmods(nopmods),
- m_functions(functions)
+ m_functions(functions),
+ inst_error(error),
+ inst_default(def)
{}
MethodType *GetFunctions(void){ return m_functions; }
const cString &GetName(const unsigned int id) {
@@ -68,3 +75,4 @@
const cInstruction & GetInstError(){ return inst_error; }
};
+#endif
\ No newline at end of file
Modified: branches/brysonda/source/defs.hh
===================================================================
--- branches/brysonda/source/defs.hh 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/defs.hh 2005-06-06 14:59:29 UTC (rev 179)
@@ -179,29 +179,11 @@
#define FILE_TYPE_TEXT 0
#define FILE_TYPE_HTML 1
-#define HARDWARE_TYPE_CPU_ORIGINAL 0
-#define HARDWARE_TYPE_CPU_4STACK 1
+enum tHARDWARE_TYPE
+{
+ HARDWARE_TYPE_CPU_ORIGINAL = 0,
+ HARDWARE_TYPE_CPU_4STACK,
+ HARDWARE_TYPE_CPU_SMT
+};
-
-
-#define TASK_GET 0
-#define TASK_PUT 1
-#define TASK_GGP 2
-
-#define TASK_ECHO 0
-#define TASK_NAND 1
-#define TASK_NOT 2
-
-#define TASK_AND 3
-#define TASK_ORN 4
-
-#define TASK_ANDN 5
-#define TASK_OR 6
-
-#define TASK_NOR 7
-#define TASK_XOR 8
-#define TASK_EQU 9
-
-#define NUM_TASKS 10
-
#endif
Modified: branches/brysonda/source/main/avida.cc
===================================================================
--- branches/brysonda/source/main/avida.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/main/avida.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -65,16 +65,7 @@
cPopulationInterface &test_interface )
{
// Build the instruction set.
- if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_ORIGINAL) {
- environment.GetInstSet().SetInstLib(cHardwareCPU::GetInstLib());
- cHardwareUtil::LoadInstSet_CPUOriginal(cConfig::GetInstFilename(),
- environment.GetInstSet());
- }
- else if (cConfig::GetHardwareType() == HARDWARE_TYPE_CPU_4STACK) {
- environment.GetInstSet().SetInstLib(cHardware4Stack::GetInstLib());
- cHardwareUtil::LoadInstSet_CPU4Stack(cConfig::GetInstFilename(),
- environment.GetInstSet());
- }
+ cHardwareUtil::LoadInstSet(cConfig::GetInstFilename(), environment.GetInstSet());
// Initialize the default environment...
if (environment.Load(cConfig::GetEnvironmentFilename()) == false) {
Modified: branches/brysonda/source/testsuites/unit_testsuites/4stack_head.t.cc
===================================================================
--- branches/brysonda/source/testsuites/unit_testsuites/4stack_head.t.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/testsuites/unit_testsuites/4stack_head.t.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,7 +1,7 @@
#include <iostream>
-#ifndef FOURSTACK_HEAD_HH
-#include "4stack_head.hh"
+#ifndef HEAD_MULTI_MEM_HH
+#include "head_multi_mem.hh"
#endif
#ifndef TEST_CASE_H
#include "third-party/yaktest/cTestCase.hh"
Modified: branches/brysonda/source/testsuites/unit_testsuites/cpu_head.t.cc
===================================================================
--- branches/brysonda/source/testsuites/unit_testsuites/cpu_head.t.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/testsuites/unit_testsuites/cpu_head.t.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -1,7 +1,7 @@
#include <iostream>
-#ifndef CPU_HEAD_HH
-#include "cpu_head.hh"
+#ifndef HEAD_CPU_HH
+#include "head_cpu.hh"
#endif
#ifndef TEST_CASE_H
#include "third-party/yaktest/cTestCase.hh"
Modified: branches/brysonda/source/viewers/zoom_screen.cc
===================================================================
--- branches/brysonda/source/viewers/zoom_screen.cc 2005-06-05 19:57:08 UTC (rev 178)
+++ branches/brysonda/source/viewers/zoom_screen.cc 2005-06-06 14:59:29 UTC (rev 179)
@@ -574,7 +574,7 @@
Print(14, 34, "%14d", hardwareCPU.Register(2));
Print(15, 34, "%14d", hardwareCPU.GetStack(0));
- cCPUHead inst_ptr(hardwareCPU.IP());
+ cHeadCPU inst_ptr(hardwareCPU.IP());
const cInstSet & inst_set = hardwareCPU.GetInstSet();
for (int pos = 0; pos < 3; pos++) {
@@ -594,7 +594,7 @@
Print(CPU_FLAGS_Y + 1, CPU_FLAGS_X + 1, "Mem Allocated");
// And print the IP.
- const cCPUHead & active_inst_ptr = hardwareCPU.IP();
+ const cHeadCPU & active_inst_ptr = hardwareCPU.IP();
// @CAO assume no parasites for now.
int cur_id = info.GetActiveCell()->GetID();
//active_inst_ptr.GetCurHardware()->GetOrganism()->GetEnvironment()->GetID();
@@ -615,7 +615,7 @@
Print(14, 34, "%14d", hardware4Stack.Stack(2).Top());
Print(15, 34, "%14d", hardware4Stack.Stack(3).Top());
- c4StackHead inst_ptr(hardware4Stack.IP());
+ cHeadMultiMem inst_ptr(hardware4Stack.IP());
const cInstSet & inst_set = hardware4Stack.GetInstSet();
for (int pos = 0; pos < 3; pos++) {
@@ -635,7 +635,7 @@
//Print(CPU_FLAGS_Y + 1, CPU_FLAGS_X + 1, "Mem Allocated");
// And print the IP.
- const c4StackHead & active_inst_ptr = hardware4Stack.IP();
+ const cHeadMultiMem & active_inst_ptr = hardware4Stack.IP();
// @CAO assume no parasites for now.
//int cur_id = info.GetActiveCell()->GetID();
//active_inst_ptr.GetCurHardware()->GetOrganism()->GetEnvironment()->GetID();
@@ -848,7 +848,7 @@
cur_mem_space = hardware4Stack.IP(cur_view_thread).GetMemSpace();
}
//hardware4Stack.SetThread(cur_view_thread);
- c4StackHead & cur_ip = hardware4Stack.IP(cur_view_thread);
+ cHeadMultiMem & cur_ip = hardware4Stack.IP(cur_view_thread);
// Place the stacks onto the screen.
SetBoldColor(COLOR_CYAN);
@@ -1056,7 +1056,7 @@
cHardwareCPU & hardware =
(cHardwareCPU &) info.GetActiveCell()->GetOrganism()->GetHardware();
const cInstSet & inst_set = hardware.GetInstSet();
- cCPUHead edit_head( hardware.IP() );
+ cHeadCPU edit_head( hardware.IP() );
if (parasite_zoom == true) {
edit_head.Set(0, &(info.GetActiveCell()->GetOrganism()->GetHardware()) );
}
@@ -1125,7 +1125,7 @@
cHardwareCPU & hardware =
(cHardwareCPU &) info.GetActiveCell()->GetOrganism()->GetHardware();
// cosnt cInstSet & inst_set = hardware.GetInstSet();
- cCPUHead view_head( hardware.IP() );
+ cHeadCPU view_head( hardware.IP() );
if (parasite_zoom == true) {
view_head.Set(0, &(info.GetActiveCell()->GetOrganism()->GetHardware()) );
}
@@ -1182,7 +1182,7 @@
cHardwareCPU & hardware =
(cHardwareCPU &) info.GetActiveCell()->GetOrganism()->GetHardware();
- cCPUHead inst_ptr( hardware.IP() );
+ cHeadCPU inst_ptr( hardware.IP() );
if (parasite_zoom == true) {
inst_ptr.Set(0, &(info.GetActiveCell()->GetOrganism()->GetHardware()) );
}
More information about the Avida-cvs
mailing list