cmd-proc.texi 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. @node Command processor
  2. @section Command processor
  3. The Scheme48 command processor is the main development environment. It
  4. incorporates a read-eval-print loop as well as an interactive inspector
  5. and debugger. It is well-integrated with the module system for rapid
  6. dynamic development, which is made even more convenient with the Emacs
  7. interface, @file{scheme48.el}; @pxref{Emacs integration}.
  8. @menu
  9. * Basic commands::
  10. * Command processor switches::
  11. * Emacs integration commands::
  12. * Focus value::
  13. * Command levels::
  14. * Module commands::
  15. * SRFI 7::
  16. * Debugging commands::
  17. * Inspector::
  18. * Command programs::
  19. * Image-building commands::
  20. * Resource statistics and control::
  21. @end menu
  22. @node Basic commands
  23. @subsection Basic commands
  24. There are several generally useful commands built-in, along with many
  25. others described in subsequent sections:
  26. @cindex help
  27. @cindex command processor help
  28. @deffn command {,help}
  29. @deffnx command {,help} command
  30. @deffnx command {,?}
  31. @deffnx command {,?} command
  32. Requests help on commands. @command{,?} is an alias for
  33. @command{,help}. Plain @samp{,help} lists a synopsis of all commands
  34. available, as well as all @embedref{Command processor switches,
  35. switches}. @samp{,help @var{command}} requests help on the particular
  36. command @var{command}.
  37. @end deffn
  38. @cindex exiting Scheme
  39. @cindex quitting Scheme
  40. @deffn command {,exit}
  41. @deffnx command {,exit} status
  42. @deffnx command {,exit-when-done}
  43. @deffnx command {,exit-when-done} status
  44. Exits the command processor. @samp{,exit} immediately exits with an
  45. exit status of 0. @samp{,exit @var{status}} exits with the status that
  46. evaluating the expression @var{status} in the interaction environment
  47. produces. @command{,exit-when-done} is like @command{,exit}, but it
  48. waits until all threads complete before exiting.
  49. @end deffn
  50. @deffn command {,go} expression
  51. @command{,go} is like @command{,exit}, except that it requires an
  52. argument, and it evaluates @var{expression} in the interaction
  53. environment in a @emph{tail context} with respect to the command
  54. processor. This means that the command processor may no longer be
  55. reachable by the garbage collector, and may be collected as garbage
  56. during the evaluation of @var{expression}. For example, the full
  57. Scheme48 command processor is bootstrapped from a minimal one that
  58. supports the @command{,go} command. The full command processor is
  59. initiated in an argument to the command, but the minimal one is no
  60. longer reachable, so it may be collected as garbage, leaving only the
  61. full one.
  62. @end deffn
  63. @deffn command {,run} expression
  64. Evaluates @var{expression} in the interaction environment. Alone, this
  65. command is not very useful, but it is required in situations such as
  66. the @embedref{Inspector, inspector} and @embedref{Command programs,
  67. command programs}.
  68. @end deffn
  69. @deffn command {,undefine} name
  70. Removes the binding for @var{name} in the interaction environment.
  71. @end deffn
  72. @deffn command {,load} filename @dots{}
  73. Loads the contents each @var{filename} as Scheme source code into the
  74. interaction environment. Each @var{filename} is translated first
  75. (@pxref{Filenames}). The given filenames may be surrounded or not by
  76. double-quotes; however, if a filename contains spaces, it must be
  77. surrounded by double-quotes. The differences between the
  78. @command{,load} command and Scheme's @code{load} procedure are that
  79. @command{,load} does not require its arguments to be quoted, allows
  80. arbitrarily many arguments while the @code{load} procedure accepts only
  81. one filename (and an optional environment), and works even in
  82. environments in which @code{load} is not bound.
  83. @end deffn
  84. @deffn command {,translate} from to
  85. A convenience for registering a filename translation without needing to
  86. open the @code{filenames} structure. For more details on filename
  87. translations, @pxref{Filenames}; this command corresponds with the
  88. @code{filename} structure's @code{set-translation!} procedure. As
  89. with @command{,load}, each of the filenames @var{from} and @var{to} may
  90. be surrounded or not by double-quotes, unless there is a space in the
  91. filenames, in which case it must be surrounded by double-quotes.
  92. Note that in the exec language (@pxref{Command programs}),
  93. @code{translate} is the same as the @code{filenames} structure's
  94. @code{set-translation!} procedure, @emph{not} the procedure named
  95. @code{translate} from the @code{filenames} structure.
  96. @end deffn
  97. @node Command processor switches
  98. @subsection Switches
  99. @cindex command processor settings
  100. @cindex configuring the command processor
  101. The Scheme48 command processor keeps track of a set of @dfn{switches},
  102. user-settable configurations.
  103. @deffn command {,set} switch
  104. @deffnx command {,set} switch @{on|off|?@}
  105. @deffnx command {,unset} switch
  106. @deffnx command {,set} ?
  107. @samp{,set @var{switch}} & @samp{,set @var{switch} on} set the switch
  108. @var{switch} on. @samp{,unset @var{switch}} & @samp{,set @var{switch}
  109. off} turn @var{switch} off. @samp{,set @var{switch} ?} gives a brief
  110. description of @var{switch}'s current status. @samp{,set ?} gives
  111. information about all the available switches and their current state.
  112. @end deffn
  113. The following switches are defined. Each switch is listed with its
  114. name and its default status.
  115. @table @asis
  116. @item @code{ask-before-loading} @emph{(off)}
  117. If this is on, Scheme48 will prompt the user before loading modules'
  118. code. If it is off, it will quietly just load it.
  119. @cindex batch mode
  120. @item @code{batch} @emph{(off)}
  121. Batch mode is intended for automated uses of the command processor.
  122. With batch mode on, errors cause the command processor to exit, and the
  123. prompt is not printed.
  124. @item @code{break-on-warnings} @emph{(off)}
  125. If the @code{break-on-warnings} switch is on, @embedref{Condition
  126. system, warnings} signalled that reach the command processor's handler
  127. will cause a @embedref{Command levels, command level} to be pushed,
  128. similarly to breakpoints and errors.
  129. @item @code{inline-values} @emph{(off)}
  130. @code{Inline-values} tells whether or not certain procedures may be
  131. integrated in-line.
  132. @cindex command levels
  133. @cindex disabling command levels
  134. @item @code{levels} @emph{(on)}
  135. Errors will push a new @embedref{Command levels, command level} if this
  136. switch is on, or they will just reset back to the top level if
  137. @code{levels} is off.
  138. @item @code{load-noisily} @emph{(off)}
  139. Loading source files will cause messages to be printed if
  140. @code{load-noisily} is on; otherwise they will be suppressed.
  141. @end table
  142. @node Emacs integration commands
  143. @subsection Emacs integration commands
  144. There are several commands that exist mostly for @embedref{Emacs
  145. integration,Emacs integration}; although they may be used elsewhere,
  146. they are not very useful or convenient without @file{scheme48.el}.
  147. @deffn command {,from-file} filename
  148. @deffnx command {,end}
  149. @samp{,from-file @var{filename}} proclaims that the code following the
  150. command, until an @command{,end} command, comes from @var{filename} ---
  151. for example, this may be due to an appropriate Emacs command, such as
  152. @kbd{C-c C-l} in @file{scheme48.el} ---; if this is the first time the
  153. command processor has seen code from @var{filename}, it is registered
  154. to correspond with the interaction environment wherein the
  155. @command{,from-file} command was used. If it is not the first time,
  156. the code is evaluated within the package that was registered for
  157. @var{filename}.
  158. @end deffn
  159. @deffn command {,forget} filename
  160. Clears the command processor's memory of the package to which
  161. @var{filename} corresponds.
  162. @end deffn
  163. @node Focus value
  164. @subsection Focus value
  165. The Scheme48 command processor maintains a current @dfn{focus value}.
  166. This is typically the value that the last expression evaluated to, or a
  167. list of values if it returned multiple values. If it evaluated to
  168. either zero values or Scheme48's `unspecific' token (@pxref{System
  169. features}), the focus value is unchanged. At the initial startup of
  170. Scheme48, the focus value is set to the arguments passed to Scheme48's
  171. virtual machine after the @option{-a} argument on the command-line
  172. (@pxref{Running Scheme48}). The focus value is accessed through the
  173. @code{##} syntax; the reader substitutes a special quotation (special
  174. so that the compiler will not generate warnings about a regular
  175. @code{quote} expression containing a weird value) for occurrences of
  176. @code{##}. Several commands, such as @command{,inspect} and
  177. @command{,dis}, either accept an argument or use the current focus
  178. value. Also, in the @embedref{Inspector, inspector}, the focus object
  179. is the object that is currently being inspected.
  180. @example
  181. > (cons 1 2)
  182. '(1 . 2)
  183. > ##
  184. '(1 . 2)
  185. > (begin (display "Hello, world!") (newline))
  186. Hello, world!
  187. > ##
  188. '(1 . 2)
  189. > (cdr ##)
  190. 2
  191. > (define x 5)
  192. ; no values returned
  193. > (+ ## x)
  194. 7
  195. > (values 1 2 3)
  196. ; 3 values returned
  197. 1
  198. 2
  199. 3
  200. > ##
  201. '(1 2 3)@end example
  202. @node Command levels
  203. @subsection Command levels
  204. @cindex command levels
  205. The Scheme48 command processor maintains a stack of @dfn{command
  206. levels}, or recursive invocations of the command processor. Each
  207. command level retains information about the point from the previous
  208. command level at which it was pushed: the threads that were running ---
  209. which the command processor suspends ---, including the thread of that
  210. command level itself; the continuation of what pushed the level; and,
  211. if applicable, the @embedref{Condition system, condition} that caused
  212. the command level to be pushed. Each command level has its own thread
  213. scheduler, which controls all threads running at that level, including
  214. those threads' children.
  215. @cindex disabling command levels
  216. Some beginning users may find command levels confusing, particularly
  217. those who are new to Scheme or who are familiar with the more
  218. simplistic interaction methods of other Scheme systems. These users
  219. may disable the command level system with the @embedref{Command
  220. processor switches, @code{levels} switch} by writing the command
  221. @samp{,set levels off}.
  222. @deffn command {,push}
  223. @deffnx command {,pop}
  224. @deffnx command {,resume}
  225. @deffnx command {,resume} level
  226. @deffnx command {,reset}
  227. @deffnx command {,reset} level
  228. @samp{,push} pushes a new command level. @samp{,pop} pops the current
  229. command level. @kbd{C-d}/@kbd{^D}, or EOF, has the same effect as the
  230. @command{,pop} command. Popping the top command level inquires the
  231. user whether to exit or to return to the top level. @samp{,resume
  232. @var{level}} pops all command levels down to @var{level} and resumes
  233. all threads that were running at @var{level} when it was suspended to
  234. push another command level. @samp{,reset @var{level}} resets the
  235. command processor to @var{level}, terminating all threads at that
  236. level but the command reader thread. @command{,resume} &
  237. @command{,reset} with no argument use the top command level.
  238. @end deffn
  239. @deffn command {,condition}
  240. @deffnx command {,threads}
  241. @samp{,condition} sets the focus value to the condition that caused the
  242. command level to be pushed, or prints `no condition' if there was no
  243. relevant condition. @samp{,threads} invokes the inspector on the list
  244. of threads of the previous command level, or on nothing if the current
  245. command level is the top one.
  246. @end deffn
  247. @example
  248. > ,push
  249. 1> ,push
  250. 2> ,pop
  251. 1> ,reset
  252. Top level
  253. > ,open threads formats
  254. > ,push
  255. 1> ,push
  256. 2> (spawn (lambda ()
  257. (let loop ()
  258. (sleep 10000) ; Sleep for ten seconds.
  259. (format #t "~&foo~%")
  260. (loop)))
  261. 'my-thread)
  262. 2>
  263. foo
  264. ,push
  265. 3> ,threads
  266. ; 2 values returned
  267. [0] '#@{Thread 4 my-thread@}
  268. [1] '#@{Thread 3 command-loop@}
  269. 3: q
  270. '(#@{Thread 4 my-thread@} #@{Thread 3 command-loop@})
  271. 3> ,resume 1
  272. foo
  273. 2>
  274. foo
  275. ,push
  276. 3> ,reset 1
  277. Back to 1> ,pop
  278. > @end example
  279. @node Module commands
  280. @subsection Module commands
  281. Scheme48's command processor is well-integrated with its
  282. @embedref{Module system, module system}. It has several dedicated
  283. environments, including the user package and the config package, and
  284. can be used to evaluate code within most packages in the Scheme48 image
  285. during program development. The config package includes bindings for
  286. Scheme48's configuration language; structure & interface definitions
  287. may be evaluated in it. The command processor also has provisions
  288. to support rapid development and module reloading by automatically
  289. updating references to redefined variables in compiled code without
  290. having to reload all of that code.
  291. @cindex opening structures
  292. @cindex structures, opening
  293. @deffn command {,open} struct @dots{}
  294. Opens each @var{struct} into the interaction environment, making all
  295. of its exported bindings available. This may have the consequence of
  296. loading code to implement those bindings. If there was code evaluated
  297. in the interaction environment that referred to a previously undefined
  298. variable for whose name a binding was exported by one of these
  299. structures, a message is printed to the effect that that binding is
  300. now available, and the code that referred to that undefined variable
  301. will be modified to subsequently refer to the newly available binding.
  302. @end deffn
  303. @deffn command {,load-package} struct
  304. @cindex reloading code
  305. @cindex code reloading
  306. @deffnx command {,reload-package} struct
  307. @command{,load-package} and @command{,reload-package} both load the
  308. code associated with the package underlying @var{struct}, after
  309. ensuring that all of the other structures opened by that package are
  310. loaded as well. @command{,load-package} loads the code only if has
  311. not already been loaded; @command{,reload-package} unconditionally
  312. loads it.
  313. @end deffn
  314. @cindex user package
  315. @cindex config package
  316. @deffn command {,user}
  317. @deffnx command {,user} command-or-exp
  318. @deffnx command {,config}
  319. @deffnx command {,config} command-or-exp
  320. @deffnx command {,for-syntax}
  321. @deffnx command {,for-syntax} command-or-exp
  322. @deffnx command {,new-package}
  323. @deffnx command {,in} structure
  324. @deffnx command {,in} structure command-or-exp
  325. These all operate on the interaction environment. @samp{,user} sets it
  326. to the user package, which is the default at initial startup.
  327. @samp{,user @var{command-or-exp}} temporarily sets the interaction
  328. environment to the user package, processes @var{command-or-exp}, and
  329. reverts the interaction environment to what it was before
  330. @command{,user} was invoked. The @command{,config} &
  331. @command{,for-syntax} commands are similar, except that they operate on
  332. the config package and the package used for the user package's macros
  333. (@pxref{Macros in concert with modules}). @samp{,new-package} creates
  334. a temporary, unnamed package with a vanilla R5RS environment and sets
  335. the interaction environment to it. That new package is not accessible
  336. in any way except to the user of the command processor, and it is
  337. destroyed after the user switches to another environment (unless the
  338. user uses the @command{,structure} command; see below). @samp{,in
  339. @var{structure}} sets the interaction environment to be
  340. @var{structure}'s package; @var{structure} is a name whose value is
  341. extracted from the config package. @samp{,in @var{structure}
  342. @var{command-or-exp}} sets the interaction environment to
  343. @var{structure} temporarily to process @var{command-or-exp} and then
  344. reverts it to what it was before the use of @command{,in}. Note that,
  345. within a structure, the bindings available are exactly those bindings
  346. that would be available within the structure's static code, @ie{} code
  347. in the structure's @code{begin} package clauses or code in files
  348. referred to by @code{files} package clauses.
  349. @end deffn
  350. @deffn command {,user-package-is} struct
  351. @deffnx command {,config-package-is} struct
  352. @command{,user-package-is} & @command{,config-package-is} set the user
  353. & config packages, respectively, to be @var{struct}'s package.
  354. @var{Struct} is a name whose value is accessed from the current config
  355. package.
  356. @end deffn
  357. @deffn command {,structure} name interface
  358. This defines a structure named @var{name} in the config package that is
  359. a view of @var{interface} on the current interaction environment.
  360. @end deffn
  361. @node SRFI 7
  362. @subsection SRFI 7
  363. @stindex srfi-7
  364. Scheme48 supports [SRFI 7] after loading the @code{srfi-7} structure by
  365. providing two commands for loading [SRFI 7] programs:
  366. @deffn command {,load-srfi-7-program} name filename
  367. @deffnx command {,load-srfi-7-script} name filename
  368. These load [SRFI 7] a program into a newly constructed structure, named
  369. @var{name}, which opens whatever other structures are needed by
  370. features specified in the program. @command{,load-srfi-7-program}
  371. loads a simple [SRFI 7] program; @command{,load-srfi-7-script} skips
  372. the first line, intended for [SRFI 22] Unix scripts.
  373. @end deffn
  374. @node Debugging commands
  375. @subsection Debugging commands
  376. There are a number of commands useful for debugging, along with a
  377. continuation inspector, all of which composes a convenient debugger.
  378. @deffn command {,bound?} name
  379. @deffnx command {,where}
  380. @deffnx command {,where} procedure
  381. @command{,bound?} prints out binding information about @var{name}, if
  382. it is bound in the interaction environment, or `Not bound' if
  383. @var{name} is unbound. @command{,where} prints out information about
  384. what file and package its procedure argument was created in. If
  385. @var{procedure} is not passed, @command{,where} uses the focus value.
  386. If @command{,where}'s argument is not a procedure, it informs the user
  387. of this fact. If @command{,where} cannot find the location of its
  388. argument's creation, it prints `Source file not recorded.'
  389. @end deffn
  390. @cindex macro expansion
  391. @cindex expanding macros
  392. @cindex syntax expansion
  393. @cindex disassembly
  394. @deffn command {,expand}
  395. @deffnx command {,expand} exp
  396. @deffnx command {,dis}
  397. @deffnx command {,dis} proc
  398. @command{,expand} prints out a macro-expansion of @var{exp}, or the
  399. focus value if @var{exp} is not provided. The expression to be
  400. expanded should be an ordinary S-expression. The expansion may contain
  401. `generated names' and `qualified names.' These merely contain lexical
  402. context information that allow one to differentiate between identifiers
  403. with the same name. Generated names look like @code{#@{Generated
  404. @var{name} @var{unique-numeric-id}@}}. Qualified names appear to be
  405. vectors; they look like @code{#(>> @var{introducer-macro} @var{name}
  406. @var{unique-numeric-id})}, where @var{introducer-macro} is the macro
  407. that introduced the name.
  408. @command{,dis} prints out a disassembly of its procedure, continuation,
  409. or template argument. If @var{proc} is passed, it is evaluated in the
  410. interaction environment; if not, @command{,dis} disassembles the focus
  411. value. The disassembly is of Scheme48's virtual machine's byte
  412. code.@footnote{A description of the byte code is forthcoming, although
  413. it does not have much priority to this manual's author. For now, users
  414. can read the rudimentary descriptions of the Scheme48 virtual machine's
  415. byte code instruction set in @file{vm/interp/arch.scm} of Scheme48's
  416. Scheme source.}
  417. @end deffn
  418. @deffn command {,condition}
  419. @deffnx command {,threads}
  420. For the descriptions of these commands, @pxref{Command levels}. These
  421. are mentioned here because they are relevant in the context of
  422. debugging.
  423. @end deffn
  424. @cindex tracing
  425. @cindex procedures, tracing
  426. @deffn command {,trace}
  427. @deffnx command {,trace} name @dots{}
  428. @deffnx command {,untrace}
  429. @deffnx command {,untrace} name @dots{}
  430. Traced procedures will print out information about when they are
  431. entered and when they exit. @samp{,trace} lists all of the traced
  432. procedures' bindings. @samp{,trace @var{name} @dots{}} sets each
  433. @var{name} in the interaction environment, which should be bound to a
  434. procedure, to be a traced procedure over the original procedure.
  435. @samp{,untrace} resets all traced procedures to their original,
  436. untraced procedures. @samp{,untrace @var{name} @dots{}} untraces each
  437. individual traced procedure of @var{name} @dots{} in the interaction
  438. environment.
  439. @end deffn
  440. @cindex backtrace
  441. @cindex continuation previews
  442. @cindex previewing continuations
  443. @deffn command {,preview}
  444. Prints a trace of the previous command level's suspended continuation.
  445. This is analogous with stack traces in many debuggers.
  446. @end deffn
  447. @deffn command {,debug}
  448. Invokes the debugger: runs the inspector on the previous command
  449. level's saved continuation. For more details, @pxref{Inspector}.
  450. @end deffn
  451. @cindex proceeding from errors
  452. @cindex returning from errors
  453. @cindex condition restarting
  454. @deffn command {,proceed}
  455. @deffnx command {,proceed} exp
  456. Returns to the continuation of the condition signalling of the previous
  457. command level. Only certain kinds of conditions will push a new
  458. command level, however --- breakpoints, errors, and interrupts, and,
  459. if the @code{break-on-warnings} switch is on, warnings ---; also,
  460. certain kinds of errors that do push new command levels do not permit
  461. being proceeded from. In particular, only with a few VM primitives may
  462. the @command{,proceed} command be used. If @var{exp} is passed, it is
  463. evaluated in the interaction environment to produce the values to
  464. return; if it is not passed, zero values are returned.
  465. @end deffn
  466. @node Inspector
  467. @subsection Inspector
  468. Scheme48 provides a simple interactive object inspector. The command
  469. processor's prompt's end changes from @samp{>} to @samp{:} when in
  470. inspection mode. The inspector is the basis of the debugger, which is,
  471. for the most part, merely an inspector of continuations. In the
  472. debugger, the prompt is @samp{debug:}. In the inspector, objects are
  473. printed followed by menus of their components. Entries in the menu are
  474. printed with the index, which optionally includes a symbolic name, and
  475. the value of the component. For example, a pair whose car is the
  476. symbol @code{a} and whose cdr is the symbol @code{b} would be printed
  477. by the inspector like this:
  478. @example
  479. '(a . b)
  480. [0: car] 'a
  481. [1: cdr] 'b@end example
  482. The inspector maintains a stack of the focus objects it previously
  483. inspected. Selecting a new focus object pushes the current one onto
  484. the stack; the @command{u} command pops the stack.
  485. @deffn command {,inspect}
  486. @deffnx command {,inspect} exp
  487. Invokes the inspector. If @var{exp} is present, it is evaluated in the
  488. user package and its result is inspected (or a list of results, if it
  489. returned multiple values, is inspected). If @var{exp} is absent, the
  490. current focus value is inspected.
  491. @end deffn
  492. The inspector operates with its own set of commands, separate from the
  493. regular interaction commands, although regular commands may be invoked
  494. from the inspector as normal. Inspector commands are entered with or
  495. without a preceding comma at the inspector prompt. Multiple inspector
  496. commands may be entered on one line; an input may also consist of an
  497. expression to be evaluated. If an expression is evaluated, its value
  498. is selected as the focus object. Note, however, that, since inspector
  499. commands are symbols, variables cannot be evaluated just by entering
  500. their names; one must use either the @command{,run} command or wrap the
  501. variables in a @code{begin}.
  502. These inspector commands are defined:
  503. @deffn {inspector command} menu
  504. @deffnx {inspector command} m
  505. @command{Menu} prints a menu for the focus object. @command{M} moves
  506. forward in the current menu if there are more than sixteen items to be
  507. displayed.
  508. @end deffn
  509. @deffn {inspector command} u
  510. Pops the stack of focus objects, discarding the current one and setting
  511. the focus object to the current top of the stack.
  512. @end deffn
  513. @deffn {inspector command} q
  514. Quits the inspector, going back into the read-eval-print loop.
  515. @end deffn
  516. @deffn {inspector command} template
  517. Attempts to coerce the focus object into a template. If successful,
  518. this selects it as the new focus object; if not, this prints an error
  519. to that effect. Templates are the static components of closures and
  520. continuations: they contain the code for the procedure, the top-level
  521. references made by the procedure, literal constants used in the code,
  522. and any inferior templates of closures that may be constructed by the
  523. code.
  524. @end deffn
  525. @deffn {inspector command} d
  526. Goes down to the parent of the continuation being inspected. This
  527. command is valid only in the debugger mode, @ie{} when the focus object
  528. is a continuation.
  529. @end deffn
  530. @node Command programs
  531. @subsection Command programs
  532. @cindex exec language
  533. @cindex exec package
  534. The Scheme48 command processor can be controlled programmatically by
  535. @dfn{command programs}, programs written in the @dfn{exec language}.
  536. This language is essentially a mirror of the commands but in a syntax
  537. using S-expressions. The language also includes all of Scheme. The
  538. exec language is defined as part of the @dfn{exec package}.
  539. @deffn command {,exec}
  540. @deffnx command {,exec} command
  541. Sets the interaction environment to be the exec package. If an
  542. argument is passed, it is set temporarily, only to run the given
  543. command.
  544. @end deffn
  545. Commands in the exec language are invoked as procedures in Scheme.
  546. Arguments should be passed as follows:
  547. @itemize @bullet
  548. @item
  549. Identifiers, such as those of structure names in the config package,
  550. should be passed as literal symbols. For instance, the command
  551. @samp{,in frobbotz} would become in the exec language @code{(in
  552. 'frobbotz)}.
  553. @item
  554. Filenames should be passed as strings; @eg{}, @samp{,dump frob.image}
  555. becomes @code{(dump "frob.image")}.
  556. @item
  557. Commands should be represented in list values with the car being the
  558. command name and the cdr being the arguments. Note that when applying
  559. a command an argument that is a command invocation is often quoted to
  560. produce a list, but the list should not include any quotation; for
  561. instance, @samp{,in mumble ,undefine frobnicate} would become @code{(in
  562. 'mumble '(undefine frobnicate))}, even though simply @samp{,undefine
  563. frobnicate} would become @code{(undefine 'frobnicate)}.
  564. The reason for this is that the command invocation in the exec language
  565. is different from a list that represents a command invocation passed as
  566. an argument to another command; since commands in the exec language are
  567. ordinary procedures, the arguments must be quoted, but the quoted
  568. arguments are not themselves evaluated: they are applied as commands.
  569. An argument to a command that expects a command invocation can also be
  570. a procedure, which would simply be called with zero arguments. For
  571. instance, @code{(config (lambda () (display (interaction-environment))
  572. (newline)))} will call the given procedure with the interaction
  573. environment set to the config package.
  574. @item
  575. Expressions must be passed using the @command{run} command. For
  576. example, the equivalent of @samp{,user (+ 1 2)} in the exec language
  577. would be @code{(user '(run (+ 1 2)))}.
  578. @end itemize
  579. Command programs can be loaded by running the @command{,load} command
  580. in the exec package. Scripts to load application bundles are usually
  581. written in the exec language and loaded into the exec package. For
  582. example, this command program, when loaded into the exec package, will
  583. load @file{foo.scm} into the config package, ensure that the package
  584. @code{frobbotzim} is loaded, and open the @code{quuxim} structure in
  585. the user package:
  586. @lisp
  587. (config '(load "foo.scm"))
  588. (load-package 'frobbotzim)
  589. (user '(open quuxim))@end lisp
  590. @node Image-building commands
  591. @subsection Image-building commands
  592. @cindex dumping heap images
  593. @cindex heap image dumping
  594. @cindex image dumping
  595. @cindex writing heap images
  596. @cindex heap image writing
  597. @cindex image writing
  598. Since Scheme48's operation revolves about an image-based model, these
  599. commands provide a way to save heap images on the file system, which
  600. may be resumed by invoking the Scheme48 virtual machine on them as in
  601. @ref{Running Scheme48}.
  602. @deffn command {,build} resumer filename
  603. @deffnx command {,dump} filename
  604. @deffnx command {,dump} filename message
  605. @command{,build} evaluates @var{resumer}, whose value should be a unary
  606. procedure, and builds a heap image in @var{filename} that, when resumed
  607. by the virtual machine, will pass the resumer all of the command-line
  608. arguments after the @option{-a} argument to the virtual machine. The
  609. run-time system will have been initialized as with @embedref{Suspending
  610. and resuming heap images,usual resumers}, and a basic condition handler
  611. will have been installed by the time that the resumer is called. On
  612. Unix, @var{resumer} must return an integer exit status for the process.
  613. @command{,dump} dumps the Scheme48 command processor, including all of
  614. the current settings, to @var{filename}. If @var{message} is passed,
  615. it should be a string delimited by double-quotes, and it will be
  616. printed as part of the welcome banner on startup; its default value, if
  617. it is not present, is @code{"(suspended image)"}.
  618. @end deffn
  619. @node Resource statistics and control
  620. @subsection Resource statistics and control
  621. Scheme48 provides several devices for querying statistics about various
  622. resources and controlling resources, both in the command processor and
  623. programmatically.
  624. @cindex garbage collection, forcing
  625. @cindex forcing garbage collection
  626. @deffn command {,collect}
  627. Forces a garbage collection and prints the amount of space in the heap
  628. before and after the collection.
  629. @end deffn
  630. @cindex timing execution
  631. @cindex execution timing
  632. @deffn command {,time} expression
  633. Evaluates @var{expression} and prints how long it took. Three numbers
  634. are printed: run time, GC time, and real time. The run time is the
  635. amount of time in Scheme code; the GC time is the amount of time spent
  636. in the garbage collector; and the real time is the actual amount of
  637. time that passed during the expression's evaluation.
  638. @end deffn
  639. @cindex debug data storage control
  640. @cindex storage control of debug data
  641. @deffn command {,keep}
  642. @deffnx command {,keep} kind @dots{}
  643. @deffnx command {,flush}
  644. @deffnx command {,flush} kind @dots{}
  645. Scheme48 maintains several different kinds of information used for
  646. debugging information. @samp{,keep} with no arguments shows what kinds
  647. of debugging data are preserved and what kinds are not. @samp{,keep
  648. @var{kind} @dots{}} requests that the debugging data of the given kinds
  649. should be kept; the @command{,flush} command requests the opposite.
  650. @samp{,flush} with no arguments flushes location names and resets the
  651. debug data table. The following are the kinds of debugging data:
  652. @table @code
  653. @item names
  654. procedure names
  655. @item maps
  656. environment maps used by the debugger to show local variable names
  657. @item files
  658. filenames where procedures were defined
  659. @item source
  660. source code surrounding continuations, printed by the debugger
  661. @item tabulate
  662. if true, will store debug data records in a global table that can be
  663. easily flushed; if false, will store directly in compiled code
  664. @end table
  665. @command{,flush} can also accept @code{location-names}, which will
  666. flush the table of top-level variables' names (printed, for example, by
  667. the @command{,bound?} command); @code{file-packages}, which will flush
  668. the table that maps filenames to packages in which code from those files
  669. should be evaluated; or @code{table}, in which case the table of debug
  670. data is flushed.
  671. Removing much debug data can significantly reduce the size of Scheme48
  672. heap images, but it can also make error messages and debugging much
  673. more difficult. Usually, all debug data is retained; only for images
  674. that must be small and that do not need to be debuggable should the
  675. debugging data flags be turned off.
  676. @end deffn
  677. @cindex space usage analysis
  678. @cindex heap space analysis
  679. @cindex displaying heap usage
  680. @stindex spatial
  681. The @code{spatial} structure exports these utilities for displaying
  682. various statistics about the heap:
  683. @deffn procedure space @returns{} unspecified
  684. @deffnx procedure vector-space [predicate] @returns{} unspecified
  685. @deffnx procedure record-space [predicate] @returns{} unspecified
  686. @code{Space} prints out a list of the numbers of all objects and the
  687. number of bytes allocated for those objects on the heap, partitioned by
  688. the objects' primitive types and whether or not they are immutable
  689. (pure) or mutable (impure). @code{Vector-space} prints the number of
  690. vectors and the number of bytes used to store those vectors of several
  691. different varieties, based on certain heuristics about their form. If
  692. the predicate argument is passed, it gathers only vectors that satisfy
  693. that predicate. @code{Record-space} prints out, for each record type
  694. in the heap, both the number of all instances of that record type and
  695. the number of bytes used to store all of those instances. Like
  696. @code{vector-space}, if the predicate argument is passed,
  697. @code{record-space} will consider only those records that satisfy the
  698. predicate.
  699. All of these three procedures first invoke the garbage collector before
  700. gathering statistics.
  701. @end deffn
  702. @cindex object reference analysis
  703. @cindex storage leak analysis
  704. @cindex heap traversal
  705. @stindex traverse
  706. The @code{traverse} structure provides a simple utility for finding
  707. paths by which objects refer to one another.
  708. @deffn procedure traverse-breadth-first object @returns{} unspecified
  709. @deffnx procedure traverse-depth-first object @returns{} unspecified
  710. These traverse the heap, starting at @var{object}, recording all
  711. objects transitively referred to. @code{Traverse-breadth-first} uses
  712. a FIFO-queue-directed breadth-first graph traversal, while
  713. @code{traverse-depth-first} uses a LIFO-stack-directed depth-first
  714. graph traversal. The traversal halts at any leaves in the graph,
  715. which are distinguished by an internal @dfn{leaf predicate} in the
  716. module. See below on @code{set-leaf-predicate!} on how to customize
  717. this and what the default is.
  718. The traversal information is recorded in a global resource; it is not
  719. thread-safe, and intended only for interactive usage. The record can
  720. be reset by passing some simple object with no references to either
  721. @code{traverse-breadth-first} or @code{traverse-depth-first}; @eg{},
  722. @code{(traverse-depth-first #f)}.
  723. @end deffn
  724. @deffn procedure trail object @returns{} unspecified
  725. After traversing the heap from an initial object, @code{(trail
  726. @var{object})} prints the path of references and intermediate objects
  727. by which the initial object holds a transitive reference to
  728. @var{object}.
  729. @end deffn
  730. @deffn procedure set-leaf-predicate! predicate @returns{} unspecified
  731. @deffnx procedure usual-leaf-predicate object @returns{} boolean
  732. @code{Set-leaf-predicate!} sets the current leaf predicate to be
  733. @var{predicate}. @code{Usual-leaf-predicate} is the default leaf
  734. predicate; it considers simple numbers (integers and flonums),
  735. strings, byte vectors, characters, and immediate objects (true, false,
  736. nil, and the unspecific object) to be leaves, and everything else to
  737. be branches.
  738. @end deffn