Gene

From WikiManual
Jump to: navigation, search

1 Genes - The Darwinbots Language

1.1 Overview Darwinbots uses a simplified programming language, which admits no conditional jumps or cycles.


The idea is that of programs made up by daemons, that means closed parts waiting silently until a particular event happens, and then activating to perform some task. These parts are called 'genes'. A robot's program, a DNA, is made only by a sequence of genes, all waiting for their own particular event to activate them. This event is specified at the head of the gene. If a gene is activated, then his body is executed. A gene's body consists in a straight sequence of instructions, without cycles or jumps, doing some operations on the robot's memory. After the body execution is complete, the gene turns silent again, until something wakes it up again.


1.1 The Code A gene looks like this (keywords in bold):

cond :head start marker

activation conditions

start :body start marker

task to perform

stop :gene end marker


cond

start

stop


and a complete dna will look like

gene

gene

.....

gene

end DNA end marker


1.1 Flow control:


cond: marks the beginning of the gene, and also the beginning of his activation condition.

start: marks the beginning of the body part of the gene

stop: marks the end of the body part of the gene, as well the end of the whole gene.

end: marks the end of the dna.


Another Explanation

This explanation is a kind of translation Darwinbots source code into English.

DNA code is parsed into several parts which may have their own context. There are commands, which define the current context.

  1. COND context starts with cond and lasts until start, else, stop or end.
  2. BODY and ELSEBODY contexts start with start and else accordingly and last until cond, start, else, stop or end.
  3. Anything else is CLEAR context (no commands are executed at all).

Whether other commands are executed depends on the context.

  1. Push stack, basic, advanced and bitwise commands are executed everywhere except CLEAR context. They operate on the integer stack.
  2. Conditions and logic commands are executed inside COND context only.
    • Conditions take values from the integer stack and put results in the boolean stack.
    • Logic commands operate with the boolean stack solely.
  3. Stores work in BODY and ELSEBODY contexts. They operate on the integer stack and the memory.
    • Stores in BODY context are executed either if there are no values in the boolean stack, or if and'ed values in the boolean stack equal true.
    • Stores in ELSEBODY context are executed, if and'ed values in the boolean stack equal false.

The memory and the integer stack is persistent during a single cycle. It means, that if you leave a value in the integer stack in one gene, it will be still there when you enter the next gene. The boolean stack is cleared each time start, else or stop is met.

How the DNA works