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

# SCM Repository

[diderot] Diff of /trunk/src/typechecker/typechecker.sml
 [diderot] / trunk / src / typechecker / typechecker.sml

# Diff of /trunk/src/typechecker/typechecker.sml

revision 69, Tue May 18 21:23:53 2010 UTC revision 70, Sat May 22 14:23:32 2010 UTC
# Line 10  Line 10
10
11    end = struct    end = struct
12
13        structure PT = ParseTree
14      structure Ty = Types      structure Ty = Types
15
16      (* check a differentiation level, which muse be >= 0 *)
17        fun checkDiff (cxt, k) =
18              if (k < 0)
19                then raise Fail "differentiation must be >= 0"
20                else Ty.NatConst(IntInf.toInt k)
21
22      (* check a dimension, which must be 2 or 3 *)
23        fun checkDim (cxt, d) =
24              if (d < 2) orelse (3 < d)
25                then raise Fail "invalid dimension; must be 2 or 3"
26                else Ty.NatConst(IntInf.toInt d)
27
28      (* check a shape *)
29        fun checkShape (cxt, shape) = let
30              fun chkDim d = if (d < 1)
31                    then raise Fail "invalid shape dimension; must be >= 1"
32                    else Ty.NatConst(IntInf.toInt d)
33              in
34                Ty.Shape(List.map chkDim shape)
35              end
36
37    (* check the well-formedness of a type and translate it to an AST type *)    (* check the well-formedness of a type and translate it to an AST type *)
38      fun checkTy ty = (case ty      fun checkTy (cxt, ty) = (case ty
39             of PT.T_Mark of ty mark             of PT.T_Mark m => checkTy(cxt, #tree m)  (* FIXME track context *)
40              | PT.T_Bool =>              | PT.T_Bool => Ty.T_Bool
41              | PT.T_Int              | PT.T_Int => Ty.T_Int
42              | PT.T_Real              | PT.T_Real => Ty.realTy
43              | PT.T_String              | PT.T_String => Ty.T_String
44              | PT.T_Vec of dim              | PT.T_Vec n => (* NOTE: the parser guarantees that 2 <= n <= 4 *)
45              | PT.T_Kernel of dim                  Ty.vecTy(IntInf.toInt n)
46              | PT.T_Field of {diff : dim, order : dim list, dim : dim}              | PT.T_Kernel k => Ty.T_Kernel(checkDiff(cxt, k))
47              | PT.T_Tensor of dim list              | PT.T_Field{diff, dim, shape} => Ty.T_Field{
48              | PT.T_Image of {order : dim list, dim : dim}                    diff = checkDiff (cxt, diff),
49              | PT.T_Array of ty * dim list                    dim = checkDim (cxt, dim),
50                      shape = checkShape (cxt, shape)
51                    }
52                | PT.T_Tensor shape => Ty.T_Tensor(checkShape(cxt, shape))
53                | PT.T_Image{dim, shape} => Ty.T_Image{
54                      dim = checkDim (cxt, dim),
55                      shape = checkShape (cxt, shape)
56                    }
57                | PT.T_Array(ty, dims) => raise Fail "Array type"
58              (* end case *))
59
60    (*
61      (* typecheck an expression and translate it to AST *)
62        fun checkExpr (env, e) = (case e
63               of PT.E_Mark of expr mark
64                | PT.E_Var of var
65                | PT.E_Lit of Literal.literal
66                | PT.E_BinOp of expr * var * expr
67                | PT.E_UnaryOp of var * expr
68                | PT.E_Tuple of expr list
69                | PT.E_Apply of var * expr list
70                | PT.E_Cons of ty * expr list
71                | PT.E_Diff of expr
72                | PT.E_Norm of expr
73            (* end case *))            (* end case *))
74
75      (* typecheck a statement and translate it to AST *)
76        fun checkStmt (env, s) = (case s
77               of PT.S_Mark of stmt mark
78                | PT.S_Block of stmt list
79                | PT.S_Decl of var_decl
80                | PT.S_IfThen of expr * stmt
81                | PT.S_IfThenElse of expr * stmt * stmt
82                | PT.S_Assign of var * expr
83                | PT.S_New of var * expr list
84                | PT.S_Die
85                | PT.S_Stabilize
86              (* end case *))
87
88        fun checkDecl (env, d) = (case d
89               of PT.D_Mark of decl mark
90                | PT.D_Input of ty * var * expr option      (* input variable decl with optional default *)
91                | PT.D_Var of var_decl                      (* global variable decl *)
92                | PT.D_Actor of {                           (* actor decl *)
93                      name : var,
94                      params : param list,
95                      state : var_decl list,
96                      methods : method list
97                    }
98                | PT.D_InitialArray of create * iter list
99                | PT.D_InitialCollection of create * iter list
100              (* end case *))
101    *)
102
103        fun check (PT.Program dcls) = AST.Program()
104
105    end    end

Legend:
 Removed from v.69 changed lines Added in v.70

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