Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /trunk/src/compiler/common/integer-lit.sml
ViewVC logotype

Annotation of /trunk/src/compiler/common/integer-lit.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 26 (* integer-lit.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 26 * All rights reserved.
7 :     *)
8 :    
9 :     structure IntegerLit :> sig
10 :    
11 :     type integer = IntInf.int
12 :    
13 :     (* range checks *)
14 :     val isInt : integer -> bool (* representable in 32-bits *)
15 :     val isLong : integer -> bool (* representable in 64-bits *)
16 :    
17 :     (* equality, comparisons, and hashing functions *)
18 :     val same : (integer * integer) -> bool
19 :     val compare : (integer * integer) -> order
20 :     val hash : integer -> word
21 :    
22 :     val toString : integer -> string
23 :    
24 :     end = struct
25 :    
26 :     type integer = IntInf.int
27 :    
28 :     (* range checks *)
29 :     fun isInt (n : IntInf.int) =
30 :     (~0x80000000 <= n) andalso (n < 0x100000000)
31 :     fun isLong (n : IntInf.int) =
32 :     (~0x8000000000000000 <= n) andalso (n < 0x10000000000000000)
33 :    
34 :     (* equality, comparisons, and hashing functions *)
35 :     fun same (a : IntInf.int, b) = (a = b)
36 :     val compare = IntInf.compare
37 :     fun hash i = Word.fromInt(IntInf.toInt(IntInf.andb(i, 0xfffffff)))
38 :    
39 :     fun toString i = if (i < 0)
40 :     then "-" ^ IntInf.toString(IntInf.~ i)
41 :     else IntInf.toString i
42 :    
43 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0