StdInt.dcl 2.53 KB
Newer Older
1 2 3 4 5 6 7 8 9
system module StdInt 

// ****************************************************************************************
//	Concurrent Clean Standard Library Module Version 2.0
//	Copyright 1998 University of Nijmegen
// ****************************************************************************************

import	StdOverloaded

10
instance +				Int		:: !Int !Int -> Int					:== code { addI }
11

12
instance -  			Int		:: !Int !Int -> Int					:== code { subI }
13

14
instance zero			Int		:: Int								:== code { pushI 0 }
15

16
instance *  			Int		:: !Int !Int -> Int					:== code { mulI }
17

18 19
instance /				Int		:: !Int !Int -> Int					:== code { divI }
instance one			Int		:: Int								:== code { pushI 1 }
20 21 22 23

instance ^				Int
instance abs			Int
instance sign			Int
24 25 26 27 28 29 30 31 32 33 34 35
instance ~				Int		:: !Int -> Int						:== code { negI }

instance ==				Int		:: !Int !Int -> Bool				:== code { eqI }
instance <  			Int		:: !Int !Int -> Bool				:== code { ltI }
instance isEven 		Int		:: !Int -> Bool						:== code { pushI 1 ; and% ; pushI 0 ; eqI }
						// True if arg1 is an even number
instance isOdd			Int		:: !Int -> Bool						:== code { pushI 1 ; and% ; pushI 0 ; eqI ; notB }
						// True if arg1 is an odd  number

instance toInt			Char	:: !Char -> Int						:== code { CtoI }
instance toInt			Int		:: !Int -> Int						:== code { no_op }
instance toInt			Real	:: !Real -> Int						:== code { RtoI }
36 37
instance toInt			{#Char}

38 39 40 41
instance fromInt		Int		:: !Int -> Int						:== code { no_op }
instance fromInt		Char	:: !Int -> Char						:== code { ItoC }
instance fromInt		Real	:: !Int -> Real						:== code { ItoR }
instance fromInt		{#Char}	:: !Int -> {#Char}					:== code { .d 0 1 i ; jsr ItoAC ; .o 1 0 }
42 43 44

// Additional functions for integer arithmetic: 

45 46
instance rem Int		:: !Int !Int -> Int							:== code { remI }
				 	//	remainder after integer division
47 48 49 50 51
instance gcd Int	//	Greatest common divider
instance lcm Int	//	Least common multiple

//	Operators on Bits:

52 53 54 55 56 57 58 59 60 61 62 63
(bitor)	infixl  6	:: !Int !Int 	->	Int							:== code { or% }
					//	Bitwise Or of arg1 and arg2
(bitand) infixl 6	:: !Int !Int 	->	Int							:== code { and% }
					//	Bitwise And of arg1 and arg2
(bitxor) infixl 6	:: !Int !Int 	->	Int							:== code { xor% }
					//	Exclusive-Or arg1 with mask arg2
(<<)	infix  7	:: !Int !Int 	->	Int							:== code { shiftl% }
					//	Shift arg1 to the left arg2 bit places
(>>)	infix  7	:: !Int !Int 	->	Int							:== code { shiftr% }
					//	Shift arg1 to the right arg2 bit places
bitnot				:: !Int 		->	Int							:== code { not% }
					//	One's complement of arg1
64 65

IF_INT_64_OR_32 int64 int32 :== int64;