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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3436 - (download) (annotate)
Mon Nov 16 13:36:46 2015 UTC (4 years ago) by jhr
File size: 1507 byte(s)
  working on better constant-expression support
(* int-lit.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure IntLit :> sig

    type t = IntInf.int

    val fromInt : int -> t

  (* arithmetic *)
    val add : t * t -> t
    val sub : t * t -> t
    val mul : t * t -> t
    val divide : t * t -> t
    val modulo : t * t -> t
    val neg : t -> t

  (* range checks *)
    val isInt32 : t -> bool	(* representable in 32-bits *)
    val isInt64 : t -> bool	(* representable in 64-bits *)

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

    val toString : t -> string

  end = struct

    type t = IntInf.int

    val fromInt = IntInf.fromInt

  (* arithmetic *)
    val add = IntInf.+
    val sub = IntInf.-
    val mul = IntInf.*
    val divide = IntInf.quot
    val modulo = IntInf.rem
    val neg = IntInf.~

  (* range checks *)
    fun isInt32 (n : IntInf.int) =
	  (~0x80000000 <= n) andalso (n < 0x100000000)
    fun isInt64 (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

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