[mercury-users] Premature exit from pragma c_code pred/func?

Warwick Harvey wharvey at cs.monash.edu.au
Tue Nov 30 17:24:01 AEDT 1999


Hi,

Is it possible (in a det/semidet context) to exit prematurely from a `pragma 
c_code' definition of a predicate/function?  That is, to do something 
analogous to inserting a `return' in the middle of a normal C function?

I'm trying to convert a C function into a `pragma c_code' implementation of 
a Mercury function.  The basic structure of the body of the function is:

	...
	while (...) {
		...
		if (...) {
			...
			return ...
		}
		...
	}
	...
	return ...

It's not that one exit succeeds and the other fails, but rather that 
constructing the return result depends on whether a search was successful or 
not.

Of course I can rewrite the code to only have one exit point, but it would 
be convenient if I didn't have to do that, and the resulting code would 
probably be more efficient (modulo my limited understanding of how this 
stuff works).

There may be something in the compiler already that allows this, but I 
couldn't find it.  If not, I don't know how much work it would be.  
(Defining a new label and a macro for branching to it?  Any inlining 
issues?).  Anyway, if it were to be added, it would have to wait 'til after 
0.9 is released, right?

I suppose another work around (to avoid rewriting the function) is to 
introduce my own label at the end and branch to it, making sure I `pragma 
no_inline' the function.

Cheers,
Warwick

--------------------------------------------------------------------------
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