Module score

Foreign predicates can be automatically generated when a Java class is loaded. The module loader will proceed in that it will analyse the Java class and automatically collect all the Java methods and Java fields and generate foreign predicates for them. For Java methods that were overloaded the module loader will generate branching code.

Example:
?- system/automatic:generated('String':valueOf/2).
% String.class
:- package(foreign(java/lang)).
:- module('String', []).
..
:- public valueOf/2.
valueOf(A, B) :-
sys_boolean(A), !,
valueOf_var0(A, B).
valueOf(A, B) :-
sys_char16(A), !,
valueOf_var1(A, B).
..

The branching code uses a type check and then a cut. The type checks go beyond what the core standard defines as type checks. Since Java uses expression infered types and we have only value manifest types, we pursue the strategy that we look at the magnitude of a value. This explains for example the variety of test predicates such as sys_integer8/1 and sys_integer16_and_not_integer8/1 defined here.

The following predicates for the module score are provided:

sys_boolean(X):
The predicate succeeds when X is an atom from the set {true, false}.
sys_integer8(X):
The predicate succeeds when X is an integer and X is in the range - 2^7 to 2^7-1.
sys_char16(X):
The predicate succeeds when X is a character and X is in the range of 0 to 2^16-1.
sys_integer16(X):
The predicate succeeds when X is an integer and X is in the range - 2^15 to 2^15-1.
sys_integer32(X):
The predicate succeeds when X is an integer and X is in the range - 2^31 to 2^31-1.
sys_integer64(X):
The predicate succeeds when X is an integer and X is in the range - 2^63 to 2^63-1.
sys_integer32_or_float32(X):
The predicate succeeds when X is an 32-bit integer or a 32-bit float.
sys_integer64_or_float(X):
The predicate succeeds when X is an 64-bit integer or a float.
sys_integer16_and_not_integer8(X):
The predicate succeeds when X is an 16-bit integer but not an 8-bit integer.
sys_integer32_and_not_integer16(X):
The predicate succeeds when X is an 32-bit integer but not an 16-bit integer.
sys_integer64_and_not_integer32(X):
The predicate succeeds when X is an 64-bit integer but not an 32-bit integer.
sys_integer_and_not_integer64(X):
The predicate succeeds when X is an integer but not an 64-bit integer.
sys_atom_or_type_of(C, X):
The predicate succeeds when X is an atom or an instance of C.
sys_type_of(C, X):
The predicate succeeds when X is an instance of C.

The following predicate properties for method branching are provided:

sys_automatic:
The foreign function was automatically added by the Java class auto loader. The property can be missing. The property can be modified.

Kommentare