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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

1 : jhr 71 (* var.sml
2 :     *
3 : jhr 3349 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 71 * All rights reserved.
7 :     *)
8 :    
9 :     structure Var =
10 :     struct
11 :    
12 :     datatype var = datatype AST.var
13 :    
14 : jhr 72 datatype var_kind = datatype AST.var_kind
15 :    
16 : jhr 79 fun nameOf (V{name, ...}) = name
17 : jhr 71 fun typeOf (V{ty, ...}) = ty
18 : jhr 171 fun monoTypeOf (V{ty=([], ty), ...}) = ty
19 :     | monoTypeOf (V{name, ...}) = raise Fail(name ^ " is not monomrphic")
20 : jhr 72 fun kindOf (V{kind, ...}) = kind
21 : jhr 173 fun uniqueNameOf (V{name, id, ...}) = name ^ Stamp.toString id
22 : jhr 71
23 : jhr 78 fun newPoly (name, kind, scheme) = let
24 :     val id = Stamp.new()
25 :     in
26 : jhr 2660 V{name=Atom.toString name, id=id, kind=kind, ty=scheme, props=PropList.newHolder()}
27 : jhr 78 end
28 :    
29 : jhr 2660 fun new (name, kind, ty) = newPoly (name, kind, ([], ty))
30 : jhr 2356
31 : jhr 2660 fun copy (V{name, kind, ty, ...}) =
32 :     V{name=name, id=Stamp.new(), kind=kind, ty=ty, props=PropList.newHolder()}
33 :    
34 : jhr 2356 (* return true if variable has global scope *)
35 :     fun isGlobal (V{kind, ...}) = (case kind
36 :     of BasisVar => true
37 :     | InputVar => true
38 :     | GlobalVar => true
39 :     | FunVar => true
40 :     | _ => false
41 :     (* end case *))
42 :    
43 : jhr 2660 fun newProp initFn = PropList.newProp (fn (V{props, ...}) => props, initFn)
44 :     fun newFlag () = PropList.newFlag (fn (V{props, ...}) => props)
45 :    
46 : jhr 136 fun compare (V{id=a, ...}, V{id=b, ...}) = Stamp.compare(a, b)
47 :     fun same (V{id=a, ...}, V{id=b, ...}) = Stamp.same(a, b)
48 :     fun hash (V{id, ...}) = Stamp.hash id
49 :    
50 : jhr 2660 fun kindToString (V{kind, ...}) = (case kind
51 :     of BasisVar => "basis variable"
52 :     | InputVar => "input variable"
53 :     | GlobalVar => "global variable"
54 :     | FunVar => "function"
55 :     | StrandParam => "strand parameter"
56 :     | StrandStateVar => "state variable"
57 :     | StrandOutputVar => "strand output variable"
58 :     | LocalVar => "variable"
59 :     (* end case *))
60 :    
61 : jhr 136 local
62 :     structure V =
63 :     struct
64 :     type ord_key = var
65 :     val compare = compare
66 :     end
67 :     in
68 :     structure Map = RedBlackMapFn (V)
69 :     structure Set = RedBlackSetFn (V)
70 :     end
71 :    
72 : jhr 193 structure Tbl = HashTableFn (
73 :     struct
74 :     type hash_key = var
75 :     val hashVal = hash
76 :     val sameKey = same
77 :     end)
78 :    
79 : jhr 71 end

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