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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4624 - (download) (annotate)
Sat Sep 24 19:24:23 2016 UTC (2 years, 9 months ago) by jhr
File size: 2804 byte(s)
  working on merge: forgot to check for new/create_array conflict
(* typechecker.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 *)

structure Typechecker : sig

  (* type check a Diderot program *)
    val check : Error.err_stream -> ParseTree.program -> AST.program * GlobalEnv.t

  end = struct

    structure PT = ParseTree
    structure E = Env

    fun check errStrm (PT.Program{span, tree}) = let
          val {globals, globInit, strand, start, create, update} = tree
          val cxt = (errStrm, span)
          val env = E.new()
          val {const_dcls, input_dcls, other_dcls, env} =
                CheckGlobals.check (env, cxt, globals)
          val globInit' = Option.map
		(fn stm => CheckStmt.check (E.initScope env, cxt, stm)) globInit
          val (strand', env) = CheckStrand.check (env, cxt, strand)
          val create' = CheckCreate.check (env, cxt, create)
          val start' = (case start
                 of SOME stm => (
                      E.recordProp (env, Properties.GlobalStart);
                      SOME(CheckStmt.check(E.startScope env, cxt, stm)))
                  | NONE => NONE
                (* end case *))
          val update' = (case update
                 of SOME stm => (
                      E.recordProp(env, Properties.GlobalUpdate);
                      SOME(CheckStmt.check(E.updateScope env, cxt, stm)))
                  | NONE => NONE
                (* end case *))
	  val props = E.properties env
          val prog = AST.Program{
                  props = props,
                  const_dcls = const_dcls,
                  input_dcls = input_dcls,
                  globals = other_dcls,
                  globInit = globInit',
                  strand = strand',
                  create = create',
                  start = start',
                  update = update'
                }
          in
	  (* check for unused/uninitialized variables *)
            CheckVarUses.check (cxt, prog);
	  (* check for new/die in a program that produces an array result *)
	    if Properties.hasProp Properties.StrandGrid props
	      then let
		fun err kind = let
		      val cxt = (case create
			     of PT.CR_Mark{span, ...} => (#1 cxt, span)
			      | _ => cxt
			    (* end case *))
		      in
			TypeError.error(cxt, [
		            TypeError.S "'create_array' conflicts with previous use of '",
			    TypeError.S kind,
			    TypeError.S "'; use 'create_collection' instead."
			  ])
		      end
		in
	          if Properties.hasProp Properties.StrandsMayDie props
		    then err "die"
		    else ();
	          if Properties.hasProp Properties.NewStrands props
		    then err "new"
		    else ()
		end
	      else ();
            (prog, E.globalEnv env)
          end

  end

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