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

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/gen/fragments/mkfrags.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/gen/fragments/mkfrags.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3995, Sat Jun 18 20:00:19 2016 UTC revision 3996, Sun Jun 19 15:21:12 2016 UTC
# Line 5  Line 5 
5   * COPYRIGHT (c) 2016 The University of Chicago   * COPYRIGHT (c) 2016 The University of Chicago
6   * All rights reserved.   * All rights reserved.
7   *   *
8   * Program to generate a file "fragments.sml" containing a structure "Fragments"   * Program to generate a file "fragments.sml" containing a fragments structure
9   * from a CATALOG file.   * from a CATALOG file.  A CATALOG file has the following layout
10     *
11     *      <structure name>
12     *      <input file>    <fragment name>
13     *      <input file>    <fragment name>
14     *      ...
15     *      <input file>    <fragment name>
16     *
17     * The resulting file (named fragments.sml) will contain a structure with the given
18     * name; the structure consists of named fragments, each of which is a string literal
19     * from the specified input file.
20   *)   *)
21    
22  structure MkFrags : sig  structure MkFrags : sig
# Line 22  Line 32 
32    (* load the catalog from the file *)    (* load the catalog from the file *)
33      fun loadCatalog file = let      fun loadCatalog file = let
34            val inS = TextIO.openIn file            val inS = TextIO.openIn file
35            fun lp l = (case TextIO.inputLine inS          (* report a bogus input line *)
36              fun error (lnum, ln) = raise Fail (concat[
37                      "[", file, ":", Int.toString lnum, "] bogus input: \"",
38                      String.toString ln, "\""
39                    ])
40            (* get the structure name *)
41              val structName = (case TextIO.inputLine inS
42                     of NONE => raise Fail "empty CATALOG file"
43                      | SOME ln => (case String.tokens Char.isSpace ln
44                           of [name] => name
45                            | _ => error (1, ln)
46                          (* end case *))
47                    (* end case *))
48              fun lp (lnum, l) = (case TextIO.inputLine inS
49                   of NONE => List.rev l                   of NONE => List.rev l
50                    | SOME ln => (case String.tokens Char.isSpace ln                    | SOME ln => (case String.tokens Char.isSpace ln
51                       of [] => lp l                       of [] => lp(lnum+1, l)
52                        | s1::sr => if String.isPrefix "#" s1                        | s1::sr => if String.isPrefix "#" s1
53                            then lp l                            then lp(lnum+1, l)
54                            else (case sr                            else (case sr
55                               of [s2] => lp ((s1, s2) :: l)                               of [s2] => lp (lnum+1, (s1, s2) :: l)
56                                | _ => raise Fail (concat[                                | _ => error (lnum, ln)
                                     "bogus input line \"", String.toString ln, "\""  
                                   ])  
57                              (* end case *))                              (* end case *))
58                      (* end case *))                      (* end case *))
59                  (* end case *))                  (* end case *))
60            in            in
61              (lp [] before TextIO.closeIn inS)              (structName, lp(2, []) before TextIO.closeIn inS)
62                handle ex => (TextIO.closeIn inS; raise ex)                handle ex => (TextIO.closeIn inS; raise ex)
63            end            end
64    
# Line 52  Line 73 
73            \ * !!! THIS FILE WAS GENERATED; DO NOT EDIT !!!\n\            \ * !!! THIS FILE WAS GENERATED; DO NOT EDIT !!!\n\
74            \ *)\n\            \ *)\n\
75            \\n\            \\n\
76            \structure Fragments =\n\            \structure %s =\n\
77            \  struct\n\            \  struct\n\
78            \"            \"
79    
# Line 89  Line 110 
110            val fragDir = OS.Path.concat(dir, "fragments")            val fragDir = OS.Path.concat(dir, "fragments")
111            val catalogFile = OS.Path.concat(fragDir, "CATALOG")            val catalogFile = OS.Path.concat(fragDir, "CATALOG")
112            val fragFile = OS.Path.concat(dir, "fragments.sml")            val fragFile = OS.Path.concat(dir, "fragments.sml")
113            val catalog = if OS.FileSys.access(catalogFile, [OS.FileSys.A_READ])            val (structName, catalog) = if OS.FileSys.access(catalogFile, [OS.FileSys.A_READ])
114                  then loadCatalog catalogFile                  then loadCatalog catalogFile
115                  else raise Fail(concat["cannot find \"", catalogFile, "\""])                  else raise Fail(concat["cannot find \"", catalogFile, "\""])
116            val outS = TextIO.openOut fragFile            val outS = TextIO.openOut fragFile
117            fun prf (fmt, items) = TextIO.output(outS, F.format fmt items)            fun prf (fmt, items) = TextIO.output(outS, F.format fmt items)
118            in            in
119              prf (smlHead, [F.STR(OS.Path.file fragFile)]);              prf (smlHead, [F.STR(OS.Path.file fragFile), F.STR structName]);
120              List.app (doFile (outS, fragDir)) catalog;              List.app (doFile (outS, fragDir)) catalog;
121              prf (smlFoot, []);              prf (smlFoot, []);
122              TextIO.closeOut outS              TextIO.closeOut outS
# Line 118  Line 139 
139            val fragDir = OS.Path.concat(dir, "fragments")            val fragDir = OS.Path.concat(dir, "fragments")
140            val catalogFile = OS.Path.concat(fragDir, "CATALOG")            val catalogFile = OS.Path.concat(fragDir, "CATALOG")
141            val makefile = OS.Path.concat(dir, "fragments.gmk")            val makefile = OS.Path.concat(dir, "fragments.gmk")
142            val catalog = if OS.FileSys.access(catalogFile, [OS.FileSys.A_READ])            val (_, catalog) = if OS.FileSys.access(catalogFile, [OS.FileSys.A_READ])
143                  then loadCatalog catalogFile                  then loadCatalog catalogFile
144                  else raise Fail(concat["cannot find \"", catalogFile, "\""])                  else raise Fail(concat["cannot find \"", catalogFile, "\""])
145            val outS = TextIO.openOut makefile            val outS = TextIO.openOut makefile

Legend:
Removed from v.3995  
changed lines
  Added in v.3996

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