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

SCM Repository

[diderot] View of /trunk/src/compiler/fields/field-def.sml
ViewVC logotype

View of /trunk/src/compiler/fields/field-def.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 268 - (download) (annotate)
Wed Aug 11 04:41:04 2010 UTC (8 years, 11 months ago) by jhr
File size: 1747 byte(s)
  merge DIFF and CONV constructors
(* field-def.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *)

structure FieldDef =
  struct

  (* the static definition of a field value *)
    datatype field_def
      = CONV of int * ImageInfo.info * Kernel.kernel	(* CONV(k, V, h) represents D^k(V*h) *)
      | NEG of field_def
      | SUM of field_def * field_def
(* scaling too? *)

  (* smart constructor for DIFF *)
    fun diff (CONV(k, img, h)) = CONV(k+1, img, h)
      | diff (NEG fld) = NEG(diff fld)
      | diff (SUM(fld1, fld2)) = SUM(diff fld1, diff fld2)

  (* slightly smart constructor for NEG *)
    fun neg (NEG fld) = fld
      | neg fld = (NEG fld)

  (* equality test for field definitions *)
    fun same (CONV(k1, img1, kern1), CONV(k2, img2, kern2)) =
	  (k1 = k2) andalso ImageInfo.same(img1, img2) andalso Kernel.same(kern1, kern2)
      | same (NEG fld1, NEG fld2) = same(fld1, fld2)
      | same (SUM(fld11, fld12), SUM(fld21, fld22)) = 
	  same(fld11, fld21) andalso same(fld12, fld22)

  (* hash value *)
    fun hash (CONV(k, img, kern)) =
	  Word.fromInt k * 0w17 + 0w3 * ImageInfo.hash img + Kernel.hash kern
      | hash (NEG fld) = 0w3 * hash fld + 0w11
      | hash (SUM(fld1, fld2)) = 0w7 * hash fld1 + hash fld2

    fun toString (CONV(0, img, kern)) =
	  concat["<", ImageInfo.toString img, "*", Kernel.name kern, ">"]
      | toString (CONV(k, img, kern)) =
	  concat["(D", Int.toString k, " <", ImageInfo.toString img, "*", Kernel.name kern, ">)"]
      | toString (NEG fld) = "-" ^ toString fld
      | toString (SUM(fld1, NEG fld2)) =
	  concat["(", toString fld1, "-", toString fld2, ")"]
      | toString (SUM(fld1, fld2)) =
	  concat["(", toString fld1, "+", toString fld2, ")"]

  end

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