[mercury-users] XML Parsing

Thomas Conway conway at cs.mu.OZ.AU
Wed Jun 6 09:41:52 AEST 2001

On Tue, Jun 05, 2001 at 10:54:33PM EST, Ralph Becket wrote:
> I'm not clear why HO calls should be so much more expensive, given that
> Mercury doesn't have full currying.  I would have thought that setting 
> up arguments would be much the same, but performing the call jump would 
> require a level of indirection to find the call target.  What *is* the
> HO call process, out of interest?

Here's some pseudocode for how call/N is implemented in the
low-level backend. Obviously the highlevel backend will do
something different.

    % r1 contains the closure
    % r2 contains the number of additional literal input arguments
    % r3... contain the literal input arguments

    t1 = r1;
    t2 = r2;

    % shift the literal arguments to
    % make room for the curried ones
    for (t3 = 0; t3 < t2; t3++)
    	r[t1->num_curried_args + t3] = r[3 + t3];

    % copy in the curried arguments
    for (t3 = 0; t3 < t1->num_curried_args; t3++)
    	r[t3 + 1] = t1->curried_args[t3];

    goto t1->procedure_entry;

So, we can imagine a closure having something like
the following struct declaration:

typedef struct
    Code procedure_entry;
    int num_curried_args;
    Word curried_args[1];
} Closure;

Note that closures are a variable sized strucutre.

> As for the XML parser, maybe we'll just have to bite the bullet and
> recode it for moose if we want speed (assuming the overhead for
> parser combinators is insurmountable).

I've yet to see a yacc grammar for XML anywhere.
I'd have to think about it, but I don't think it
would be too hard. SGML is another matter entirely
of course, since you can't parse SGML without
validating at the same time, unless you resort
to "tag soup" parsing.

  Thomas Conway )O+
 <conway at cs.mu.oz.au>       499 User error! Replace user, and press any key.
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list