org.holtz.zoe.zoel
Enum Operator

java.lang.Object
  extended by java.lang.Enum<Operator>
      extended by org.holtz.zoe.zoel.Operator
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Operator>

public enum Operator
extends java.lang.Enum<Operator>

The verb of an Operation in a Zoel program. Binary operators first push any arg onto the stack. Stack.0 is the right operand, and Stack.1 is the left. Stack.0 is popped, and Stack.1 is replaced with the operation result. If a string and a number are the operands and the string can parse to a number, then it is treated as such, else the number is treated as a string. Unary operators first evaluate any arg and replace Stack.0 with it. They then replace Stack.0 with the result of the operation on it.

Author:
Brian Holtz

Enum Constant Summary
AbsoluteVal
          Absolute value or string length.
And
          Iff stack top is true (nonzero/nonempty), evaluate arg.
Bite
          Bite energy from the nearest Bug or Joule within Feel/Bite range.
Call
          Use the string value of Stack.0 as the label to call.
DividedBy
          Arithmetic division or substring removal/extraction.
Else
          If Stack.0 is false (zero/empty), evaluate arg.
EndTurn
          End the current turn, preventing evaluation of remaining genes.
Equals
           
Get
          Copy a heap value to the stack, where arg is the map key.
GreaterThan
           
IfThen
          If Stack.0 is true (nonzero/nonempty), evaluate arg.
LessThan
           
Mate
          Set LastMate to the nearest visible bug that is within Feel range.
Minus
          Subtraction or string suffix removal.
Modulus
          Arithmetic modulus or string prefix removal.
Mood
          Set the Mood register.
Move
          Move forward along $Heading.
Negate
          Negation or string reversal.
Not
          Logical negation or string isEmpty.
Or
          If Stack.0 is false (zero/empty), evaluate arg.
Plus
          Addition or string concatenation.
Pop
          Pop the top off the stack.
Print
          Send a message to the gods.
Push
          Push the arg onto the stack.
Random
          Replace Stack.0 with a number 0 <= n < Stack.0.
SenseFarther
          Set It to the closest object farther than the current It.
Set
          Set a mapping in the heap, where arg is the map key and the stack top is the value.
Spawn
          Attempt to spawn a child using only available strength.
Split
          Attempt to split into a parent and child of equal size and strength.
Times
          Multiplication or tokenizing for strings.
Turn
          Turn to a different direction in order to Move that way.
While
          While Stack.0 is true (nonzero/nonempty), evaluate arg.
 
Method Summary
static Operator fromString(java.lang.String str)
           
 boolean isBinary()
           
 int maxNumArgs()
           
static Operator pseudoRandom(java.util.Random random, boolean actionOperatorsAllowed)
           
