info-gnuprologjava
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Info-gnuprologjava] Adding hooks for executing code when frames are bei


From: Matt Lilley
Subject: [Info-gnuprologjava] Adding hooks for executing code when frames are being discarded
Date: Wed, 14 Dec 2011 11:27:03 +1300

Hello,

I'm trying to implement setup_call_cleanup/3 [1] in GNU Prolog for Java so that I can port some code from SWI Prolog to GNU Prolog for Java.

For most cases, this is quite simple, but the case where the called goal succeeds leaving backtrack points isn't possible at present (I think). If you can see why, feel free to skip the next paragraph.

Consider setup_call_cleanup(true, member(A, [a,b,c]), throw(foo)), !. After executing member(A, [a,b,c]), the interpreter pushes a backtrack point. Then the ICut VM instruction is executed, which simply pops the backtrack point off again, and then execution (of this goal, anyway) stops - and throw(foo) isn't ever run. In order to execute the throw(foo), I need to overload Interpreter.popBacktrackInfo (and similar methods) to check for the cleanup-type goals and run them then. Adding in an extra backtrack point won't work either, since we never actually undo anything - we simply discard frames.

The simplest option from my perspective is to make Interpreter non-final and make the constructor public. That would allow me to create my own derived interpreter which could include such changes without causing problems for anyone else. The second alternative would be to write code to handle this and provide it back as a new standard feature of GNU Prolog for Java, though since the predicate isn't ISO (as far as I know), this might not be desirable for you. As a final point, I'd say that although it might not be ISO, it's *extremely* useful!

Kind regards,
Matt Lilley

[1] http://www.swi-prolog.org/pldoc/doc_for?object=setup_call_cleanup/3

--
_____________________________________________
Matt Lilley
Software Engineer
SecuritEase

Tel:    +64 4 912-2100
Fax:    +64 4 912-2101
E-mail: address@hidden
Web:    http://www.securitease.com
_____________________________________________

This e-mail has passed our content security scan.
It is covered by the confidentiality clauses at 
http://www.securitease.com/content_and_confidentiality




reply via email to

[Prev in Thread] Current Thread [Next in Thread]