Empirical
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT > Struct Template Reference

#include <AvidaCPU_InstLib.h>

Inheritance diagram for emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >:
emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >

Public Types

using hardware_t = HARDWARE_T
 
using arg_t = ARG_T
 
using this_t = AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >
 
using inst_t = typename hardware_t::inst_t
 
using genome_t = emp::vector< inst_t >
 
using fun_t = std::function< void(hardware_t &, const inst_t &)>
 
using inst_properties_t = std::unordered_set< std::string >
 

Public Member Functions

const std::string & GetName (size_t id) const
 Return the name associated with the specified instruction ID. More...
 
const fun_tGetFunction (size_t id) const
 Return the function associated with the specified instruction ID. More...
 
size_t GetNumArgs (size_t id) const
 Return the number of arguments expected for the specified instruction ID. More...
 
const std::string & GetDesc (size_t id) const
 Return the provided description for the provided instruction ID. More...
 
ScopeType GetScopeType (size_t id) const
 What type of scope does this instruction state? ScopeType::NONE is default. More...
 
size_t GetScopeArg (size_t id) const
 If this instruction alters scope, identify which argument does so. More...
 
const inst_properties_tGetProperties (size_t id) const
 Return the set of properties for the provided instruction ID. More...
 
bool HasProperty (size_t id, std::string property) const
 Does the given instruction ID have the given property value? More...
 
size_t GetSize () const
 Get the number of instructions in this set. More...
 
bool IsInst (const std::string name) const
 
size_t GetID (const std::string &name) const
 Return the ID of the instruction that has the specified name. More...
 
arg_t GetArg (const std::string &name)
 Return the argument value associated with the provided keyword. More...
 
void AddInst (const std::string &name, const fun_t &fun_call, size_t num_args=0, const std::string &desc="", ScopeType scope_type=ScopeType::NONE, size_t scope_arg=(size_t)-1, const inst_properties_t &inst_properties=inst_properties_t())
 Add a new instruction to the set. More...
 
void AddArg (const std::string &name, arg_t value)
 Specify a keyword and arg value. More...
 
void ProcessInst (hardware_t &hw, const inst_t &inst) const
 Process a specified instruction in the provided hardware. More...
 
template<typename IN_HW >
void ProcessInst (emp::Ptr< IN_HW > hw, const inst_t &inst) const
 Process a specified instruction on hardware that can be converted to the correct type. More...
 
void WriteGenome (const genome_t &genome, std::ostream &os=std::cout) const
 Write out a full genome to the provided ostream. More...
 
void ReadInst (genome_t &genome, std::string info) const
 Read the instruction in the provided info and append it to the provided genome. More...
 

Static Public Member Functions

static void Inst_Inc (hardware_t &hw, const inst_t &inst)
 
static void Inst_Dec (hardware_t &hw, const inst_t &inst)
 
static void Inst_Not (hardware_t &hw, const inst_t &inst)
 
static void Inst_SetReg (hardware_t &hw, const inst_t &inst)
 
static void Inst_Add (hardware_t &hw, const inst_t &inst)
 
static void Inst_Sub (hardware_t &hw, const inst_t &inst)
 
static void Inst_Mult (hardware_t &hw, const inst_t &inst)
 
static void Inst_Div (hardware_t &hw, const inst_t &inst)
 
static void Inst_Mod (hardware_t &hw, const inst_t &inst)
 
static void Inst_TestEqu (hardware_t &hw, const inst_t &inst)
 
static void Inst_TestNEqu (hardware_t &hw, const inst_t &inst)
 
static void Inst_TestLess (hardware_t &hw, const inst_t &inst)
 
static void Inst_If (hardware_t &hw, const inst_t &inst)
 
static void Inst_While (hardware_t &hw, const inst_t &inst)
 
static void Inst_Countdown (hardware_t &hw, const inst_t &inst)
 
static void Inst_Break (hardware_t &hw, const inst_t &inst)
 
static void Inst_Scope (hardware_t &hw, const inst_t &inst)
 
static void Inst_Define (hardware_t &hw, const inst_t &inst)
 
static void Inst_Call (hardware_t &hw, const inst_t &inst)
 
static void Inst_Push (hardware_t &hw, const inst_t &inst)
 
static void Inst_Pop (hardware_t &hw, const inst_t &inst)
 
static void Inst_Input (hardware_t &hw, const inst_t &inst)
 
static void Inst_Output (hardware_t &hw, const inst_t &inst)
 
static void Inst_CopyVal (hardware_t &hw, const inst_t &inst)
 
static void Inst_ScopeReg (hardware_t &hw, const inst_t &inst)
 
static const this_tDefaultInstLib ()
 
static constexpr char GetSymbol (size_t id)
 Retrieve a unique letter associared with the specified instruction ID. More...
 
static constexpr size_t GetID (char symbol)
 Return the ID of the instruction associated with the specified symbol. More...
 

Static Public Attributes

static constexpr size_t arg_count = ARG_COUNT
 

Protected Attributes

emp::vector< InstDefinst_lib
 Full definitions for instructions. More...
 