static Operator valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static Operator[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 ZoelVM.Turn whetherTurnContinues()
           
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

Move

public static final Operator Move
Move forward along $Heading. If no arg, arg = 1.0. If 0 <= arg <= 2, arg is speed. Energy cost is proportional to speed ^ 2.


Turn

public static final Operator Turn
Turn to a different direction in order to Move that way. Arg can be Me.Toward or Me.Away from last-sensed ZObject. If no arg, arg is Me.Toward. Arg can be a Location e.g. Me.BirthLocation or It.AncestralLocation. Direction registers (Toward Away Heading) evaluate to Direction - Me.Heading, and so do as expected when used as a Turn operand. If -2 PI <= arg <= 2 PI, arg is radians. Else, if -180 <= arg <= 180, arg is degrees.


Bite

public static final Operator Bite
Bite energy from the nearest Bug or Joule within Feel/Bite range.


Spawn

public static final Operator Spawn
Attempt to spawn a child using only available strength. A child is only created if
  1. she would have at least the mass-energy of a max-strength min-size bug, and the mother would be left with strength >= 0.
If LastMate is set, then the child's genome is created from the mother and her mate.


Split

public static final Operator Split
Attempt to split into a parent and child of equal size and strength. A child is only created if she would have at least the mass-energy of a max-strength min-size bug. Because bugs are ignored by their own Feel/Look/Bite operations, mother and child are invisible to each other's Feel/Look/Bite operations for a brief period following a Split, until their differential interactions with their environment make the distinguishable. If LastMate is set, then the child's genome is created from the mother and her mate.


Mate

public static final Operator Mate
Set LastMate to the nearest visible bug that is within Feel range. A system property controls whether


EndTurn

public static final Operator EndTurn
End the current turn, preventing evaluation of remaining genes.


SenseFarther

public static final Operator SenseFarther
Set It to the closest object farther than the current It.


Mood

public static final Operator Mood
Set the Mood register. Pushes any arg, then copies the popped stack top to Me.Mood.


Print

public static final Operator Print
Send a message to the gods. Pushes any arg, then prints popped stack top on System.out.


Call

public static final Operator Call
Use the string value of Stack.0 as the label to call. Search upward in the syntax tree for an ExpressionList with the same label, or with an immediate child ExpressionList with that label, and evaluate the labeled ExpressionList.


IfThen

public static final Operator IfThen
If Stack.0 is true (nonzero/nonempty), evaluate arg. If stack top is not true and the next Statement is Else, then skip the Else.


Else

public static final Operator Else
If Stack.0 is false (zero/empty), evaluate arg.


While

public static final Operator While
While Stack.0 is true (nonzero/nonempty), evaluate arg.


Push

public static final Operator Push
Push the arg onto the stack. The stack size is limited to a function of bug age, so the deepest stack element might be discarded. If no arg, arg is Stack.0, and thus the stack top is duplicated.


Pop

public static final Operator Pop
Pop the top off the stack.


Set

public static final Operator Set
Set a mapping in the heap, where arg is the map key and the stack top is the value. If no arg, Stack.0 is the key, Stack.1 is the value, and Stack.0 is popped. The heap size is limited to a function of bug age, so the oldest stack element might be discarded.


Get

public static final Operator Get
Copy a heap value to the stack, where arg is the map key. If no arg, arg is Stack.0 -- i.e., the key is replaced with the value. If the key is not found, the value copied is 0.


And

public static final Operator And
Iff stack top is true (nonzero/nonempty), evaluate arg.


Or

public static final Operator Or
If Stack.0 is false (zero/empty), evaluate arg. The only difference from Else is that Or cannot be skipped by a prior IfThen.


Equals

public static final Operator Equals

LessThan

public static final Operator LessThan

GreaterThan

public static final Operator GreaterThan

Plus

public static final Operator Plus
Addition or string concatenation.


Minus

public static final Operator Minus
Subtraction or string suffix removal. If Stack.1 is a string and Stack.0 is a number, then removes Stack.0 characters from the end of the string. If Stack.0 and Stack.1 are Points, compute the distance.


Times

public static final Operator Times
Multiplication or tokenizing for strings. S1 * S0 leaves S1, pushes tokens as would be returned from PHP explode(), and finally pushes a count of tokens pushed.


DividedBy

public static final Operator DividedBy
Arithmetic division or substring removal/extraction. Division can yield NaN, -infinity, or +infinity, as in Java. If string/n, then leaves the first 1/|n| of the string. If n/string and n>0, then leaves the nth character from front of string. If n/string and n<0, then leaves the nth character from back of string.


Modulus

public static final Operator Modulus
Arithmetic modulus or string prefix removal. If Stack.1 is a string and Stack.0 is a number, then leaves the last Stack.0 characters of the string.


Not

public static final Operator Not
Logical negation or string isEmpty.


Random

public static final Operator Random
Replace Stack.0 with a number 0 <= n < Stack.0. If Stack.0 is an integer other than 1.0 or -1.0, then n will be an integer too. If Stack.0 is a string, the result is a random substring of it.


Negate

public static final Operator Negate
Negation or string reversal.


AbsoluteVal

public static final Operator AbsoluteVal
Absolute value or string length.

Method Detail

values

public static Operator[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Operator c : Operator.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Operator valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

isBinary

public boolean isBinary()

maxNumArgs

public int maxNumArgs()

whetherTurnContinues

public ZoelVM.Turn whetherTurnContinues()

pseudoRandom

public static Operator pseudoRandom(java.util.Random random,
                                    boolean actionOperatorsAllowed)

fromString

public static Operator fromString(java.lang.String str)