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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/common/int-lit.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/common/int-lit.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4588 - (view) (download)

1 : jhr 3348 (* int-lit.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *)
8 :    
9 :     structure IntLit :> sig
10 :    
11 :     type t = IntInf.int
12 :    
13 : jhr 4588 (* set the precision of tje Diderot "int" type to be 64-bits *)
14 :     val setDiderotLongInt : unit -> unit
15 :    
16 : jhr 3390 val fromInt : int -> t
17 :    
18 : jhr 4588 (* minimum and maximum values that are representable as Diderot ints *)
19 :     val minInt : unit -> t
20 :     val maxInt : unit -> t
21 :    
22 : jhr 3348 (* arithmetic *)
23 :     val add : t * t -> t
24 :     val sub : t * t -> t
25 :     val mul : t * t -> t
26 : jhr 3436 val divide : t * t -> t
27 :     val modulo : t * t -> t
28 : jhr 3348 val neg : t -> t
29 :    
30 : jhr 4588 (* is an integer in range for the Diderot "int" type? *)
31 :     val inRange : t -> bool
32 : jhr 3348
33 :     (* equality, comparisons, and hashing functions *)
34 :     val same : (t * t) -> bool
35 :     val compare : (t * t) -> order
36 :     val hash : t -> word
37 :    
38 :     val toString : t -> string
39 :    
40 :     end = struct
41 :    
42 :     type t = IntInf.int
43 :    
44 : jhr 3390 val fromInt = IntInf.fromInt
45 :    
46 : jhr 4588 (* set the precision of tje Diderot "int" type to be 64-bits *)
47 :     val isLongInt = ref false
48 :     fun setDiderotLongInt () = isLongInt := true
49 :    
50 :     (* minimum and maximum values that are representable as Diderot ints *)
51 :     fun minInt () : t = if !isLongInt then ~0x8000000000000000 else ~0x80000000
52 :     fun maxInt () : t = if !isLongInt then 0x7fffffffffffffff else 0x7fffffff
53 :    
54 : jhr 3348 (* arithmetic *)
55 :     val add = IntInf.+
56 :     val sub = IntInf.-
57 :     val mul = IntInf.*
58 : jhr 3436 val divide = IntInf.quot
59 :     val modulo = IntInf.rem
60 : jhr 3348 val neg = IntInf.~
61 :    
62 :     (* range checks *)
63 : jhr 4588 fun inRange (n : IntInf.int) = if !isLongInt
64 :     then (~0x8000000000000000 <= n) andalso (n <= 0x7fffffffffffffff)
65 :     else (~0x80000000 <= n) andalso (n <= 0x7fffffff)
66 : jhr 3348
67 :     (* equality, comparisons, and hashing functions *)
68 :     fun same (a : IntInf.int, b) = (a = b)
69 :     val compare = IntInf.compare
70 :     fun hash i = Word.fromInt(IntInf.toInt(IntInf.andb(i, 0xfffffff)))
71 :    
72 :     fun toString i = if (i < 0)
73 : jhr 4317 then "-" ^ IntInf.toString(IntInf.~ i)
74 :     else IntInf.toString i
75 : jhr 3348
76 :     end

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