emp::vector< fun_tinst_funs
 Map of instruction IDs to their functions. More...
 
std::map< std::string, size_t > name_map
 How do names link to instructions? More...
 
std::map< std::string, arg_targ_map
 How are different arguments named? More...
 

Detailed Description

template<typename HARDWARE_T, typename ARG_T = size_t, size_t ARG_COUNT = 3>
struct emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >

AvidaCPU_InstLib is a pure-virtual class that defines a series of instructions that can be used with AvidaCPU_Base or any of its derived classes.

Member Typedef Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::arg_t = ARG_T
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::fun_t = std::function<void(hardware_t &, const inst_t &)>
inherited
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::genome_t = emp::vector<inst_t>
inherited
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::hardware_t = HARDWARE_T
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_properties_t = std::unordered_set<std::string>
inherited
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_t = typename hardware_t::inst_t
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
using emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::this_t = AvidaCPU_InstLib<HARDWARE_T, ARG_T, ARG_COUNT>

Member Function Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::AddArg ( const std::string &  name,
arg_t  value 
)
inlineinherited

Specify a keyword and arg value.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::AddInst ( const std::string &  name,
const fun_t fun_call,
size_t  num_args = 0,
const std::string &  desc = "",
ScopeType  scope_type = ScopeType::NONE,
size_t  scope_arg = (size_t) -1,
const inst_properties_t inst_properties = inst_properties_t() 
)
inlineinherited

Add a new instruction to the set.

Parameters
nameA unique string name for this instruction.
fun_callThe function that should be called when this instruction is executed.
num_argsHow many arguments does this function require? (default=0)
descA description of how this function operates. (default="")
scope_typeType of scope does this instruction creates. (default=ScopeType::NONE)
scope_argIf instruction changes scope, which argument specified new scope? (defualt=-1)
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static const this_t& emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::DefaultInstLib ( )
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
arg_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetArg ( const std::string &  name)
inlineinherited

Return the argument value associated with the provided keyword.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const std::string& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetDesc ( size_t  id) const
inlineinherited

Return the provided description for the provided instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const fun_t& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetFunction ( size_t  id) const
inlineinherited

Return the function associated with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetID ( const std::string &  name) const
inlineinherited

Return the ID of the instruction that has the specified name.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static constexpr size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetID ( char  symbol)
inlinestaticinherited

Return the ID of the instruction associated with the specified symbol.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const std::string& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetName ( size_t  id) const
inlineinherited

Return the name associated with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetNumArgs ( size_t  id) const
inlineinherited

Return the number of arguments expected for the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
const inst_properties_t& emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetProperties ( size_t  id) const
inlineinherited

Return the set of properties for the provided instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetScopeArg ( size_t  id) const
inlineinherited

If this instruction alters scope, identify which argument does so.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
ScopeType emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetScopeType ( size_t  id) const
inlineinherited

What type of scope does this instruction state? ScopeType::NONE is default.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
size_t emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetSize ( ) const
inlineinherited

Get the number of instructions in this set.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static constexpr char emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::GetSymbol ( size_t  id)
inlinestaticinherited

Retrieve a unique letter associared with the specified instruction ID.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
bool emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::HasProperty ( size_t  id,
std::string  property 
) const
inlineinherited

Does the given instruction ID have the given property value?

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Add ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Break ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Call ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_CopyVal ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Countdown ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Dec ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Define ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Div ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_If ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Inc ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Input ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Mod ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Mult ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Not ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Output ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Pop ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Push ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Scope ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_ScopeReg ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_SetReg ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_Sub ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_TestEqu ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_TestLess ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_TestNEqu ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
static void emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::Inst_While ( hardware_t hw,
const inst_t inst 
)
inlinestatic
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
bool emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::IsInst ( const std::string  name) const
inlineinherited
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ProcessInst ( hardware_t hw,
const inst_t inst 
) const
inlineinherited

Process a specified instruction in the provided hardware.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
template<typename IN_HW >
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ProcessInst ( emp::Ptr< IN_HW >  hw,
const inst_t inst 
) const
inlineinherited

Process a specified instruction on hardware that can be converted to the correct type.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::ReadInst ( genome_t genome,
std::string  info 
) const
inlineinherited

Read the instruction in the provided info and append it to the provided genome.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
void emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::WriteGenome ( const genome_t genome,
std::ostream &  os = std::cout 
) const
inlineinherited

Write out a full genome to the provided ostream.

Member Data Documentation

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
constexpr size_t emp::AvidaCPU_InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::arg_count = ARG_COUNT
static
template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
std::map<std::string, arg_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::arg_map
protectedinherited

How are different arguments named?

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::vector<fun_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_funs
protectedinherited

Map of instruction IDs to their functions.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
emp::vector<InstDef> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::inst_lib
protectedinherited

Full definitions for instructions.

template<typename HARDWARE_T , typename ARG_T = size_t, size_t ARG_COUNT = 3>
std::map<std::string, size_t> emp::InstLib< HARDWARE_T, ARG_T, ARG_COUNT >::name_map
protectedinherited

How do names link to instructions?


The documentation for this struct was generated from the following file: