1. John Eriksson
  2. migol

Commits

John Eriksson  committed bea5f45

Added a debug mode for I/O

  • Participants
  • Parent commits 8d6cc1a
  • Branches default

Comments (0)

Files changed (7)

File se/psilon/migomipo/migol2/LabelValue.java

View file
  • Ignore whitespace
     public LabelValue(String label) {
         this.label = label;
     }
-
-    public void resolve(Map<String, Integer> vars){
-        value = IntegerValue.getInstance(vars.get(label).intValue());
-    }
-    
+       
     public int get(MigolExecutionSession session) throws MigolExecutionException {
         return value.get(session);
     }

File se/psilon/migomipo/migol2/MigolExecutionSession.java

View file
  • Ignore whitespace
 
 import se.psilon.migomipo.migol2.io.*;
 import java.util.*;
-import se.psilon.migomipo.migol2.*;
 import java.util.concurrent.LinkedBlockingQueue;
 
 /**
     private int result = -1;
     private int handler = -1;
     private boolean isInterruptMode = false;
+    private boolean debug = false;
     
     private boolean pplocked = false;
     private LinkedBlockingQueue<Integer> results = new LinkedBlockingQueue<Integer>();
         this.waitInterrupt = waitInterrupt;
     }
 
+    public boolean isDebugMode() {
+        return debug;
+    }
+
+    public void setDebugMode(boolean debug) {
+        this.debug = debug;
+    }
+    
+    
+
 
     /**
      * Executes the program with the given session.

File se/psilon/migomipo/migol2/io/FileOperationManager.java

View file
  • Ignore whitespace
 
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (IllegalArgumentException ex) {
                 error = 2;
             } catch (NegativeArraySizeException ex) {
                 error = 4;
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {
                 error = 2;
             }
                 error = 4;
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {
                 error = 2;
             }
                 error = 4;
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {
                 error = 2;
             }

File se/psilon/migomipo/migol2/io/IOManager.java

View file
  • Ignore whitespace
 
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {                
                 error = 2;
             } catch(IllegalArgumentException ex){
 
             } catch (IOException ex) {
                 error = 1;
-
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {
                 error = 2;
             } catch(IllegalArgumentException ex){
                 channel.close();
             } catch (IOException ex) {
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (NullPointerException ex) {
                 error = 2;
             } catch(ClassCastException ex){

File se/psilon/migomipo/migol2/io/SocketManager.java

View file
  • Ignore whitespace
                 handle = io.addObject(ch);
                 
             } catch (IOException ex) {
-                error = 1;                
+                error = 1; 
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch (IllegalArgumentException ex){
                 error = 3;
             }
                 }
             } catch(UnknownHostException ex){
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             }
             mem[structPos + 4] = error;
             mem[structPos + 5] = mode;
                 handle = io.addObject(server);
             } catch(IOException ex){
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch(NullPointerException ex){
                 error = 2;
             } catch(IllegalArgumentException ex){
                 handle = io.addObject(channel);
             } catch(IOException ex){
                 error = 1;
+                if(session.isDebugMode()){
+                    ex.printStackTrace();
+                }
             } catch(NullPointerException ex){
                 error = 2;
             } catch(ClassCastException ex){

File se/psilon/migomipo/migol2/parse/MigolParser.java

View file
  • Ignore whitespace
 
         private void resolve(Map<String, Integer> constants) throws MigolParsingException {
             try {
-                value.resolve(constants);
+                String label = value.getLabel();
+                value.setValue(IntegerValue.getInstance(constants.get(label).intValue()));
+                
             } catch (NullPointerException ex) {
                 throw new MigolParsingException("Undefined label", cLine, linenum, strpos);
             }

File switest.mgl

View file
  • Ignore whitespace
-20<11, 21<2, 22<30, 23<5
+100<'H,101<'e,102<'l,103<'l,104<'o,105<',,106<' ,107<'W,108<'o,109<'r,110<'l,111<'d,112<'! 
+// Output buffer
 
-30<'H, 31<'e, 32<'l, 33<'l, 34<'o, 35<10
+!#<handler
+2<0 // I/O completion flag
+20<11 // Write operation (11)
+21<2 // I/O handle (2 = STDOUT)
+22<100 // Buffer address
+23<13 // Buffer length
 
-!#<Handle
+!<20 // Start output operation
+\<1?<>[2] // Block until operation has completed
+#<$-1?<>[2]
+#<30000 // End program
 
-!<20
+2<1:handler // sets I/O completion flag
+#!<[*#] // ..and returns. No error numbers are checked
 
-'a>
 
-#<eof
 
-_:Handle
-'b>
-#!<[*#]
 
-_:eof