[m-rev.] diff: browser changes for ssdb

Peter Wang novalazy at gmail.com
Wed May 12 12:04:45 AEST 2010


Branches: main, 10.04

browser/util.m:
        Implement fallback versions of `call_trace_getline' and
        `trace_get_command' for non-C grades.

ssdb/ssdb.m:
        Support `browse N' command, where N is a variable number.

diff --git a/browser/util.m b/browser/util.m
index f6a6ae5..410652a 100644
--- a/browser/util.m
+++ b/browser/util.m
@@ -125,8 +125,21 @@ trace_getline(Prompt, Result, MdbIn, MdbOut, !IO) :-
     IO = IO0;
 ").
 
-call_trace_getline(_, _, _, _, _, !IO) :-
-    private_builtin.sorry("mdb.call_trace_getline").
+call_trace_getline(MdbIn, MdbOut, Prompt, Line, Success, !IO) :-
+    io.write_string(MdbOut, Prompt, !IO),
+    io.flush_output(MdbOut, !IO),
+    io.read_line_as_string(MdbIn, Result, !IO),
+    (
+        Result = ok(Line),
+        Success = 1
+    ;
+        Result = eof,
+        Line = "",
+        Success = 0
+    ;
+        Result = error(Error),
+        error("call_trace_getline: " ++ io.error_message(Error))
+    ).
 
 trace_get_command(Prompt, Result, !IO) :-
     io.input_stream(MdbIn, !IO),
@@ -157,8 +170,8 @@ trace_get_command(Prompt, Result, !IO) :-
     State = State0;
 ").
 
-trace_get_command(_, _, _, _, !IO) :-
-    private_builtin.sorry("mdb.trace_get_command/6").
+trace_get_command(Prompt, Line, MdbIn, MdbOut, !IO) :-
+    trace_get_command_fallback(Prompt, Line, MdbIn, MdbOut, !IO).
 
     % This is called by trace_get_command when the trace library is not linked
     % in.
diff --git a/ssdb/ssdb.m b/ssdb/ssdb.m
index 0327c0d..17b41bf 100755
--- a/ssdb/ssdb.m
+++ b/ssdb/ssdb.m
@@ -1466,37 +1466,19 @@ execute_ssdb_print(Args, Event, ShadowStack, Depth, WhatNext, !IO) :-
 
 execute_ssdb_browse(Args, Event, ShadowStack, Depth, WhatNext, !IO) :-
     (
-        Args = [],
-        % We should provide more detailed help.
-        print_help(!IO),
-        read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO)
-    ;
         Args = [VarName],
-        (
             get_correct_frame_with_num(0, ShadowStack, CurFrame),
             ListVarValue = CurFrame ^ se_list_var_value,
-            list_var_value_to_assoc_list(ListVarValue, AssListVarValue),
-            assoc_list.search(AssListVarValue, VarName, Univ)
-        ->
-            io.stdin_stream(StdIn, !IO),
-            io.stdout_stream(StdOut, !IO),
-            browser_info.init_persistent_state(State0),
-            BT = browser_term.univ_to_browser_term(Univ),
-            promise_equivalent_solutions [!:IO] (
-                browse.browse_browser_term_no_modes(BT, StdIn, StdOut, _,
-                State0, _State1, !IO)
-            ),
-            read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO)
+        list_var_value_to_assoc_list(ListVarValue, VarDescs),
+        browse_var(VarDescs, VarName, !IO)
         ;
-            io.format("There is no variable named `%s'.\n", [s(VarName)], !IO),
-            read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO)
-        )
-    ;
-        Args = [_, _ | _],
+        ( Args = []
+        ; Args = [_, _ | _]
+        ),
         % We should provide more detailed help.
-        print_help(!IO),
-        read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO)
-    ).
+        print_help(!IO)
+    ),
+    read_and_execute_cmd(Event, ShadowStack, Depth, WhatNext, !IO).
 
 :- pred execute_ssdb_vars(list(string)::in, ssdb_event_type::in,
     stack(stack_elem)::in, int::in, what_next::out, io::di, io::uo) is det.
@@ -1972,6 +1954,8 @@ print_help(!IO) :-
     io.write_string("\n<print> or <p>", !IO),
     io.write_string("\n<print VAR> or <p VAR>", !IO),
     io.write_string("\n<print N> or <p N>", !IO),
+    io.write_string("\n<browse VAR>", !IO),
+    io.write_string("\n<browse N>", !IO),
     io.write_string("\n<vars> or <v>", !IO),
     io.write_string("\n<stack> or <st>", !IO),
     io.write_string("\n<up> or <u>", !IO),
@@ -2146,6 +2130,41 @@ get_var_name(bound_other_var(Name, _)) = Name.
 
 %-----------------------------------------------------------------------------%
 
+:- pred browse_var(assoc_list(string, univ)::in, string::in, io::di, io::uo)
+    is det.
+
+browse_var(VarDescs, VarName, !IO) :-
+    (
+        string.to_int(VarName, VarNum),
+        VarNum > 0
+    ->
+        ( list.index1(VarDescs, VarNum, _ - Univ) ->
+            browse_univ(Univ, !IO)
+        ;
+            io.write_string("ssdb: there aren't that many variables.\n", !IO)
+        )
+    ;
+        assoc_list.search(VarDescs, VarName, Univ)
+    ->
+        browse_univ(Univ, !IO)
+    ;
+        io.write_string("ssdb: there is no such variable.\n", !IO)
+    ).
+
+:- pred browse_univ(univ::in, io::di, io::uo) is det.
+
+browse_univ(Univ, !IO) :-
+    io.stdin_stream(StdIn, !IO),
+    io.stdout_stream(StdOut, !IO),
+    browser_info.init_persistent_state(State0),
+    BT = browser_term.univ_to_browser_term(Univ),
+    promise_equivalent_solutions [!:IO] (
+        browse.browse_browser_term_no_modes(BT, StdIn, StdOut, _,
+        State0, _State1, !IO)
+    ).
+
+%-----------------------------------------------------------------------------%
+
 :- pred print_vars_list(list(var_value)::in, int::in, io::di, io::uo) is det.
 
 print_vars_list([], _, !IO).

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list