Commits

Anonymous committed c89887d

Added basic debugger integration.

  • Participants
  • Parent commits 6bedcee

Comments (0)

Files changed (2)

src/org/lispdev/repl/AbstractRepl.java

     }
   }
 
+  private class DebugRunnable extends SwankRunnable
+  {
+    private final AbstractRepl repl;
+
+    public DebugRunnable(AbstractRepl r)
+    {
+      repl = r;
+    }
+
+    @Override
+    public void run()
+    {
+      String key = result.get(1).value + ":" + result.get(2).value;
+      System.out.println("*debug found: " + key + "->" + debugInfos.get(key));
+      pushDebugState(debugInfos.get(key));
+    }
+  }
+
+  private void pushDebugState(LispNode debugInfo)
+  {
+    DebugState state = new DebugState(this, debugInfo);
+    System.out.println("currState:" + currState());
+    if( !currState().equals(state) )
+    {
+      pushState(state);
+    }
+  }
+
   private final SwankDisplayRunnable displayRunnable =
     new SwankDisplayRunnable(this);
   private final ReadRunnable readRunnable = new ReadRunnable(this);
     new DisconnectRunnable(this);
   private final DebugInfoRunnable debugInfoRunnable =
     new DebugInfoRunnable();
+  private final DebugRunnable debugRunnable =
+    new DebugRunnable(this);
 
   public AbstractRepl(ISwank s)
   {
     swank.addListener(SwankEvent.READ_STRING, readRunnable);
     swank.addListener(SwankEvent.DISCONNECT, disconnectRunnable);
     swank.addListener(SwankEvent.DEBUG, debugInfoRunnable);
+    swank.addListener(SwankEvent.DEBUG_ACTIVATE, debugRunnable);
   }
 
   public abstract void appendOut(String text);
   public abstract void disconnecting();
   public abstract void connected();
   public abstract void connecting();
+  public abstract void startDebug(LispNode debugInfo);
+  public abstract void debugStoped();
 
   private void pushState(IState s)
   {
     if( states.size() > 1 )
     {
       // Assuming anything above one is a debug state?
-//      if( currState() instanceof DebugState )
-//      {
-//        ((DebugState)currState()).deactivate();
-//      }
+      if( currState() instanceof DebugState )
+      {
+        ((DebugState)currState()).deactivate();
+      }
     }
     states.push(s);
     currState().activate();
     }
   }
 
-
 }

src/org/lispdev/repl/DebugState.java

+package org.lispdev.repl;
+
+import org.lispdev.swank.LispNode;
+
+public class DebugState implements IState
+{
+  private final AbstractRepl repl;
+  private final LispNode desc, options, backtrace, debugInfo;
+  private final String thread, level;
+
+  public DebugState(AbstractRepl r, LispNode debugInfo)
+  {
+    repl = r;
+    this.debugInfo = debugInfo;
+    thread = debugInfo.get(1).value;
+    level = debugInfo.get(2).value;
+
+    desc = debugInfo.get(3);
+    options = debugInfo.get(4);
+    backtrace = debugInfo.get(5);
+  }
+
+  @Override
+  public boolean equals(Object obj)
+  {
+    if( obj instanceof DebugState )
+    {
+      DebugState state = (DebugState)obj;
+      return (thread.equals(state.thread) && level.equals(state.level));
+    }
+    return false;
+  }
+
+  @Override
+  public void activate()
+  {
+    repl.startDebug(debugInfo);
+  }
+
+  public void deactivate()
+  {
+    repl.debugStoped();
+  }
+
+  @Override
+  public boolean handle(String command)
+  {
+    return false;
+  }
+
+}