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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/typechecker/typechecker.sml
ViewVC logotype

Annotation of /trunk/src/compiler/typechecker/typechecker.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (view) (download)

1 : jhr 69 (* typechecker.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure Typechecker : sig
8 :    
9 : jhr 88 exception Error
10 :    
11 : jhr 86 val check : Error.err_stream -> ParseTree.program -> AST.program
12 : jhr 69
13 :     end = struct
14 :    
15 : jhr 70 structure PT = ParseTree
16 : jhr 69 structure Ty = Types
17 : jhr 96 structure TU = TypeUtil
18 : jhr 81 structure U = Util
19 : jhr 69
20 : jhr 169 type env = {globalScope : bool, env : Env.env}
21 :    
22 : jhr 88 exception Error
23 :    
24 : jhr 86 type context = Error.err_stream * Error.span
25 :    
26 :     fun withContext ((errStrm, _), {span, tree}) =
27 :     ((errStrm, span), tree)
28 :     fun withEnvAndContext (env, (errStrm, _), {span, tree}) =
29 :     (env, (errStrm, span), tree)
30 :    
31 : jhr 88 fun error ((errStrm, span), msg) = (
32 :     Error.errorAt(errStrm, span, msg);
33 :     raise Error)
34 : jhr 86
35 : jhr 88 datatype token
36 :     = S of string | A of Atom.atom
37 :     | V of AST.var | TY of Types.ty | TYS of Types.ty list
38 :    
39 :     fun err (cxt, toks) = let
40 :     fun tok2str (S s) = s
41 :     | tok2str (A a) = Atom.toString a
42 :     | tok2str (V x) = Var.nameOf x
43 : jhr 96 | tok2str (TY ty) = TU.toString ty
44 : jhr 88 | tok2str (TYS []) = "()"
45 : jhr 96 | tok2str (TYS[ty]) = TU.toString ty
46 : jhr 88 | tok2str (TYS tys) = String.concat[
47 : jhr 96 "(", String.concatWith " * " (List.map TU.toString tys), ")"
48 : jhr 88 ]
49 :     in
50 :     error(cxt, List.map tok2str toks)
51 :     end
52 :    
53 : jhr 83 val realZero = AST.E_Lit(Literal.Float(FloatLit.zero true))
54 :    
55 : jhr 70 (* check a differentiation level, which muse be >= 0 *)
56 :     fun checkDiff (cxt, k) =
57 :     if (k < 0)
58 :     then raise Fail "differentiation must be >= 0"
59 : jhr 75 else Ty.DiffConst(IntInf.toInt k)
60 : jhr 70
61 :     (* check a dimension, which must be 2 or 3 *)
62 :     fun checkDim (cxt, d) =
63 : jhr 82 if (d <= 0)
64 :     then raise Fail "invalid dimension; must be > 0"
65 : jhr 75 else Ty.DimConst(IntInf.toInt d)
66 : jhr 70
67 :     (* check a shape *)
68 :     fun checkShape (cxt, shape) = let
69 :     fun chkDim d = if (d < 1)
70 :     then raise Fail "invalid shape dimension; must be >= 1"
71 : jhr 75 else Ty.DimConst(IntInf.toInt d)
72 : jhr 70 in
73 :     Ty.Shape(List.map chkDim shape)
74 :     end
75 :    
76 : jhr 69 (* check the well-formedness of a type and translate it to an AST type *)
77 : jhr 70 fun checkTy (cxt, ty) = (case ty
78 : jhr 86 of PT.T_Mark m => checkTy(withContext(cxt, m))
79 : jhr 70 | PT.T_Bool => Ty.T_Bool
80 :     | PT.T_Int => Ty.T_Int
81 :     | PT.T_Real => Ty.realTy
82 :     | PT.T_String => Ty.T_String
83 :     | PT.T_Vec n => (* NOTE: the parser guarantees that 2 <= n <= 4 *)
84 :     Ty.vecTy(IntInf.toInt n)
85 :     | PT.T_Kernel k => Ty.T_Kernel(checkDiff(cxt, k))
86 :     | PT.T_Field{diff, dim, shape} => Ty.T_Field{
87 :     diff = checkDiff (cxt, diff),
88 :     dim = checkDim (cxt, dim),
89 :     shape = checkShape (cxt, shape)
90 :     }
91 :     | PT.T_Tensor shape => Ty.T_Tensor(checkShape(cxt, shape))
92 :     | PT.T_Image{dim, shape} => Ty.T_Image{
93 :     dim = checkDim (cxt, dim),
94 :     shape = checkShape (cxt, shape)
95 :     }
96 : jhr 99 | PT.T_Array(ty, dims) => raise Fail "Array type not supported"
97 : jhr 69 (* end case *))
98 :    
99 : jhr 71 fun checkLit lit = (case lit
100 :     of (Literal.Int _) => (AST.E_Lit lit, Ty.T_Int)
101 :     | (Literal.Float _) => (AST.E_Lit lit, Ty.realTy)
102 :     | (Literal.String s) => (AST.E_Lit lit, Ty.T_String)
103 :     | (Literal.Bool _) => (AST.E_Lit lit, Ty.T_Bool)
104 :     (* end case *))
105 :    
106 : jhr 85 (* resolve overloading: we use a simple scheme that selects the first operator in the
107 :     * list that matches the argument types.
108 :     *)
109 : jhr 91 fun resolveOverload (cxt, rator, argTys, args, candidates) = let
110 :     fun tryCandidates [] = err(cxt, [
111 :     S "unable to resolve overloaded operator \"", A rator, S "\"\n",
112 :     S " argument type is: ", TYS argTys, S "\n"
113 : jhr 85 ])
114 :     | tryCandidates (x::xs) = let
115 :     val (tyArgs, Ty.T_Fun(domTy, rngTy)) = Util.instantiate(Var.typeOf x)
116 :     in
117 :     if U.tryMatchTypes(domTy, argTys)
118 :     then (AST.E_Apply(x, tyArgs, args, rngTy), rngTy)
119 :     else tryCandidates xs
120 :     end
121 :     in
122 :     tryCandidates candidates
123 :     end
124 :    
125 : jhr 70 (* typecheck an expression and translate it to AST *)
126 : jhr 169 fun checkExpr (env : env, cxt, e) = (case e
127 : jhr 86 of PT.E_Mark m => checkExpr (withEnvAndContext (env, cxt, m))
128 : jhr 169 | PT.E_Var x => (case Env.findVar (#env env, x)
129 : jhr 170 of SOME x' => (case Var.typeOf x'
130 :     of ([], ty) => (AST.E_Var x', ty)
131 :     | _ => raise Fail "Unexpected polymorphic variable"
132 :     (* end case *))
133 : jhr 88 | NONE => err(cxt, [S "undeclared variable ", A x])
134 : jhr 71 (* end case *))
135 :     | PT.E_Lit lit => checkLit lit
136 : jhr 81 | PT.E_OrElse(e1, e2) => let
137 :     val (e1', ty1) = checkExpr(env, cxt, e1)
138 :     val (e2', ty2) = checkExpr(env, cxt, e2)
139 :     in
140 :     case (ty1, ty2)
141 :     of (Ty.T_Bool, Ty.T_Bool) =>
142 :     (AST.E_Cond(e1', AST.E_Lit(Literal.Bool true), e2'), Ty.T_Bool)
143 : jhr 99 | _ => err (cxt, [S "arguments to \"||\" must have bool type"])
144 : jhr 81 (* end case *)
145 :     end
146 :     | PT.E_AndAlso(e1, e2) => let
147 :     val (e1', ty1) = checkExpr(env, cxt, e1)
148 :     val (e2', ty2) = checkExpr(env, cxt, e2)
149 :     in
150 :     case (ty1, ty2)
151 :     of (Ty.T_Bool, Ty.T_Bool) =>
152 :     (AST.E_Cond(e1', e2', AST.E_Lit(Literal.Bool false)), Ty.T_Bool)
153 : jhr 99 | _ => err (cxt, [S "arguments to \"&&\" must have bool type"])
154 : jhr 81 (* end case *)
155 :     end
156 :     | PT.E_BinOp(e1, rator, e2) => let
157 :     val (e1', ty1) = checkExpr(env, cxt, e1)
158 :     val (e2', ty2) = checkExpr(env, cxt, e2)
159 :     in
160 :     case Basis.findOp rator
161 :     of [rator] => let
162 :     val (tyArgs, Ty.T_Fun(domTy, rngTy)) = Util.instantiate(Var.typeOf rator)
163 :     in
164 :     if U.matchTypes(domTy, [ty1, ty2])
165 :     then (AST.E_Apply(rator, tyArgs, [e1', e2'], rngTy), rngTy)
166 : jhr 89 else err (cxt, [
167 :     S "type error for binary operator \"", V rator, S "\"\n",
168 :     S " expected: ", TYS domTy, S "\n",
169 :     S " but found: ", TYS[ty1, ty2], S "\n"
170 : jhr 85 ])
171 : jhr 81 end
172 : jhr 91 | ovldList => resolveOverload (cxt, rator, [ty1, ty2], [e1', e2'], ovldList)
173 : jhr 81 (* end case *)
174 :     end
175 :     | PT.E_UnaryOp(rator, e) => let
176 :     val (e', ty) = checkExpr(env, cxt, e)
177 :     in
178 :     case Basis.findOp rator
179 :     of [rator] => let
180 :     val (tyArgs, Ty.T_Fun([domTy], rngTy)) = Util.instantiate(Var.typeOf rator)
181 :     in
182 :     if U.matchType(domTy, ty)
183 :     then (AST.E_Apply(rator, tyArgs, [e'], rngTy), rngTy)
184 : jhr 89 else err (cxt, [
185 :     S "type error for unary operator \"", V rator, S "\"\n",
186 :     S " expected: ", TY domTy, S "\n",
187 :     S " but found: ", TY ty, S "\n"
188 : jhr 85 ])
189 : jhr 81 end
190 : jhr 91 | ovldList => resolveOverload (cxt, rator, [ty], [e'], ovldList)
191 : jhr 81 (* end case *)
192 :     end
193 :     | PT.E_Tuple args => let
194 :     val (args, tys) = checkExprList (env, cxt, args)
195 :     in
196 :     raise Fail "E_Tuple not yet implemented"
197 :     end
198 :     | PT.E_Apply(f, args) => let
199 :     val (args, tys) = checkExprList (env, cxt, args)
200 :     in
201 : jhr 169 case Env.findFunc (#env env, f)
202 :     of SOME f =>
203 :     if (#globalScope env) orelse not(Basis.isRestricted f)
204 :     then (case Util.instantiate(Var.typeOf f)
205 :     of (tyArgs, Ty.T_Fun(domTy, rngTy)) =>
206 :     if U.matchTypes(domTy, tys)
207 :     then (AST.E_Apply(f, tyArgs, args, rngTy), rngTy)
208 :     else err(cxt, [
209 :     S "type error in application of ", V f, S "\n",
210 :     S " expected: ", TYS domTy, S "\n",
211 :     S " but found: ", TYS tys, S "\n"
212 :     ])
213 :     | _ => err(cxt, [S "application of non-function ", V f])
214 :     (* end case *))
215 :     else err(cxt, [S "use of restricted operation ", V f, S " in actor body"])
216 : jhr 99 | NONE => err(cxt, [S "unknown function ", A f])
217 : jhr 81 (* end case *)
218 :     end
219 : jhr 86 | PT.E_Cons args => let
220 :     val (args, ty::tys) = checkExprList (env, cxt, args)
221 : jhr 81 in
222 : jhr 96 case TU.pruneHead ty
223 : jhr 86 of Ty.T_Tensor shape => let
224 :     fun chkTy ty' = U.matchType(ty, ty')
225 :     val resTy = Ty.T_Tensor(Ty.shapeExt(shape, Ty.DimConst(List.length args)))
226 : jhr 83 in
227 : jhr 86 if List.all chkTy tys
228 :     then (AST.E_Cons args, resTy)
229 : jhr 99 else err(cxt, [S "arguments of tensor construction must have same type"])
230 : jhr 83 end
231 : jhr 99 | _ => err(cxt, [S "Invalid argument type for tensor construction"])
232 : jhr 83 (* end case *)
233 : jhr 81 end
234 : jhr 86 | PT.E_Real e => (case checkExpr (env, cxt, e)
235 :     of (e', Ty.T_Int) =>
236 :     (AST.E_Apply(BasisVars.i2r, [], [e'], Ty.realTy), Ty.realTy)
237 : jhr 99 | _ => err(cxt, [S "argument of real conversion must be int"])
238 : jhr 86 (* end case *))
239 : jhr 70 (* end case *))
240 :    
241 : jhr 81 (* typecheck a list of expressions returning a list of AST expressions and a list
242 :     * of types of the expressions.
243 :     *)
244 :     and checkExprList (env, cxt, exprs) = let
245 :     fun chk (e, (es, tys)) = let
246 :     val (e, ty) = checkExpr (env, cxt, e)
247 :     in
248 :     (e::es, ty::tys)
249 :     end
250 :     in
251 :     List.foldr chk ([], []) exprs
252 :     end
253 :    
254 : jhr 72 fun checkVarDecl (env, cxt, kind, d) = (case d
255 : jhr 86 of PT.VD_Mark m => checkVarDecl (env, (#1 cxt, #span m), kind, #tree m)
256 : jhr 72 | PT.VD_Decl(ty, x, e) => let
257 : jhr 81 val ty = checkTy (cxt, ty)
258 : jhr 72 val x' = Var.new (x, kind, ty)
259 :     val (e', ty') = checkExpr (env, cxt, e)
260 :     in
261 : jhr 99 (* FIXME: this check is not flexible enough; should allow lhs type to support
262 :     * fewer levels of differentiation than rhs provides.
263 :     *)
264 :     if U.matchType(ty, ty')
265 :     then (x, x', e')
266 :     else err(cxt, [
267 :     S "type of variable ", A x,
268 :     S " does not match type of initializer\n",
269 :     S " expected: ", TY ty, S "\n",
270 :     S " but found: ", TY ty', S "\n"
271 :     ])
272 : jhr 72 end
273 :     (* end case *))
274 :    
275 : jhr 169 fun checkGlobalExpr (env, cxt, exp) = checkExpr ({globalScope=true, env=env}, cxt, exp)
276 :     fun checkLocalExpr (env, cxt, exp) = checkExpr ({globalScope=false, env=env}, cxt, exp)
277 :     fun checkLocalExprList (env, cxt, exp) = checkExprList ({globalScope=false, env=env}, cxt, exp)
278 :    
279 : jhr 70 (* typecheck a statement and translate it to AST *)
280 : jhr 71 fun checkStmt (env, cxt, s) = (case s
281 : jhr 86 of PT.S_Mark m => checkStmt (withEnvAndContext (env, cxt, m))
282 : jhr 72 | PT.S_Block stms => let
283 :     fun chk (_, [], stms) = AST.S_Block(List.rev stms)
284 :     | chk (env, s::ss, stms) = let
285 :     val (s', env') = checkStmt (env, cxt, s)
286 :     in
287 : jhr 81 chk (env', ss, s'::stms)
288 : jhr 72 end
289 :     in
290 :     (chk (env, stms, []), env)
291 :     end
292 :     | PT.S_Decl vd => let
293 : jhr 169 val (x, x', e) = checkVarDecl ({globalScope=false, env=env}, cxt, Var.LocalVar, vd)
294 : jhr 72 in
295 : jhr 81 (AST.S_Decl(AST.VD_Decl(x', e)), Env.insertLocal(env, x, x'))
296 : jhr 72 end
297 :     | PT.S_IfThen(e, s) => let
298 : jhr 169 val (e', ty) = checkLocalExpr (env, cxt, e)
299 : jhr 81 val (s', _) = checkStmt (env, cxt, s)
300 : jhr 72 in
301 :     (* check that condition has bool type *)
302 :     case ty
303 :     of Ty.T_Bool => ()
304 : jhr 99 | _ => err(cxt, [S "condition not boolean type"])
305 : jhr 72 (* end case *);
306 :     (AST.S_IfThenElse(e', s', AST.S_Block[]), env)
307 :     end
308 :     | PT.S_IfThenElse(e, s1, s2) => let
309 : jhr 169 val (e', ty) = checkLocalExpr (env, cxt, e)
310 : jhr 81 val (s1', _) = checkStmt (env, cxt, s1)
311 :     val (s2', _) = checkStmt (env, cxt, s2)
312 : jhr 72 in
313 :     (* check that condition has bool type *)
314 :     case ty
315 :     of Ty.T_Bool => ()
316 : jhr 99 | _ => err(cxt, [S "condition not boolean type"])
317 : jhr 72 (* end case *);
318 :     (AST.S_IfThenElse(e', s1', s2'), env)
319 :     end
320 :     | PT.S_Assign(x, e) => (case Env.findVar (env, x)
321 : jhr 99 of NONE => err(cxt, [
322 :     S "undefined variable ", A x
323 :     ])
324 : jhr 72 | SOME x' => let
325 : jhr 99 (* FIXME: check for polymorphic variables *)
326 :     val ([], ty) = Var.typeOf x'
327 : jhr 169 val (e', ty') = checkLocalExpr (env, cxt, e)
328 : jhr 72 in
329 : jhr 99 if U.matchType(ty, ty')
330 :     then (x, x', e')
331 :     else err(cxt, [
332 :     S "type of assigned variable ", A x,
333 :     S " does not match type of rhs\n",
334 :     S " expected: ", TY ty, S "\n",
335 :     S " but found: ", TY ty', S "\n"
336 :     ]);
337 : jhr 72 (* check that x' is mutable *)
338 :     case Var.kindOf x'
339 :     of Var.ActorStateVar => ()
340 :     | Var.LocalVar => ()
341 : jhr 99 | _ => err(cxt, [
342 :     S "assignment to immutable variable ", A x
343 :     ])
344 : jhr 72 (* end case *);
345 :     (AST.S_Assign(x', e'), env)
346 :     end
347 :     (* end case *))
348 :     | PT.S_New(actor, args) => let
349 : jhr 169 val argsAndTys' = List.map (fn e => checkLocalExpr(env, cxt, e)) args
350 : jhr 81 val (args', tys') = ListPair.unzip argsAndTys'
351 : jhr 72 in
352 :     (* FIXME: check that actor is defined and has the argument types match *)
353 : jhr 81 (AST.S_New(actor, args'), env)
354 : jhr 72 end
355 :     | PT.S_Die => (AST.S_Die, env)
356 :     | PT.S_Stabilize => (AST.S_Stabilize, env)
357 : jhr 70 (* end case *))
358 :    
359 : jhr 82 fun checkParams (env, cxt, params) = let
360 :     fun chkParam (env, cxt, param) = (case param
361 : jhr 86 of PT.P_Mark m => chkParam (withEnvAndContext (env, cxt, m))
362 : jhr 82 | PT.P_Param(ty, x) => let
363 :     val x' = Var.new(x, AST.ActorParam, checkTy (cxt, ty))
364 :     in
365 :     (x', Env.insertLocal(env, x, x'))
366 :     end
367 :     (* end case *))
368 :     fun chk (param, (xs, env)) = let
369 :     val (x, env) = chkParam (env, cxt, param)
370 :     in
371 :     (x::xs, env)
372 :     end
373 :     in
374 :     (* FIXME: need to check for multiple occurences of the same parameter name! *)
375 :     List.foldr chk ([], env) params
376 :     end
377 :    
378 :     fun checkMethod (env, cxt, meth) = (case meth
379 : jhr 86 of PT.M_Mark m => checkMethod (withEnvAndContext (env, cxt, m))
380 : jhr 82 | PT.M_Method(name, body) => let
381 :     val (body, _) = checkStmt(env, cxt, body)
382 :     in
383 :     AST.M_Method(name, body)
384 :     end
385 :     (* end case *))
386 :    
387 :     fun checkActor (env, cxt, {name, params, state, methods}) = let
388 :     (* check the actor parameters *)
389 :     val (params, env) = checkParams (env, cxt, params)
390 :     (* check the actor state variable definitions *)
391 :     val (vds, env) = let
392 : jhr 164 fun checkStateVar ((isOut, vd), (vds, env)) = let
393 : jhr 169 val (x, x', e') = checkVarDecl ({globalScope=false, env=env}, cxt, AST.ActorStateVar, vd)
394 : jhr 82 in
395 : jhr 164 ((isOut, AST.VD_Decl(x', e'))::vds, Env.insertLocal(env, x, x'))
396 : jhr 82 end
397 :     val (vds, env) = List.foldl checkStateVar ([], env) state
398 :     in
399 :     (List.rev vds, env)
400 :     end
401 :     (* check the actor methods *)
402 :     val methods = List.map (fn m => checkMethod (env, cxt, m)) methods
403 :     in
404 :     AST.D_Actor{name = name, params = params, state = vds, methods = methods}
405 :     end
406 :    
407 : jhr 89 fun checkCreate (env, cxt, PT.C_Mark m) = checkCreate (withEnvAndContext (env, cxt, m))
408 :     | checkCreate (env, cxt, PT.C_Create(actor, args)) = let
409 : jhr 169 val (args, tys) = checkLocalExprList (env, cxt, args)
410 : jhr 89 in
411 :     (* FIXME: check against actor definition *)
412 :     AST.C_Create(actor, args)
413 :     end
414 :    
415 :     fun checkIter (env, cxt, PT.I_Mark m) = checkIter (withEnvAndContext (env, cxt, m))
416 :     | checkIter (env, cxt, PT.I_Range(x, e1, e2)) = let
417 : jhr 169 val (e1', ty1) = checkLocalExpr (env, cxt, e1)
418 :     val (e2', ty2) = checkLocalExpr (env, cxt, e2)
419 : jhr 89 val x' = Var.new(x, Var.LocalVar, Ty.T_Int)
420 :     val env' = Env.insertLocal(env, x, x')
421 :     in
422 :     case (ty1, ty2)
423 :     of (Ty.T_Int, Ty.T_Int) => (AST.I_Range(x', e1', e2'), env')
424 :     | _ => err(cxt, [
425 :     S "range expressions must have integer type\n",
426 :     S " but found: ", TY ty1, S " .. ", TY ty2, S "\n"
427 :     ])
428 :     (* end case *)
429 :     end
430 :    
431 :     fun checkIters (env, cxt, iters) = let
432 :     fun chk (env, [], iters) = (List.rev iters, env)
433 :     | chk (env, iter::rest, iters) = let
434 :     val (iter, env) = checkIter (env, cxt, iter)
435 :     in
436 :     chk (env, rest, iter::iters)
437 :     end
438 :     in
439 :     chk (env, iters, [])
440 :     end
441 :    
442 : jhr 71 fun checkDecl (env, cxt, d) = (case d
443 : jhr 86 of PT.D_Mark m => checkDecl (withEnvAndContext (env, cxt, m))
444 : jhr 72 | PT.D_Input(ty, x, optExp) => let
445 : jhr 71 val ty = checkTy(cxt, ty)
446 :     val x' = Var.new(x, Var.InputVar, ty)
447 :     val dcl = (case optExp
448 :     of NONE => AST.D_Input(x', NONE)
449 :     | SOME e => let
450 : jhr 169 val (e', ty') = checkGlobalExpr (env, cxt, e)
451 : jhr 71 in
452 : jhr 89 if U.matchType (ty, ty')
453 :     then AST.D_Input(x', SOME e')
454 :     else err(cxt, [
455 :     S "definition of ", V x', S " has wrong type\n",
456 :     S " expected: ", TY ty, S "\n",
457 :     S " but found: ", TY ty', S "\n"
458 :     ])
459 : jhr 71 end
460 :     (* end case *))
461 :     in
462 :     (dcl, Env.insertGlobal(env, x, x'))
463 :     end
464 : jhr 72 | PT.D_Var vd => let
465 : jhr 169 val (x, x', e') = checkVarDecl ({globalScope=true, env=env}, cxt, Var.GlobalVar, vd)
466 : jhr 72 in
467 : jhr 81 (AST.D_Var(AST.VD_Decl(x', e')), Env.insertGlobal(env, x, x'))
468 : jhr 72 end
469 : jhr 82 | PT.D_Actor arg => (checkActor(env, cxt, arg), env)
470 : jhr 89 | PT.D_InitialArray(create, iterators) => let
471 :     val (iterators, env') = checkIters (env, cxt, iterators)
472 :     val create = checkCreate (env', cxt, create)
473 :     in
474 :     (AST.D_InitialArray(create, iterators), env)
475 :     end
476 :     | PT.D_InitialCollection(create, iterators) => let
477 :     val (iterators, env') = checkIters (env, cxt, iterators)
478 :     val create = checkCreate (env', cxt, create)
479 :     in
480 :     (AST.D_InitialCollection(create, iterators), env)
481 :     end
482 : jhr 70 (* end case *))
483 :    
484 : jhr 86 fun check errStrm (PT.Program{span, tree}) = let
485 :     val cxt = (errStrm, span)
486 : jhr 81 fun chk (env, [], dcls') = AST.Program(List.rev dcls')
487 :     | chk (env, dcl::dcls, dcls') = let
488 : jhr 86 val (dcl', env) = checkDecl (env, cxt, dcl)
489 : jhr 81 in
490 :     chk (env, dcls, dcl'::dcls')
491 :     end
492 :     in
493 :     chk (Basis.env, tree, [])
494 :     end
495 : jhr 70
496 : jhr 69 end

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