home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / compiler / Globals.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  6.0 KB  |  271 lines  |  [TEXT/R*ch]

  1. local
  2.   open Fnlib Mixture Const Smlprim;
  3. in
  4.  
  5. (* Internally, a global is represented by its fully qualified name,
  6.    plus associated information. *)
  7.  
  8. type 'a global =
  9. {
  10.   info: 'a,               (* Description *)
  11.   qualid: QualifiedIdent  (* Full name *)
  12. };
  13.  
  14. datatype TyNameEqu = FALSEequ | TRUEequ | REFequ;
  15.  
  16. datatype TyStr  =
  17.     NILts
  18.   | TYPEts of TypeVar list * Type
  19.   | DATATYPEts of int
  20.   | REAts of TyName
  21.  
  22. and Type =
  23.     VARt of TypeVar
  24.   | ARROWt of Type * Type
  25.   | CONt of Type list * TyName
  26.   | RECt of { fields: (Lab * Type) list, rho: RowType } ref
  27.  
  28. and TypeVarKind =
  29.     Explicit of string
  30.   | NoLink
  31.   | LinkTo of Type
  32.  
  33. and RowTypeKind =
  34.     NILrow
  35.   | VARrow of RowVar
  36.   | LINKrow of RowType
  37.   | FIELDrow of Lab * Type * RowType
  38.  
  39. and TypeScheme = TypeScheme of
  40. {
  41.   tscParameters: TypeVar list,
  42.   tscBody: Type
  43. }
  44.  
  45. withtype TyName =
  46. {
  47.   tnArity: int,
  48.   tnEqu: TyNameEqu,
  49.   tnStamp: int,
  50.   tnStr: TyStr
  51. } ref global
  52.  
  53. and ConInfo =
  54. {
  55.   conArity: int,
  56.   conIsGreedy: bool,
  57.   conSpan: int,
  58.   conTag: int,
  59.   conType : TypeScheme
  60. } ref
  61.  
  62. and ExConInfo =
  63. {
  64.   exconArity: int,
  65.   exconIsGreedy: bool,
  66.   exconTag : (QualifiedIdent * int) option
  67. } ref
  68.  
  69. and TypeVar =
  70. {
  71.   tvEqu : bool,
  72.   tvImp : bool,
  73.   tvKind : TypeVarKind,
  74.   tvLevel : int,
  75.   tvOvl : bool
  76. } ref
  77.  
  78. and RowType = RowTypeKind ref
  79.  
  80. and RowVar =
  81. {
  82.   rvEqu : bool,
  83.   rvImp : bool,
  84.   rvLevel : int
  85. } ref
  86. ;
  87.  
  88. type RecType = { fields: (Lab * Type) list, rho: RowType } ref;
  89.  
  90. type ConEnv = ConInfo global list;
  91.  
  92. datatype OvlType =
  93.     REGULARo
  94.   | OVL1NNo
  95.   | OVL1NSo
  96.   | OVL2NNBo
  97.   | OVL2NNNo
  98.   | OVL1TXXo
  99.   | OVL1TPUo
  100. ;
  101.  
  102. type PrimInfo =
  103. {
  104.   primArity: int,
  105.   primOp: SMLPrim
  106. };
  107.  
  108. datatype ConStatusDesc =
  109.     VARname of OvlType
  110.   | PRIMname of PrimInfo
  111.   | CONname of ConInfo
  112.   | EXNname of ExConInfo
  113.   | REFname
  114. ;
  115.  
  116. type ConStatus = ConStatusDesc global;
  117.  
  118. type ConBasis = (string, ConStatus) Env;
  119. type TyEnv  = (string, TyName) Env;
  120. type VarEnv = (string, TypeScheme) Env;
  121.  
  122. datatype InfixStatus =
  123.     NONFIXst
  124.   | INFIXst of int
  125.   | INFIXRst of int
  126. ;
  127.  
  128. type InfixBasis = (string, InfixStatus) Env;
  129.  
  130. (* Updaters *)
  131.  
  132. fun setTnStamp r new_stamp =
  133.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  134.     r := { tnStamp=new_stamp, tnArity=arity, tnEqu=equ, tnStr=str }
  135.   end;
  136.  
  137. fun setTnEqu r new_equ =
  138.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  139.     r := { tnStamp=stamp, tnArity=arity, tnEqu=new_equ, tnStr=str }
  140.   end;
  141.  
  142. fun setTnStr r new_str =
  143.   let val { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=str } = !r in
  144.     r := { tnStamp=stamp, tnArity=arity, tnEqu=equ, tnStr=new_str }
  145.   end;
  146.  
  147. fun setConArity r new_arity =
  148.   let val { conArity=arity, conIsGreedy=isGreedy,
  149.             conTag=tag, conSpan=span, conType=typ }
  150.           = !r
  151.   in r :=
  152.     { conArity=new_arity, conIsGreedy=isGreedy,
  153.       conTag=tag, conSpan=span, conType=typ }
  154.   end;
  155.  
  156. fun setConIsGreedy r new_isGreedy =
  157.   let val { conArity=arity, conIsGreedy=isGreedy,
  158.             conTag=tag, conSpan=span, conType=typ }
  159.           = !r
  160.   in r :=
  161.     { conArity=arity, conIsGreedy=new_isGreedy,
  162.       conTag=tag, conSpan=span, conType=typ }
  163.   end;
  164.  
  165. fun setConTag r new_tag =
  166.   let val { conArity=arity, conIsGreedy=isGreedy,
  167.             conTag=tag, conSpan=span, conType=typ }
  168.           = !r
  169.   in r :=
  170.     { conArity=arity, conIsGreedy=isGreedy,
  171.       conTag=new_tag, conSpan=span, conType=typ }
  172.   end;
  173.  
  174. fun setConSpan r new_span =
  175.   let val { conArity=arity, conIsGreedy=isGreedy,
  176.             conTag=tag, conSpan=span, conType=typ }
  177.           = !r
  178.   in r :=
  179.     { conArity=arity, conIsGreedy=isGreedy,
  180.       conTag=tag, conSpan=new_span, conType=typ }
  181.   end;
  182.  
  183. fun setConType (r : ConInfo) new_typ =
  184.   let val { conArity=arity, conIsGreedy=isGreedy,
  185.             conTag=tag, conSpan=span, conType=typ }
  186.           = !r
  187.   in r :=
  188.     { conArity=arity, conIsGreedy=isGreedy,
  189.       conTag=tag, conSpan=span, conType=new_typ }
  190.   end;
  191.  
  192. fun setExConArity r new_arity =
  193.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  194.   in r :=
  195.     { exconArity=new_arity, exconIsGreedy=isGreedy, exconTag=tag }
  196.   end;
  197.  
  198. fun setExConIsGreedy r new_isGreedy =
  199.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  200.   in r :=
  201.     { exconArity=arity, exconIsGreedy=new_isGreedy, exconTag=tag }
  202.   end;
  203.  
  204. fun setExConTag r new_tag =
  205.   let val { exconArity=arity, exconIsGreedy=isGreedy, exconTag=tag } = !r
  206.   in r :=
  207.     { exconArity=arity, exconIsGreedy=isGreedy, exconTag=new_tag }
  208.   end;
  209.  
  210. fun setTvKind r new_kind =
  211.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  212.           = !r
  213.   in r :=
  214.     { tvKind=new_kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  215.   end;
  216.  
  217. fun setTvLevel r new_level =
  218.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  219.           = !r
  220.   in r :=
  221.     { tvKind=kind, tvLevel=new_level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  222.   end;
  223.  
  224. fun setTvEqu r new_equ =
  225.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  226.           = !r
  227.   in r :=
  228.     { tvKind=kind, tvLevel=level, tvEqu=new_equ, tvImp=imp, tvOvl=ovl }
  229.   end;
  230.  
  231. fun setTvImp r new_imp =
  232.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  233.           = !r
  234.   in r :=
  235.     { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=new_imp, tvOvl=ovl }
  236.   end;
  237.  
  238. fun setTvOvl r new_ovl =
  239.   let val { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=ovl }
  240.           = !r
  241.   in r :=
  242.     { tvKind=kind, tvLevel=level, tvEqu=equ, tvImp=imp, tvOvl=new_ovl }
  243.   end;
  244.  
  245. fun setRtFields r new_fields =
  246.   let val { fields=fields, rho=rho } = !r in
  247.     r := { fields=new_fields, rho=rho }
  248.   end;
  249.  
  250. fun setRtRho r new_rho =
  251.   let val { fields=fields, rho=rho } = !r in
  252.     r := { fields=fields, rho=new_rho }
  253.   end;
  254.  
  255. fun setRvEqu r new_equ =
  256.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  257.     r := { rvEqu=new_equ, rvImp=imp, rvLevel=level }
  258.   end;
  259.  
  260. fun setRvImp r new_imp =
  261.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  262.     r := { rvEqu=equ, rvImp=new_imp, rvLevel=level }
  263.   end;
  264.  
  265. fun setRvLevel r new_level =
  266.   let val { rvEqu=equ, rvImp=imp, rvLevel=level } = !r in
  267.     r := { rvEqu=equ, rvImp=imp, rvLevel=new_level }
  268.   end;
  269.  
  270. end;
  271.