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

SCM Repository

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

Annotation of /branches/vis15/src/compiler/typechecker/typechecker.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5540 - (view) (download)

1 : jhr 3401 (* typechecker.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 : jhr 5540 * COPYRIGHT (c) 2018 The University of Chicago
6 : jhr 3401 * All rights reserved.
7 :     *)
8 :    
9 :     structure Typechecker : sig
10 :    
11 : jhr 3410 (* type check a Diderot program *)
12 : jhr 5081 val check : CmdLineConstants.t
13 :     -> Error.err_stream
14 : jhr 5540 -> (ParseTree.version * ParseTree.program)
15 : jhr 5081 -> AST.program * GlobalEnv.t
16 : jhr 3401
17 :     end = struct
18 :    
19 :     structure PT = ParseTree
20 : jhr 3410 structure E = Env
21 : jhr 3401
22 : jhr 5540 fun check defs errStrm (vers, PT.Program{span, tree}) = let
23 : jhr 4491 val {globals, globInit, strand, start, create, update} = tree
24 : jhr 3401 val cxt = (errStrm, span)
25 : jhr 5540 val env = E.new vers
26 : jhr 4317 val {const_dcls, input_dcls, other_dcls, env} =
27 : jhr 5081 CheckGlobals.check (defs, env, cxt, globals)
28 : jhr 4327 val globInit' = Option.map
29 : jhr 5081 (fn stm => CheckStmt.check (E.initScope env, cxt, stm)) globInit
30 : jhr 4317 val (strand', env) = CheckStrand.check (env, cxt, strand)
31 :     val create' = CheckCreate.check (env, cxt, create)
32 : jhr 4491 val start' = (case start
33 : jhr 4317 of SOME stm => (
34 : jhr 4491 E.recordProp (env, Properties.GlobalStart);
35 :     SOME(CheckStmt.check(E.startScope env, cxt, stm)))
36 : jhr 4317 | NONE => NONE
37 :     (* end case *))
38 :     val update' = (case update
39 :     of SOME stm => (
40 :     E.recordProp(env, Properties.GlobalUpdate);
41 :     SOME(CheckStmt.check(E.updateScope env, cxt, stm)))
42 :     | NONE => NONE
43 :     (* end case *))
44 : jhr 5081 val props = E.properties env
45 : jhr 4317 val prog = AST.Program{
46 : jhr 4502 props = props,
47 : jhr 4317 const_dcls = const_dcls,
48 :     input_dcls = input_dcls,
49 :     globals = other_dcls,
50 :     globInit = globInit',
51 :     strand = strand',
52 :     create = create',
53 : jhr 4491 start = start',
54 : jhr 4317 update = update'
55 :     }
56 : jhr 3401 in
57 : jhr 5081 (* check for unused/uninitialized variables *)
58 : jhr 3413 CheckVarUses.check (cxt, prog);
59 : jhr 5081 (* check for new/die in a program that produces an array result *)
60 :     if Properties.hasProp Properties.StrandArray props
61 :     then let
62 :     fun err kind = let
63 :     val cxt = (case create
64 :     of PT.CR_Mark{span, ...} => (#1 cxt, span)
65 :     | _ => cxt
66 :     (* end case *))
67 :     in
68 :     TypeError.error(cxt, [
69 :     TypeError.S "'create_array' conflicts with previous use of '",
70 :     TypeError.S kind,
71 :     TypeError.S "'; use 'create_collection' instead."
72 :     ])
73 :     end
74 :     in
75 :     if Properties.hasProp Properties.StrandsMayDie props
76 :     then err "die"
77 :     else ();
78 :     if Properties.hasProp Properties.NewStrands props
79 :     then err "new"
80 :     else ()
81 :     end
82 :     else ();
83 : jhr 4371 (prog, E.globalEnv env)
84 : jhr 3401 end
85 :    
86 :     end

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