drt24 / gnuprologjava

GNU Prolog for Java
8 stars 5 forks source link

Modules #4

Closed thetrime closed 8 years ago

thetrime commented 8 years ago

This pull request implements modules in the style of SWI-Prolog.

Code should be backward compatible with any existing code, (provided that existing code does not declare :-module/2 anywhere, or define a predicate :/2 obviously!)

The actual mechanics are probably quite different. When a predicate is called that we do not know about in the current module, before we return getUndefinedPredicateCode(), check the user module to see if it's declared there. if it is, return that. When we compile a module, all the exported predicates are turned into shims in user of the form Head:- :(ModuleName, Head).

:/2 is defined to push a new module context onto a stack. This is popped once the goal exits (and is restored appropriately during backtracking).

I'm more than happy to discuss the design, implementation, test cases and whether this is documented well enough - this is really a starting point for a patch rather than a final submission!

drt24 commented 8 years ago

This looks good. I have only made a couple of minor comments. I think this feature wants a brief mention in the manual: docs/manual.texinfo but that can be done separately. I am happy to merge this now or you can address the minor questions first.

thetrime commented 8 years ago

Ok. I've hopefully tidied up the issues reported. Let me know what you think

drt24 commented 8 years ago

LGTM.