annotate lab4/check.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* lab4/check.mli *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 open Tree
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 (* This module is the semantic analysis pass of the compiler. It
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 provides a single function |annotate| that takes a program, checks
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 it for semantic errors, and annotates defining and applied
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 occurrences identifiers with the corresponding definitions. These
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 annotations are used by the code generation pass to generate code
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11 for variable references.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 If a semantic error is detected, |annotate| raises the exception
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 |Sem_error|. There is no way of resuming the analysis, and only
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 one error can be detected per run of the compiler. *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 (* |annotate| -- check tree for type errors and annotate with definitions *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 val annotate : program -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 (* |Sem_error| -- exception raised on semantic error *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 exception Sem_error of string * Print.arg list * int
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 (* |regvars| -- whether to allocate register varaibles *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 val regvars : bool ref