File: modcode.scrbl

package info (click to toggle)
racket 7.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,432 kB
  • sloc: ansic: 258,980; pascal: 59,975; sh: 33,650; asm: 13,558; lisp: 7,124; makefile: 3,329; cpp: 2,889; exp: 499; python: 274; xml: 11
file content (151 lines) | stat: -rw-r--r-- 7,704 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#lang scribble/doc
@(require "common.rkt" (for-label syntax/modcode))

@title[#:tag "modcode"]{Getting Module Compiled Code}

@defmodule[syntax/modcode]

@defproc[(get-module-code [path path-string?]
                          [#:submodule-path submodule-path (listof symbol?) '()]
                          [#:sub-path compiled-subdir0 (and/c path-string? relative-path?) (get-default-compiled-sub-path)]
                          [compiled-subdir (and/c path-string? relative-path?) compiled-subdir0]
                          [#:roots roots (listof (or/c path-string? 'same)) (current-compiled-file-roots)]
                          [#:compile compile-proc0 (any/c . -> . any) compile] 
                          [compile-proc (any/c . -> . any) compile-proc0] 
                          [#:extension-handler ext-proc0 (or/c false/c (path? boolean? . -> . any)) #f]
                          [ext-proc (or/c false/c (path? boolean? . -> . any)) ext-proc0]
                          [#:choose choose-proc 
                           (path? path? path? 
                            . -> . 
                            (or/c (symbols 'src 'zo 'so) false/c))
                           (lambda (src zo so) #f)]
                          [#:notify notify-proc (any/c . -> . any) void]
                          [#:source-reader read-syntax-proc 
                                        (any/c input-port? . -> . (or/c syntax? eof-object?)) 
                                        read-syntax]
                          [#:rkt-try-ss? rkt-try-ss? boolean? #t])
         any]{

Returns a compiled expression for the declaration of the module
specified by @racket[path] and @racket[submodule-path], where
@racket[submodule-path] is empty for a root module or a list for a
submodule.

The @racket[compiled-subdir] argument defaults to @racket[(get-default-compiled-sub-path)];
it specifies the sub-directory to search for a compiled version of the
module. The @racket[roots] list specifies a compiled-file search path
in the same way as the @racket[current-compiled-file-roots] parameter.

The @racket[compile-proc] argument defaults to @racket[compile]. This
procedure is used to compile module source if an already-compiled
version is not available. If @racket[submodule-path] is not @racket['()],
then @racket[compile-proc] must return a compiled module form.

The @racket[ext-proc] argument defaults to @racket[#f]. If it is not
@racket[#f], it must be a procedure of two arguments that is called
when a native-code version of @racket[path] should be used. In that
case, the arguments to @racket[ext-proc] are the path for the
extension, and a boolean indicating whether the extension is a @tt{_loader}
file (@racket[#t]) or not (@racket[#f]).

The @racket[rkt-try-ss?] argument defaults to @racket[#t].  If it is not
@racket[#f], then if @racket[path] ends in @filepath{.rkt}, then the
corresponding file ending in @filepath{.ss} will be tried as well.

The @racket[choose-proc] argument is a procedure that takes three
paths: a source path, a @filepath{.zo} file path, and an extension path
(for a non-@tt{_loader} extension). Some of the paths may not
exist. The result should be either @racket['src], @racket['zo],
@racket['so], or @racket[#f], indicating which variant should be used
or (in the case of @racket[#f]) that the default choice should be
used.

The default choice is computed as follows: if a @filepath{.zo} version
of @racket[path] is available and newer than @racket[path] itself (in
one of the directories specified by @racket[compiled-subdir]), then it
is used instead of the source. Native-code versions of @racket[path]
are ignored, unless only a native-code non-@tt{_loader} version exists
(i.e., @racket[path] itself does not exist). A @tt{_loader} extension
is selected a last resort.

If an extension is preferred or is the only file that exists, it is
supplied to @racket[ext-proc] when @racket[ext-proc] is @racket[#f],
or an exception is raised (to report that an extension file cannot be
used) when @racket[ext-proc] is @racket[#f].

If @racket[notify-proc] is supplied, it is called for the file
(source, @filepath{.zo} or extension) that is chosen.

If @racket[read-syntax-proc] is provided, it is used to read the
module from a source file (but not from a bytecode file).

@history[#:changed "6.90.0.7" @elem{Use @racket[(get-default-compiled-sub-path)]
                                    for the default value of @racket[compiled-subdir].}]}

@defproc[(get-module-path [path path-string?]
                          [#:submodule? submodule? boolean?]
                          [#:sub-path compiled-subdir0 (and/c path-string? relative-path?) (get-default-compiled-sub-path)]
                          [compiled-subdir (and/c path-string? relative-path?) compiled-subdir0]
                          [#:roots roots (listof (or/c path-string? 'same)) (current-compiled-file-roots)]
                          [#:choose choose-proc 
                           (path? path? path? 
                            . -> . 
                            (or/c (symbols 'src 'zo 'so) false/c))
                           (lambda (src zo so) #f)]
                          [#:rkt-try-ss? rkt-try-ss? boolean? #t])
         (values path? (or/c 'src 'zo 'so))]{

Produces two values.  The first is the path of the latest source or compiled
file for the module specified by @racket[path]; this result is the path of the
file that @racket[get-module-code] would read to produce a compiled module
expression.  The second value is @racket['src], @racket['zo], or @racket['so],
depending on whether the first value represents a Racket source file, a
compiled bytecode file, or a native library file.

The @racket[compiled-subdir], @racket[roots], @racket[choose-proc], and
@racket[rkt-try-ss?] arguments are interpreted the same as by
@racket[get-module-code].

The @racket[submodule?] argument represents whether the desired module is a
submodule of the one specified by @racket[path].  When @racket[submodule?] is
true, the result is never a @racket['so] path, as native libraries cannot
provide submodules.

@history[#:changed "6.90.0.7" @elem{Use @racket[(get-default-compiled-sub-path)]
                                    for the default value of @racket[compiled-subdir].}]}


@defproc[(get-default-compiled-sub-path) path-string?]{

If @racket[(use-compiled-file-paths)] is not @racket['()], returns the
first element of the list. Otherwise, results @racket["compiled"].

@history[#:added "6.90.0.7"]}


@defproc[(get-metadata-path [path path-string?]
                            [#:roots roots (listof (or/c path-string? 'same))
                                           (current-compiled-file-roots)]
                            [sub-path (or/c path-string? 'same)]
                            ...+)
         path?]{

Constructs the path used to store compilation metadata for a source file stored
in the directory @racket[path].  The argument @racket[roots] specifies the
possible root directories to consider and to search for an existing file.  The
@racket[sub-path] arguments specify the subdirectories and filename of the
result relative to the chosen root.  For example, the compiled @filepath{.zo}
file for @filepath{/path/to/source.rkt} might be stored in
@racket[(get-metadata-path (build-path "/path/to") "compiled" "source_rkt.zo")].

}

@defparam[moddep-current-open-input-file proc (path-string? . -> . input-port?)]{

A parameter whose value is used like @racket[open-input-file] to read
a module source or @filepath{.zo} file.}

@defstruct[(exn:get-module-code exn:fail) ([path path?])]{

An exception structure type for exceptions raised by
@racket[get-module-code].}