[m-dev.] draft ssdb transformation proposal

Peter Wang novalazy at gmail.com
Wed Oct 3 10:48:28 AEST 2007


Proposed transformation:

original:

    p(...) :-
        <original body>

model_det transformed:

    p(...) :-
        promise_<original_purity> (
            CallVarDescs = [ ... ],
            impure call_port(ProcId, CallVarDescs),
            <original body>,    % renaming outputs
            ExitVarDescs = [ ... | CallVarDescs ],
            impure exit_port(ProcId, ExitVarDescs, DoRetry),
            (
                DoRetry = do_retry,
                p(...)
            ;
                DoRetry = do_not_retry,
                % bind outputs
            )
        ).

model_semi transformed:

    p(...) :-
        promise_<original_purity> (
            CallVarDescs = [ ... ],
            (
                impure call_port(ProcId, CallVarDescs),
                <original body>    % renaming outputs
            ->
                ExitVarDescs = [ ... | CallVarDescs ],
                impure exit_port(ProcId, ExitVarDescs, DoRetryA),
                (
                    DoRetryA = do_retry,
                    p(...)
                ;
                    DoRetryA = do_not_retry,
                    % bind outputs
                )
            ;
                impure fail_port(ProcId, CallVarDescs, DoRetryB),
                (
                    DoRetryB = do_retry,
                    p(...)
                ;
                    DoRetryB = do_not_retry,
                    fail
                )
            )
        ).

model_non transformed:

    p(...) :-
        promise_<original_purity> (
            (
                CallVarDescs = [ ... ],
                impure call_port(ProcId, CallVarDescs),
                <original body>,    % renaming outputs
                ExitVarDescs = [ ... | CallVarDescs ],
                (
                    impure exit_port(ProcId, ExitVarDescs, DoRetryA),
                    (
                        DoRetryA = do_retry,
                        p(...)
                        % Will give same result as long as p is pure or
                        % semipure.  Retry of impure procedures should probably
                        % be disallowed anyway.
                    ;
                        DoRetryB = do_not_retry,
                        % bind outputs
                    )
                ;
                    % preserve_backtrack_into,
                    impure redo_port(ProcId, ExitVarDescs),
                    fail
                )
            ;
                % preserve_backtrack_into
                impure fail_port(ProcId, CallVarDescs, DoRetryB),
                (
                    DoRetryB = do_retry,
                    p(...)
                ;
                    DoRetryB = do_not_retry,
                    fail
                )
            )
        ).

where CallVarDescs, ExitVarDescs are lists of var_value

    :- type var_value
        --->    unbound_head_var(var_name, pos)
        ;       some [T] bound_head_var(var_name, pos, T)
        ;       some [T] bound_other_var(var_name, T).

    :- type var_name == string.

    :- type pos == int.

Output head variables may appear twice in a variable description list --
initially unbound, then overridden by a bound_head_var functor.  Then the
ExitVarDescs can add output variable bindings to the CallVarDescs list, instead
of building new lists.  The pos fields give the argument numbers of head
variables.

I'm not sure whether variables names should include their unique numbers
or not.

Not sure whether proc_id should be structured or a string

    proc_id(module_name, name, pred_or_func, arity)

-------------------------------------------------------------------------------

In each shadow stack frame we would keep the

    proc id
    event number of the CALL event
    call sequence number
    variable description list

-------------------------------------------------------------------------------

STEP 1

Initially transform det procedures to call call_port and exit_port procedures,
with empty variable desc lists.  Then, add in the code to generate the variable
description lists.

We need to add a new grade component, initially .ssdb, and set up the
infrastructure to hold the ssdb code.

The ssdb should be able to step through a toy det program, with approximately
the following commands:

    step
    next
    print
    retry
    stack
    down
    up

STEP 2

Add the transformation for semidet procedures.

STEP 3

Add the transformation for nondet procedures.

FURTHER WORK

break points
finish
step N
retry N
enable
disable
browse
quit

internal events

different tracing levels


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



More information about the developers mailing list