1(* 2 Title: Rebuild the basis library: integer 3 Copyright David C.J. Matthews 2016 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License version 2.1 as published by the Free Software Foundation. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*) 18 19 20type int = IntInf.int; 21 22(* Integer *) 23(* Define this first. It's explicitly referenced in the INTEGER signature. *) 24structure Int = struct type int = IntInf.int end; 25 26(* This uses Int.int so needs to be rebuilt. *) 27useBasis "INTEGER"; 28 29signature INT_INF = 30sig 31 include INTEGER 32 val divMod : int * int -> int * int 33 val quotRem : int * int -> int * int 34 val pow : int * Int.int -> int 35 val log2 : int -> Int.int 36 val orb : int * int -> int 37 val xorb : int * int -> int 38 val andb : int * int -> int 39 val notb : int -> int 40 val << : int * Word.word -> int 41 val ~>> : int * Word.word -> int 42end; 43 44structure IntInf: INT_INF = 45struct 46 open IntInf 47 val toInt = toLarge and fromInt = fromLarge 48 val precision = Option.map FixedInt.toLarge precision 49 val sign = FixedInt.toLarge o sign 50 val log2 = FixedInt.toLarge o log2 51 val pow = fn (i, j) => pow(i, FixedInt.fromLarge j) 52end; 53 54structure LargeInt: INTEGER = IntInf; 55 56structure Int: INTEGER = LargeInt; 57 58structure FixedInt: INTEGER = 59struct 60 open FixedInt 61 val toInt = toLarge and fromInt = fromLarge 62 val precision = Option.map toLarge precision 63 val sign = FixedInt.toLarge o sign 64end; 65 66val () = 67 case FixedInt.precision of SOME 31 => useBasis "Int31.sml" | SOME 63 => useBasis "Int63.sml" | _ => (); 68