home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-03 | 7.1 KB | 283 lines | [TEXT/R*ch] |
- (* Initialization of built-in units *)
-
- open List Fnlib Const Smlexc Prim Smlprim Globals Units Types;
-
- (* --- Global infix basis --- *)
-
- val std_infix_basis =
- [
- ("before", INFIXst 0),
- ("o", INFIXst 3), (":=", INFIXst 3),
- ("=", INFIXst 4), ("<>", INFIXst 4),
- ("<", INFIXst 4), (">", INFIXst 4),
- ("<=", INFIXst 4), (">=", INFIXst 4),
- ("@", INFIXRst 5), ("::", INFIXRst 5),
- ("+", INFIXst 6), ("-", INFIXst 6),
- ("^", INFIXst 6),
- ("div", INFIXst 7), ("mod", INFIXst 7),
- ("rem", INFIXst 7), ("quot", INFIXst 7),
- ("*", INFIXst 7), ("/", INFIXst 7)
- ];
-
- val () =
- app
- (fn(id, status) =>
- Hasht.insert pervasiveInfixTable id status)
- std_infix_basis
- ;
-
- (* --- Initial constructor basis --- *)
-
- val infoFalse = hd(initial_bool_CE)
- and infoTrue = hd(tl initial_bool_CE)
- and infoNil = hd(initial_list_CE)
- and infoCons = hd(tl initial_list_CE)
- and infoNONE = hd(initial_option_CE)
- and infoSOME = hd(tl initial_option_CE)
- and infoLESS = hd(initial_ordering_CE)
- and infoEQUAL = hd(tl initial_ordering_CE)
- and infoGREATER = hd(tl (tl initial_ordering_CE))
- and infoQUOTE = hd(initial_frag_CE)
- and infoANTIQUOTE = hd(tl initial_frag_CE)
- ;
-
- val initial_prim_basis =
- [
- ("=", (1, MLPeq)),
- ("<>", (1, MLPnoteq)),
- ("div", (1, MLPdiv_int)),
- ("mod", (1, MLPmod_int)),
- ("quot", (1, MLPquot_int)),
- ("rem", (1, MLPrem_int)),
- ("/", (1, MLPdiv_real)),
- ("floor", (1, MLPccall(1, "sml_floor"))),
- ("real", (1, MLPprim(1, Pfloatprim Pfloatofint))),
- ("sqrt", (1, MLPccall(1, "sml_sqrt"))),
- ("sin", (1, MLPccall(1, "sml_sin"))),
- ("cos", (1, MLPccall(1, "sml_cos"))),
- ("arctan", (1, MLPccall(1, "atan_float"))),
- ("exp", (1, MLPccall(1, "sml_exp"))),
- ("ln", (1, MLPccall(1, "sml_ln"))),
- ("^", (1, MLPconcat)),
- ("size", (1, MLPprim(1, Pstringlength))),
- ("!", (1, MLPprim(1, Pfield 0))),
- (":=", (1, MLPsetref)),
- ("not", (1, MLPprim(1, Pnot))),
- ("ignore", (1, MLPprim(1, Patom 0)))
- ];
-
- val initial_con_basis =
- [
- (* --- Constructors --- *)
- ("false", CONname (#info infoFalse)),
- ("true", CONname (#info infoTrue)),
- ("nil", CONname (#info infoNil)),
- ("::", CONname (#info infoCons)),
- ("NONE", CONname (#info infoNONE)),
- ("SOME", CONname (#info infoSOME)),
- ("LESS", CONname (#info infoLESS)),
- ("EQUAL", CONname (#info infoEQUAL)),
- ("GREATER", CONname (#info infoGREATER)),
- ("QUOTE", CONname (#info infoQUOTE)),
- ("ANTIQUOTE", CONname (#info infoANTIQUOTE)),
- ("ref", REFname),
- (* --- Overloaded operators --- *)
- ("~", VARname OVL1NNo),
- ("abs", VARname OVL1NNo),
- ("+", VARname OVL2NNNo),
- ("-", VARname OVL2NNNo),
- ("*", VARname OVL2NNNo),
- ("<", VARname OVL2NNBo),
- (">", VARname OVL2NNBo),
- ("<=", VARname OVL2NNBo),
- (">=", VARname OVL2NNBo),
- ("makestring", VARname OVL1NSo)
- ];
-
- (* *** Initial static environments *** *)
-
- (* Typing variable environment *)
-
- val sc_bool =
- trivial_scheme type_bool
- and sc_ii_i = trivial_scheme
- (type_arrow (type_pair type_int type_int) type_int)
- and sc_r_r = trivial_scheme
- (type_arrow type_real type_real)
- and sc_s_i = trivial_scheme
- (type_arrow type_string type_int)
- and sc_ss_s = trivial_scheme
- (type_arrow (type_pair type_string type_string) type_string)
- and sc_exn =
- trivial_scheme type_exn
- ;
-
- fun VEofCE (CE : ConEnv) =
- map (fn ci => (#id(#qualid ci), #conType(! (#info ci)))) CE
- ;
-
- val initial_eq_VE =
- [
- ("=", scheme_1u_eq (fn a =>
- type_arrow (type_pair a a) type_bool)),
- ("<>", scheme_1u_eq (fn a =>
- type_arrow (type_pair a a) type_bool))
- ];
-
- val initial_int_VE =
- [
- ("div", sc_ii_i),
- ("mod", sc_ii_i),
- ("quot", sc_ii_i),
- ("rem", sc_ii_i)
- ];
-
- val initial_real_VE =
- [
- ("/", trivial_scheme
- (type_arrow (type_pair type_real type_real) type_real)),
- ("floor", trivial_scheme (type_arrow type_real type_int)),
- ("real", trivial_scheme (type_arrow type_int type_real)),
- ("sqrt", sc_r_r),
- ("sin", sc_r_r),
- ("cos", sc_r_r),
- ("arctan", sc_r_r),
- ("exp", sc_r_r),
- ("ln", sc_r_r)
- ];
-
- val initial_string_VE =
- [
- ("^", sc_ss_s),
- ("size", sc_s_i)
- ];
-
- val initial_ref_VE =
- [
- ("ref", scheme_1u_imp (fn a =>
- type_arrow a (type_ref a))),
- ("!", scheme_1u (fn a =>
- type_arrow (type_ref a) a)),
- (":=", scheme_1u (fn a =>
- type_arrow (type_pair (type_ref a) a) type_unit))
- ];
-
- val sml_initial_VE = concat
- [
- initial_eq_VE,
- VEofCE initial_bool_CE,
- initial_int_VE,
- initial_real_VE,
- initial_string_VE,
- VEofCE initial_list_CE,
- VEofCE initial_option_CE,
- VEofCE initial_ordering_CE,
- VEofCE initial_frag_CE,
- initial_ref_VE,
- [("not", trivial_scheme(type_arrow type_bool type_bool))],
- [("ignore", scheme_1u (fn a => type_arrow a type_unit))]
- ];
-
- val sml_initial_TE =
- [
- ("unit", tyname_unit),
- ("bool", tyname_bool),
- ("int", tyname_int),
- ("char", tyname_char),
- ("real", tyname_real),
- ("string", tyname_string),
- ("list", tyname_list),
- ("vector", tyname_vector),
- ("option", tyname_option),
- ("ordering", tyname_ordering),
- ("frag", tyname_frag),
- ("ref", tyname_ref),
- ("exn", tyname_exn),
- ("ppstream", tyname_ppstream)
- ];
-
- val generalExceptions =
- [
- ];
-
- fun mkEmptyInfixBasis() =
- (Hasht.new 23 : (string, InfixStatus) Hasht.t)
- ;
-
- val () =
- app (fn (id, (arity,prim)) =>
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid={qual="General", id=id},
- info=PRIMname (mkPrimInfo arity prim) })
- initial_prim_basis
- ;
-
- val () =
- app (fn (id, ci) =>
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid={qual="General", id=id}, info=ci })
- initial_con_basis
- ;
-
- val () =
- app (fn (id, sc) =>
- Hasht.insert (#uVarEnv unit_General) id sc)
- sml_initial_VE
- ;
-
- val () =
- app (fn (id, tn) =>
- Hasht.insert (#uTyEnv unit_General) id tn)
- sml_initial_TE
- ;
-
- fun mkEi q arity =
- let val ei = mkExConInfo() in
- setExConArity ei arity;
- setExConTag ei (SOME (q, 0));
- ei
- end;
-
- val () =
- app (fn (id, ((q, stamp), arity)) =>
- let val q = {qual="General", id=id} in
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid=q, info=EXNname(mkEi q arity)}
- end)
- predefExceptions
- ;
-
- val () =
- app (fn (id, arity, sc) =>
- let val q = {qual="General", id=id} in
- Hasht.insert
- (#uConBasis unit_General) id
- { qualid=q, info=EXNname(mkEi q arity)}
- end)
- generalExceptions
-
- ;
-
- val sc_str_exn = trivial_scheme (type_arrow type_string type_exn);
-
- val () =
- app (fn (id, sc) => Hasht.insert (#uVarEnv unit_General) id sc)
- (map (fn (id, (_, 1)) => (id, sc_str_exn)
- | (id, (_, 0)) => (id, sc_exn)
- | (_, _) => fatalError "smlperv: ill-defined exception")
- predefExceptions)
-
- ;
-
- val () =
- app (fn (id, arity, sc) => Hasht.insert (#uVarEnv unit_General) id sc)
- generalExceptions
- ;
-
- val () =
- Hasht.insert pervSigTable "General" unit_General
- ;
-