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

SCM Repository

[diderot] Diff of /branches/vis12/src/compiler/typechecker/typechecker.sml
ViewVC logotype

Diff of /branches/vis12/src/compiler/typechecker/typechecker.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2148, Sun Feb 17 17:56:50 2013 UTC revision 2149, Sun Feb 17 18:22:12 2013 UTC
# Line 1  Line 1 
1  (* typechecker.sml  (* typechecker.sml
2   *   *
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2013 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * TODO:   * TODO:
7   *      check that variables are not redefined in the same scope   *      check for unreachable code and prune it (see simplify/simplify.sml)
8   *      int --> real type promotion   *      error recovery so that we can detect multiple errors in a single compile
9   *      sequence operations   *      check that functions have a return on all paths
10     *      check that strands have at least one output variable.
11   *)   *)
12    
13  structure Typechecker : sig  structure Typechecker : sig
14    
     exception Error  
   
15      val check : Error.err_stream -> ParseTree.program -> AST.program      val check : Error.err_stream -> ParseTree.program -> AST.program
16    
17    end = struct    end = struct
# Line 23  Line 22 
22      structure TU = TypeUtil      structure TU = TypeUtil
23      structure U = Util      structure U = Util
24    
25      (* exception to abort typechecking when we hit an error.  Eventually, we should continue
26       * checking for more errors and not use this.
27       *)
28        exception TypeError
29    
30      datatype scope      datatype scope
31        = GlobalScope        = GlobalScope
32        | FunctionScope of Ty.ty        | FunctionScope of Ty.ty
# Line 71  Line 75 
75              env=Env.insertGlobal(env, x, x')              env=Env.insertGlobal(env, x, x')
76            }            }
77    
     exception Error  
   
78      fun withContext ((errStrm, _), {span, tree}) =      fun withContext ((errStrm, _), {span, tree}) =
79            ((errStrm, span), tree)            ((errStrm, span), tree)
80      fun withEnvAndContext (env, (errStrm, _), {span, tree}) =      fun withEnvAndContext (env, (errStrm, _), {span, tree}) =
# Line 80  Line 82 
82    
83      fun error ((errStrm, span), msg) = (      fun error ((errStrm, span), msg) = (
84            Error.errorAt(errStrm, span, msg);            Error.errorAt(errStrm, span, msg);
85            raise Error)            raise TypeError)
86    
87      datatype token      datatype token
88        = S of string | A of Atom.atom        = S of string | A of Atom.atom
# Line 112  Line 114 
114    
115      val realZero = AST.E_Lit(Literal.Float(FloatLit.zero true))      val realZero = AST.E_Lit(Literal.Float(FloatLit.zero true))
116    
117    (* check a differentiation level, which muse be >= 0 *)    (* check a differentiation level, which must be >= 0 *)
118      fun checkDiff (cxt, k) =      fun checkDiff (cxt, k) =
119            if (k < 0)            if (k < 0)
120              then err (cxt, [S "differentiation must be >= 0"])              then err (cxt, [S "differentiation must be >= 0"])
# Line 742  Line 744 
744                    | PT.P_Param(ty, x) => let                    | PT.P_Param(ty, x) => let
745                        val x' = Var.new(x, AST.StrandParam, checkTy (cxt, ty))                        val x' = Var.new(x, AST.StrandParam, checkTy (cxt, ty))
746                        in                        in
747    (* FIXME: should use an empty bindings list for the parameters *)
748                          checkForRedef (env, cxt, x);                          checkForRedef (env, cxt, x);
749                          (x', insertLocal(env, cxt, x, x'))                          (x', insertLocal(env, cxt, x, x'))
750                        end                        end
# Line 752  Line 755 
755                    (x::xs, env)                    (x::xs, env)
756                  end                  end
757            in            in
 (* FIXME: need to check for multiple occurences of the same parameter name! *)  
758              List.foldr chk ([], env) params              List.foldr chk ([], env) params
759            end            end
760    
# Line 940  Line 942 
942            in            in
943              chk ({scope=GlobalScope, bindings=AtomMap.empty, env=Basis.env}, tree, [])              chk ({scope=GlobalScope, bindings=AtomMap.empty, env=Basis.env}, tree, [])
944            end            end
945                handle TypeError => AST.Program[]
946    
947    end    end

Legend:
Removed from v.2148  
changed lines
  Added in v.2149

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