|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfi.hu.cs.titokone.Control
Control class offers the extenal interface to titokone. Using the methods of this class one can compile and emulate the execution process of a ttk91-program from a text file or straight from a string object, which contain symbolic ttk91 machine code, A complete debugging and trackability of compilation, loading and execution cycles are provided with CompileInfo, LoadInfo and RunInfo objects, which can be used to get information of what had just happened. This doesn't take a position on how to show the output. That's left for the GUI, actually a piece of code between Control and the GUI, which prepares the output provided here to be shown in GUI. In this software that piece of code is the GUIBrain class.
Field Summary | |
private Application |
application
|
private Compiler |
compiler
|
private java.io.File |
currentStdOutFile
|
static int |
DEF_HOME_POS
|
static int |
DEF_STDIN_POS
This field set directs handling of an array containing file definitions set in the application. |
static int |
DEF_STDOUT_POS
|
static int |
DEFAULT_MEMORY_SIZE
This is the memory size that will be used by default, unless a higher class (GUIBrain) chooses to change the size later. |
private java.io.File |
defaultStdInFile
|
private java.io.File |
defaultStdOutFile
|
private FileHandler |
fileHandler
This has control to all the files this program has opened. |
private LoadInfo |
pendingLoadInfo
|
private Processor |
processor
|
private java.io.File |
sourceFile
|
Constructor Summary | |
Control(java.io.File defaultStdInFile,
java.io.File defaultStdOutFile)
This constructor sets up the Control instance. |
Method Summary | |
void |
changeMemorySize(int powerOfTwo)
Changes the size of memory measured in words. |
TTK91Application |
compile(TTK91CompileSource source)
Compiles a symbolic TTK91-assembly language to binary executable application. |
CompileInfo |
compileLine()
This compiles one next line of the t91 program that has been opened recently and hasn't yet been compiled to binary code. |
void |
eraseMemory()
Erases the memory ie. |
java.io.File[] |
getApplicationDefinitions()
This helper method gets the definitions in the currently loaded application. |
java.lang.String |
getBinary(TTK91Application app)
Returns a string that contains the binary presentation of the application. |
TTK91Cpu |
getCpu()
Returns a reference to the Processor object. |
TTK91Memory |
getMemory()
Returns a reference to the RandomAccessMemory object which is attached to the current Processor object. |
LoadInfo |
getPendingLoadInfo()
Sometimes load() throws an exception when the situation is not really requiring an error message. |
private void |
insertStdinToApplication(java.io.File applicationStdin)
This method does the actual inserting STDIN datat to an application. |
void |
keyboardInput(int inputValue)
GUIBrain calls this when it has recieved the TTK91NoKbdData exception. |
LoadInfo |
load()
This method loads an application that has been either compiled or read from binary earlier. |
TTK91Application |
loadBinary(java.lang.String binary)
Returns a TTK91Application object of the given string, which should contain proper binary code. |
java.util.ResourceBundle |
loadLanguageFile(java.io.File languageFile)
This is called when user the has changed language to another one by choosing it from a dialog after selecting Set language from the GUI menu, and has chosen a special file to load. |
java.lang.String |
loadSettingsFileContents(java.io.File settingsFile)
This is called when GUIBrain wants to load the settings. |
java.lang.String |
loadSettingsStreamContents(java.io.InputStream settingsStream)
This is called when GUIBrain wants to load the settings from a stream. |
java.lang.String |
modifySource(java.lang.String[] modifiedSource)
This method makes it possible to re-open the same source file, only modified. |
void |
openBinary(java.io.File openedFile)
This is called when a binary file is opened from GUI. |
java.lang.String |
openSource(java.io.File openedFile)
This is called when a source file is opened from GUI. |
void |
run(TTK91Application app,
int steps)
Runs a given app for |
RunInfo |
runLine()
This runs one next line of the program that is currently loaded into the TTK91's memory. |
void |
saveBinary()
This method saves the opened source file to a binary of the same filename as the previous source file was loaded from, with the extension changed (probably from .k91) to .b91. |
void |
saveBinary(java.io.File specialFile)
This method saves the current application to a given file. |
void |
saveSettings(java.lang.String currentSettings,
java.io.File settingsFile)
This method stores the settings string to the given file. |
void |
setDefaultStdIn(java.io.File stdinFile)
This is called when the user has changed the file from which the stdin operations will be read. |
void |
setDefaultStdOut(java.io.File stdoutFile)
This is called when the user has changed the file into which the stdout operations will be written. |
private void |
writeToCRT(int inputValue)
RunLine() calls this, when the processor wants to write a value to CRT. |
private void |
writeToStdOut(int inputValue)
RunLine() calls this, when the processor wants to write a value to StdOut. |
private void |
writeToStdoutFile(java.lang.String data)
This method appends the given data to the current stdout file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_MEMORY_SIZE
public static final int DEF_STDIN_POS
public static final int DEF_STDOUT_POS
public static final int DEF_HOME_POS
private FileHandler fileHandler
private Processor processor
private Compiler compiler
private Application application
private java.io.File defaultStdInFile
private java.io.File defaultStdOutFile
private java.io.File currentStdOutFile
private java.io.File sourceFile
private LoadInfo pendingLoadInfo
Constructor Detail |
public Control(java.io.File defaultStdInFile, java.io.File defaultStdOutFile)
Method Detail |
public TTK91Application compile(TTK91CompileSource source) throws TTK91Exception, TTK91CompileException
compile
in interface TTK91Core
source
- The source code to be compiled.
TTK91CompileException
- If the compiler throws one.
TTK91Exception
- Never in this implementation. (Except for
TTK91CompileExceptions, which inherit it.)public LoadInfo load() throws TTK91AddressOutOfBounds, TTK91NoStdInData
TTK91OutOfMemory
- If the memory cannot fit the
application.
TTK91NoStdInData
- If the current STDIN file contains invalid
STDIN input or the file cannot be opened.
java.lang.IllegalStateException
- If application is null.
TTK91AddressOutOfBounds
public LoadInfo getPendingLoadInfo()
private void insertStdinToApplication(java.io.File applicationStdin) throws java.text.ParseException, java.io.IOException
applicationStdin
- The application's suggestion for a file
to read the stdin data from. If null, the data is read from the
set default stdin file.
java.io.IOException
- If the current STDIN file cannot be opened.
java.text.ParseException
- If the current STDIN file contains
invalid input.public java.io.File[] getApplicationDefinitions()
public void run(TTK91Application app, int steps) throws TTK91Exception, TTK91RuntimeException
run
in interface TTK91Core
app
- Application to be run.steps
- Number of steps the application will be run.
TTK91NoStdInData
- If the STDIN data file is unreadable or
syntactically incorrect even if the file is not really needed.
TTK91Exception
- place holder for extension.
TTK91RuntimeException
- when encountered an invalid
operation by the TTK91Application.public TTK91Memory getMemory()
getMemory
in interface TTK91Core
public TTK91Cpu getCpu()
getCpu
in interface TTK91Core
public java.lang.String getBinary(TTK91Application app)
getBinary
in interface TTK91Core
app
- The application that is to be transformed into
binary.
public TTK91Application loadBinary(java.lang.String binary) throws java.text.ParseException
loadBinary
in interface TTK91Core
binary
- The binary to be compiled.
java.text.ParseException
- if binary is not of TTK91 binary formatpublic void changeMemorySize(int powerOfTwo)
powerOfTwo
- Implies the total size of memory which is
2^powerOfTwo. Legitimate values are
9,...,16.
java.lang.IllegalArgumentException
- if powerOfTwo is not between
9 and 16.public void eraseMemory()
public CompileInfo compileLine() throws TTK91CompileException
TTK91CompileException
public RunInfo runLine() throws TTK91RuntimeException
TTK91RuntimeException
private void writeToStdoutFile(java.lang.String data) throws TTK91FailedWrite
data
- The data to append to the stdout file.
TTK91FailedWrite
- If there was an I/O error.public java.util.ResourceBundle loadLanguageFile(java.io.File languageFile) throws ResourceLoadFailedException
languageFile
- The language file to load into a
ResourceBundle.
ResourceLoadFailedException
- If opening the resourcebundle
from the file failed.public void setDefaultStdIn(java.io.File stdinFile) throws java.io.IOException, java.text.ParseException
stdinFile
- The stdin file.
java.io.IOException
- If an I/O error occurs.
java.text.ParseException
- *After* everything else is done, if the
contents of the file are invalid. This exception can be ignored
until it leads into TTK91NoStdInData when an application tries
to read from STDIN.public void setDefaultStdOut(java.io.File stdoutFile) throws java.io.IOException
stdoutFile
- The stdout file.
java.io.IOException
public java.lang.String openSource(java.io.File openedFile) throws java.io.IOException
openedFile
- The file.
java.io.IOException
public java.lang.String modifySource(java.lang.String[] modifiedSource) throws java.io.IOException
modifiedSource
- The modified source as a string array, one
line per cell. The format is optimized for GUI/GUIBrain use. The
source must not be null.
java.io.IOException
- Just before the last return if the saving of
the modified source failed.
java.lang.IllegalStateException
- If there is no source file set.
The method openSource() must be called before this method.public void saveBinary() throws java.io.IOException
java.lang.IllegalStateException
- If the method is called before
a source file has been opened or if there is no application
to save.
java.io.IOException
public void saveBinary(java.io.File specialFile) throws java.io.IOException
specialFile
- A filename to save the binary to.
java.lang.IllegalStateException
- If there is no application to save.
java.io.IOException
public void openBinary(java.io.File openedFile) throws java.io.IOException, java.text.ParseException
openedFile
- The file.
java.io.IOException
java.text.ParseException
public java.lang.String loadSettingsFileContents(java.io.File settingsFile) throws java.io.IOException
java.io.IOException
public java.lang.String loadSettingsStreamContents(java.io.InputStream settingsStream) throws java.io.IOException
java.io.IOException
public void saveSettings(java.lang.String currentSettings, java.io.File settingsFile) throws java.io.IOException
currentSettings
- A string representation of the current
settings.settingsFile
- The file to store the settings to.
java.io.IOException
- if FileHandler throws one to indicate an I/O
error.public void keyboardInput(int inputValue)
inputValue
- The input to pass on.private void writeToCRT(int inputValue)
inputValue
- The input to CRT.private void writeToStdOut(int inputValue)
inputValue
- The inpuit to StdOut.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |