home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / xplatfrm / tierra / tierra.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-26  |  11.5 KB  |  305 lines

  1. /* tierra.h 19-8-91 */
  2. /* type, structure and function definitions for the Tierra simulator */
  3. /** Tierra Simulator V3.0: Copyright (c) 1991 Thomas S. Ray **/
  4.  
  5. #include "license.h"
  6.  
  7. /*
  8. tierra_h_sccsid: @(#)tierra.h    2.9    10/6/91
  9. */
  10.  
  11. #ifndef LTIERRA_H
  12. #define LTIERRA_H 
  13.  
  14. #include <stdio.h>
  15. #include <math.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include "configur.h"
  19. #include "portable.h"
  20.  
  21. #define IsBit(seed, bit) (((seed) & (1 << (bit))) ? 1 : 0)
  22. #define ad(A) ((A) >=0 ? ((A)%SoupSize):((SoupSize-(-(A)%SoupSize))%SoupSize))
  23. #define mo(A,B) ((A) >=0 ? ((A)%(B)) : (((B)-(-(A)%(B)))%(B)))
  24.  
  25. #if INSTBITNUM == 5
  26.  
  27. #ifdef __TURBOC__
  28. struct Inst {
  29.     unsigned int  inst:5;
  30.     unsigned int  exec:1;
  31.     unsigned int write:1;
  32.     unsigned int  read:1;
  33.     } ;
  34. #else
  35. struct Inst {
  36.     unsigned char  inst:5;
  37.     unsigned char  exec:1;
  38.     unsigned char write:1;
  39.     unsigned char  read:1;
  40.     } ;
  41. #endif
  42.  
  43. #endif
  44.  
  45. typedef struct Inst  Instruction[PLOIDY];
  46.  
  47. typedef Instruction Hp  HpInst;
  48. typedef Instruction Fp  FpInst;
  49. typedef Instruction Np  NpInst;
  50. typedef struct Inst Fp  FpIns;
  51.  
  52. typedef I8s GenBits[PLOIDY];
  53.  
  54. typedef GenBits Hp  HpGenB;
  55.  
  56. typedef struct cell Hp  Pcells;
  57. typedef struct s_list  Hp Psl;
  58. typedef struct g_list  Hp Pgl;
  59. typedef struct mem_fr  Hp Pmf;
  60. typedef I32s  Ind;   /* index for addressing instructions in soup */
  61. typedef I32s  Num;   /* type for use in numerical CPU registers */
  62. typedef I32s  Reg;   /* type for use in CPU registers */
  63. typedef Reg  *Preg; 
  64.  
  65. struct InstDef { /* structure for instruction set definitions */
  66.     I8s   op; /* op code */
  67.     I8s   mn[9]; /* assembler mnemonic */
  68.     void  (*execute) P_((I32s)); /* pointer to execute function */
  69.     void  (*parse) P_((I32s)); /* pointer to parse function */
  70.     } ;
  71.  
  72. struct ArgInstDef { /* structure for instruction set definitions */
  73.     I8s   op; /* op code */
  74.     I8s   mn[9]; /* assembler mnemonic */
  75.     } ;
  76.  
  77. struct inst { /* struct for passing arguments from parse to execute */
  78.     Preg   dreg; /* pointer to destination register */
  79.     I32s   dval; /* original destination value */
  80.     FpIns  dins; /* pointer to destination instruction */
  81.     I8s    dtra; /* destination track */
  82.     I32s   dmod; /* destination modulused positive this size */
  83.     I32s   dran; /* destination kept in signed range of this value */
  84.  
  85.     Preg   dreg2; /* pointer to 2nd destination register */
  86.     I32s   dval2; /* original destination value */
  87.     FpIns  dins2; /* pointer to 2nd destination instruction */
  88.     I8s    dtra2; /* 2nd destination track */
  89.     I32s   dmod2; /* 2nd dest modulused positive this size */
  90.     I32s   dran2; /* 2nd dest kept in signed range of this value */
  91.  
  92.     Preg   sreg; /* pointer to source register */
  93.     FpIns  sins; /* pointer to source instruction */
  94.     I32s   sval; /* source value */
  95.     I8s    stra; /* source track */
  96.  
  97.     Preg   sreg2; /* pointer to 2nd source register */
  98.     FpIns  sins2; /* pointer to 2nd source instruction */
  99.     I32s   sval2; /* 2nd source value */
  100.     I8s    stra2; /* 2nd source track */
  101.  
  102.     I8s    mode;    /* mode of instruction */
  103.     I8s    mode2;   /* 2nd mode of instruction */
  104.     Ind    oip;     /* address of instruction being executed: ce->c.ip */
  105.     I8s    iip;     /* amount to increment instruction pointer */
  106.     I8s    dib;     /* amount to decrement instruction bank */
  107.     I16s   ts;      /* size of time slice, used to control central loop */
  108.     } ;
  109.  
  110. struct event {  /* structure for time measured in executed instructions */
  111.     I32s  m;   /* count of millions of instructions */
  112.     I32s  i;   /* count of instructions */
  113.     } ;
  114.  
  115. struct genotype {
  116.     I32s  size;      /* size class (~species) */
  117.     I8s   label[4];  /* genotype label */
  118.     } ;
  119.  
  120. struct gl_index {
  121.     I32s  si;  /* size index */
  122.     I32s  gi;  /* genotype index */
  123.     } ;
  124.  
  125. struct metabolism {  /* structure for metabolic data */
  126.     I32s  inst;       /* count of instructions executed */
  127.     I32s  flags;      /* count of flags (error conditions) set */
  128.     I32s  mov_daught; /* count of number of instructions moved to daughter */
  129.     I8s   BreedTrue; /* 0=not, 1 = this daughter genetically same as parent */
  130.     } ;
  131.  
  132. struct dem {  /* structure for demographic data */
  133.     struct genotype  gen; /* size and genotype name of cell */
  134.     I32s  fecundity;   /* count of number of daughter cells produced */
  135.     I32s  flags;       /* count of flags (error conditions) set */
  136.     I32s  mov_daught;  /* count of number of instructions moved to daughter */
  137.     I32s  inst;        /* count of instructions executed */
  138.     I32s  mut;        /* 0 = no somatic mutations, >= 1 = somatic mutations */
  139.     I32s  flaw;        /* 0 = no flaws, >= 1 = flaws */
  140.     struct metabolism  d1;    /* metabolic data for first daughter */
  141.     struct genotype  parent;  /* size and genotype name of parent */
  142.     struct gl_index  gli;  /* index to this genotype in the sl-gl arrays */
  143.     I16s  ib;  /* instruction bank */
  144.     I32s  ni;  /* index to cells array of daughter cell */
  145.     I8s   is;  /* 1 = this cpu is active, in the slicer; 0 = not active */
  146.     I8s   dm;  /* 0 = mother, 1 = daughter */
  147.     I8s   ploidy; /* how many tracks */
  148.     } ;
  149.  
  150. struct que {  /* pointers to previous and next cells in queues */
  151.     I32s  n_time; /* index of next cell in slicer queue */
  152.     I32s  p_time; /* index of previous cell in slicer queue */
  153.     I32s  n_reap; /* index of next cell in reaper queue */
  154.     I32s  p_reap; /* index of previous cell in reaper queue */
  155.     } ;
  156.  
  157. struct mem {  /* structure for allocated memory block of cell */
  158.     Ind   p;  /* location of start of cell memory */
  159.     I32s  s;  /* size of cell memory */
  160.     } ;
  161.  
  162. struct cpu {  /* structure for registers of virtual cpu */
  163.     Reg   re[NUM_REGS];  /* array of registers */
  164.     Reg   sp;  /* stack pointer */
  165.     Reg   st[STACK_SIZE];  /* stack */
  166.     Reg   ip;  /* instruction pointer */
  167.     I8s   fl;  /* flag */
  168.     I8s   tr; /* which track currently being executed */
  169.     } ;
  170.  
  171. struct cell {  /* structure for cell of organisms */
  172.     struct dem  d;   /* fecundity and times and dates of birth and death */
  173.     struct que  q;   /* pointers to previous and next cells in queues */
  174.     struct mem  mm;  /* main cell memory */
  175.     struct mem  md;  /* daughter cell memory */
  176.     struct cpu  c;   /* virtual cpu */
  177.     I8s         ld;  /* 0 = dead, 1 = alive */
  178.     } ;  /* sizeof(struct cell) = XX */
  179.  
  180. struct mem_fr { /* structure for free memory list */
  181.     Ind   p;  /* location in soup of free block */
  182.     Ind   s;  /* size of free block */
  183.     I32s  n;  /* index of next free block in FreeMem array */
  184.     I8s   o;  /* 1 = element in use, 0 = element open for use */
  185.     } ;  /* sizeof(struct mem_fr) = X */
  186.  
  187. struct s_list { /* structure for size list */
  188.     I32s  size;  /* genotype size */
  189.     I32s  num;   /* number of genotypes of this size */
  190.     I32s  num_s; /* number of genotypes of this size saved to disk */
  191.     I32s  num_q; /* number of genotypes of this size in gen_queue */
  192.     I32s  num_e; /* number of genotypes saved to disk or extant */
  193.     I32s  a_num; /* allocated size of *g array */
  194.     Pgl   g;    /* array of g_list structures */
  195.     } ;
  196.  
  197. struct g_list {  /* structure for genotype list */
  198.     I32s   pop;        /* current number of adults of this genotype in soup */
  199.     struct genotype  gen;  /* genotype of creature */
  200.     struct genotype  parent;    /* genotype of parent genotype (ancestor) */
  201.     I32u   bits;           /* see below */
  202.     struct metabolism  d1; /* metabolic data for first daughter */
  203.     struct metabolism  d2; /* metabolic data for second daughter */
  204.     struct event  originI;  /* time of origin, in instruction time */
  205.     I32s   originC;  /* time of first origin of genotype, in clock time */
  206.     float  MaxPropPop;  /* max. propor. of NumCells reached by this gen. */
  207.     float  MaxPropInst; /* max. propor. of SoupSize reached by this gen. */
  208.     I8s    Fp comments;  /* pointer to string containing comments */
  209.     I8s    ploidy; /* how many tracks */
  210.     I8s    track; /* which track are we on now ... */
  211.     HpInst genome;       /* pointer to genome itself */
  212.     HpGenB gbits;        /* pointer to genome itself */
  213.     struct gl_index  b;  /* next (below) in queue */
  214.     struct gl_index  a;  /* previous (above) in queue */
  215.     } ;
  216.  
  217. /* definitions of bits:
  218.     bit  0  permanent genotype name
  219.     bit  1  saved to disk
  220.     bit  2  EXs = executes own instructions (self)
  221.     bit  3  EXd = executes daughter's instructions
  222.     bit  4  EXo = executes other cell's instructions
  223.     bit  5  EXf = executes instructions in free memory
  224.     bit  6  EXh = own instructions are executed by other creature (host)
  225.     bit  7  TCs = matches template complement of self
  226.     bit  8  TCd = matches template complement of daughter
  227.     bit  9  TCo = matches template complement of other
  228.     bit 10  TCf = matches template complement of free memory
  229.     bit 11  TCh = own template complement is matched by other creature (host)
  230.     bit 12  TPs = uses template pattern of self
  231.     bit 13  TPd = uses template pattern of daughter
  232.     bit 14  TPo = uses template pattern of other
  233.     bit 15  TPf = uses template pattern of free memory
  234.     bit 16  TPh = own template pattern is used by other creature (host)
  235.     bit 17  MFs = moves instruction from self
  236.     bit 18  MFd = moves instruction from daughter
  237.     bit 19  MFo = moves instruction from other cell
  238.     bit 20  MFf = moves instruction from free memory
  239.     bit 21  MFh = own instructions are moved by other creature (host)
  240.     bit 22  MTs = moves instruction to self
  241.     bit 23  MTd = moves instruction to daughter
  242.     bit 24  MTo = moves instruction to other cell
  243.     bit 25  MTf = moves instruction to free memory
  244.     bit 26  MTh = is written on by another creature (host)
  245.     bit 27  MBs = executing other creatures code, moves inst from self
  246.     bit 28  MBd = executing other creatures code, moves inst from daughter
  247.     bit 29  MBo = executing other creatures code, moves inst from other cell
  248.     bit 30  MBf = executing other creatures code, moves inst from free memory
  249.     bit 31  MBh = other creature uses another cpu to move your instructions
  250. */
  251.  
  252. struct LastOut { /* record of last data output to disk */
  253.     I32s  time;  /* elapsed time */
  254.     I32s  ctime; /* millions of instructions */
  255.     I8s   bd;    /* b = birth, d = death */
  256.     I32s  size;  /* size of creature */
  257.     I8s   label[4];  /* genotype name of creature, e.g., aaa */
  258.     } ;
  259.  
  260. struct SizList { /* use for output of size list */
  261.     I32s  size;  /* genome size */
  262.     I32s  pos;   /* position is sl */
  263.     I32s  ext;   /* number of saved or extant genotypes of this size */
  264.     I8s   dir;   /* does a directory for this size exist */
  265.     } ;
  266.  
  267. typedef struct {
  268.     I8s   magic[4];
  269.     I32s  g_off;
  270.     I16s  size, n, n_alloc;
  271. } head_t;
  272.  
  273. typedef struct {
  274.     I8s   gen[3];
  275.     I8s   pgen[3];
  276.     I16s  psize;
  277.     I32u  bits;
  278.     I32s  originC;
  279.     I16s  mpp, mpi;
  280.     I32s  ptr;        /* reserved for future versions */
  281.     struct event originI;
  282.     struct metabolism d1, d2;
  283.     I8s pt;  /* ploidy and track */
  284. } indx_t;
  285.  
  286. #ifdef SOCKETS
  287. /*** new structure for global data *************************************/
  288.  
  289. #ifndef MAXHOSTNAMELEN
  290. #include <sys/param.h>
  291. #endif
  292.  
  293. #ifndef u_long
  294. #include <sys/types.h>
  295. #endif
  296.  
  297. extern char * ALRealloc P_((char  *ptr; u_int  size));
  298.  
  299. /***********************************************************************/
  300. #endif
  301.  
  302. #include "prototyp.h"
  303.  
  304. #endif
  305.