The code below crashes in 64bit mode. The somewhat longer example is an excerpt from a radix set class for keys which support type
. I suppose the problem stems from same origin as in the before 32bit example:
Code: Select all
open math, core
domains
dictionary{Key} =
empty;
leaf(Key Key);
branch(unsigned Prefix, unsigned BranchingBit, dictionary{Key} Left, dictionary{Key} Right).
class predicates
insert : (dictionary{Key} Dictionary_0, Key Key) -> dictionary{Key} Dictionary
where Key supports positive.
class predicates
isMember : (Key Key, dictionary{Key} Dictionary) determ
where Key supports positive.
%---
class predicates
branchingBit : (unsigned PrefixA, unsigned BrBitA, unsigned PrefixB, unsigned BrBitB) -> unsigned BrBit.
clauses
branchingBit(Pa, Ba, Pb, Bb) = highestBit(Pa ^^ Pb, max(1, 2 * max(Ba, Bb))).
class predicates
matchPrefix : (unsigned KeyU, unsigned Prefix, unsigned BrBit) determ.
clauses
matchPrefix(K, P, B) :-
mask(K, B) = P.
class predicates
mask : (unsigned KeyU, unsigned Mask) -> unsigned MaskedKey.
clauses
mask(K, M) = (K ++ M - 1) ** ~~M.
class predicates
highestBit : (unsigned Prefix, unsigned BrBit) -> unsigned BrBit.
clauses
highestBit(P, B) = getHighBitMask32(PN) :-
PN = P ** ~~(B - 1).
class predicates
getHighBitMask32 : (unsigned X) -> unsigned Mask.
clauses
getHighBitMask32(X) = X_6 ** ~~(X_6 >> 1) :-
X_1 = X ++ X >> 1,
X_2 = X_1 ++ X_1 >> 1,
X_3 = X_2 ++ X_2 >> 2,
X_4 = X_3 ++ X_3 >> 4,
X_5 = X_4 ++ X_4 >> 8,
X_6 = X_5 ++ X_5 >> 16.
class predicates
join : (unsigned Pr1, unsigned BrBit1, dictionary{Key} T1, unsigned Pr2, unsigned BrBit2, dictionary{Key} T2) -> dictionary{Key} T1_join_T2
where Key supports positive.
clauses
join(P1, B1, T1, P2, B2, T2) = Dict :-
BrBit = branchingBit(P1, B1, P2, B2),
Dict = if P1 ** BrBit = 0 then branch(mask(P1, BrBit), BrBit, T1, T2) else branch(mask(P1, BrBit), BrBit, T2, T1) end if.
clauses
insert(empty, K) = leaf(K).
insert(leaf(Ky), Kx) = Dict :-
KxPo = convert(positive, Kx),
KyPo = convert(positive, Ky),
if KyPo = KxPo then
Dict = leaf(Kx)
else
Dict = join(uncheckedConvert(unsigned, KxPo), 0, leaf(Kx), uncheckedConvert(unsigned, KyPo), 0, leaf(Ky))
end if.
insert(branch(Pr, BrBit, Left, Right), K) = Dict :-
KPo = convert(positive, K),
if matchPrefix(uncheckedConvert(unsigned, KPo), Pr, BrBit) then
if uncheckedConvert(unsigned, KPo) ** BrBit = 0 then
Dict = branch(Pr, BrBit, insert(Left, K), Right)
else
Dict = branch(Pr, BrBit, Left, insert(Right, K))
end if
else
Dict = join(uncheckedConvert(unsigned, KPo), 0, leaf(K), Pr, BrBit, branch(Pr, BrBit, Left, Right))
end if.
clauses
isMember(K, leaf(K)).
isMember(K, branch(P, _BrBit, Left, _Right)) :-
uncheckedConvert(unsigned, K) <= P,
!,
isMember(K, Left).
isMember(K, branch(_P, _BrBit, _Left, Right)) :-
isMember(K, Right).
%======
clauses
run() :-
Set0 = insert(empty, 0),
Set1 = insert(Set0, 1),
if isMember(2, Set1) then
stdIo::write("yes")
else
stdIo::write("no")
end if.