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

# SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/mid-il/check-mid-il.sml
 [diderot] / branches / vis12 / src / compiler / mid-il / check-mid-il.sml

# Diff of /branches/vis12/src/compiler/mid-il/check-mid-il.sml

trunk/src/compiler/mid-il/check-mid-il.sml revision 1444, Mon Jul 11 12:11:53 2011 UTC branches/vis12/src/compiler/mid-il/check-mid-il.sml revision 1925, Sat Jun 23 14:16:09 2012 UTC
# Line 14  Line 14
14
15      val vec3Ty = Ty.vecTy 3      val vec3Ty = Ty.vecTy 3
16
17      (* utility function for synthesizing eigenvector/eigenvalue signature *)
18        fun eigenSig dim = let
19              val tplTy = Ty.TupleTy[
20                      Ty.SeqTy(Ty.realTy, dim),
21                      Ty.SeqTy(Ty.vecTy dim, dim)
22                    ]
23              in
24                (tplTy, [Ty.TensorTy[dim, dim]])
25              end
26
27    (* Return the signature of a MidIL operator. *)    (* Return the signature of a MidIL operator. *)
28      fun sigOf rator = (case rator      fun sigOf rator = (case rator
29             of Op.Add ty => (ty, [ty, ty])             of Op.Add ty => (ty, [ty, ty])
# Line 38  Line 48
48              | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])              | Op.MulMatVec(d1, d2) => (Ty.vecTy d1, [Ty.TensorTy[d1, d2], Ty.vecTy d2])
49              | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])              | Op.MulMatMat(d1, d2, d3) => (Ty.TensorTy[d1, d3], [Ty.TensorTy[d1, d2], Ty.TensorTy[d2, d3]])
50              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])              | Op.Cross => (vec3Ty, [vec3Ty, vec3Ty])
| Op.Select(ty as Ty.IVecTy 1, _) => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
| Op.Select(ty as Ty.IVecTy d, _) => (Ty.intTy, [ty])
| Op.Select(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
51              | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])              | Op.Norm(ty as Ty.TensorTy _) => (Ty.realTy, [ty])
52              | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])              | Op.Normalize d => (Ty.vecTy d, [Ty.vecTy d])
53              | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])              | Op.Scale(ty as Ty.TensorTy(_::_)) => (ty, [Ty.realTy, ty])
54              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"              | Op.PrincipleEvec _ => raise Fail "Op.PrincipleEvec unimplemented"
55                | Op.EigenVecs2x2 => eigenSig 2
56                | Op.EigenVecs3x3 => eigenSig 3
57                | Op.EigenVals2x2 => (Ty.SeqTy(Ty.realTy, 2), [Ty.TensorTy[2,2]])
58                | Op.EigenVals3x3 => (Ty.SeqTy(Ty.realTy, 3), [Ty.TensorTy[3,3]])
59              | Op.Identity d => (Ty.TensorTy[d,d], [])              | Op.Identity d => (Ty.TensorTy[d,d], [])
60              | Op.Zero ty => (ty, [])              | Op.Zero ty => (ty, [])
61              | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])              | Op.Trace d => (Ty.realTy, [Ty.TensorTy[d, d]])
62              | Op.Subscript(Ty.IVecTy d) => (Ty.intTy, [Ty.IVecTy d, Ty.intTy])              | Op.Select(ty as Ty.TupleTy tys, i) => (List.nth(tys, i-1), [ty])
63                | Op.Index(ty as Ty.TensorTy[d], _) => (Ty.realTy, [ty])
64                | Op.Index(ty as Ty.SeqTy(elemTy, _), _) => (elemTy, [ty])
65              | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)              | Op.Subscript(ty as Ty.TensorTy dd) => (Ty.realTy, ty :: List.map (fn _ => Ty.intTy) dd)
66                | Op.Subscript(ty as Ty.SeqTy(elemTy, d)) => (elemTy, [ty, Ty.intTy])
67                | Op.MkDynamic(ty, n) => (Ty.DynSeqTy ty, [Ty.SeqTy(ty, n)])
68                | Op.Prepend ty => (Ty.DynSeqTy ty, [ty, Ty.DynSeqTy ty])
69                | Op.Append ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, ty])
70                | Op.Concat ty => (Ty.DynSeqTy ty, [Ty.DynSeqTy ty, Ty.DynSeqTy ty])
71                | Op.Length ty => (Ty.intTy, [Ty.DynSeqTy ty])
72              | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])              | Op.Ceiling d => (Ty.vecTy d, [Ty.vecTy d])
73              | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])              | Op.Floor d => (Ty.vecTy d, [Ty.vecTy d])
74              | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])              | Op.Round d => (Ty.vecTy d, [Ty.vecTy d])
75              | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])              | Op.Trunc d => (Ty.vecTy d, [Ty.vecTy d])
76              | Op.IntToReal => (Ty.realTy, [Ty.intTy])              | Op.IntToReal => (Ty.realTy, [Ty.intTy])
77              | Op.RealToInt d => (Ty.IVecTy d, [Ty.vecTy d])              | Op.RealToInt 1 => (Ty.IntTy, [Ty.realTy])
78                | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.TensorTy[d]])
79    (* FIXME: the type of RealToInt should be
80                | Op.RealToInt d => (Ty.SeqTy(Ty.IntTy, d), [Ty.SeqTy(Ty.realTy, d)])
81    *)
82              | Op.VoxelAddress(info, offset) => let              | Op.VoxelAddress(info, offset) => let
83                  val dim = ImageInfo.dim info                  val dim = ImageInfo.dim info
84                  in                  in
# Line 73  Line 96
96              | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])              | Op.Inside(info, _) => (Ty.BoolTy, [Ty.vecTy(ImageInfo.dim info), Ty.ImageTy info])
97              | Op.Input(ty, _, _) => (ty, [])              | Op.Input(ty, _, _) => (ty, [])
98              | Op.InputWithDefault(ty, _, _) => (ty, [ty])              | Op.InputWithDefault(ty, _, _) => (ty, [ty])
99                | Op.Print tys => (Ty.TupleTy[], tys)
100              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)              | _ => raise Fail("sigOf: invalid operator " ^ Op.toString rator)
101            (* end case *))            (* end case *))
102
103      fun typeOfCons (_, []) = false      fun typeOfCons (_, []) = false
104          | typeOfCons (Ty.SeqTy(ty, n), tys) =
105              List.all (fn ty' => Ty.same(ty, ty')) tys andalso (List.length tys = n)
106        | typeOfCons (expectedTy, tys as ty1::_) =        | typeOfCons (expectedTy, tys as ty1::_) =
107            if List.all (fn ty => Ty.same(ty1, ty)) tys            if List.all (fn ty => Ty.same(ty1, ty)) tys
108              then (case (expectedTy, ty1)              then (case (expectedTy, ty1)
109                 of (Ty.IVecTy n, Ty.IVecTy 1) => (n = List.length tys)                 of (Ty.SeqTy(_, n), Ty.IntTy) => (n = List.length tys)
110                  | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')                  | (Ty.TensorTy dd, Ty.TensorTy dd') => (dd = List.length tys :: dd')
111                  | _ => false                  | _ => false
112                (* end case *))                (* end case *))

Legend:
 Removed from v.1444 changed lines Added in v.1925

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