Skip to content
This repository
Browse code

Add initial version of debugger support

Use Rubinus::Debugger but provide some fancy-specific output on method
names / signatures etc.
  • Loading branch information...
commit 23d767231388bf304d6269149649c55dfc7caaa4 1 parent 483730d
Christopher Bertels authored June 03, 2012
5  lib/main.fy
@@ -21,6 +21,7 @@ if: (ARGV size == 1) then: {
21 21
      "  -e 'command'            One line of Fancy code that gets evaluated immediately",
22 22
      "  -c [filenames]          Compile given files to Rubinius bytecode",
23 23
      "  -cv [filenames]         Compile given files to Rubinius bytecode verbosely (outputting the generated bytecode)",
  24
+     "  -debug                  Start the Rubinius Debugger with Fancy",
24 25
      "",
25 26
      "Fancy package management:",
26 27
      "  install   [packagename] Install a Fancy package with a given name to $FANCYPACK_DIR",
@@ -65,6 +66,10 @@ ARGV for_option: "-cv" do: {
65 66
   System exit
66 67
 }
67 68
 
  69
+ARGV for_option: "-debug" do: {
  70
+  require: "rbx/debugger"
  71
+}
  72
+
68 73
 ARGV for_option: "install" do: |package_name| {
69 74
   match package_name {
70 75
     case "--deps" -> Fancy Package install_dependencies
1  lib/rbx.fy
@@ -42,3 +42,4 @@ require: "rbx/actor"
42 42
 require: "rbx/mutex"
43 43
 require: "rbx/module"
44 44
 require: "rbx/proc"
  45
+require: "rbx/compiled_method"
14  lib/rbx/compiled_method.fy
... ...
@@ -0,0 +1,14 @@
  1
+class Rubinius CompiledMethod {
  2
+  forwards_unary_ruby_methods
  3
+
  4
+  def selectors_with_args {
  5
+    local_names = local_names to_a
  6
+    if: (required_args > 0) then: {
  7
+      name to_s split: ":" . map_with_index: |sel i| {
  8
+        "#{sel}: #{local_names[i]}"
  9
+      } . join: " "
  10
+    } else: {
  11
+      name to_s rest
  12
+    }
  13
+  }
  14
+}
72  lib/rbx/debugger.fy
... ...
@@ -0,0 +1,72 @@
  1
+require("rubinius/debugger")
  2
+
  3
+class Rubinius Debugger {
  4
+  forwards_unary_ruby_methods
  5
+  metaclass forwards_unary_ruby_methods
  6
+}
  7
+
  8
+class Rubinius Debugger Command SetBreakPoint {
  9
+  def match_method: method_identifier {
  10
+    match method_identifier {
  11
+      case /##/ ->
  12
+        class_name, method_name = method_identifier split: "##"
  13
+        method_identifier = "#{class_name}::#{method_name message_name}"
  14
+      case /#/ ->
  15
+        class_name, method_name = method_identifier split: "#"
  16
+        method_identifier = "#{class_name}##{method_name message_name}"
  17
+    }
  18
+
  19
+    /([A-Z]\w*(?:::[A-Z]\w*)*)([.#]|::)([a-zA-Z0-9_\[\]:]+[!?=]?)(?:[:](\d+))?/ match: method_identifier
  20
+  }
  21
+
  22
+  alias_method('match_method, 'match_method:)
  23
+}
  24
+
  25
+class Rubinius Location {
  26
+  forwards_unary_ruby_methods
  27
+}
  28
+
  29
+class Rubinius Debugger Frame {
  30
+  forwards_unary_ruby_methods
  31
+
  32
+  def describe {
  33
+    arg_str = ""
  34
+    recv = nil
  35
+    signature = method selectors_with_args
  36
+
  37
+    loc = @location
  38
+
  39
+    if: (loc is_block) then: {
  40
+      if: (method required_args == 0) then: {
  41
+        recv = "{ } in #{loc describe_receiver}#{loc name}"
  42
+      } else: {
  43
+        block_args = method local_names join: ", "
  44
+        recv = "|#{block_args}| { } in #{loc describe_receiver}#{loc name}"
  45
+      }
  46
+    } else: {
  47
+      if: (method required_args == 0) then: {
  48
+        recv = loc describe
  49
+      } else: {
  50
+        recv = "#{loc describe}"
  51
+      }
  52
+    }
  53
+
  54
+    recv = recv replace: "#:" with: "#"
  55
+    recv = recv replace: ".:" with: "##"
  56
+    recv = recv replace: "." with: "##"
  57
+
  58
+    str = "#{recv} at #{loc method active_path}:#{loc line} (#{loc ip})"
  59
+    { str << " (+#{loc ip})" } if: $ @debugger variables['show_ip]
  60
+    str
  61
+  }
  62
+
  63
+  alias_method('describe, ':describe)
  64
+
  65
+  def run: code {
  66
+    Fancy eval: (code to_s) binding: binding
  67
+  }
  68
+
  69
+  alias_method('run, 'run:)
  70
+}
  71
+
  72
+Rubinius Debugger start

0 notes on commit 23d7672

Please sign in to comment.
Something went wrong with that request. Please try again.