home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sa104os2.zip
/
SATHR104.ZIP
/
SATHER
/
LIBRARY
/
TUP.SA
< prev
next >
Wrap
Text File
|
1995-02-05
|
6KB
|
184 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- tup.sa: Tuples
-------------------------------------------------------------------
value class TUP{T1} < $HASH, $IS_EQ{SAME} is
attr t1:T1;
create(at1:T1):SAME is
return t1(at1) end;
is_eq(e:SAME):BOOL is
-- True if the component of self and `e' are equal.
lt1::=t1;
typecase lt1
when $IS_EQ{T1} then return lt1.is_eq(e.t1)
-- else return SYS::ob_eq(lt1,e.t1) end end; -- NLP
else; end; return SYS::ob_eq(lt1,e.t1); end; -- NLP
hash:INT is
-- A simple hash value computed from the hash values of the
-- component. For this to work, this must either be a value
-- type which defines a hash value or a reference type.
lt1::=t1;
typecase lt1
when $HASH then return lt1.hash
-- else return SYS::id(lt1) end end; -- NLP
else; end; return SYS::id(lt1); end; -- NLP
end; -- class TUP{T1}
-------------------------------------------------------------------
value class TUP{T1,T2} < $HASH, $IS_EQ{SAME} is
attr t1:T1;
attr t2:T2;
create(at1:T1, at2:T2):SAME is
return t1(at1).t2(at2) end;
is_eq(e:SAME):BOOL is
-- True if the components of self and `e' are equal.
lt1::=t1;
typecase lt1
when $IS_EQ{T1} then
if ~lt1.is_eq(e.t1) then return false end;
else
if ~SYS::ob_eq(lt1,e.t1) then return false end end;
lt2::=t2;
typecase lt2
when $IS_EQ{T2} then
if ~lt2.is_eq(e.t2) then return false end;
else
if ~SYS::ob_eq(lt2,e.t2) then return false end end;
return true end;
hash:INT is
-- A simple hash value computed from the hash values of the
-- components. For this to work, these must either be value
-- types which define hash values or reference types.
h1,h2:INT; lt1::=t1; lt2::=t2;
typecase lt1
when $HASH then h1:=lt1.hash
else h1:=SYS::id(lt1) end;
typecase lt2
when $HASH then h2:=lt2.hash
else h2:=SYS::id(lt2) end;
return h1.bxor(h2.lshift(2)) end;
end; -- class TUP{T1,T2}
-------------------------------------------------------------------
value class TUP{T1,T2,T3} < $HASH, $IS_EQ{SAME} is
attr t1:T1;
attr t2:T2;
attr t3:T3;
create(at1:T1, at2:T2, at3:T3):SAME is
return t1(at1).t2(at2).t3(at3) end;
is_eq(e:SAME):BOOL is
-- True if the components of self and `e' are equal.
lt1::=t1;
typecase lt1
when $IS_EQ{T1} then
if ~lt1.is_eq(e.t1) then return false end;
else
if ~SYS::ob_eq(lt1,e.t1) then return false end end;
lt2::=t2;
typecase lt2
when $IS_EQ{T2} then
if ~lt2.is_eq(e.t2) then return false end;
else
if ~SYS::ob_eq(lt2,e.t2) then return false end end;
lt3::=t3;
typecase lt3
when $IS_EQ{T3} then
if ~lt3.is_eq(e.t3) then return false end;
else
if ~SYS::ob_eq(lt3,e.t3) then return false end end;
return true end;
hash:INT is
-- A simple hash value computed from the hash values of the
-- components. For this to work, these must either be value
-- types which define hash values or reference types.
h1,h2,h3:INT; lt1::=t1; lt2::=t2; lt3::=t3;
typecase lt1
when $HASH then h1:=lt1.hash
else h1:=SYS::id(lt1) end;
typecase lt2
when $HASH then h2:=lt2.hash
else h2:=SYS::id(lt2) end;
typecase lt3
when $HASH then h3:=lt3.hash
else h3:=SYS::id(lt3) end;
return h1.bxor(h2.lshift(2)).bxor(h3.lshift(4)) end;
end; -- class TUP{T1,T2,T3}
-------------------------------------------------------------------
value class TUP{T1,T2,T3,T4} < $HASH, $IS_EQ{SAME} is
attr t1:T1;
attr t2:T2;
attr t3:T3;
attr t4:T4;
create(at1:T1, at2:T2, at3:T3, at4:T4):SAME is
return t1(at1).t2(at2).t3(at3).t4(at4) end;
is_eq(e:SAME):BOOL is
-- True if the components of self and `e' are equal.
lt1::=t1;
typecase lt1
when $IS_EQ{T1} then
if ~lt1.is_eq(e.t1) then return false end;
else
if ~SYS::ob_eq(lt1,e.t1) then return false end end;
lt2::=t2;
typecase lt2
when $IS_EQ{T2} then
if ~lt2.is_eq(e.t2) then return false end;
else
if ~SYS::ob_eq(lt2,e.t2) then return false end end;
lt3::=t3;
typecase lt3
when $IS_EQ{T3} then
if ~lt3.is_eq(e.t3) then return false end;
else
if ~SYS::ob_eq(lt3,e.t3) then return false end end;
lt4::=t4;
typecase lt4
when $IS_EQ{T4} then
if ~lt4.is_eq(e.t4) then return false end;
else
if ~SYS::ob_eq(lt4,e.t4) then return false end end;
return true end;
hash:INT is
-- A simple hash value computed from the hash values of the
-- components. For this to work, these must either be value
-- types which define hash values or reference types.
h1,h2,h3,h4:INT; lt1::=t1; lt2::=t2; lt3::=t3; lt4::=t4;
typecase lt1
when $HASH then h1:=lt1.hash
else h1:=SYS::id(lt1) end;
typecase lt2
when $HASH then h2:=lt2.hash
else h2:=SYS::id(lt2) end;
typecase lt3
when $HASH then h3:=lt3.hash
else h3:=SYS::id(lt3) end;
typecase lt4
when $HASH then h4:=lt4.hash
else h4:=SYS::id(lt4) end;
return h1.bxor(h2.lshift(2)).bxor(h3.lshift(4)).bxor(h4.lshift(6)) end;
end; -- class TUP{T1,T2,T3,T4}
-------------------------------------------------------------------