Commit 0e106949 authored by thomas@cs.ru.nl's avatar thomas@cs.ru.nl
Browse files

Cleaned up imports

parent c598bdba
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; abstract class AbstractMemoryCellModel extends Model implements MemoryCellModel{ protected void fireCellChange( MemoryCellModel m, MemoryCellEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MemoryCellListener l = (MemoryCellListener)e.nextElement() ; l.cellChanged( ev ) ; } } protected void fireCellChange( MemoryCellModel m, int cellIndex, int oldCellValue, Modification mdf ) { fireCellChange( m, new MemoryCellEvent( m, cellIndex, oldCellValue, mdf ) ) ; } protected void fireCellChange( MemoryCellModel m, int cellIndex, MemoryAnnotation oldCellValue, Modification mdf ) { fireCellChange( m, new MemoryCellEvent( m, cellIndex, oldCellValue, mdf ) ) ; } public void addMemoryCellListener( MemoryCellListener l ) { addListener( l ) ; } public void removeMemoryCellListener( MemoryCellListener l ) { removeListener( l ) ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; abstract class AbstractMemoryCellModel extends Model implements MemoryCellModel{ protected void fireCellChange( MemoryCellModel m, MemoryCellEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MemoryCellListener l = (MemoryCellListener)e.nextElement() ; l.cellChanged( ev ) ; } } protected void fireCellChange( MemoryCellModel m, int cellIndex, int oldCellValue, Modification mdf ) { fireCellChange( m, new MemoryCellEvent( m, cellIndex, oldCellValue, mdf ) ) ; } protected void fireCellChange( MemoryCellModel m, int cellIndex, MemoryAnnotation oldCellValue, Modification mdf ) { fireCellChange( m, new MemoryCellEvent( m, cellIndex, oldCellValue, mdf ) ) ; } public void addMemoryCellListener( MemoryCellListener l ) { addListener( l ) ; } public void removeMemoryCellListener( MemoryCellListener l ) { removeListener( l ) ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.awt.* ; public class ColoredText{ public static final ColoredText blankDefault = new ColoredText( "", Color.gray ) ; private String text ; private Color color ; public ColoredText( String t, Color c ) { text = t ; color = c ; } public String getText() { return text ; } public Color getColor() { return color ; } public String toString() { return "ColoredText " + text ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.awt.Color; public class ColoredText{ public static final ColoredText blankDefault = new ColoredText( "", Color.gray ) ; private String text ; private Color color ; public ColoredText( String t, Color c ) { text = t ; color = c ; } public String getText() { return text ; } public Color getColor() { return color ; } public String toString() { return "ColoredText " + text ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ /** * Configuration * */package nl.uu.cs.ssm ; import java.awt.event.KeyEvent ; public class Config{ public static final int[] keysLoad = { KeyEvent.VK_O } ; public static final int[] keysReload = { KeyEvent.VK_R } ; public static final int[] keysPause = { KeyEvent.VK_SPACE } ; public static final int[] keysFullForward = { KeyEvent.VK_DOWN } ; public static final int[] keysFullBackward = { KeyEvent.VK_UP } ; public static final int[] keysStep1Forward = { KeyEvent.VK_RIGHT, KeyEvent.VK_SPACE } ; public static final int[] keysStep1Backward = { KeyEvent.VK_LEFT, KeyEvent.VK_BACK_SPACE } ; public static final String extensionSSM = "ssm" ; public static final int allowedAutomaticMemoryIncrease = 100 ; public static final String version() { return "1.3.3" ; } public static final String versionDate() { return "2002 04 15" ; } public static final String author() { return "Atze Dijkstra, Utrecht University" ; } public static final String authorEmail() { return "atze@cs.uu.nl" ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ /** * Configuration * */package nl.uu.cs.ssm ; import java.awt.event.KeyEvent; public class Config{ public static final int[] keysLoad = { KeyEvent.VK_O } ; public static final int[] keysReload = { KeyEvent.VK_R } ; public static final int[] keysPause = { KeyEvent.VK_SPACE } ; public static final int[] keysFullForward = { KeyEvent.VK_DOWN } ; public static final int[] keysFullBackward = { KeyEvent.VK_UP } ; public static final int[] keysStep1Forward = { KeyEvent.VK_RIGHT, KeyEvent.VK_SPACE } ; public static final int[] keysStep1Backward = { KeyEvent.VK_LEFT, KeyEvent.VK_BACK_SPACE } ; public static final String extensionSSM = "ssm" ; public static final int allowedAutomaticMemoryIncrease = 100 ; public static final String version() { return "1.3.3" ; } public static final String versionDate() { return "2002 04 15" ; } public static final String author() { return "Atze Dijkstra, Utrecht University" ; } public static final String authorEmail() { return "atze@cs.uu.nl" ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.io.* ; public abstract class HelpAccumulator{ //private StringBuffer accumulator ; protected Writer accumulator ; public HelpAccumulator( String fileName ) { try { //System.out.println( "help acc " + fileName ) ; if ( fileName == null ) accumulator = new StringWriter() ; else accumulator = new FileWriter( fileName ) ; } catch( IOException ex ) { ex.printStackTrace() ; accumulator = null ; } } protected boolean canWrite() { return accumulator != null ; } public abstract void beginHeadTitleBody( String t ) ; public abstract void endHeadTitleBody() ; public abstract void anchor( String a ) ; public abstract void a( String href, String title ) ; public abstract void anchorA( String href, String title ) ; public abstract void beginCentered() ; public abstract void endCentered() ; public abstract void beginPara() ; public abstract void endPara() ; public void para( String text ) { beginPara( ) ; append( text ) ; endPara() ; } public abstract void beginSectionTitle() ; public abstract void endSectionTitle() ; public void sectionTitle( String s ) { beginSectionTitle() ; append( s ) ; endSectionTitle() ; } public abstract void beginSubsectionTitle() ; public abstract void endSubsectionTitle() ; public void subsectionTitle( String s ) { beginSubsectionTitle() ; append( s ) ; endSubsectionTitle() ; } public abstract void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) ; public abstract void endTable() ; public abstract void beginTableRow( ) ; public abstract void endTableRow() ; public abstract void beginTableData( ) ; public abstract void endTableData() ; public void tableRow( Object[] data ) // not recursive (yet) { beginTableRow() ; for ( int i = 0 ; i < data.length ; i++ ) { beginTableData() ; append( data[i].toString() ) ; endTableData() ; } endTableRow() ; } public void tableHeaderRow( Object[] data ) // not recursive (yet) { beginTableRow() ; for ( int i = 0 ; i < data.length ; i++ ) { beginTableData() ; bold( data[i].toString() ) ; endTableData() ; } endTableRow() ; } public abstract void beginBlockQuote( ) ; public abstract void endBlockQuote() ; public abstract void linebreak() ; public void append( String o ) { if ( ! canWrite() ) return ; try { accumulator.write( o ) ; } catch ( IOException ex ) { accumulator = null ; } } public void append( char o ) { append( "" + o ) ; } public void append( int o ) { append( "" + o ) ; } public void nl( ) { append( '\n' ) ; } //public abstract void font( String f, String s ) ; public abstract void bold( String s ) ; public void string( String s ) { append( "\"" ) ; append( s ) ; append( "\"" ) ; } //public abstract void define( String nm, String val ) ; public void close( ) { try { accumulator.close() ; } catch ( IOException ex ) { } } public String toString() { close() ; if ( accumulator instanceof StringWriter ) return accumulator.toString() ; else return "" ; } public abstract void mathEquationList( Enumeration e, char subscript ) ; public abstract void beginVerbatimList() ; public abstract void endVerbatimList() ; public abstract void verbatimLine( String s ) ; public void verbatimList( Enumeration e ) { if ( ! e.hasMoreElements() ) return ; beginVerbatimList() ; for ( ; e.hasMoreElements() ; ) { verbatimLine( (String)e.nextElement() ) ; } endVerbatimList() ; } public abstract void beginAttributeList( ) ; public abstract void endAttributeList( ) ; public abstract void attributeName( String s ) ; public abstract void beginAttributeValue( ) ; public abstract void endAttributeValue( ) ; public String reprAsHex( int v ) { return Utils.asHex( v, false ) ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.io.FileWriter;import java.io.IOException;import java.io.StringWriter;import java.io.Writer;import java.util.Enumeration; public abstract class HelpAccumulator{ //private StringBuffer accumulator ; protected Writer accumulator ; public HelpAccumulator( String fileName ) { try { //System.out.println( "help acc " + fileName ) ; if ( fileName == null ) accumulator = new StringWriter() ; else accumulator = new FileWriter( fileName ) ; } catch( IOException ex ) { ex.printStackTrace() ; accumulator = null ; } } protected boolean canWrite() { return accumulator != null ; } public abstract void beginHeadTitleBody( String t ) ; public abstract void endHeadTitleBody() ; public abstract void anchor( String a ) ; public abstract void a( String href, String title ) ; public abstract void anchorA( String href, String title ) ; public abstract void beginCentered() ; public abstract void endCentered() ; public abstract void beginPara() ; public abstract void endPara() ; public void para( String text ) { beginPara( ) ; append( text ) ; endPara() ; } public abstract void beginSectionTitle() ; public abstract void endSectionTitle() ; public void sectionTitle( String s ) { beginSectionTitle() ; append( s ) ; endSectionTitle() ; } public abstract void beginSubsectionTitle() ; public abstract void endSubsectionTitle() ; public void subsectionTitle( String s ) { beginSubsectionTitle() ; append( s ) ; endSubsectionTitle() ; } public abstract void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) ; public abstract void endTable() ; public abstract void beginTableRow( ) ; public abstract void endTableRow() ; public abstract void beginTableData( ) ; public abstract void endTableData() ; public void tableRow( Object[] data ) // not recursive (yet) { beginTableRow() ; for ( int i = 0 ; i < data.length ; i++ ) { beginTableData() ; append( data[i].toString() ) ; endTableData() ; } endTableRow() ; } public void tableHeaderRow( Object[] data ) // not recursive (yet) { beginTableRow() ; for ( int i = 0 ; i < data.length ; i++ ) { beginTableData() ; bold( data[i].toString() ) ; endTableData() ; } endTableRow() ; } public abstract void beginBlockQuote( ) ; public abstract void endBlockQuote() ; public abstract void linebreak() ; public void append( String o ) { if ( ! canWrite() ) return ; try { accumulator.write( o ) ; } catch ( IOException ex ) { accumulator = null ; } } public void append( char o ) { append( "" + o ) ; } public void append( int o ) { append( "" + o ) ; } public void nl( ) { append( '\n' ) ; } //public abstract void font( String f, String s ) ; public abstract void bold( String s ) ; public void string( String s ) { append( "\"" ) ; append( s ) ; append( "\"" ) ; } //public abstract void define( String nm, String val ) ; public void close( ) { try { accumulator.close() ; } catch ( IOException ex ) { } } public String toString() { close() ; if ( accumulator instanceof StringWriter ) return accumulator.toString() ; else return "" ; } public abstract void mathEquationList( Enumeration e, char subscript ) ; public abstract void beginVerbatimList() ; public abstract void endVerbatimList() ; public abstract void verbatimLine( String s ) ; public void verbatimList( Enumeration e ) { if ( ! e.hasMoreElements() ) return ; beginVerbatimList() ; for ( ; e.hasMoreElements() ; ) { verbatimLine( (String)e.nextElement() ) ; } endVerbatimList() ; } public abstract void beginAttributeList( ) ; public abstract void endAttributeList( ) ; public abstract void attributeName( String s ) ; public abstract void beginAttributeValue( ) ; public abstract void endAttributeValue( ) ; public String reprAsHex( int v ) { return Utils.asHex( v, false ) ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.io.* ; public class HelpHTMLAccumulator extends HelpAccumulator{ private boolean isOldHtml ; public HelpHTMLAccumulator( boolean old, String fileName ) { super( fileName ) ; isOldHtml = old ; } private void beginTag( String t, boolean end ) { append( '<' ) ; if ( end ) append( '/' ) ; append( t ) ; } private void endTag( ) { append( '>' ) ; } private void tag( String t, boolean end, String params ) { beginTag( t, end ) ; if ( params != null ) { append( " " ) ; append( params ) ; } endTag() ; } private void tag( String t, boolean end ) { tag( t, end, null ) ; } private void tagged( String t, String s ) { tag( t, false ) ; append( s ) ; tag( t, true ) ; } public void beginHeadTitleBody( String t ) { if ( ! isOldHtml ) { tag( "!doctype", false, "html public \"-//w3c//dtd html 4.0 transitional//en\"" ) ; tag( "html", false ) ; tag( "head", false ) ; tag( "meta", false, "http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"" ) ; tag( "meta", false, "name=\"GENERATOR\" content=\"Simple Stack Machine, " + Config.version() + ", " + Config.versionDate() + "\"" ) ; tag( "title", false ) ; append( t ) ; tag( "title", true ) ; tag( "head", true ) ; } tag( "body", false ) ; } public void endHeadTitleBody() { tag( "body", true ) ; if ( ! isOldHtml ) { tag( "html", true ) ; } } private void beginA( String name, String href ) { beginTag( "a", false ) ; if ( href != null ) define( "href", href ) ; if ( name != null ) define( "name", name ) ; endTag() ; } private void endA() { tag( "a", true ) ; } public void anchor( String a ) { beginA( a, null ) ; endA( ) ; } public void a( String href, String title ) { beginA( null, href ) ; append( title ) ; endA( ) ; } public void anchorA( String href, String title ) { a( "#" + href, title ) ; } private void beginPara( String align ) { beginTag( "p", false ) ; if ( align != null ) define( "align", align ) ; endTag() ; } public void beginPara( ) { beginPara( null ) ; } public void endPara() { tag( "p", true ) ; } public void beginCentered( ) { beginPara( "center" ) ; } public void endCentered() { endPara() ; } public void beginSectionTitle() { tag( "h2", false ) ; } public void endSectionTitle() { tag( "h2", true ) ; } public void beginSubsectionTitle() { tag( "h3", false ) ; } public void endSubsectionTitle() { tag( "h3", true ) ; } public void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) { tag( "table", false, "BORDER COLS=" + nCols + " WIDTH=\"" + (widthPerc == 0 ? 100 : widthPerc) + "%\"" ) ; } public void endTable() { tag( "table", true ) ; } public void beginTableRow( ) { tag( "tr", false ) ; } public void endTableRow() { tag( "tr", true ) ; } public void beginTableData( ) { tag( "td", false ) ; } public void endTableData() { tag( "td", true ) ; } public void beginBlockQuote( ) { tag( "blockquote", false ) ; } public void endBlockQuote() { tag( "blockquote", true ) ; } public void linebreak() { tag( "br", false ) ; } private void font( String f, String s ) { tag( f, false ) ; append( s ) ; tag( f, true ) ; } public void bold( String s ) { font( "b", s ) ; } private void define( String nm, String val ) { append( " " ) ; append( nm ) ; append( "=" ) ; string( val ) ; } public void mathEquationList( Enumeration e, char subscript ) { for ( ; e.hasMoreElements() ; ) { append( ((String)e.nextElement()) ) ; if ( e.hasMoreElements() ) linebreak() ; } } public void beginAttributeList( ) { } public void endAttributeList( ) { } public void attributeName( String s ) { subsectionTitle( s ) ; } public void beginAttributeValue( ) { beginBlockQuote() ; } public void endAttributeValue( ) { endBlockQuote() ; } public void beginVerbatimList() { tag( "pre", false ) ; nl() ; } public void endVerbatimList() { tag( "pre", true ) ; nl() ; } public void verbatimLine( String s ) { append( s ) ; nl() ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; public class HelpHTMLAccumulator extends HelpAccumulator{ private boolean isOldHtml ; public HelpHTMLAccumulator( boolean old, String fileName ) { super( fileName ) ; isOldHtml = old ; } private void beginTag( String t, boolean end ) { append( '<' ) ; if ( end ) append( '/' ) ; append( t ) ; } private void endTag( ) { append( '>' ) ; } private void tag( String t, boolean end, String params ) { beginTag( t, end ) ; if ( params != null ) { append( " " ) ; append( params ) ; } endTag() ; } private void tag( String t, boolean end ) { tag( t, end, null ) ; } private void tagged( String t, String s ) { tag( t, false ) ; append( s ) ; tag( t, true ) ; } public void beginHeadTitleBody( String t ) { if ( ! isOldHtml ) { tag( "!doctype", false, "html public \"-//w3c//dtd html 4.0 transitional//en\"" ) ; tag( "html", false ) ; tag( "head", false ) ; tag( "meta", false, "http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"" ) ; tag( "meta", false, "name=\"GENERATOR\" content=\"Simple Stack Machine, " + Config.version() + ", " + Config.versionDate() + "\"" ) ; tag( "title", false ) ; append( t ) ; tag( "title", true ) ; tag( "head", true ) ; } tag( "body", false ) ; } public void endHeadTitleBody() { tag( "body", true ) ; if ( ! isOldHtml ) { tag( "html", true ) ; } } private void beginA( String name, String href ) { beginTag( "a", false ) ; if ( href != null ) define( "href", href ) ; if ( name != null ) define( "name", name ) ; endTag() ; } private void endA() { tag( "a", true ) ; } public void anchor( String a ) { beginA( a, null ) ; endA( ) ; } public void a( String href, String title ) { beginA( null, href ) ; append( title ) ; endA( ) ; } public void anchorA( String href, String title ) { a( "#" + href, title ) ; } private void beginPara( String align ) { beginTag( "p", false ) ; if ( align != null ) define( "align", align ) ; endTag() ; } public void beginPara( ) { beginPara( null ) ; } public void endPara() { tag( "p", true ) ; } public void beginCentered( ) { beginPara( "center" ) ; } public void endCentered() { endPara() ; } public void beginSectionTitle() { tag( "h2", false ) ; } public void endSectionTitle() { tag( "h2", true ) ; } public void beginSubsectionTitle() { tag( "h3", false ) ; } public void endSubsectionTitle() { tag( "h3", true ) ; } public void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) { tag( "table", false, "BORDER COLS=" + nCols + " WIDTH=\"" + (widthPerc == 0 ? 100 : widthPerc) + "%\"" ) ; } public void endTable() { tag( "table", true ) ; } public void beginTableRow( ) { tag( "tr", false ) ; } public void endTableRow() { tag( "tr", true ) ; } public void beginTableData( ) { tag( "td", false ) ; } public void endTableData() { tag( "td", true ) ; } public void beginBlockQuote( ) { tag( "blockquote", false ) ; } public void endBlockQuote() { tag( "blockquote", true ) ; } public void linebreak() { tag( "br", false ) ; } private void font( String f, String s ) { tag( f, false ) ; append( s ) ; tag( f, true ) ; } public void bold( String s ) { font( "b", s ) ; } private void define( String nm, String val ) { append( " " ) ; append( nm ) ; append( "=" ) ; string( val ) ; } public void mathEquationList( Enumeration e, char subscript ) { for ( ; e.hasMoreElements() ; ) { append( ((String)e.nextElement()) ) ; if ( e.hasMoreElements() ) linebreak() ; } } public void beginAttributeList( ) { } public void endAttributeList( ) { } public void attributeName( String s ) { subsectionTitle( s ) ; } public void beginAttributeValue( ) { beginBlockQuote() ; } public void endAttributeValue( ) { endBlockQuote() ; } public void beginVerbatimList() { tag( "pre", false ) ; nl() ; } public void endVerbatimList() { tag( "pre", true ) ; nl() ; } public void verbatimLine( String s ) { append( s ) ; nl() ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.io.* ; public class HelpLaTeXAccumulator extends HelpAccumulator{ public HelpLaTeXAccumulator( String fileName ) { super( fileName ) ; } private void beginEnv( String t, String param ) { macro( "begin", t ) ; if ( param != null ) bracket( param ) ; } private void beginEnv( String t ) { beginEnv( t, null ) ; } private void endEnv( String t ) { macro( "end", t ) ; } private void beginMath( ) { macro( "(" ) ; } private void endMath() { macro( ")" ) ; } private void beginParen( ) { append( '(' ) ; } private void endParen( ) { append( ')' ) ; } private void beginBracket( ) { append( '{' ) ; } private void endBracket( ) { append( '}' ) ; } private void bracket( String t ) { beginBracket( ) ; append( t ) ; endBracket() ; } private void beginMacro( String t ) { append( '\\' ) ; append( t ) ; beginBracket() ; } private void endMacro( ) { endBracket() ; } private void macro( String t, String a1 ) { append( '\\' ) ; append( t ) ; if ( a1 != null ) bracket( a1 ) ; else append( " " ) ; } private void macro( String t ) { macro( t, null ) ; } public void beginHeadTitleBody( String t ) { } public void endHeadTitleBody() { } public void anchor( String a ) { macro( "label", "ssmanchor:" + a ) ; macro( "Ix", a ) ; } public void a( String href, String title ) { append( title ) ; beginParen() ; macro( "Ref", href ) ; endParen() ; } public void anchorA( String href, String title ) { a( "ssmanchor:" + href, title ) ; } public void beginPara( ) { nl() ; nl() ; } public void endPara() { nl() ; nl() ; } public void beginCentered( ) { beginEnv( "center" ) ; } public void endCentered() { endEnv( "center" ) ; } public void beginSectionTitle() { beginMacro( "Sec" ) ; } public void endSectionTitle() { endMacro() ; } public void beginSubsectionTitle() { beginMacro( "Par" ) ; } public void endSubsectionTitle() { endMacro() ; } public void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) { int perc = Math.min( 99, widthPerc ) ; StringBuffer colFmt = new StringBuffer() ; colFmt.append( "l" ) ; beginEnv( "tabular*", "0." + perc + "\\textwidth" ) ; if ( colWidthWeight == null ) { colFmt.append( "l" + Utils.repeat( "p{0." + (perc / nCols) + "\\textwidth}", nCols ) ) ; } else { int sum = 0 ; for ( int i = 0 ; i < colWidthWeight.length ; i++ ) sum += colWidthWeight[ i ] ; for ( int i = 0 ; i < colWidthWeight.length ; i++ ) colFmt.append( "p{0." + (perc * colWidthWeight[ i ] / sum) + "\\textwidth}" ) ; } bracket( colFmt.toString() ) ; } public void endTable() { endEnv( "tabular*" ) ; } public void beginTableRow( ) { } public void endTableRow() { linebreak() ; } public void beginTableData( ) { append( "& " ) ; macro( "begingroup" ) ; macro( "raggedright" ) ; } public void endTableData() { macro( "endgroup" ) ; } public void beginBlockQuote( ) { } public void endBlockQuote() { } public void linebreak() { append( "\\\\" ) ; nl() ; } public void bold( String s ) { beginBracket() ; macro( "bf" ) ; append( s ) ; endBracket() ; } private final static int MATH_NORMAL = 0 ; private final static int MATH_SUBSCRIPT = 1 ; private void mathMangle( String s, char subscript ) { StreamTokenizer t = new StreamTokenizer( new StringReader( s ) ) ; t.resetSyntax() ; t.wordChars( 'a', 'z' ) ; t.wordChars( 'A', 'Z' ) ; int tok ; int state = MATH_NORMAL ; beginMath() ; try { while ( ( tok = t.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( tok == StreamTokenizer.TT_WORD ) { if ( state == MATH_SUBSCRIPT ) { bracket( t.sval ) ; state = MATH_NORMAL ; } else append( t.sval ) ; } else { if ( tok == subscript ) state = MATH_SUBSCRIPT ; if ( tok == '&' || tok == '%' ) append( '\\' ) ; append( (char)tok ) ; } } } catch ( IOException ex ) { append( ex.toString() ) ; } endMath() ; } public void mathEquationList( Enumeration e, char subscript ) { for ( ; e.hasMoreElements() ; ) { mathMangle( ((String)e.nextElement()), subscript ) ; if ( e.hasMoreElements() ) linebreak() ; } } public void beginAttributeList( ) { beginBracket() ; macro( "renewcommand", "\\arraystretch" ) ; bracket( "1.7" ) ; beginTable( 2, 90, new int[] {1,2} ) ; } public void endAttributeList( ) { endTable() ; endBracket() ; } public void attributeName( String s ) { beginTableRow() ; beginTableData() ; bold( s ) ; endTableData() ; } public void beginAttributeValue( ) { beginTableData() ; beginEnv( "minipage" ) ; append( "[t]" ) ; bracket( "0.6\\textwidth" ) ; } public void endAttributeValue( ) { endEnv( "minipage" ) ; endTableData() ; endTableRow() ; } public void beginVerbatimList() { beginEnv( "Verbatim" ) ; nl() ; } public void endVerbatimList() { endEnv( "Verbatim" ) ; nl() ; } public void verbatimLine( String s ) { append( s ) ; nl() ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.io.IOException;import java.io.StreamTokenizer;import java.io.StringReader;import java.util.Enumeration; public class HelpLaTeXAccumulator extends HelpAccumulator{ public HelpLaTeXAccumulator( String fileName ) { super( fileName ) ; } private void beginEnv( String t, String param ) { macro( "begin", t ) ; if ( param != null ) bracket( param ) ; } private void beginEnv( String t ) { beginEnv( t, null ) ; } private void endEnv( String t ) { macro( "end", t ) ; } private void beginMath( ) { macro( "(" ) ; } private void endMath() { macro( ")" ) ; } private void beginParen( ) { append( '(' ) ; } private void endParen( ) { append( ')' ) ; } private void beginBracket( ) { append( '{' ) ; } private void endBracket( ) { append( '}' ) ; } private void bracket( String t ) { beginBracket( ) ; append( t ) ; endBracket() ; } private void beginMacro( String t ) { append( '\\' ) ; append( t ) ; beginBracket() ; } private void endMacro( ) { endBracket() ; } private void macro( String t, String a1 ) { append( '\\' ) ; append( t ) ; if ( a1 != null ) bracket( a1 ) ; else append( " " ) ; } private void macro( String t ) { macro( t, null ) ; } public void beginHeadTitleBody( String t ) { } public void endHeadTitleBody() { } public void anchor( String a ) { macro( "label", "ssmanchor:" + a ) ; macro( "Ix", a ) ; } public void a( String href, String title ) { append( title ) ; beginParen() ; macro( "Ref", href ) ; endParen() ; } public void anchorA( String href, String title ) { a( "ssmanchor:" + href, title ) ; } public void beginPara( ) { nl() ; nl() ; } public void endPara() { nl() ; nl() ; } public void beginCentered( ) { beginEnv( "center" ) ; } public void endCentered() { endEnv( "center" ) ; } public void beginSectionTitle() { beginMacro( "Sec" ) ; } public void endSectionTitle() { endMacro() ; } public void beginSubsectionTitle() { beginMacro( "Par" ) ; } public void endSubsectionTitle() { endMacro() ; } public void beginTable( int nCols, int widthPerc, int[] colWidthWeight ) { int perc = Math.min( 99, widthPerc ) ; StringBuffer colFmt = new StringBuffer() ; colFmt.append( "l" ) ; beginEnv( "tabular*", "0." + perc + "\\textwidth" ) ; if ( colWidthWeight == null ) { colFmt.append( "l" + Utils.repeat( "p{0." + (perc / nCols) + "\\textwidth}", nCols ) ) ; } else { int sum = 0 ; for ( int i = 0 ; i < colWidthWeight.length ; i++ ) sum += colWidthWeight[ i ] ; for ( int i = 0 ; i < colWidthWeight.length ; i++ ) colFmt.append( "p{0." + (perc * colWidthWeight[ i ] / sum) + "\\textwidth}" ) ; } bracket( colFmt.toString() ) ; } public void endTable() { endEnv( "tabular*" ) ; } public void beginTableRow( ) { } public void endTableRow() { linebreak() ; } public void beginTableData( ) { append( "& " ) ; macro( "begingroup" ) ; macro( "raggedright" ) ; } public void endTableData() { macro( "endgroup" ) ; } public void beginBlockQuote( ) { } public void endBlockQuote() { } public void linebreak() { append( "\\\\" ) ; nl() ; } public void bold( String s ) { beginBracket() ; macro( "bf" ) ; append( s ) ; endBracket() ; } private final static int MATH_NORMAL = 0 ; private final static int MATH_SUBSCRIPT = 1 ; private void mathMangle( String s, char subscript ) { StreamTokenizer t = new StreamTokenizer( new StringReader( s ) ) ; t.resetSyntax() ; t.wordChars( 'a', 'z' ) ; t.wordChars( 'A', 'Z' ) ; int tok ; int state = MATH_NORMAL ; beginMath() ; try { while ( ( tok = t.nextToken() ) != StreamTokenizer.TT_EOF ) { if ( tok == StreamTokenizer.TT_WORD ) { if ( state == MATH_SUBSCRIPT ) { bracket( t.sval ) ; state = MATH_NORMAL ; } else append( t.sval ) ; } else { if ( tok == subscript ) state = MATH_SUBSCRIPT ; if ( tok == '&' || tok == '%' ) append( '\\' ) ; append( (char)tok ) ; } } } catch ( IOException ex ) { append( ex.toString() ) ; } endMath() ; } public void mathEquationList( Enumeration e, char subscript ) { for ( ; e.hasMoreElements() ; ) { mathMangle( ((String)e.nextElement()), subscript ) ; if ( e.hasMoreElements() ) linebreak() ; } } public void beginAttributeList( ) { beginBracket() ; macro( "renewcommand", "\\arraystretch" ) ; bracket( "1.7" ) ; beginTable( 2, 90, new int[] {1,2} ) ; } public void endAttributeList( ) { endTable() ; endBracket() ; } public void attributeName( String s ) { beginTableRow() ; beginTableData() ; bold( s ) ; endTableData() ; } public void beginAttributeValue( ) { beginTableData() ; beginEnv( "minipage" ) ; append( "[t]" ) ; bracket( "0.6\\textwidth" ) ; } public void endAttributeValue( ) { endEnv( "minipage" ) ; endTableData() ; endTableRow() ; } public void beginVerbatimList() { beginEnv( "Verbatim" ) ; nl() ; } public void endVerbatimList() { endEnv( "Verbatim" ) ; nl() ; } public void verbatimLine( String s ) { append( s ) ; nl() ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public interface HelpSupplier{ public Enumeration<String> getTopics() ; public String getHelpSupplierName() ; public String getShortSummaryForTopic( String topic ) ; public void getHelpForTopic( String topic, HelpAccumulator acc ) ; }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; public interface HelpSupplier{ public Enumeration<String> getTopics() ; public String getHelpSupplierName() ; public String getShortSummaryForTopic( String topic ) ; public void getHelpForTopic( String topic, HelpAccumulator acc ) ; }
\ No newline at end of file
......
This diff is collapsed.
This diff is collapsed.
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public class MachineState extends Model{ protected int stackBottom ; protected int stackGrowthDir ; protected int code ; protected int instrPC ; protected Instruction instr ; protected int nInlineOpnds ; protected int inlineOpnds[] ; protected Memory memory ; protected Registers registers ; protected MemoryUser memoryUser ; public boolean isHalted ; public MachineState( int initMemCapacity, Messenger m ) { memory = new Memory( initMemCapacity, m ) ; registers = new Registers( memory, m ) ; stackGrowthDir = 1 ; reset() ; } protected void fireStateChange( MachineStateEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MachineStateListener l = (MachineStateListener)e.nextElement() ; l.stateChanged( ev ) ; } } public void addMachineStateListener( MachineStateListener l ) { addListener( l ) ; } public void removeMachineStateListener( MachineStateListener l ) { removeListener( l ) ; } public void reset( ) { memory.reset() ; registers.reset() ; resetToInitialState() ; } public void resetToInitialState() { registers.setPC( 0 ) ; stackBottom = memory.getUsedForCode() + 16 ; registers.setSP( stackBottom - stackGrowthDir ) ; registers.setMP( registers.getSP() ) ; isHalted = false ; } public int dir( int v ) { return v * stackGrowthDir ; } public void setCurrentInstr( int pc, int code, Instruction instr ) { this.code = code ; instrPC = pc ; this.instr = instr ; nInlineOpnds = instr.getNrInlineOpnds() ; if ( nInlineOpnds > 0 ) inlineOpnds = new int[ nInlineOpnds ] ; } public Memory getMemory() { return memory ; } public int getStackBottom() { return stackBottom ; } public Registers getRegisters() { return registers ; } public boolean stackIsEmpty() { return stackBottom == registers.getSP() ; } public int stackTop() { return registers.getRegInd( registers.SP ) ; } public int getSR( ) { return stackIsEmpty() ? 0 : stackTop() ; } public String getSRAsString( ) { int sr = getSR() ; return "Z=" + ((sr & Instruction.ZZ) >> Instruction.SR_Z) + " C=" + ((sr & Instruction.CC) >> Instruction.SR_C) + " V=" + ((sr & Instruction.VV) >> Instruction.SR_V) + " N=" + ((sr & Instruction.NN) >> Instruction.SR_N) ; } class UndoStateModification implements Modification { private boolean wasHalted ; UndoStateModification( boolean h ) { wasHalted = h ; } public void modify() { isHalted = wasHalted ; } } public void setHalted() { isHalted = true ; fireStateChange( new MachineStateEvent( this, new UndoStateModification( false ) ) ) ; } public boolean isHalted() { return isHalted ; } public String toString() { return "state code=" + code + " instr-pc=" + instrPC + " n-inl=" + nInlineOpnds ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration; public class MachineState extends Model{ protected int stackBottom ; protected int stackGrowthDir ; protected int code ; protected int instrPC ; protected Instruction instr ; protected int nInlineOpnds ; protected int inlineOpnds[] ; protected Memory memory ; protected Registers registers ; protected MemoryUser memoryUser ; public boolean isHalted ; public MachineState( int initMemCapacity, Messenger m ) { memory = new Memory( initMemCapacity, m ) ; registers = new Registers( memory, m ) ; stackGrowthDir = 1 ; reset() ; } protected void fireStateChange( MachineStateEvent ev ) { for( Enumeration e = getListeners() ; e.hasMoreElements() ; ) { MachineStateListener l = (MachineStateListener)e.nextElement() ; l.stateChanged( ev ) ; } } public void addMachineStateListener( MachineStateListener l ) { addListener( l ) ; } public void removeMachineStateListener( MachineStateListener l ) { removeListener( l ) ; } public void reset( ) { memory.reset() ; registers.reset() ; resetToInitialState() ; } public void resetToInitialState() { registers.setPC( 0 ) ; stackBottom = memory.getUsedForCode() + 16 ; registers.setSP( stackBottom - stackGrowthDir ) ; registers.setMP( registers.getSP() ) ; isHalted = false ; } public int dir( int v ) { return v * stackGrowthDir ; } public void setCurrentInstr( int pc, int code, Instruction instr ) { this.code = code ; instrPC = pc ; this.instr = instr ; nInlineOpnds = instr.getNrInlineOpnds() ; if ( nInlineOpnds > 0 ) inlineOpnds = new int[ nInlineOpnds ] ; } public Memory getMemory() { return memory ; } public int getStackBottom() { return stackBottom ; } public Registers getRegisters() { return registers ; } public boolean stackIsEmpty() { return stackBottom == registers.getSP() ; } public int stackTop() { return registers.getRegInd( registers.SP ) ; } public int getSR( ) { return stackIsEmpty() ? 0 : stackTop() ; } public String getSRAsString( ) { int sr = getSR() ; return "Z=" + ((sr & Instruction.ZZ) >> Instruction.SR_Z) + " C=" + ((sr & Instruction.CC) >> Instruction.SR_C) + " V=" + ((sr & Instruction.VV) >> Instruction.SR_V) + " N=" + ((sr & Instruction.NN) >> Instruction.SR_N) ; } class UndoStateModification implements Modification { private boolean wasHalted ; UndoStateModification( boolean h ) { wasHalted = h ; } public void modify() { isHalted = wasHalted ; } } public void setHalted() { isHalted = true ; fireStateChange( new MachineStateEvent( this, new UndoStateModification( false ) ) ) ; } public boolean isHalted() { return isHalted ; } public String toString() { return "state code=" + code + " instr-pc=" + instrPC + " n-inl=" + nInlineOpnds ; } }
\ No newline at end of file
......
......@@ -8,7 +8,6 @@
package nl.uu.cs.ssm ;
import java.util.* ;
public class MachineStateEvent extends UndoableEvent
{
......
......@@ -8,7 +8,7 @@
package nl.uu.cs.ssm ;
import java.util.* ;
import java.util.EventListener;
public interface MachineStateListener extends EventListener
{
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public class Memory extends AbstractMemoryCellModel implements MemoryCellModel{ private int cells[] ; private Hashtable<Integer,Object> annotations ; private int nUsedForCode ; private Messenger messenger ; protected Memory( int initCapacity, Messenger m ) { messenger = m ; cells = new int[ initCapacity ] ; for ( int i = 0 ; i < cells.length ; i++ ) cells[ i ] = 0 ; reset() ; } public void reset() { nUsedForCode = 0 ; annotations = new Hashtable<Integer,Object>() ; for ( int i = 0 ; i < cells.length ; i++ ) setAt( i, 0 ) ; } public int getCapacity() { return cells.length ; } public int getUsedForCode() { return nUsedForCode ; } private boolean checkWithinMemory( int addr ) { boolean res ; if ( res = ( addr < 0 || addr >= cells.length ) ) { messenger.println ( java.text.MessageFormat.format ( "attempt to access location {0} outside {1}" , new Object[] { Utils.asHex(addr), ""+this } ) ) ; } return ! res ; } class UndoMemoryModification implements Modification { private int offset, value ; UndoMemoryModification( int o, int v ) { offset = o ; value = v ; } public void modify() { setAt( offset, value ) ; } } public void setAt( int addr, int v ) { if ( checkWithinMemory( addr ) ) { int oldv = cells[ addr ] ; cells[ addr ] = v ; fireCellChange( this, addr, oldv, new UndoMemoryModification( addr, oldv ) ) ; } } public void setAt( int addr, String v ) { setAt( addr, Utils.fromHex( v ) ) ; } public int getAt( int addr ) { int res = 0 ; if ( checkWithinMemory( addr ) ) { res = cells[ addr ] ; } return res ; } public int[] getAt( int addr, int len ) { int res[] = new int[ len ] ; for ( int i = 0 ; i < len && checkWithinMemory( addr + i ) ; i++ ) { res[ i ] = cells[ addr + i ] ; } return res ; } public String getAsHexAt( int addr ) { return Utils.asHex( getAt( addr ) ) ; } class UndoAnnotationModification implements Modification { private int offset ; private MemoryAnnotation value ; UndoAnnotationModification( int o, MemoryAnnotation v ) { offset = o ; value = v ; } public void modify() { setAnnotationAt( offset, value ) ; } } public void setAnnotationAt( int addr, MemoryAnnotation v ) { if ( checkWithinMemory( addr ) ) { //System.out.println( "mem set annote at " + addr + "=" + v ) ; Integer a = new Integer( addr ) ; Object oldv ; if ( v != null ) oldv = annotations.put( a, v ) ; else oldv = annotations.remove( a ) ; if ( oldv != v ) fireCellChange( this, addr, (MemoryAnnotation)oldv, new UndoAnnotationModification( addr, (MemoryAnnotation)oldv ) ) ; } } public MemoryAnnotation getAnnotationAt( int addr ) { MemoryAnnotation res ; res = (MemoryAnnotation)annotations.get( new Integer(addr) ) ; //System.out.println( "mem got annote at " + addr + "=" + res ) ; return res ; } public void ensureCapacity( int nCells ) { if ( nCells > (cells.length - nUsedForCode) ) { int newCells[] = new int[ 2 * (nCells + 10) + cells.length ] ; System.arraycopy( cells, 0, newCells, 0, cells.length ) ; cells = newCells ; } } public void deleteAt( int pos, int n ) { for( int i = pos + n ; i < nUsedForCode ; i++ ) cells[ i-n ] = cells[ i ] ; nUsedForCode -= n ; } public void reserveAt( int pos, int n ) { ensureCapacity( n ) ; for( int i = nUsedForCode - 1 ; i >= pos ; i-- ) { cells[ i+n ] = cells[ i ] ; } for( int i = 0 ; i < n ; i++ ) cells[ i+pos ] = 0 ; nUsedForCode += n ; } public void shiftAt( int pos, int n ) { if ( n > 0 ) reserveAt( pos, n ) ; else if ( n < 0 ) deleteAt( pos, -n ) ; } public void copyAt( int pos, int[] vals ) { for( int i = 0 ; i < vals.length ; i++ ) cells[ i+pos ] = vals[ i ] ; } public void insertAt( int pos, int[] vals ) { reserveAt( pos, vals.length ) ; copyAt( pos, vals ) ; } public String toString() { return "memory [0(" + Utils.asHex(nUsedForCode,false) + ").." + Utils.asHex(getCapacity()-1,false) + "]" ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Hashtable; public class Memory extends AbstractMemoryCellModel implements MemoryCellModel{ private int cells[] ; private Hashtable<Integer,Object> annotations ; private int nUsedForCode ; private Messenger messenger ; protected Memory( int initCapacity, Messenger m ) { messenger = m ; cells = new int[ initCapacity ] ; for ( int i = 0 ; i < cells.length ; i++ ) cells[ i ] = 0 ; reset() ; } public void reset() { nUsedForCode = 0 ; annotations = new Hashtable<Integer,Object>() ; for ( int i = 0 ; i < cells.length ; i++ ) setAt( i, 0 ) ; } public int getCapacity() { return cells.length ; } public int getUsedForCode() { return nUsedForCode ; } private boolean checkWithinMemory( int addr ) { boolean res ; if ( res = ( addr < 0 || addr >= cells.length ) ) { messenger.println ( java.text.MessageFormat.format ( "attempt to access location {0} outside {1}" , new Object[] { Utils.asHex(addr), ""+this } ) ) ; } return ! res ; } class UndoMemoryModification implements Modification { private int offset, value ; UndoMemoryModification( int o, int v ) { offset = o ; value = v ; } public void modify() { setAt( offset, value ) ; } } public void setAt( int addr, int v ) { if ( checkWithinMemory( addr ) ) { int oldv = cells[ addr ] ; cells[ addr ] = v ; fireCellChange( this, addr, oldv, new UndoMemoryModification( addr, oldv ) ) ; } } public void setAt( int addr, String v ) { setAt( addr, Utils.fromHex( v ) ) ; } public int getAt( int addr ) { int res = 0 ; if ( checkWithinMemory( addr ) ) { res = cells[ addr ] ; } return res ; } public int[] getAt( int addr, int len ) { int res[] = new int[ len ] ; for ( int i = 0 ; i < len && checkWithinMemory( addr + i ) ; i++ ) { res[ i ] = cells[ addr + i ] ; } return res ; } public String getAsHexAt( int addr ) { return Utils.asHex( getAt( addr ) ) ; } class UndoAnnotationModification implements Modification { private int offset ; private MemoryAnnotation value ; UndoAnnotationModification( int o, MemoryAnnotation v ) { offset = o ; value = v ; } public void modify() { setAnnotationAt( offset, value ) ; } } public void setAnnotationAt( int addr, MemoryAnnotation v ) { if ( checkWithinMemory( addr ) ) { //System.out.println( "mem set annote at " + addr + "=" + v ) ; Integer a = new Integer( addr ) ; Object oldv ; if ( v != null ) oldv = annotations.put( a, v ) ; else oldv = annotations.remove( a ) ; if ( oldv != v ) fireCellChange( this, addr, (MemoryAnnotation)oldv, new UndoAnnotationModification( addr, (MemoryAnnotation)oldv ) ) ; } } public MemoryAnnotation getAnnotationAt( int addr ) { MemoryAnnotation res ; res = (MemoryAnnotation)annotations.get( new Integer(addr) ) ; //System.out.println( "mem got annote at " + addr + "=" + res ) ; return res ; } public void ensureCapacity( int nCells ) { if ( nCells > (cells.length - nUsedForCode) ) { int newCells[] = new int[ 2 * (nCells + 10) + cells.length ] ; System.arraycopy( cells, 0, newCells, 0, cells.length ) ; cells = newCells ; } } public void deleteAt( int pos, int n ) { for( int i = pos + n ; i < nUsedForCode ; i++ ) cells[ i-n ] = cells[ i ] ; nUsedForCode -= n ; } public void reserveAt( int pos, int n ) { ensureCapacity( n ) ; for( int i = nUsedForCode - 1 ; i >= pos ; i-- ) { cells[ i+n ] = cells[ i ] ; } for( int i = 0 ; i < n ; i++ ) cells[ i+pos ] = 0 ; nUsedForCode += n ; } public void shiftAt( int pos, int n ) { if ( n > 0 ) reserveAt( pos, n ) ; else if ( n < 0 ) deleteAt( pos, -n ) ; } public void copyAt( int pos, int[] vals ) { for( int i = 0 ; i < vals.length ; i++ ) cells[ i+pos ] = vals[ i ] ; } public void insertAt( int pos, int[] vals ) { reserveAt( pos, vals.length ) ; copyAt( pos, vals ) ; } public String toString() { return "memory [0(" + Utils.asHex(nUsedForCode,false) + ").." + Utils.asHex(getCapacity()-1,false) + "]" ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.awt.* ; public class MemoryAnnotation extends ColoredText{ public MemoryAnnotation( String ann, Color col ) { super( ann, col ) ; } public String getAnnotation() { return getText() ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.awt.Color; public class MemoryAnnotation extends ColoredText{ public MemoryAnnotation( String ann, Color col ) { super( ann, col ) ; } public String getAnnotation() { return getText() ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; class MemoryCell{ private int value = 0 ; private String label = null ; protected MemoryCell( int v ) { setValue( v ) ; } protected MemoryCell( ) { } public int getValue() { return value ; } public int setValue( int v ) { return value = v ; } public int swapValue( int v ) { int oldv = value ; value = v ; return oldv ; } public String getLabel() { return label ; } public String setLabel( String v ) { return label = v ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; class MemoryCell{ private int value = 0 ; private String label = null ; protected MemoryCell( int v ) { setValue( v ) ; } protected MemoryCell( ) { } public int getValue() { return value ; } public int setValue( int v ) { return value = v ; } public int swapValue( int v ) { int oldv = value ; value = v ; return oldv ; } public String getLabel() { return label ; } public String setLabel( String v ) { return label = v ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public class MemoryCellEvent extends UndoableEvent{ private static final long serialVersionUID = 1L ; public static final int CELL = 0 ; public static final int ANNOTATION = 1 ; public int cellIndex ; public Object oldCellValue ; public int event ; protected MemoryCellEvent( Object src, int which, int previous, Modification mdf ) { super( src, mdf ) ; event = CELL ; cellIndex = which ; oldCellValue = new Integer( previous ) ; } protected MemoryCellEvent( Object src, int which, MemoryAnnotation previous, Modification mdf ) { super( src, mdf ) ; event = ANNOTATION ; cellIndex = which ; oldCellValue = previous ; } public int getCellIndex() { return cellIndex ; } public int getOldCellValue() { return ((Integer)oldCellValue).intValue() ; } public MemoryAnnotation getOldAnnotation() { return (MemoryAnnotation)oldCellValue ; } public String toString() { return "MemCellEvent src=" + getSource() + " inx=" + cellIndex + " prev=" + oldCellValue ; }}
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; public class MemoryCellEvent extends UndoableEvent{ private static final long serialVersionUID = 1L ; public static final int CELL = 0 ; public static final int ANNOTATION = 1 ; public int cellIndex ; public Object oldCellValue ; public int event ; protected MemoryCellEvent( Object src, int which, int previous, Modification mdf ) { super( src, mdf ) ; event = CELL ; cellIndex = which ; oldCellValue = new Integer( previous ) ; } protected MemoryCellEvent( Object src, int which, MemoryAnnotation previous, Modification mdf ) { super( src, mdf ) ; event = ANNOTATION ; cellIndex = which ; oldCellValue = previous ; } public int getCellIndex() { return cellIndex ; } public int getOldCellValue() { return ((Integer)oldCellValue).intValue() ; } public MemoryAnnotation getOldAnnotation() { return (MemoryAnnotation)oldCellValue ; } public String toString() { return "MemCellEvent src=" + getSource() + " inx=" + cellIndex + " prev=" + oldCellValue ; }}
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public interface MemoryCellListener extends EventListener{ public void cellChanged( MemoryCellEvent e ) ;}
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.EventListener; public interface MemoryCellListener extends EventListener{ public void cellChanged( MemoryCellEvent e ) ;}
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public abstract class MetaInstrInstantiator{ protected MetaInstrInstantiator() { } public abstract MetaInstruction instantiate( Instruction instr, Vector args ) ; public static MetaInstrInstantiator newAnnoteInstantiator() { return new MetaInstrInstantiator() { public MetaInstruction instantiate( Instruction instr, Vector args ) { return MetaInstruction.newAnnote( instr, args ) ; } } ; }}
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Vector; public abstract class MetaInstrInstantiator{ protected MetaInstrInstantiator() { } public abstract MetaInstruction instantiate( Instruction instr, Vector args ) ; public static MetaInstrInstantiator newAnnoteInstantiator() { return new MetaInstrInstantiator() { public MetaInstruction instantiate( Instruction instr, Vector args ) { return MetaInstruction.newAnnote( instr, args ) ; } } ; }}
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ;import java.awt.* ; public abstract class MetaInstruction{ private static Hashtable<String,Color> colorMap ; static { colorMap = new Hashtable<String,Color>() ; colorMap.put( "black" , Color.black ) ; colorMap.put( "blue" , Color.blue ) ; colorMap.put( "cyan" , Color.cyan ) ; colorMap.put( "darkGray" , Color.darkGray ) ; colorMap.put( "gray" , Color.gray ) ; colorMap.put( "green" , Color.green ) ; colorMap.put( "lightGray" , Color.lightGray ) ; colorMap.put( "magenta" , Color.magenta ) ; colorMap.put( "orange" , Color.orange ) ; colorMap.put( "pink" , Color.pink ) ; colorMap.put( "red" , Color.red ) ; colorMap.put( "yellow" , Color.yellow ) ; } protected Instruction instruction ; private MetaInstruction( Instruction instr ) { instruction = instr ; } public abstract void exec( MachineState machineState ) ; private static class Annote extends MetaInstruction { int register ; int loDispl, hiDispl ; Color color ; String text ; Annote( Instruction i, int r, int l, int h, Color c, String t ) { super( i ) ; register = r ; loDispl = l ; hiDispl = h ; color = c ; text = t ; } public void exec( MachineState machineState ) { Memory mem = machineState.getMemory() ; Registers regs = machineState.getRegisters() ; for ( int i = loDispl ; i <= hiDispl ; i++ ) { mem.setAnnotationAt( regs.getRegDispl( register, i ), new MemoryAnnotation( text, color ) ) ; } } public String toString() { return "Annote reg=" + register + " displ=" + loDispl + "/" + hiDispl + " col=" + color + " text=" + text ; } } public static MetaInstruction newAnnote( Instruction instr, Vector args ) { int r = Registers.findRegOfName( (String)args.elementAt(0) ) ; int l = Utils.fromHex( (String)args.elementAt(1) ) ; int h = Utils.fromHex( (String)args.elementAt(2) ) ; Color c = (Color)colorMap.get( (String)args.elementAt(3) ) ; String t = (String)args.elementAt(4) ; if ( r >= 0 && l <= h && c != null && t != null ) return new Annote( instr, r, l, h, c, t ) ; else return null ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.awt.Color;import java.util.Hashtable;import java.util.Vector; public abstract class MetaInstruction{ private static Hashtable<String,Color> colorMap ; static { colorMap = new Hashtable<String,Color>() ; colorMap.put( "black" , Color.black ) ; colorMap.put( "blue" , Color.blue ) ; colorMap.put( "cyan" , Color.cyan ) ; colorMap.put( "darkGray" , Color.darkGray ) ; colorMap.put( "gray" , Color.gray ) ; colorMap.put( "green" , Color.green ) ; colorMap.put( "lightGray" , Color.lightGray ) ; colorMap.put( "magenta" , Color.magenta ) ; colorMap.put( "orange" , Color.orange ) ; colorMap.put( "pink" , Color.pink ) ; colorMap.put( "red" , Color.red ) ; colorMap.put( "yellow" , Color.yellow ) ; } protected Instruction instruction ; private MetaInstruction( Instruction instr ) { instruction = instr ; } public abstract void exec( MachineState machineState ) ; private static class Annote extends MetaInstruction { int register ; int loDispl, hiDispl ; Color color ; String text ; Annote( Instruction i, int r, int l, int h, Color c, String t ) { super( i ) ; register = r ; loDispl = l ; hiDispl = h ; color = c ; text = t ; } public void exec( MachineState machineState ) { Memory mem = machineState.getMemory() ; Registers regs = machineState.getRegisters() ; for ( int i = loDispl ; i <= hiDispl ; i++ ) { mem.setAnnotationAt( regs.getRegDispl( register, i ), new MemoryAnnotation( text, color ) ) ; } } public String toString() { return "Annote reg=" + register + " displ=" + loDispl + "/" + hiDispl + " col=" + color + " text=" + text ; } } public static MetaInstruction newAnnote( Instruction instr, Vector args ) { int r = Registers.findRegOfName( (String)args.elementAt(0) ) ; int l = Utils.fromHex( (String)args.elementAt(1) ) ; int h = Utils.fromHex( (String)args.elementAt(2) ) ; Color c = (Color)colorMap.get( (String)args.elementAt(3) ) ; String t = (String)args.elementAt(4) ; if ( r >= 0 && l <= h && c != null && t != null ) return new Annote( instr, r, l, h, c, t ) ; else return null ; } }
\ No newline at end of file
......
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.* ; public class Model{ private Vector<EventListener> listeners = new Vector<EventListener>() ; protected void addListener( EventListener l ) { listeners.addElement( l ) ; } protected void removeListener( EventListener l ) { listeners.removeElement( l ) ; } protected Enumeration getListeners() { return listeners.elements() ; } }
\ No newline at end of file
/** * Simple Stack Machine * * Written by Atze Dijkstra, atze@cs.uu.nl, * Copyright Utrecht University. * */ package nl.uu.cs.ssm ; import java.util.Enumeration;import java.util.EventListener;import java.util.Vector; public class Model{ private Vector<EventListener> listeners = new Vector<EventListener>() ; protected void addListener( EventListener l ) { listeners.addElement( l ) ; } protected void removeListener( EventListener l ) { listeners.removeElement( l ) ; } protected Enumeration getListeners() { return listeners.elements() ; } }
\ No newline at end of file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment