[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Info-gnuprologjava] Adding hooks for executing code when frames are bei
[Info-gnuprologjava] Adding hooks for executing code when frames are being discarded
Wed, 14 Dec 2011 11:27:03 +1300
I'm trying to implement setup_call_cleanup/3  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!
Tel: +64 4 912-2100
Fax: +64 4 912-2101
This e-mail has passed our content security scan.
It is covered by the confidentiality clauses at
- [Info-gnuprologjava] Adding hooks for executing code when frames are being discarded,
Matt Lilley <=