de.projectory.koivima.core
Class CodeBlock

java.lang.Object
  extended by de.projectory.koivima.core.Element
      extended by de.projectory.koivima.core.AbstractElementList
          extended by de.projectory.koivima.core.CodeBlock
All Implemented Interfaces:
java.lang.Iterable<Element>

public class CodeBlock
extends AbstractElementList

An executable piece of a program consisting of elements.


Field Summary
(package private)  int codePointer
          pointer to the current element to execute
(package private)  boolean codePointerIsClean
          set to false if the code pointer has been changed from the outside
(package private)  ExecutionContext localContext
          Execution context for the elements of this CodeBlock
 
Fields inherited from class de.projectory.koivima.core.AbstractElementList
code
 
Fields inherited from class de.projectory.koivima.core.Element
context
 
Constructor Summary
CodeBlock()
           
 
Method Summary
 void add(Element element)
          Adds an element to the end of this code block.
 void addFirst(Element element)
          Adds an element to the beginning of this list.
 void evaluate()
          Evaluates this whole code block
 void moveCodePointer(int offset)
          Moves the code pointer.
 void onError(java.lang.String message)
          Called if an error ocurs.
 Element removeFirst()
          Removes the first element of executable code.
 void setExecutionContext(ExecutionContext context)
          Overwrites setExecutionContext of AbstractElementList
 java.lang.String toString()
          Returns a String representation of this code block.
 
Methods inherited from class de.projectory.koivima.core.AbstractElementList
execute, iterator
 
Methods inherited from class de.projectory.koivima.core.Element
getExecutionContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

codePointer

int codePointer
pointer to the current element to execute


codePointerIsClean

boolean codePointerIsClean
set to false if the code pointer has been changed from the outside


localContext

ExecutionContext localContext
Execution context for the elements of this CodeBlock

Constructor Detail

CodeBlock

public CodeBlock()
Method Detail

setExecutionContext

public void setExecutionContext(ExecutionContext context)
Overwrites setExecutionContext of AbstractElementList

Overrides:
setExecutionContext in class AbstractElementList
Parameters:
context - ExecutionContext for this CodeBlock.

add

public void add(Element element)
Adds an element to the end of this code block.

Specified by:
add in class AbstractElementList
Parameters:
element - A code element: data element, operator or other

addFirst

public void addFirst(Element element)
Adds an element to the beginning of this list.

Specified by:
addFirst in class AbstractElementList
Parameters:
element - A code element: data element, operator or other

removeFirst

public Element removeFirst()
Removes the first element of executable code.

Returns:
First element of the code.

evaluate

public void evaluate()
Evaluates this whole code block


moveCodePointer

public void moveCodePointer(int offset)
Moves the code pointer. Needed to implement moves, ifs and so on.

Parameters:
offset - Steps to move the code pointer.

onError

public void onError(java.lang.String message)
Called if an error ocurs. At the moment it just prints out an error message


toString

public java.lang.String toString()
Returns a String representation of this code block.

Overrides:
toString in class java.lang.Object