de.projectory.koivima.compiler.assembler
Class AssemblerCompiler

java.lang.Object
  extended by de.projectory.koivima.compiler.assembler.AssemblerCompiler

public class AssemblerCompiler
extends java.lang.Object

Compiles a piece of assembly code for the virtual machine.


Field Summary
 java.util.ArrayList<java.lang.String> operators
          names of available operators
(package private)  java.lang.String packageName
          Name of the package containing the operators.
(package private)  java.lang.String packagePath
          Path to the directory containing the operators
 
Constructor Summary
AssemblerCompiler()
          Creates a new compiler.
 
Method Summary
 CodeBlock compile(java.lang.String assemblyCode, ExecutionContext context)
          Compiles a string into an executable code block
 CodeBlock compileCodeBlock(Parser parser, ExecutionContext context)
          Reads tokens in assembly language from a parser until the end of a code block and compiles them to an executable codeblock.
protected  AbstractElementList compileList(AbstractElementList list, Parser parser, ExecutionContext context)
           
 java.util.ArrayList<java.lang.String> createListOfOperators()
          Looks for class files in de/projectory/koivima/operators/ and creates an internal list of operators.
 void setOperatorsPath(java.lang.String pathname)
          Sets the path to a new set of operators.
protected  Element tokenToElement(java.lang.String token, Parser parser, ExecutionContext context)
          Converts a token to an executable element of the virtual machine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

operators

public java.util.ArrayList<java.lang.String> operators
names of available operators


packagePath

java.lang.String packagePath
Path to the directory containing the operators


packageName

java.lang.String packageName
Name of the package containing the operators. Note that this needs a . at the end

Constructor Detail

AssemblerCompiler

public AssemblerCompiler()
Creates a new compiler. Operators are created dynamically from the classes in the vm's operators directory. So the list of tokens this compiler knows depends on the contents of that directory.

Method Detail

setOperatorsPath

public void setOperatorsPath(java.lang.String pathname)
Sets the path to a new set of operators. This method should be used if the compiler should compile a custumized instruction set.

Parameters:
pathname - Directory containing the operators, for example de/projectory/koivima/operators/

createListOfOperators

public java.util.ArrayList<java.lang.String> createListOfOperators()
Looks for class files in de/projectory/koivima/operators/ and creates an internal list of operators. The compiler uses this list to map tokens to operators. This method should be called if the operators are changed at runtime.


tokenToElement

protected Element tokenToElement(java.lang.String token,
                                 Parser parser,
                                 ExecutionContext context)
                          throws java.io.IOException
Converts a token to an executable element of the virtual machine.

Returns:
The element that created from the token. null if the token is invalid.
Throws:
java.io.IOException

compileList

protected AbstractElementList compileList(AbstractElementList list,
                                          Parser parser,
                                          ExecutionContext context)
                                   throws java.io.IOException
Throws:
java.io.IOException

compileCodeBlock

public CodeBlock compileCodeBlock(Parser parser,
                                  ExecutionContext context)
                           throws java.io.IOException
Reads tokens in assembly language from a parser until the end of a code block and compiles them to an executable codeblock.

Parameters:
parser - Previously created Parser that provides the tokens for the compiler.
Throws:
java.io.IOException

compile

public CodeBlock compile(java.lang.String assemblyCode,
                         ExecutionContext context)
                  throws java.io.IOException
Compiles a string into an executable code block

Throws:
java.io.IOException