Home My Page Projects Code Snippets Project Openings diderot

SCM Repository

[diderot] View of /trunk/src/compiler/common/integer-lit.sml
 [diderot] / trunk / src / compiler / common / integer-lit.sml View of /trunk/src/compiler/common/integer-lit.sml

Tue Oct 27 15:16:36 2015 UTC (6 years, 2 months ago) by jhr
File size: 1167 byte(s)
making copyrights consistent for all code in the repository
(* integer-lit.sml
*
* This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
*
* COPYRIGHT (c) 2015 The University of Chicago
*)

structure IntegerLit :> sig

type integer = IntInf.int

(* range checks *)
val isInt : integer -> bool		(* representable in 32-bits *)
val isLong : integer -> bool	(* representable in 64-bits *)

(* equality, comparisons, and hashing functions *)
val same : (integer * integer) -> bool
val compare : (integer * integer) -> order
val hash : integer -> word

val toString : integer -> string

end = struct

type integer = IntInf.int

(* range checks *)
fun isInt (n : IntInf.int) =
(~0x80000000 <= n) andalso (n < 0x100000000)
fun isLong (n : IntInf.int) =
(~0x8000000000000000 <= n) andalso (n < 0x10000000000000000)

(* equality, comparisons, and hashing functions *)
fun same (a : IntInf.int, b) = (a = b)
val compare = IntInf.compare
fun hash i = Word.fromInt(IntInf.toInt(IntInf.andb(i, 0xfffffff)))

fun toString i = if (i < 0)
then "-" ^ IntInf.toString(IntInf.~ i)
else IntInf.toString i

end