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

SCM Repository

[diderot] Annotation of /trunk/src/compiler/ast/meta-var.sml
ViewVC logotype

Annotation of /trunk/src/compiler/ast/meta-var.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 81 - (view) (download)
Original Path: trunk/src/ast/meta-var.sml

1 : jhr 75 (* meta-var.sml
2 : jhr 65 *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 : jhr 75 *
6 :     * The Diderot typechecker uses four kinds of meta variables:
7 :     *
8 :     * type variables
9 :     * differentiation variables
10 :     * shape variables
11 :     * dimension variables
12 : jhr 65 *)
13 :    
14 : jhr 75 structure MetaVar =
15 : jhr 65 struct
16 :    
17 : jhr 75 datatype ty_var = datatype Types.ty_var
18 :     datatype diff_var = datatype Types.diff_var
19 :     datatype shape_var = datatype Types.shape_var
20 :     datatype dim_var = datatype Types.dim_var
21 :     datatype kind = datatype Types.kind
22 : jhr 65
23 : jhr 75
24 :     (***** Type variables ****)
25 :    
26 :     fun newTyVar () = TV{
27 :     id = Stamp.new(),
28 :     bind = ref NONE
29 : jhr 65 }
30 :    
31 : jhr 75 fun tyVarToString (TV{id, ...}) = "'ty" ^ Stamp.toString id
32 :    
33 :    
34 :     (***** Differentiation variables ****)
35 :    
36 : jhr 81 fun newDiffVar bnd = DfV{
37 : jhr 75 id = Stamp.new(),
38 : jhr 81 bound = ref bnd,
39 : jhr 75 bind = ref NONE
40 :     }
41 :    
42 :     fun diffVarToString (DfV{id, ...}) = "'diff" ^ Stamp.toString id
43 :    
44 :    
45 :     (***** Shape variables ****)
46 :    
47 :     fun newShapeVar () = SV{
48 :     id = Stamp.new(),
49 :     bind = ref NONE
50 :     }
51 :    
52 :     fun shapeVarToString (SV{id, ...}) = "'shp" ^ Stamp.toString id
53 :    
54 :    
55 :     (***** Dimension variables ****)
56 :    
57 :     fun newDimVar () = DV{
58 :     id = Stamp.new(),
59 :     bind = ref NONE
60 :     }
61 :    
62 :     fun dimVarToString (DV{id, ...}) = "'dim" ^ Stamp.toString id
63 :    
64 :    
65 :     (***** Meta variables ****)
66 :    
67 :     fun metaToString (TYPE tv) = tyVarToString tv
68 :     | metaToString (DIFF dv) = diffVarToString dv
69 :     | metaToString (SHAPE sv) = shapeVarToString sv
70 :     | metaToString (DIM dv) = dimVarToString dv
71 :    
72 : jhr 81 fun stamp (TYPE(TV{id, ...})) = id
73 :     | stamp (DIFF(DfV{id, ...})) = id
74 :     | stamp (SHAPE(SV{id, ...})) = id
75 :     | stamp (DIM(DV{id, ...})) = id
76 :    
77 :     fun copy (TYPE _) = TYPE(newTyVar())
78 :     | copy (DIFF(k as DfV{bound, ...})) = DIFF(newDiffVar(!bound))
79 :     | copy (SHAPE _) = SHAPE(newShapeVar())
80 :     | copy (DIM _) = DIM(newDimVar())
81 :    
82 :     structure Map = RedBlackMapFn (
83 :     struct
84 :     type ord_key = Types.meta_var
85 :     fun compare (mv1, mv2) = Stamp.compare(stamp mv1, stamp mv2)
86 :     end)
87 :    
88 : jhr 65 end

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