home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / boot / system.sig < prev   
Encoding:
Text File  |  1993-02-05  |  25.5 KB  |  818 lines

  1. (* Copyright 1989 by AT&T Bell Laboratories *)
  2. (* boot/system.sig *)
  3.  
  4. signature HOOKS =
  5. sig
  6.   structure Assembly : ASSEMBLY
  7.  
  8.   (* System.Symbol components *)
  9.   val valSymbol_ref : (unit -> unit) ref
  10.   val tycSymbol_ref : (unit -> unit) ref
  11.   val sigSymbol_ref : (unit -> unit) ref
  12.   val strSymbol_ref : (unit -> unit) ref
  13.   val fctSymbol_ref : (unit -> unit) ref
  14.   val fixSymbol_ref : (unit -> unit) ref
  15.   val labSymbol_ref : (unit -> unit) ref
  16.   val tyvSymbol_ref : (unit -> unit) ref
  17.   val fsigSymbol_ref : (unit -> unit) ref
  18.   val name_ref      : (unit -> unit) ref
  19.   val makestring_ref: (unit -> unit) ref
  20.   val kind_ref      : (unit -> unit) ref
  21.   val nameSpace_ref : (unit -> unit) ref
  22.  
  23.   (* System.Env components *)
  24.   val emptyEnv_ref     : (unit -> unit) ref
  25.   val concatEnv_ref    : (unit -> unit) ref
  26.   val layerEnv_ref     : (unit -> unit) ref
  27.   val staticPart_ref   : (unit -> unit) ref
  28.   val layerStatic_ref  : (unit -> unit) ref
  29.   val filterEnv_ref    : (unit -> unit) ref
  30.   val filterStaticEnv_ref    : (unit -> unit) ref
  31.   val catalogEnv_ref   : (unit -> unit) ref
  32.   val describe_ref     : (unit -> unit) ref
  33.  
  34.   (* System.Compile components *)
  35.   val makeSource_ref  : (unit -> unit) ref
  36.   val closeSource_ref : (unit -> unit) ref
  37.   val changeLvars_ref : (unit -> unit) ref
  38.   val elaborate_ref   : (unit -> unit) ref
  39.   val parse_ref       : (unit -> unit) ref
  40.   val compile_ref     : (unit -> unit) ref
  41.   val compileAst_ref  : (unit -> unit) ref
  42.   val execute_ref     : (unit -> unit) ref
  43.   val eval_stream_ref : (unit -> unit) ref
  44.   val use_file_ref    : (unit -> unit) ref
  45.   val use_stream_ref  : (unit -> unit) ref
  46.  
  47.   (* System.PrettyPrint components *)
  48.   val mk_ppstream_ref : (unit -> unit) ref
  49.   val dest_ppstream_ref   : (unit -> unit) ref
  50.   val begin_block_ref : (unit -> unit) ref
  51.   val end_block_ref   : (unit -> unit) ref
  52.   val add_break_ref   : (unit -> unit) ref
  53.   val add_string_ref  : (unit -> unit) ref
  54.   val add_newline_ref : (unit -> unit) ref
  55.   val clear_ppstream_ref : (unit -> unit) ref 
  56.   val flush_ppstream_ref : (unit -> unit) ref 
  57.   val with_pp_ref     : (unit -> unit) ref 
  58.   val install_pp_ref  : (unit -> unit) ref
  59.  
  60.   val allocProfReset_ref : (unit -> unit) ref 
  61.   val allocProfPrint_ref : (unit -> unit) ref 
  62.   val prLambda        : (unit -> unit) ref
  63.   val debugInterface  : (int -> unit) ref
  64.   val lookup_r        : (int -> Assembly.object) ref
  65.   val profile_register : (string -> int * int array * int ref) ref
  66.   val toplevelcont    : unit cont ref
  67.  
  68.   val clear : unit -> unit
  69.   val profile_sregister : (Assembly.object * string -> Assembly.object) ref
  70.   val pervasiveEnvRef : Assembly.object ref
  71.   val topLevelEnvRef : Assembly.object ref
  72. end
  73.  
  74. signature RUNTIMECONTROL =
  75. sig
  76.   val collected : int ref
  77.   val collectedfrom : int ref
  78.   val gcmessages : int ref
  79.   val majorcollections : int ref
  80.   val minorcollections : int ref
  81.   val ratio : int ref
  82.   val softmax : int ref
  83.   val lastratio : int ref
  84. end
  85.  
  86. signature MCCONTROL =
  87. sig
  88.   val printArgs : bool ref
  89.   val printRet : bool ref
  90.   val bindContainsVar : bool ref
  91.   val bindExhaustive : bool ref
  92.   val matchExhaustive : bool ref
  93.   val matchRedundant : bool ref
  94.   val expandResult : bool ref
  95. end
  96.  
  97. signature CGCONTROL =
  98. sig
  99.   structure M68 : sig val trapv : bool ref end
  100.   val tailrecur : bool ref
  101.   val recordopt : bool ref
  102.   val tail : bool ref
  103.   val allocprof : bool ref
  104.   val closureprint : bool ref
  105.   val closureStrategy : int ref
  106.   val lambdaopt : bool ref
  107.   val cpsopt : bool ref
  108.   val rounds : int ref
  109.   val path : bool ref
  110.   val betacontract : bool ref
  111.   val eta : bool ref
  112.   val selectopt : bool ref
  113.   val dropargs : bool ref
  114.   val deadvars : bool ref
  115.   val flattenargs : bool ref
  116.   val switchopt : bool ref
  117.   val handlerfold : bool ref
  118.   val branchfold : bool ref
  119.   val arithopt : bool ref
  120.   val betaexpand : bool ref
  121.   val unroll : bool ref
  122.   val knownfiddle : bool ref
  123.   val invariant: bool ref
  124.   val targeting: int ref
  125.   val lambdaprop: bool ref
  126.   val newconreps : bool ref
  127.   val unroll_recur : bool ref
  128.   val hoistup : bool ref
  129.   val hoistdown : bool ref
  130.   val maxregs : int ref
  131.   val recordcopy : bool ref
  132.   val tagopt : bool ref
  133.   val recordpath : bool ref
  134.   val machdep : bool ref
  135.   val misc1 : bool ref
  136.   val misc2 : bool ref
  137.   val misc3 : int ref
  138.   val misc4 : int ref
  139.   val hoist : bool ref
  140.   val argrep : bool ref
  141.   val reduce : bool ref
  142.   val bodysize : int ref
  143.   val reducemore : int ref
  144.   val alphac : bool ref
  145.   val comment : bool ref
  146.   val knownGen : int ref
  147.   val knownClGen : int ref
  148.   val escapeGen : int ref
  149.   val calleeGen : int ref
  150.   val spillGen : int ref
  151.   val foldconst : bool ref
  152.   val etasplit : bool ref
  153.   val printLambda : bool ref
  154.   val printit : bool ref
  155.   val printsize : bool ref
  156.   val scheduling : bool ref
  157.   val cse : bool ref
  158.   val optafterclosure : bool ref
  159.   val calleesaves : int ref
  160.   val extraflatten : bool ref
  161.   val uncurry : bool ref
  162.   val ifidiom : bool ref
  163.   val comparefold : bool ref
  164.   val csehoist : bool ref
  165.   val rangeopt : bool ref
  166.   val floatargs : int ref
  167.   val floatvars : int ref
  168.   val floatreg_params : bool ref
  169.   val icount : bool ref
  170.   val representations : bool ref
  171. end
  172.  
  173. signature PRINTCONTROL =
  174. sig
  175.   type outstream
  176.   val printDepth : int ref
  177.   val printLength : int ref
  178.   val stringDepth : int ref
  179.   val printLoop : bool ref
  180.   val signatures : int ref
  181.   val pathnames : int ref
  182.   val out : outstream ref
  183.   val linewidth : int ref
  184.   val say : string -> unit 
  185.   val flush: unit -> unit
  186. end
  187.  
  188. signature DEBUG =
  189. sig
  190.   val debugging : bool ref
  191.   val getDebugf : (int -> 'a) ref
  192.   val interface : (int -> ('a -> 'b)) ref
  193. end
  194.  
  195. signature CONTROL =
  196. sig
  197.   structure Runtime : RUNTIMECONTROL
  198.   structure MC : MCCONTROL
  199.   structure CG : CGCONTROL
  200.   structure Print : PRINTCONTROL
  201.   structure Debug : DEBUG
  202.   val allocProfReset : unit -> unit
  203.   val allocProfPrint : unit -> unit
  204.   val prLambda : (unit -> unit) ref
  205.   val debugging : bool ref
  206.   val primaryPrompt : string ref
  207.   val secondaryPrompt : string ref
  208.   val internals : bool ref
  209.   val weakUnderscore : bool ref
  210.   val interp : bool ref
  211.   val debugLook : bool ref
  212.   val debugCollect : bool ref
  213.   val debugBind : bool ref
  214.   val saveLambda : bool ref
  215.   val saveLvarNames : bool ref
  216.   val timings : bool ref
  217.   val reopen : bool ref
  218.   val markabsyn : bool ref
  219.   val indexing : bool ref
  220.   val instSigs : bool ref
  221.   val quotation : bool ref
  222. end
  223.  
  224. signature TIMER =
  225. sig
  226.   datatype time = TIME of {sec : int, usec : int}
  227.   type timer
  228.   val start_timer : unit -> timer
  229.   val check_timer : timer -> time
  230.   val check_timer_sys: timer -> time
  231.   val check_timer_gc: timer -> time
  232.   val makestring : time -> string
  233.   val add_time : time * time -> time
  234.   val sub_time : time * time -> time
  235.   val earlier : time * time -> bool
  236. end
  237.  
  238. signature TAGS =
  239.   sig
  240.     type tag
  241.     val width_tags : int (* number of bits to hold a tag *)
  242.     val power_tags : int (* 2 ^ width_tags *)
  243.     val max_length : int (* one greater than max length value *)
  244.   (* tag values *)
  245.     val tag_record : tag
  246.     val tag_pair : tag
  247.     val tag_array : tag
  248.     val tag_string : tag
  249.     val tag_embedded_string : tag
  250.     val tag_bytearray : tag
  251.     val tag_reald : tag
  252.     val tag_embedded_reald : tag
  253.     val tag_realdarray : tag
  254.     val tag_variant : tag (* currently not used *)
  255.     val tag_special : tag
  256.     val tag_backptr : tag
  257.   (* build a descriptor from a tag and length *)
  258.     val make_desc : (int * tag) -> int
  259.   (* fixed descriptors *)
  260.     val desc_pair : int
  261.     val desc_reald : int
  262.     val desc_embedded_reald : int
  263.   (* special descriptors *)
  264.     val desc_special : int
  265.     val special_evaled_susp : int
  266.     val special_unevaled_susp : int
  267.     val special_weak : int
  268.     val special_nulled_weak : int
  269.   end
  270.  
  271. signature STATS =
  272. sig
  273.   structure Timer : TIMER
  274.   val lines : int ref
  275.   val parse : Timer.time ref
  276.   val debuginstrum: Timer.time ref
  277.   val translate : Timer.time ref
  278.   val codeopt : Timer.time ref
  279.   val convert : Timer.time ref
  280.   val hoist : Timer.time ref
  281.   val cpsopt : Timer.time ref
  282.   val closure : Timer.time ref
  283.   val globalfix : Timer.time ref
  284.   val spill : Timer.time ref
  285.   val codegen : Timer.time ref
  286.   val schedule : Timer.time ref
  287.   val freemap : Timer.time ref
  288.   val execution : Timer.time ref
  289.   val codesize : int ref
  290.   val update : Timer.time ref * Timer.time -> unit
  291.   val summary : unit -> unit
  292.   val reset : unit -> unit
  293. end
  294.  
  295. signature CINTERFACE =
  296. sig
  297.   exception CFunNotFound of string
  298.   exception SysError of (int * string)
  299.   exception SystemCall of string
  300.  
  301.   type time
  302.  
  303.   val c_function : string -> ('a -> 'b)
  304.   val c_string : string -> string (* insure that a string is safe to pass to C *)
  305.   val wrap_sysfn : string -> ('a -> 'b) -> 'a -> 'b
  306.  
  307. (* C functions *)
  308.   val argv        : unit -> string list
  309.   val environ        : unit -> string list
  310.   val gethostname : unit -> string
  311.   val exec        : (string * string list * string list) -> (int * int)
  312.   val system      : string -> int
  313.   val export      : int -> bool
  314.   val blas        : (int * 'a) -> int
  315.   val salb        : string -> 'a
  316.   val gettime     : unit -> {usr : time, sys : time, gc : time}
  317.   val setitimer   : (int * time * time) -> unit
  318.   val gc          : int -> unit
  319.   val syscall        : (int * string list) -> int
  320. (* System calls *)
  321.   val exit        : int -> 'a
  322.   val getpid        : unit -> int
  323.   val getuid        : unit -> int
  324.   val getgid        : unit -> int
  325.   val chdir        : string -> unit
  326.   val gethostid   : unit -> string
  327.   val gettimeofday   : unit -> time
  328. end (* CINTERFACE *)
  329.  
  330. signature SYSIO =
  331. sig
  332.   type bytearray
  333.   type time
  334.  
  335.   type fd
  336.   eqtype fileid
  337.   datatype fname    = DESC of fd | PATH of string
  338.   datatype mode    = O_READ | O_WRITE | O_APPEND
  339.   datatype whence    = L_SET | L_INCR | L_XTND
  340.   datatype access    = A_READ | A_WRITE | A_EXEC
  341.   datatype file_type    = F_REGULAR | F_DIR | F_SYMLINK | F_SOCK | F_CHR | F_BLK
  342.  
  343.   val dtablesize    : int
  344.   val openf        : (string * mode) -> fd
  345.   val closef        : fd -> unit
  346.   val unlink        : string -> unit
  347.   val pipe        : unit -> (fd * fd)
  348.   val connect_unix    : string -> fd
  349.   val connect_inet    : (string * string) -> fd
  350.   val link        : (string * string) -> unit
  351.   val symlink        : (string * string) -> unit
  352.   val mkdir        : (string * int) -> unit
  353.   val dup        : fd -> fd
  354.  
  355.   val read        : (fd * bytearray * int) -> int
  356.   val readi        : (fd * bytearray * int * int) -> int
  357.   val write        : (fd * bytearray * int) -> unit
  358.   val writei        : (fd * bytearray * int * int) -> unit
  359.   val writev        : (fd * (bytearray * int) list) -> unit
  360.   val send_obd    : (fd * bytearray * int) -> unit
  361.   val getdirent    : fd -> string list
  362.   val readlink    : string -> string
  363.   val truncate    : (fname * int) -> unit
  364.   val lseek        : (fd * int * whence) -> int
  365.  
  366.   val getmod        : fname -> int
  367.   val chmod        : (fname * int) -> unit
  368.   val umask        : int -> int
  369.  
  370.   val access        : (string * access list) -> bool
  371.   val isatty        : fd -> bool
  372.   val fionread    : fd -> int
  373.   val getfid        : fname -> fileid
  374.   val ftype        : fname -> file_type
  375.   val getownid    : fname -> (int * int)
  376.   val fsize        : fname -> int
  377.   val atime        : fname -> time
  378.   val ctime        : fname -> time
  379.   val mtime        : fname -> time
  380.   val select        : (fd list * fd list * fd list * time option)
  381.               -> (fd list * fd list * fd list)
  382. end (* SYSIO *)
  383.  
  384. signature SIGNALS =
  385. sig
  386.   datatype signal
  387.     = SIGHUP | SIGINT | SIGQUIT | SIGALRM | SIGVTALRM | SIGTERM | SIGURG
  388.     | SIGCHLD | SIGIO | SIGWINCH | SIGUSR1 | SIGUSR2 | SIGPROF
  389.     | SIGTSTP | SIGCONT (* not yet supported *)
  390.     | SIGGC
  391.   val setHandler : (signal * ((int * unit cont) -> unit cont) option) -> unit
  392.   val inqHandler : signal -> ((int * unit cont) -> unit cont) option
  393.   val maskSignals : bool -> unit
  394.   val masked : unit -> bool
  395.   val pause : unit -> unit (* sleep until the next signal *)
  396. end
  397.  
  398. signature DIRECTORY =
  399. sig
  400.   val isDir : string -> bool
  401.       (* return true, if path is a directory *)
  402.   exception NotDirectory
  403.   val listDir : string -> string list
  404.       (* return a list of the files in the specified directory,
  405.      raises NotDirectory *)
  406.   val cd : string -> unit
  407.       (* change directory, raises NotDirectory*)
  408.   val getWD : unit -> string
  409.       (* return the current working directory *)
  410. end (* DIRECTORY *)
  411.  
  412. signature SYMBOL =
  413. sig
  414.   type symbol
  415.   datatype namespace =
  416.      VALspace | TYCspace | SIGspace | STRspace | FCTspace | FIXspace |
  417.      LABspace | TYVspace | FSIGspace
  418.   val valSymbol : string -> symbol
  419.   val tycSymbol : string -> symbol
  420.   val sigSymbol : string -> symbol
  421.   val strSymbol : string -> symbol
  422.   val fctSymbol : string -> symbol
  423.   val fixSymbol : string -> symbol
  424.   val labSymbol : string -> symbol
  425.   val tyvSymbol : string -> symbol
  426.   val fsigSymbol : string -> symbol
  427.   val name      : symbol -> string
  428.   val makestring: symbol -> string
  429.   val kind      : symbol -> string
  430.   val nameSpace : symbol -> namespace
  431.   val makeSymbol: namespace * string -> symbol
  432. end
  433.  
  434. signature ENVIRONMENT =
  435. sig
  436.   exception Unbound
  437.   type environment
  438.   type staticEnv
  439.   val emptyEnv     : unit -> environment
  440.   val concatEnv    : environment * environment -> environment
  441.   val layerEnv     : environment * environment -> environment
  442.   val staticPart   : environment -> staticEnv
  443.   val layerStatic  : staticEnv * staticEnv -> staticEnv
  444.   val filterEnv    : environment * symbol list -> environment
  445.   val filterStaticEnv
  446.            : staticEnv * symbol list -> staticEnv
  447.   val catalogEnv   : staticEnv -> symbol list
  448.   val describe     : staticEnv -> symbol -> unit
  449.   val pervasiveEnvRef : environment ref
  450.   val topLevelEnvRef : environment ref
  451. end
  452.  
  453. signature AST = sig
  454.  
  455.   type fixity
  456.   type symbol
  457.   val infixleft : int -> fixity
  458.   val infixright : int -> fixity
  459.  
  460.   (* to mark positions in files *)
  461.   type filePos
  462.   (* symbolic path (Modules.spath) *)
  463.   type path
  464.  
  465.   (* EXPRESSIONS *)
  466.  
  467.   datatype exp
  468.     = VarExp of path        (* variable *)
  469.     | FnExp of rule list        (* abstraction *)
  470.     | AppExp of {function:exp,argument:exp}
  471.                   (* application *)
  472.     | CaseExp of{expr:exp,rules:rule list}
  473.                   (* case expression *)
  474.     | LetExp of {dec:dec,expr:exp} (* let expression *)
  475.     | SeqExp of exp list        (* sequence of expressions *)
  476.     | IntExp of int        (* integer *)
  477.     | RealExp of string        (* floating point coded by its string *)
  478.     | StringExp of string        (* string *)
  479.     | RecordExp of (symbol * exp) list    (* record *)
  480.     | TupleExp of exp list    (* tuple (derived form) *)
  481.     | SelectorExp of symbol    (* selector of a record field *)
  482.     | ConstraintExp of {expr:exp,constraint:ty}
  483.                   (* type constraint *)
  484.     | HandleExp of {expr:exp, rules:rule list}
  485.                   (* exception handler *)
  486.     | RaiseExp of exp        (* raise an exception *)
  487.     | IfExp of {test:exp, thenCase:exp, elseCase:exp}
  488.                   (* if expression (derived form) *)
  489.     | AndalsoExp of exp * exp    (* andalso (derived form) *)
  490.     | OrelseExp of exp * exp    (* orelse (derived form) *)
  491.     | VectorExp of exp list       (* vector *)
  492.     | WhileExp of {test:exp,expr:exp}
  493.                   (* while (derived form) *)
  494.     | MarkExp of exp * filePos * filePos    (* mark an expression *)
  495.  
  496.   (* RULE for case functions and exception handler *)
  497.   and rule = Rule of {pat:pat,exp:exp}
  498.  
  499.   (* PATTERN *)
  500.   and pat = WildPat                (* empty pattern *)
  501.       | VarPat of path            (* variable pattern *)
  502.       | IntPat of int            (* integer *)
  503.       | RealPat of string            (* floating point number *)
  504.       | StringPat of string            (* string *)
  505.       | RecordPat of {def:(symbol * pat) list, flexibility:bool}
  506.                         (* record *)
  507.       | TuplePat of pat list        (* tuple *)
  508.       | AppPat of {constr:path,argument:pat}(* application *)
  509.       | ConstraintPat of {pattern:pat,constraint:ty}
  510.                           (* constraint *)
  511.       | LayeredPat of {varPat:pat,expPat:pat}    (* as expressions *)
  512.           | VectorPat of pat list                 (* vector pattern *)
  513.       | MarkPat of pat * filePos * filePos    (* mark a pattern *)
  514.  
  515.   (* STRUCTURE EXPRESSION *)
  516.   and strexp = VarStr of path            (* variable structure *)
  517.          | StructStr of dec            (* defined structure *)
  518.          | AppStr of path * (strexp * bool) list (* application *)
  519.          | LetStr of dec * strexp        (* let in structure *)
  520.          | MarkStr of strexp * filePos * filePos (* mark *)
  521.  
  522.   (* FUNCTOR EXPRESSION *)
  523.   and fctexp = VarFct of path * fsigexp option    (* functor variable *)
  524.          | FctFct of {            (* definition of a functor *)
  525.           params   : (symbol option * sigexp) list,
  526.           body       : strexp,
  527.           constraint : sigexp option}
  528.          | LetFct of dec * fctexp
  529.          | AppFct of path * (strexp * bool) list * fsigexp option
  530.                           (* application *)
  531.          | MarkFct of fctexp * filePos * filePos (* mark *)
  532.  
  533.   (* SIGNATURE EXPRESSION *)
  534.   and sigexp = VarSig of symbol            (* signature variable *)
  535.          | SigSig of spec list        (* defined signature *)
  536.          | MarkSig of sigexp * filePos * filePos    (* mark *)
  537.  
  538.   (* FUNCTOR SIGNATURE EXPRESSION *)
  539.   and fsigexp = VarFsig of symbol            (* funsig variable *)
  540.           | FsigFsig of {param: (symbol option * sigexp) list, def:sigexp}
  541.                           (* defined funsig *)
  542.           | MarkFsig of fsigexp * filePos * filePos    (* mark a funsig *)
  543.  
  544.   (* SPECIFICATION FOR SIGNATURE DEFINITIONS *)
  545.   and spec = StrSpec of (symbol * sigexp) list            (* structure *)
  546.        | TycSpec of ((symbol * tyvar list) list * bool)    (* type *)
  547.        | FctSpec of (symbol * fsigexp) list            (* functor *)
  548.        | ValSpec of (symbol * ty) list            (* value *)
  549.        | DataSpec of db list                (* datatype *)
  550.        | ExceSpec of (symbol * ty option) list        (* exception *)
  551.        | FixSpec of  {fixity: fixity, ops: symbol list}     (* fixity *)
  552.        | ShareSpec of path list            (* structure sharing *)
  553.        | ShatycSpec of path list            (* type sharing *)
  554.        | LocalSpec of spec list * spec list        (* local specif *)
  555.        | IncludeSpec of symbol            (* include specif *)
  556.        | OpenSpec of path list            (* open structures *)
  557.        | MarkSpec of spec * filePos * filePos    (* mark a spec *)
  558.  
  559.   (* DECLARATIONS (let and structure) *)
  560.   and dec    = ValDec of vb list            (* values *)
  561.       | ValrecDec of rvb list            (* recursive values *)
  562.       | FunDec of fb list                (* recurs functions *)
  563.       | TypeDec of tb list                (* type dec *)
  564.       | DatatypeDec of {datatycs: db list, withtycs: tb list}
  565.                               (* datatype dec *)
  566.       | AbstypeDec of {abstycs: db list, withtycs: tb list, body: dec}
  567.                               (* abstract type *)
  568.       | ExceptionDec of eb list            (* exception *)
  569.       | StrDec of strb list                (* structure *)
  570.       | AbsDec of strb list                (* abstract struct *)
  571.       | FctDec of fctb list                (* functor *)
  572.       | SigDec of sigb list                (* signature *)
  573.       | FsigDec of fsigb list                (* funsig *)
  574.       | LocalDec of dec * dec                (* local dec *)
  575.       | SeqDec of dec list                (* sequence of dec *)
  576.       | OpenDec of path list                (* open structures *)
  577.       | OvldDec of symbol * ty * exp list    (* overloading (internal) *)
  578.       | FixDec of {fixity: fixity, ops: symbol list}  (* fixity *)
  579.       | ImportDec of string list        (* import (unused) *)
  580.       | MarkDec of dec * filePos * filePos        (* mark a dec *)
  581.  
  582.   (* VALUE BINDINGS *)
  583.   and vb = Vb of {pat:pat, exp:exp}
  584.      | MarkVb of vb * filePos * filePos
  585.  
  586.   (* RECURSIVE VALUE BINDINGS *)
  587.   and rvb = Rvb of {var:symbol, exp:exp, resultty: ty option}
  588.       | MarkRvb of rvb * filePos * filePos
  589.  
  590.   (* RECURSIVE FUNCTIONS BINDINGS *)
  591.   and fb = Fb of {var:symbol, clauses:clause list}
  592.      | MarkFb of fb * filePos * filePos
  593.  
  594.   (* CLAUSE: a definition for a single pattern in a function binding *)
  595.   and clause = Clause of {pats: pat list, resultty: ty option, exp:exp}
  596.  
  597.   (* TYPE BINDING *)
  598.   and tb = Tb of {tyc : symbol, def : ty, tyvars : tyvar list}
  599.      | MarkTb of tb * filePos * filePos
  600.  
  601.   (* DATATYPE BINDING *)
  602.   and db = Db of {tyc : symbol, tyvars : tyvar list,
  603.           def : (symbol * ty option) list}
  604.      | MarkDb of db * filePos * filePos
  605.  
  606.   (* EXCEPTION BINDING *)
  607.   and eb = EbGen of {exn: symbol, etype: ty option} (* Exception definition *)
  608.      | EbDef of {exn: symbol, edef: path}      (* defined by equality *)
  609.      | MarkEb of eb * filePos * filePos
  610.  
  611.   (* STRUCTURE BINDING *)
  612.   and strb = Strb of {name: symbol,def: strexp,constraint: sigexp option}
  613.        | MarkStrb of strb * filePos * filePos
  614.  
  615.   (* FUNCTOR BINDING *)
  616.   and fctb = Fctb of {name: symbol,def: fctexp}
  617.        | MarkFctb of fctb * filePos * filePos
  618.  
  619.   (* SIGNATURE BINDING *)
  620.   and sigb = Sigb of {name: symbol,def: sigexp}
  621.        | MarkSigb of sigb * filePos * filePos
  622.  
  623.   (* FUNSIG BINDING *)
  624.   and fsigb = Fsigb of {name: symbol,def: fsigexp}
  625.         | MarkFsigb of fsigb * filePos * filePos
  626.  
  627.   (* TYPE VARIABLE *)
  628.   and tyvar = Tyv of symbol
  629.         | MarkTyv of tyvar * filePos * filePos
  630.  
  631.   (* TYPES *)
  632.   and ty 
  633.       = VarTy of tyvar            (* type variable *)
  634.       | ConTy of symbol list * ty list    (* type constructor *)
  635.       | RecordTy of (symbol * ty) list     (* record *)
  636.       | TupleTy of ty list        (* tuple *)
  637.       | MarkTy of ty * filePos * filePos    (* mark type *)
  638. end (* structure Ast *)
  639.  
  640. signature CODE =
  641.   sig
  642.     structure IO : sig type instream end
  643.     type code
  644.     val mkCode : string -> code
  645.     val inputCode : (IO.instream * int) -> code
  646.     val sizeOf : code -> int
  647.     val apply : code -> ('a -> 'b)
  648.     (* NOTE: this cannot be more precise, since mo files and code compiled
  649.      * interactively have different types.
  650.      *)
  651.   end (* CODE *)
  652.  
  653. signature PRETTYPRINT =
  654. sig
  655.   type ppstream
  656.   type ppconsumer
  657.   datatype break_style = CONSISTENT | INCONSISTENT
  658.   val mk_ppstream    : ppconsumer -> ppstream
  659.   val dest_ppstream  : ppstream -> ppconsumer
  660.   val add_break      : ppstream -> int * int -> unit
  661.   val add_newline    : ppstream -> unit
  662.   val add_string     : ppstream -> string -> unit
  663.   val begin_block    : ppstream -> break_style -> int -> unit
  664.   val end_block      : ppstream -> unit
  665.   val clear_ppstream : ppstream -> unit
  666.   val flush_ppstream : ppstream -> unit
  667.   val with_pp : ppconsumer -> (ppstream -> unit) -> unit
  668.   val install_pp : string list -> (ppstream -> 'a -> unit) -> unit  (* unsafe! *)
  669.   val pp_to_string : int -> (ppstream -> 'a -> unit) -> 'a -> string
  670. end
  671.  
  672. signature COMPILE =
  673. sig
  674.   structure PP : sig type ppconsumer end
  675.   structure IO : sig type instream type outstream end
  676.   structure Ast : sig type dec end
  677.   type source
  678.   type staticUnit
  679.   type codeUnit
  680.   type compUnit (* = staticUnit * codeUnit *)
  681.   exception Compile of string
  682.   val makeSource  : string * int * IO.instream * bool * PP.ppconsumer -> source
  683.   val closeSource : source -> unit
  684.   val changeLvars : staticUnit -> staticUnit
  685.   val elaborate   : source * staticEnv -> staticUnit
  686.   val parse      : source * staticEnv -> Ast.dec * staticEnv
  687.   val compile     : source * staticEnv -> staticUnit * codeUnit
  688.   val compileAst  : Ast.dec * staticEnv * source option -> compUnit
  689.   val execute     : (staticUnit * codeUnit) * environment -> environment
  690.   val eval_stream : IO.instream * environment -> environment
  691.   val use         : string -> unit
  692.   val use_stream  : IO.instream -> unit
  693. end
  694.  
  695. signature CLEANUP =
  696. sig
  697.   datatype clean_mode
  698.     = CleanForExportML | CleanForExportFn | CleanForQuit | CleanForInit
  699.   val addCleaner : (string * (clean_mode -> unit)) -> bool
  700.   val removeCleaner : string -> unit
  701.   val cleanup : clean_mode -> unit
  702.   val shutdown : unit -> 'a
  703. end (* CLEANUP *)
  704.  
  705. signature WEAK = 
  706. sig
  707.   type 'a weak
  708.   val weak : 'a -> 'a weak
  709.   val strong : 'a weak -> 'a option
  710.   type weak'
  711.   val weak' : 'a -> weak'
  712.   val strong' : weak' -> bool
  713. end (* WEAK *)
  714.  
  715. signature SUSP =
  716.   sig
  717.     type 'a susp
  718.     val delay : (unit -> 'a) -> 'a susp
  719.     val force : 'a susp -> 'a
  720.   end (* SUSP *)
  721.  
  722. (* fully polymorphic (and thus not typesafe) versions of the continuation
  723.  * operations
  724.  *)
  725. signature POLY_CONT =
  726. sig
  727.   type 'a cont
  728.   val callcc : ('a cont -> 'a) -> 'a
  729.   val throw : 'a cont -> 'a -> 'b
  730.   type 'a control_cont
  731.   val capture : ('a control_cont -> 'a) -> 'a
  732.   val escape : 'a control_cont -> 'a -> 'b
  733. end
  734.  
  735. signature UNSAFE =
  736. sig
  737.   type object
  738.   type instream and outstream
  739.   structure Assembly : ASSEMBLY
  740.   structure CInterface : CINTERFACE
  741.   structure SysIO : SYSIO
  742.   structure CleanUp : CLEANUP
  743.   structure Weak : WEAK
  744.   structure Susp : SUSP
  745.   structure PolyCont : POLY_CONT
  746.   val boxed : 'a -> bool
  747.   val ordof : 'a * int -> int
  748.   val slength : 'a -> int        (* string length *)
  749.   val objLength : 'a -> int        (* object length *)
  750.   val getObjTag : 'a -> int        (* get width_tag bits of object descriptor *)
  751.   val special : (int * 'a) -> 'b
  752.   val setSpecial : ('a * int) -> unit
  753.   val getSpecial : 'a -> int
  754.   val store : string * int * int -> unit
  755.   val bstore : Assembly.A.bytearray * int * int -> unit
  756.   val subscript : 'a array * int -> 'a
  757.   val update : 'a array * int * 'a -> unit
  758.   val subscriptv : 'a vector * int -> 'a
  759.   val subscriptf : Assembly.A.realarray * int -> real
  760.   val updatef : Assembly.A.realarray * int * real -> unit
  761.   val getvar : unit -> 'a
  762.   val setvar : 'a -> unit
  763.   val gethdlr : unit -> 'a
  764.   val sethdlr : 'a -> unit
  765. (*****
  766.   val boot : 'a -> ('b -> 'c)        (* code -> ('b -> 'c) *)
  767. *****)
  768.   val cast : 'a -> 'b
  769.   val blast_write : outstream * 'a -> int
  770.   val blast_read : instream * int -> 'a
  771.   val create_s : int -> string
  772.   val create_b : int -> Assembly.A.bytearray
  773.   val store_s : string * int * int -> unit
  774.   val lookup_r : (int -> object) ref
  775.   val lookup : int -> object
  776.   val toplevelcont : unit cont ref
  777.   val pstruct : {core: object, initial: object, math: object} ref
  778.   exception Boxity
  779.   val tuple : object -> object vector
  780.   val string : object -> string
  781.   val real : object -> real
  782.   val int : object -> int
  783.  
  784.   datatype datalist = DATANIL | DATACONS of (string * (unit -> unit) * datalist)
  785.   val datalist : datalist
  786.   val profiling : bool ref
  787.   val sprofiling : bool ref
  788. end
  789.  
  790. signature SYSTEM =
  791. sig
  792.   structure ByteArray : BYTEARRAY
  793.   structure Hooks : HOOKS
  794.   structure Symbol : SYMBOL
  795.   structure Env : ENVIRONMENT
  796.   structure Ast : AST
  797.   structure Code : CODE
  798.   structure Compile: COMPILE
  799.   structure PrettyPrint : PRETTYPRINT
  800.   structure Print : PRINTCONTROL
  801.   structure Control : CONTROL
  802.   structure Tags : TAGS
  803.   structure Timer : TIMER
  804.   structure Stats : STATS
  805.   structure Unsafe : UNSAFE
  806.   structure Signals : SIGNALS
  807.   structure Directory : DIRECTORY
  808.   val exn_name : exn -> string
  809.   val version : string
  810.   val architecture : string ref
  811.   val runtimeStamp : string ref
  812.   val interactive : bool ref
  813.   val system : string -> int (* execute a shell command *)
  814.   val argv : unit -> string list
  815.   val environ : unit -> string list
  816.   val errorMatch : string ref
  817. end
  818.