home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / games / inform / compiler / manuals / Technical < prev   
Encoding:
Text File  |  1994-10-14  |  67.3 KB  |  1,422 lines

  1. %
  2. %  TeX source for the Inform Technical Manual
  3. %
  4.  
  5.  
  6. \newif\iffiles\filesfalse
  7. %
  8. %  Manual macros
  9. %
  10. %  Page layout
  11. %
  12. \newif\ifshutup\shutupfalse
  13. \magnification=\magstep 1
  14. \hoffset=0.15 true in
  15. \voffset=2\baselineskip
  16. %
  17. %  General hacks
  18. %
  19. \def\PAR{\par}
  20. %
  21. %  Font loading
  22. %
  23. \font\medfont=cmr10 scaled \magstep2
  24. \font\bigfont=cmr10 scaled \magstep3
  25. %\def\sectfont{\bf}
  26. \font\sectfont=cmbx12
  27. \def\small{\sevenrm}
  28. \font\rhrm=cmr8
  29. \font\rhit=cmsl8
  30. %
  31. %  Titles
  32. %
  33. \newcount\subsectno    %  Subsection number
  34. \def\rhead{}           %  The running head will go here
  35. %
  36. \def\newsection#1#2{%     To begin a section...
  37. %\global\titletrue%        Declare this as a title page
  38. \xdef\rhead{{\rhrm #1}\quad #2}%       Initialise running head and ssn
  39. \subsectno=0%
  40. \iffiles
  41. \write\conts{\string\sli\string{#1\string}\string{#2\string}\string{\the\pageno\string}}%
  42. \fi
  43. }
  44. %
  45. \def\section#1#2{\vskip 1 true in\goodbreak\newsection{#1}{#2}
  46. \noindent{\sectfont #1\quad #2}\bigskip\noindent}
  47. %
  48. %  Headers and footers
  49. %
  50. \newif\iftitle
  51. \headline={\iftitle\hfil\global\titlefalse%
  52.            \else{\hfil{\rhit \rhead}}%
  53.            \fi}
  54. \footline={\ifnum\pageno<0\hfil{\tenbf\romannumeral -\pageno}%
  55. \else\hfil{\tenbf \number\pageno}\fi}
  56. %\footline={\ifnum\pageno=1\hfil\else\hfil{\tenbf \number\pageno}\fi}
  57. %
  58. %  (Old date-stamping version:)
  59. % \footline={\hfil{\rm \number\pageno}\hfil{\rm \number\day/\number\month}}
  60. %
  61. % If this works I'll be impressed
  62. %
  63.  
  64. \font\ninerm=cmr9
  65. \font\ninei=cmmi9
  66. \font\ninesy=cmsy9
  67. \font\ninebf=cmbx9
  68. \font\eightbf=cmbx8
  69. \font\ninett=cmtt9
  70. \font\nineit=cmti9
  71. \font\ninesl=cmsl9
  72. \def\ninepoint{\def\rm{\fam0\ninerm}%
  73.   \textfont0=\ninerm
  74.   \textfont1=\ninei
  75.   \textfont2=\ninesy
  76.   \textfont3=\tenex
  77.   \textfont\itfam=\nineit \def\it{\fam\itfam\nineit}%
  78.   \textfont\slfam=\ninesl \def\sl{\fam\slfam\ninesl}%
  79.   \textfont\ttfam=\ninett \def\tt{\fam\ttfam\ninett}%
  80.   \textfont\bffam=\ninebf
  81.   \normalbaselineskip=11pt
  82.   \setbox\strutbox=\hbox{\vrule height8pt depth3pt width0pt}%
  83.   \normalbaselines\rm}
  84.  
  85. \def\tenpoint{\def\rm{\fam0\tenrm}%
  86.   \textfont0=\tenrm
  87.   \textfont1=\teni
  88.   \textfont2=\tensy
  89.   \textfont3=\tenex
  90.   \textfont\itfam=\tenit \def\it{\fam\itfam\tenit}%
  91.   \textfont\slfam=\tensl \def\sl{\fam\slfam\tensl}%
  92.   \textfont\ttfam=\tentt \def\tt{\fam\ttfam\tentt}%
  93.   \textfont\bffam=\tenbf
  94.   \normalbaselineskip=12pt
  95.   \setbox\strutbox=\hbox{\vrule height8.5pt depth3.5pt width0pt}%
  96.   \normalbaselines\rm}
  97.  
  98. \parindent=30pt
  99. \def\inpar{\hangindent40pt\hangafter1\qquad}
  100. \def\onpar{\par\hangindent40pt\hangafter0}
  101.  
  102. \newskip\ttglue
  103. \ttglue=.5em plus.25em minus.15em
  104.  
  105. \def\orsign{$\mid\mid$}
  106.  
  107. \outer\def\begindisplay{\obeylines\startdisplay}
  108. {\obeylines\gdef\startdisplay#1
  109.   {\catcode`\^^M=5$$#1\halign\bgroup\indent##\hfil&&\qquad##\hfil\cr}}
  110. \outer\def\enddisplay{\crcr\egroup$$}
  111.  
  112. \chardef\other=12
  113.  
  114. \def\ttverbatim{\begingroup \catcode`\\=\other \catcode`\{=\other
  115.   \catcode`\}=\other \catcode`\$=\other \catcode`\&=\other 
  116.   \catcode`\#=\other \catcode`\%=\other \catcode`\~=\other 
  117.   \catcode`\_=\other \catcode`\^=\other
  118.   \obeyspaces \obeylines \tt}
  119. {\obeyspaces\gdef {\ }}
  120.  
  121. \outer\def\beginstt{$$\let\par=\endgraf \ttverbatim\ninett \parskip=0pt
  122.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  123. \outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=0pt
  124.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  125. {\catcode`\|=0 |catcode`|\=\other
  126.   |obeylines
  127.   |gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}}
  128.  
  129. \catcode`\|=\active
  130. {\obeylines\gdef|{\ttverbatim\spaceskip=\ttglue\let^^M=\ \let|=\endgroup}}
  131.  
  132. \def\beginlines{\par\begingroup\nobreak\medskip\parindent=0pt
  133.   \nobreak\ninepoint \obeylines \everypar{\strut}}
  134. \def\endlines{\endgroup\medbreak\noindent}
  135.  
  136. \def\<#1>{\leavevmode\hbox{$\langle$#1\/$\rangle$}}
  137.  
  138. \def\dbend{{$\triangle$}}
  139. \def\d@nger{\medbreak\begingroup\clubpenalty=10000
  140.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  141.   \hbox to0pt{\hskip-\hangindent\dbend\hfill}\ninepoint}
  142. \outer\def\danger{\d@nger}
  143. \def\dd@nger{\medskip\begingroup\clubpenalty=10000
  144.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  145.   \hbox to0pt{\hskip-\hangindent\dbend\kern 1pt\dbend\hfill}\ninepoint}
  146. \outer\def\ddanger{\dd@nger}
  147. \def\enddanger{\endgraf\endsubgroup}
  148.  
  149. \def\cstok#1{\leavevmode\thinspace\hbox{\vrule\vtop{\vbox{\hrule\kern1pt
  150.        \hbox{\vphantom{\tt/}\thinspace{\tt#1}\thinspace}}
  151.      \kern1pt\hrule}\vrule}\thinspace}
  152.  
  153. \newcount\exno
  154. \exno=0
  155.  
  156. \def\xd@nger{%
  157.   \begingroup\def\par{\endgraf\endgroup\medbreak}\ninepoint}
  158.  
  159. \outer\def\warning{\medbreak
  160.   \noindent\llap{$\bullet$\rm\kern.15em}%
  161.   {\ninebf WARNING}\par\nobreak\noindent}
  162. \outer\def\exercise{\medbreak \global\advance\exno by 1
  163.   \noindent\llap{$\bullet$\rm\kern.15em}%
  164.   {\ninebf EXERCISE \bf\the\exno}\par\nobreak\noindent}
  165. \def\dexercise#1{\global\advance\exno by 1
  166.   \medbreak\noindent\llap{$\bullet$\rm\kern.15em}%
  167.   #1{\eightbf ~EXERCISE \bf\the\exno}\hfil\break}
  168. \outer\def\dangerexercise{\xd@nger \dexercise{\dbend}}
  169. \outer\def\ddangerexercise{\xd@nger \dexercise{\dbend\dbend}}
  170.  
  171.  
  172. \newwrite\ans%
  173. \newwrite\conts%
  174. \iffiles
  175. \immediate\openout\conts=$.games.infocom.ftp.toolkit.mandir.conts
  176. \fi
  177.  
  178. \iffiles\else\outer\def\answer#1{\par\medbreak}\shutuptrue\fi
  179.  
  180. \newwrite\inx
  181. \ifshutup\else
  182. \immediate\openout\inx=$.games.infocom.ftp.toolkit.mandir.inxdata
  183. \fi
  184. \def\marginstyle{\sevenrm %
  185.   \vrule height6pt depth2pt width0pt } %
  186.  
  187. \newif\ifsilent
  188. \def\specialhat{\ifmmode\def\next{^}\else\let\next=\beginxref\fi\next}
  189. \def\beginxref{\futurelet\next\beginxrefswitch}
  190. \def\beginxrefswitch{\ifx\next\specialhat\let\next=\silentxref
  191.   \else\silentfalse\let\next=\xref\fi \next}
  192. \catcode`\^=\active \let ^=\specialhat
  193. \def\silentxref^{\silenttrue\xref}
  194.  
  195. \newif\ifproofmode
  196. \proofmodetrue %
  197.  
  198. \def\xref{\futurelet\next\xrefswitch}
  199. \def\xrefswitch{\begingroup\ifx\next|\aftergroup\vxref
  200.   \else\ifx\next\<\aftergroup\anglexref
  201.     \else\aftergroup\normalxref \fi\fi \endgroup}
  202. \def\vxref|{\catcode`\\=\active \futurelet\next\vxrefswitch}
  203. \def\vxrefswitch#1|{\catcode`\\=0
  204.   \ifx\next\empty\def\xreftype{2}%
  205.     \def\next{{\tt\text}}%
  206.   \else\def\xreftype{1}\def\next{{\tt\text}}\fi %
  207.   \edef\text{#1}\makexref}
  208. {\catcode`\|=0 \catcode`\\=\active |gdef\{}}
  209. \def\anglexref\<#1>{\def\xreftype{3}\def\text{#1}%
  210.   \def\next{\<\text>}\makexref} %
  211. \def\normalxref#1{\def\xreftype{0}\def\text{#1}\let\next=\text\makexref}
  212.  
  213. \def\makexref{\ifproofmode%
  214.   \xdef\writeit{\write\inx{\text\space!\xreftype\space
  215.     \noexpand\number\pageno.}}\iffiles\writeit\fi
  216.   \else\ifhmode\kern0pt \fi\fi
  217.  \ifsilent\ignorespaces\else\next\fi}
  218.  
  219. \newdimen\fullhsize
  220. \def\fullline{\hbox to\fullhsize}
  221. \let\lr=L \newbox\leftcolumn
  222.  
  223. \def\doubleformat{\shipout\vbox{\makeheadline
  224.     \fullline{\box\leftcolumn\hfil\columnbox}
  225.     \makefootline}
  226.   \advancepageno}
  227. \def\tripleformat{\shipout\vbox{\makeheadline
  228.     \fullline{\box\leftcolumn\hfil\box\midcolumn\hfil\columnbox}
  229.     \makefootline}
  230.   \advancepageno}
  231. \def\columnbox{\leftline{\pagebody}}
  232.  
  233. \newbox\leftcolumn
  234. \newbox\midcolumn
  235. \def\beginindex{
  236. \fullhsize=6.5true in \hsize=2.1true in
  237.  \global\def\makeheadline{\vbox to 0pt{\vskip-22.5pt
  238.       \fullline{\vbox to8.5pt{}\the\headline}\vss}\nointerlineskip}
  239.  \global\def\makefootline{\baselineskip=24pt \fullline{\the\footline}}
  240.  \output={\if L\lr
  241.    \global\setbox\leftcolumn=\columnbox \global\let\lr=M
  242.  \else\if M\lr
  243.    \global\setbox\midcolumn=\columnbox \global\let\lr=R
  244.  \else\tripleformat \global\let\lr=L\fi\fi
  245.  \ifnum\outputpenalty>-20000 \else\dosupereject\fi}
  246. \begingroup
  247.   \parindent=1em \maxdepth=\maxdimen
  248.   \def\par{\endgraf \futurelet\next\inxentry}
  249.   \obeylines \everypar={\hangindent 2\parindent}
  250.   \exhyphenpenalty=10000 \raggedright}
  251. \def\inxentry{\ifx\next\sub \let\next=\subentry
  252.   \else\ifx\next\endindex \let\next=\vfill
  253.   \else\let\next=\mainentry \fi\fi\next}
  254. \def\endindex{\mark{}\break\endgroup
  255. \supereject
  256. \if L\lr \else\null\vfill\eject\fi
  257. \if L\lr \else\null\vfill\eject\fi
  258. }
  259. \let\sub=\indent \newtoks\maintoks \newtoks\subtoks
  260. \def\mainentry#1,{\mark{}\noindent
  261.   \maintoks={#1}\mark{\the\maintoks}#1,}
  262. \def\subentry\sub#1,{\mark{\the\maintoks}\indent
  263.   \subtoks={#1}\mark{\the\maintoks\sub\the\subtoks}#1,}
  264.  
  265. \def\subsection#1{\medbreak\par\noindent{\bf #1}\qquad}
  266.  
  267. %  For contents
  268.  
  269. \def\cl#1#2{\bigskip\par\noindent{\bf #1}\quad {\bf #2}}
  270. \def\li#1#2#3{\smallskip\par\noindent\hbox to 5 in{{\bf #1}\quad #2\dotfill #3}}
  271. \def\sli#1#2#3{\par\noindent\hbox to 5 in{\qquad\item{#1}\quad #2\dotfill #3}}
  272. \def\fcl#1#2{\bigskip\par\noindent\hbox to 5 in{\phantom{\bf 1}\quad {\bf #1}\dotfill #2}}
  273.  
  274. % Epigrams
  275.  
  276. \def\poem{\begingroup\narrower\narrower\narrower\obeylines\ninepoint}
  277. \def\widepoem{\begingroup\narrower\narrower\obeylines\ninepoint}
  278. \def\verywidepoem{\begingroup\narrower\obeylines\ninepoint}
  279. \def\quote{\medskip\begingroup\narrower\narrower\noindent\ninepoint}
  280. \def\poemby#1#2{\par\smallskip\qquad\qquad\qquad\qquad\qquad -- #1, {\it #2}
  281. \tenpoint\endgroup\bigskip}
  282. \def\widepoemby#1#2{\par\smallskip\qquad\qquad\qquad -- #1, {\it #2}
  283. \tenpoint\endgroup\bigskip}
  284. \def\quoteby#1{\par\smallskip\qquad\qquad\qquad\qquad\qquad
  285.  -- #1\tenpoint\endgroup\bigskip}
  286. \def\endquote{\par\tenpoint\endgroup\medskip}
  287.  
  288. %
  289. %  End of macros
  290.  
  291. \def\subtitle#1{\bigbreak\noindent{\bf #1}\medskip}
  292.  
  293. \titletrue\tenpoint
  294.  
  295. \centerline{\bigfont The Inform Technical Manual}
  296. \vskip 0.5in
  297. \centerline{\sl for revision 5.4, last updated 14/10/94}
  298. \vskip 0.5in 
  299.  
  300. \sli{1}{Introduction}{2}
  301. \sli{2}{Recondite directives}{2}
  302. \sli{3}{Unusual constant forms}{4}
  303. \sli{4}{String indirection and low strings}{5}
  304. \sli{5}{Game control commands and keyboard reading}{5}
  305. \sli{6}{Obselete commands}{7}
  306. \sli{7}{The abbreviations optimiser}{8}
  307. \sli{8}{Dictionary and parsing table formats}{9}
  308. \sli{9}{Porter's notes}{12}
  309. \sli{10}{Geography and history of the source code}{14}
  310.  
  311. \vfill\eject
  312.  
  313. \section{1}{Introduction}
  314.  
  315. This is a short collection of notes on low-level matters covering what
  316. is neither in {\sl The Inform Designer's Manual} nor the assembly-language
  317. documentation in {\sl The Specification of the Z-machine}.
  318.  
  319. The Designer's Manual is, however, intended to be entirely self-contained
  320. for all practical purposes.  If this document contains nothing either
  321. interesting or useful, I feel I shall have achieved my purpose.
  322.  
  323. It contains much of the commentary which used to be in the source code's
  324. header, such as its modification history, notes on porting the Inform
  325. compiler to new machines and documentation of obselete or internally-used
  326. features.  I anticipate revising this (though not necessarily the
  327. Designer's Manual) each time the source code is updated.
  328.  
  329. \medskip
  330. \hbox to\hsize{\hfill\it Graham Nelson}
  331. \hbox to\hsize{\hfill\it Magdalen College, Oxford}
  332. \hbox to\hsize{\hfill\it September 1994}
  333. \ninepoint
  334.  
  335. \section{2}{Recondite directives}
  336.  
  337. These are the directives airily dismissed as `recondite' in \S A1 to the
  338. Designer's Manual.
  339. \beginstt
  340. Default <cname> <value>;
  341. \endtt
  342. If the constant has not yet been defined, define it with this value.
  343. (In |Verblib| this is used to give constants like |MAX_CARRIED| their
  344. default values if the main game source has not already set them;
  345. hence the name.)
  346. \beginstt
  347. Stub <rname> <n>;
  348. \endtt
  349. If the routine has not yet been defined, define one which has $n$ local
  350. variables and simply returns false.  (Setting the number of local variables
  351. prevents the game from calling a routine with more arguments than it has
  352. local variables to put them in; this should not do any harm to the
  353. interpreter, but neither does a little caution.)  This is how ``entry
  354. point'' routines are handled: the |Grammar| library file stubs out any
  355. undeclared entry points.
  356. \beginstt
  357. Dictionary <name> <text>;
  358. \endtt
  359. Enters |<text>| in dictionary, and makes a new constant for its address.
  360. This is not so much recondite as obselete; nowadays one would write
  361. something like
  362. \beginstt
  363. Constant frog_word 'frog';
  364. \endtt
  365. but in any case now that one can write simply |'frog'| the need has gone
  366. away.
  367. \beginstt
  368. System_file;
  369. \endtt
  370. Declares the present file to be a `system file'.  The only way in which
  371. these differ from other files is that if Inform has been told to |Replace|
  372. a given routine, it will ignore a definition of this routine in a `system
  373. file'.  Thus |Parser| and |Verblib| are system files, and conceivably
  374. other user-written library extensions (for magic, say) might want to be.
  375. \beginstt
  376. Lowstring <name> <string>;
  377. \endtt
  378. Puts |string| in the ``low strings" area of the Z-machine (an area in the
  379. lowest 64K of memory which holds static strings, usually to hold
  380. abbreviations), and creates a constant with the given |name| to hold its
  381. word address.  Any string which is to be used with the |@| string escape
  382. must be declared in this low strings area.  (But the use of the |@|
  383. string escape is clumsy and there are probably better ways to get the
  384. effect in Inform 5.)
  385. \beginstt
  386. Version <v>;
  387. \endtt
  388. sets the game file version (3 for Standard games, 5 for Advanced; 4 and 6
  389. are present for completeness).  This directive isn't so much recondite
  390. as redundant; the preferred way is to either set |-v3| or some such at
  391. the command line, or to include a |switches| directive, e.g.
  392. \beginstt
  393. Switches v3;
  394. \endtt
  395. \medskip
  396. The remaining directives are for debugging Inform only:
  397. \beginstt
  398. Listsymbols;
  399. Listdict;
  400. Listverbs;
  401. Listobjects;
  402. \endtt
  403. are fairly self-explanatory (be warned: they can produce a lot of output).
  404. In addition, a number of tracing modes can be turned on and off in
  405. mid-pass:
  406. \beginstt
  407. Trace    Btrace    Ltrace    Etrace
  408. NoTrace  NoBtrace  NoLtrace  NoEtrace
  409. \endtt
  410. |Trace| is an assembly-language style trace, with addresses and bytes
  411. as compiled; |Btrace| is the same, but produced on both passes, not just
  412. on pass 2; |Ltrace| traces each internal line of code; and |Etrace|, the
  413. highest-level of these, traces the expression evaluator at work by
  414. printing out the expression trees made and the assembly source these are
  415. reduced to.  (A more vehement, less legible version is |etrace full|,
  416. which shows the process in minute detail.)
  417.  
  418. \section{3}{Unusual constant forms}
  419.  
  420. There are more constant forms in Inform 5 than are dreamt of in the
  421. Designer's Manual.  Some are obselete, others obscure.  To begin with,
  422. Inform predefines a number of constants which are used by the library:
  423. \beginstt
  424.   adjectives_table   (byte address)
  425.   preactions_table   (byte address)
  426.   actions_table      (byte address)
  427.   code_offset        (packed address of code)
  428.   strings_offset     (packed address of strings)
  429.   version_number     (3 or 5 as appropriate)
  430.   largest_object     (the number of the largest created object + 255)
  431.   dict_par1
  432.   dict_par2
  433.   dict_par3      
  434. \endtt
  435. which can be read by something like
  436. \beginstt
  437. lookup = #adjectives_table;
  438. \endtt
  439. One does occasionally want to know the largest object number in
  440. high-level code, but the library provides a variable |top_object|
  441. such that the legal variable numbers are
  442. $$ 1 \leq n \leq \hbox{|top_object|} $$
  443. and using this is preferable.
  444.  
  445. The |dict_par| constants are byte offsets into a dictionary entry
  446. of the three bytes of data about the word, and are provided because
  447. these offsets are different between Standard and Advanced games;
  448. thus, the parser uses these constants to ensure portability between
  449. the two.
  450. \medskip
  451.  
  452. A constant beginning |#a$| means ``the action number of this action
  453. routine''.  Thus, |#a$TakeSub| is equivalent to the more usual
  454. |##Take|.
  455. \medskip
  456.  
  457. A constant beginning |#w$|, followed by a word of text, has as value the
  458. address of the given word in the dictionary (Inform will give an
  459. error at compile time if no such word is present).  Largely obselete.
  460. \medskip
  461.  
  462. A constant beginning |#n$|, followed by a word of text, has as value the
  463. address of the given word in the dictionary (Inform adds it to the
  464. dictionary as a new word if it is not already there).  Thus,
  465. |#n$leopard| is equivalent to |'leopard'|.  However, this constant form
  466. is still useful to enter single-letter words into the dictionary
  467. (like |y|, which the parser defines as an abbreviation for ``yes'')
  468. since |'y'| would instead mean the ASCII value of the character `y'.
  469. \medskip
  470.  
  471. A constant beginning |#r$|, followed by a routine name, gives the (packed)
  472. address of the given routine.  This is chiefly useful for changing the
  473. routine-valued properties of an object in mid-game, e.g.
  474. \beginstt
  475. lamp.before = #r$NewBeforeRoutine;
  476. \endtt
  477. where |NewBeforeRoutine| is defined as a global routine somewhere.
  478.  
  479. \section{4}{String indirection and low strings}
  480.  
  481. Inside a static string (in double-quotes), the string escape |@nn|,
  482. an |@| sign followed by a two digit number, means ``print the
  483. $n$-th string variable here''.  |nn| is a decimal number from |00|
  484. to |31|.  Now such a variable string can be set with the
  485. \beginstt
  486. String <number> <low-string-constant>;
  487. \endtt
  488. which means that any string to be used in this way has to have been
  489. defined as a ``low string'' (see above).  For example,
  490. \beginstt
  491. Lowstring L_Frog "little green frog";
  492. ...
  493. String 0 #L_Frog;
  494. "You notice a @00!^";
  495. \endtt
  496. will result in the output
  497. \beginstt
  498. You notice a little green frog!
  499. \endtt
  500. Actually, since the first 32 entries of the ``synonyms table'' in the
  501. Z-machine are reserved for this purpose, the command |String n x|
  502. is in fact equivalent to
  503. \beginstt
  504. (0-->12)-->n=x;
  505. \endtt
  506. Due to a minor design infelicity of the Z-machine, the more
  507. friendly-looking usage
  508. \beginstt
  509. String 0 "illegal frog";
  510. \endtt
  511. will work in a Standard game but may unpredictably fail in an
  512. Advanced one exceeding 128K in length; hence the need to ensure
  513. all relevant strings are ``low'' (in the bottom 128K of memory).
  514.  
  515. \section{5}{Game control commands and keyboard reading}
  516.  
  517. \beginstt
  518. quit;
  519. \endtt
  520. (Actually an assembly language opcode.)  This quits the game
  521. (at once, with no confirmatory question to the user): all games must
  522. end this way, since it is illegal to return from the |Main| routine).
  523. \beginstt
  524. restart;
  525. \endtt
  526. (Similarly an opcode.)  Restarts the game exactly to its initial state,
  527. losing the previous state for good.
  528. \beginstt
  529. save <label>;
  530. restore <label>;
  531. verify <label>;
  532. \endtt
  533. Tries to save or load in a saved game file, or to verify that the
  534. existing story file is not corrupted (by calculating a checksum and
  535. comparing it against the one in the header).  In each case, |jump|
  536. to the given label if successful (otherwise run on into the next
  537. statement as usual).  |save| and |restore| are actually commands and
  538. not opcodes because the relevant opcodes function differently between
  539. Standard and Advanced games; this command ensures portability.
  540.  
  541. \bigskip
  542. \beginstt
  543. Read <a> <b> [<routine>];
  544. \endtt
  545. This reads from the keyboard (printing no prompt: it is assumed this
  546. has already been done) into buffer |a| and tokenises it into buffer |b|.
  547. (|a| and |b| are expected to point to global string variables, defined
  548. by something like
  549. \beginstt
  550. Global a string 120;
  551. \endtt
  552. meaning that |a->0| contains the number 120, and that |a->1| to
  553. |a->120| are bytes of available read/write memory.)  In Standard games,
  554. this command automatically redisplays the status line.  In Advanced ones,
  555. if no routine is given then Inform compiles code to emulate the
  556. Standard game status line automatically; if a routine is given, this
  557. is called instead, and is expected to update the status line itself.
  558. See the Designer's Manual for an example of such a routine.
  559.  
  560. \noindent After |read| has taken place:
  561. \item{$\bullet$} |a->1| holds the number of characters typed;
  562. \item{$\bullet$} the text, unterminated, is held in |a->2| to |a->(a->1 + 1)|;
  563. \item{$\bullet$} |b->1| holds the number of words typed (note that commas
  564. and full stops become separate words in their own right);
  565. \item{$\bullet$} from byte 2 onward, |b| contains 4-byte blocks, one for
  566. each word, in the form
  567. \itemitem{0,1} byte address of dictionary entry if word is known, 0 otherwise;
  568. \itemitem{2} number of letters in word
  569. \itemitem{3} first character of word in the |a| buffer.
  570.  
  571. \noindent More flexible tokenising and keyboard-reading methods are available
  572. by resorting to assembly language; see the |aread| opcode and the
  573. `special effects' section of the Designer's Manual.
  574.  
  575. \section{6}{Obselete commands}
  576.  
  577. Inform 5 continues to provide a number of out-dated features from Inform 1
  578. to 4; `out-dated' in the sense that there are now much better ways to do
  579. the same things.  The old features have not been removed because the
  580. largest Inform program in existence (`Curses') still makes use of them;
  581. their further use is not encouraged.
  582. \medskip
  583. The |put| command takes the form:
  584. \beginstt
  585. put <addr> byte <index> <v>;
  586. put <addr> word <index> <v>;
  587. \endtt
  588. which are the old way to use arrays, now superceded by
  589. \beginstt
  590. addr->index=v;
  591. addr-->index=v;
  592. \endtt
  593. \medskip
  594. The |write| command can be used to write to many properties of an object
  595. at once:
  596. \beginstt
  597. write <object> <p1> <v1> [<p2> <v2>...];
  598. \endtt
  599. and was useful in the days when the only alternative was using the
  600. |@put_prop| assembly opcode, but is now superceded by lines like
  601. \beginstt
  602. lamp.time_left = 0;
  603. \endtt
  604. which are clearer and more consistent.
  605. \medskip
  606. Before Inform provided C-style |for| loops, it had BASIC-style ones:
  607. these were the so-called `old-style |for| loops',
  608. \beginstt
  609. for <var> <start> to <finish> { ...code... }
  610. \endtt
  611. which were restricted in having only simple finish values (i.e., not
  612. compound expressions) and in requiring braces around the code (even
  613. if it contained only a single statement).  The effect can be duplicated
  614. with
  615. \beginstt
  616. for (<var>=<start> : <var> <= <finish> : <var>++) ...code...
  617. \endtt
  618. one form of a much more general and flexible construct.
  619.  
  620. \section{7}{The abbreviations optimiser}
  621.  
  622. When the game becomes full, 8 to 10\% of its length can be saved by making
  623. use of text abbreviations: a method under which up to 64 commonly occurring
  624. phrases can be abbreviated whenever they occur.  This makes no difference
  625. to text as seen by the player.  Because checking for these causes a speed
  626. overhead (again, of about 10\%) and it isn't worthwhile unless a game is
  627. very large, Inform does not do so except in economy mode (compiling with
  628. the switch |-e| on).  Abbreviations must be declared explicitly, before
  629. any other text appears, by a directive such as:
  630. \beginstt
  631. Abbreviate "the ";
  632. \endtt
  633. This causes "the " to be stored internally as only 2 text chunks (5-bit
  634. segments), rather than 4, whenever it occurs: which is very often.
  635. Only 64 may be declared (the remaining 32 slots in the Z-machine's
  636. ``synonyms table'' being kept for string indirection).
  637.  
  638. To see how good your current choice of abbreviations is, try compiling with
  639. the |-f| (frequencies) option set, which will count the number of times each
  640. abbreviation is used, and work out how many bytes it saved.  For instance,
  641. |" the "| occurs some 2445 times in `Curses'.  Experiment soon reveals that
  642. parts of speech and words like |"there"| make big savings, but that almost
  643. any proper noun makes little difference.
  644.  
  645. Infocom's own compiler does not seem to have chosen abbreviations very
  646. rigorously, since Infocom story files contain just such a naive list.  (This
  647. may have been wise from the point of view of printing speed in the days of
  648. much slower computers.)
  649.  
  650. In any case, the |-u| option of Inform (if your computer is large enough and
  651. fast enough to make this feasible) will try to work out a nearly-optimal set
  652. of abbreviations.
  653.  
  654. The algorithm for doing so is too complex to give here: see the source code.
  655. Briefly, it runs in two phases: building a table of cross-references, and
  656. then running a number of passes looking for good substrings and choosing
  657. good antichains from the partially ordered set resulting.  (The main problem
  658. being that abbreviations interfere with each other: taking both of
  659. |"the"| and |"the "| will not give the same saving as the individual savings
  660. added up.)  The result is not guaranteed to be optimal but seems pretty good.
  661. The output it finally produces is a list of legal Inform |Abbreviate|
  662. commands which can be pasted into source code.
  663.  
  664. Since there are something like
  665. $$ 2^{300000} $$
  666. possible choices for a typical-sized game, this is bound to be an
  667. expensive job.  A 128K game takes about 45 seconds to compile on my machine,
  668. and slightly under two hours to optimise.  There are three passes, of which
  669. the first is by far the longest.
  670.  
  671. Reasonable guesswork and experiment (resulting in the words suggested in
  672. earlier editions of this manual) actually doesn't perform too badly, but
  673. when I first optimised a 128K version of `Curses', the |-u| option saved
  674. 1200 bytes over the best choices made by hand: here is the selection
  675. produced, in the form of |-f| output:
  676. \beginlines
  677. |    How frequently abbreviations were used, and roughly how many|
  678. |    bytes they saved:  ('_' denotes spaces)|
  679. |       you   668/  444         with   144/  190        which    92/  182   |
  680. |       urs    58/   38         tion   142/  188          ter   274/  182   |
  681. |       t_w   134/   88          t_s   117/   77          t_o   164/  108   |
  682. |       t_i   167/  110          ing   960/  639         ight   187/  248   |
  683. |       her   283/  188          e_w   146/   96          e_s   160/  106   |
  684. |       e_o   227/  150          e_i   245/  162          e_a   254/  168   |
  685. |       der    87/   57          d_s    61/   40          d_o   122/   80   |
  686. |       d_i    82/   54          d_a   122/   80          and   560/  372   |
  687. |       all   289/  192          You   297/  394         This    47/   92   |
  688. |       The   384/  510      Meldrew    28/  108        It_is    40/  104   |
  689. | Aunt_Jemima  15/  102           ._   680/  452           ,_  1444/  962   |
  690. |      's_~    42/  109        's_no    41/  106          _un   105/   69   |
  691. |       _to   708/  471        _the_  1328/ 2654          _th   578/  384   |
  692. |       _ro   110/   72          _pr    95/   62          _po    78/   51   |
  693. |       _no   246/  163          _ma   165/  109          _lo   119/   78   |
  694. |       _ho    87/   57          _hi    99/   65          _ha   309/  205   |
  695. |       _gr    67/   44          _ga    60/   39        _from    94/  186   |
  696. |      _for   185/  245          _fi   130/   86          _fa    97/   64   |
  697. |       _ex    89/   58          _ea    61/   40        _door    46/   90   |
  698. |       _di   110/   72         _con    88/  116         _com    72/   94   |
  699. |       _cl    81/   53         _can   164/  217          _ba   120/   79   |
  700. |       _a_   587/  390   |
  701. \endlines
  702. On a version of `Curses' taking up about 240K, using abbreviations saved
  703. about 23000 bytes and added 9 seconds to a 91-second compilation time.
  704.  
  705. It's interesting how few words in common the naive and optimised lists
  706. have.  Only two proper nouns survived, and they provide the only longish
  707. words.  |"is "| as such turned out not to be worthwhile.  |" the "| was
  708. perhaps obvious in retrospect, but I didn't think of it.  The best strategy
  709. for abbreviating seems to be to choose three-character strings which make
  710. a fractional saving each (only one Z-character each time, for the most part)
  711. but which occur very often indeed.
  712.  
  713. Note also that another 32 abbreviations (which could be accommodated, if the
  714. string indirections mechanism were dropped) would be little help, as
  715. the least worthwhile of these already saves only 38 bytes or so.
  716.  
  717. \section{8}{Dictionary and parsing table formats}
  718.  
  719. Some of the tables Inform writes into the Z-machine have formats which are
  720. not imposed by the Z-machine specification but by Inform's own conventions,
  721. and these are covered here.  These conventions are based on (but different
  722. to) those used in the middle-period Infocom games.
  723. \medskip
  724.  
  725. {\ninebf Adjectives} are numbered downwards from |$ff| in order of their appearance in
  726. defined grammar.  The adjective table contains 4-byte entries:
  727. \beginstt
  728. <dictionary address of word>  00  <adjective number>
  729. ----2 bytes-----------------  ----2 bytes----------- 
  730. \endtt
  731. To make life more interesting, these entries are stored in reverse
  732. order (i.e., lowest adjective number first).  The address of this table is
  733. rather difficult to deduce from the file header information, so the constant
  734. |#adjectives_table| is set up by Inform to refer to it.
  735. \medskip
  736.  
  737. The {\ninebf grammar table} address is stored in word 7 (i.e. bytes 14 and 15)
  738. of the header.  The table consists of a list of two-byte addresses to
  739. the entries for each word.  This list is immediately followed by these
  740. entries, one after another.
  741.  
  742. An entry consists of one byte giving the number of lines and then that
  743. many 8-byte lines.  These lines have the form
  744. \beginstt
  745. <objects>  <sequence of words>  <action number>
  746. --1 byte-  ----6 bytes--------  --1 byte-------
  747. \endtt
  748. |<objects>| is the number of objects which need to be supplied: eg, 0 for
  749. ``inventory", 1 for ``take frog", 2 for ``tie rope to dog".  The sequence
  750. of words gives up to 6 tokens following the verb, to be matched in order.
  751. The token values are given by the table:
  752. \beginstt
  753.    noun             0  
  754.    held             1  
  755.    multi            2  
  756.    multiheld        3  
  757.    multiexcept      4  
  758.    multiinside      5  
  759.    creature         6  
  760.    special          7  
  761.    number           8
  762.    (noun=Routine)   16+parsing-routine-number
  763.    (Routine)        48+parsing-routine-number
  764.    (scope=Routine)  80+parsing-routine-number
  765.    (attribute)      128+attribute number
  766.    (adjective)      adjective number
  767.    ...reserved...   9-15, 112-127
  768. \endtt
  769. Parsing routines have addresses which are too large to store in a single
  770. byte.  Instead they are numbered from 0, and their (packed) addresses are
  771. stored in the {\ninebf preactions table} of the story file.  (This is called
  772. ``preactions table" because of what the original Infocom parser used it
  773. for; the Inform library parser has no such concept as `preaction'.)
  774.  
  775. The sequence is padded out to 6 bytes with zeros.  (This is a tiresome
  776. convention, as it means that the value 0 can only be understood by
  777. looking back at what has come before, but it's too late to change it now.)
  778. \medskip
  779.  
  780. {\ninebf Actions} are numbered from 0 upwards in order of appearance in the
  781. grammar.  (Whereas fake actions are numbered from |$ff| down, but that's
  782. another story.)  The packed addresses of the corresponding action routines
  783. are stored in the {\ninebf actions table}.  Once again, Inform puts this table
  784. in its conventional place, but its address is difficult to work out and
  785. so the constant |#actions_table| is set up to hold it.
  786. \medskip
  787.  
  788. {\ninebf Verbs} are numbered from |$ff| downwards in order of appearance,
  789. with synonyms getting the same number (thus, ``get'' and ``take'' have
  790. the same verb number); they are entered into the dictionary as they are
  791. defined in grammar.
  792. \medskip
  793.  
  794. In the {\ninebf dictionary} header, Inform defines only three characters as
  795. `separators' which break up words in tokenisation: these are full stop,
  796. comma and open-double-quote.  (In theory the Z-machine allows any list
  797. here, but these three are conventional in old Infocom story files.)
  798.  
  799. Inform writes dictionary entries consisting of the word itself, plus
  800. three data bytes.  (This makes them 7 bytes long in Standard games,
  801. 9 in Advanced.)
  802. The entries are in alphabetical order, and look like:
  803. \beginstt
  804. <the text of the word>  <flags>  <verb number>  <adjective number>
  805. ----4 or 6 bytes------  --1 b--  ----1 byte---  ----1 byte--------
  806. \endtt
  807. The text is stored in the usual text format, thus allowing up to 6 or 9
  808. characters.  These data bytes can be safely accessed (portably between
  809. either format of game) by, e.g.
  810. \beginstt
  811. address->#dict_par1
  812. \endtt
  813. which reads the flags byte of the word at |address|.
  814.  
  815. The flags (chosen once again to conform loosely to Infocom conventions, not
  816. for any sensible reason) have the eight bits
  817. \beginstt
  818. 7      6  5  4  3     2      1      0
  819. <noun> .. .. .. <adj> <spec> <meta> <verb>
  820. \endtt
  821. |<verb>|, |<noun>| and |<adj>| mean the word can be a verb, noun or adjective;
  822. the |<spec>| bit means the word was inserted by a |Dictionary| command in the
  823. program, except that |<verb>| words also have the |<spec>| bit set (ours not to
  824. wonder why).
  825.  
  826. Verbs declared as |"meta"| have the |<meta>| bit set.  (These are such
  827. out-of-world experiences as ``save'' and ``score''.)
  828.  
  829. Note that a word can be any combination of these at once.  It can even be
  830. simultaneously a verb, adjective and noun, and will be understood as such
  831. in different contexts.
  832.  
  833. \vfill\eject
  834. \section{9}{Porter's notes}
  835.  
  836. The following ports have (generally) successfully been made:
  837. \beginstt
  838.   the Commodore Amiga under SAS/C              Christopher A. Wichura
  839.   the Acorn Archimedes under Norcroft C        (the author)
  840.   the Atari ST                                 Charles Briscoe-Smith
  841.   Linux under gcc (essentially as per Unix)    Spedge, aka Dark Mage
  842.   the Apple Macintosh                          Robert Pelak
  843.   the Mac, under the Programmer's Workshop     Brad Jones
  844.   OS/2 32-bit mode under IBM's C Set++         John W. Kennedy
  845.   386+ IBM PCs, eg. Microsoft Visual C/C++     Toby Nelson
  846.   small IBM PCs under QuickC                   Bob Newell
  847.   Unix under gcc (or big IBM PCs under djgpp)  Dilip Sequeira
  848.   VAX mainframes under Digital's VAX C         (the author)
  849. \endtt
  850. (Apologies to anyone left out.)  Recent ports have been relative painless,
  851. and on many machines (particularly those with 32-bit integers and flat
  852. memory maps) the code has simply compiled and worked first-time without
  853. trouble.  Executables from most of the above ports may be found
  854. ready-compiled in the archive |ftp.gmd.de|.
  855.  
  856. Porters are asked to name such executables, when they post them, with
  857. a filename which clearly indicates the machine and the revision number
  858. (e.g. by ending |.5.4|); and to email the author, if possible, with
  859. details of any modifications they needed to make, so that the main
  860. source can be improved.  In particular, |diff|s (that is, differences
  861. between the source code as last posted, and the source as compiled
  862. for the machine in question) would be a great help.
  863.  
  864. See the |header.h| file for some make-files for different compilers.
  865. Note that some over-zealous make utilities object to the lack of a
  866. file called |version.h|, somewhat stupidly since it is never referred to
  867. except in a conditional compilation which never happens: this is
  868. the header file for my own machine defining the current version
  869. number.  You may therefore have to create some null |version.h|
  870. file yourself.
  871.  
  872. The code assumes that |long int| is at least 32 bits long, though
  873. plain |int| can be either 16 or 32.
  874.  
  875. The general procedure is as follows: all code special to your port should
  876. appear inside |#IFDEF|s, with a constant for your port being defined
  877. at the head of the file.  A block of definitions should appear in the
  878. header file along with the others.  For instance, here is the block for
  879. Unix:
  880. \beginlines
  881. |#ifdef UNIX|
  882. |#define MACHINE_STRING   "Unix"|
  883. |#define Source_Prefix    ""|
  884. |#define Source_Extension ".inf"|
  885. |#define Include_Extension ".h"|
  886. |#define Code_Prefix      ""|
  887. |#define Code_Extension   ".z3"|
  888. |#define V5Code_Extension ".z5"|
  889. |#define Transcript_Name "game.txt"|
  890. |#define Debugging_Name  "game.dbg"|
  891. |extern char Temp1_Name[], Temp2_Name[];|
  892. |#define Temp1_Hdr "/tmp/InformTemp1"|
  893. |#define Temp2_Hdr "/tmp/InformTemp2"|
  894. |#define DEFAULT_MEMORY_SIZE LARGE_SIZE|
  895. |#define US_POINTERS|
  896. |#endif|
  897. \endlines
  898. Notice that since some abysmally poor C compilers (such as VAX C, which
  899. has the affrontery to call itself ANSI) require that all |#| directives
  900. begin on the first column of the source code, you should abide by this
  901. as well.
  902.  
  903. |MACHINE_STRING| should name the machine.  The prefixes and extensions
  904. are defaults for filenaming conventions.  Under Unix, then, ``frog''
  905. will mean |frog.inf| it it's a source file, |frog.h| if an include
  906. file (such as a library file), |frog.z3| or |frog.z5| it it's to be
  907. written as a Standard or Advanced game respectively.  The
  908. |Transcript_Name| and |Debugging_Name|s hold names for the transcribed
  909. text and debugging information files (both optionally produced).
  910. Arrangements for naming temporary files (used for temporary storage
  911. space during compilation) are more vexed on some machines; under Unix,
  912. they are given unique names depending on the current process, for
  913. instance.  Code to work out these names is defined in |files.c|,
  914. conditionally compiled when |UNIX| is defined.  If there is no such
  915. multi-tasking issue, or you can't be bothered, you can just write
  916. something like
  917. \beginlines
  918. |#define Temp1_Name "Inftmp1.tmp"|
  919. |#define Temp2_Name "Inftmp2.tmp"|
  920. \endlines
  921.  
  922. Set the |DEFAULT_MEMORY_SIZE| to |LARGE_SIZE| if you can; but if this is
  923. too consumptive for a small model of your machine, choose |SMALL_SIZE|.
  924. (In any case this default can be over-ridden on the command line.)
  925.  
  926. There are a few options:
  927.  
  928. |TEMPORARY_FILES| means `use temporary files for scratch workspace'.
  929. The alternative is to use a good deal of extra RAM, say 256K or so,
  930. and possibly to have trouble allocating it since it will need to
  931. have large contiguous chunks.
  932.  
  933. |US_POINTERS| uses unsigned rather than signed |char *| pointers when
  934. calculating things like checksums; you may need this if your compiler
  935. signs |char| by default.
  936.  
  937. |TIME_UNAVAILABLE| indicates that the ANSI what's-the-date-today routines
  938. can't be used.  (The serial number of a game will then be 940000 unless
  939. otherwise set by a |Serial| directive in it.)
  940.  
  941. |PROMPT_INPUT| indicates that the usual ANSI command-line arguments
  942. system cannot be used, which makes Inform ask questions instead.  This
  943. is tiresome, so if you can find an alternative, take it.
  944.  
  945. |GRAHAM| indicates that you are Graham Nelson (not to be recommended).
  946.  
  947. \medskip
  948. All claims of memory are routed through |my_malloc| and |my_calloc|
  949. in |files.c|.  The Quick C port shows what can be done in the case when
  950. your compiler will not allow you to allocate more than 64K contiguously
  951. without great trouble.
  952.  
  953. \medskip
  954. If two copies of Inform on different machines are given
  955. {\sl identical} source code (and have identical version numbers, and
  956. identical ideas about what today's date is) then they should produce
  957. {\sl identical} game files.  If your port can pass this test for the
  958. `Advent' example game, it's probably in good shape.  A quicker test
  959. is to try typing ``verify'' into a game produced by your port; often
  960. accidents of porting are shown up by wrong checksums in this way.
  961.  
  962. Don't worry if you can't get some of the more unusual switches to work,
  963. such as the gargantuan |-u|, but please cope with the user asking for
  964. it by giving some suitable error message.
  965.  
  966. \section{10}{Geography and history of the source code}
  967.  
  968. The Inform source code is written in ever stricter and more pragmatic ANSI
  969. C.  It consists of a header file |header.h| and eight files of code:
  970. \beginstt
  971. asm.c  express.c  files.c  inform.c  inputs.c  tables.c  zcode.c  symbols.c
  972. \endtt
  973. (see the attached map).
  974. \midinsert
  975. \hrule\smallskip
  976. \centerline{\sl A tourist's map of the Inform archipelago}
  977. \medskip
  978. $$\vbox{%
  979. \settabs\+\indent&\qquad&\qquad&\qquad&reallyreallyquitealongsampleword&\cr%
  980. \+ Main (top level) &&&&& |inform.c|\cr
  981. \+ & Initialisation\cr
  982. \+ & Command line switches\cr
  983. \+ & Top level line parser\cr
  984. \+ & & Compiler\cr
  985. \smallskip
  986. \+ & & & Assignments and conditions && |express.c|\cr
  987. \+ & & & Expression evaluator\cr
  988. \smallskip
  989. \+ & & Assembler directives &&& |asm.c|\cr
  990. \+ & & Line assembler\cr
  991. \+ & & & Constant evaluator\cr
  992. \+ & & & Make attributes/properties\cr
  993. \smallskip
  994. \+ & & & Make objects and classes && |tables.c|\cr
  995. \+ & & & Make globals\cr
  996. \+ & & & Make verbs\cr
  997. \+ & & & Make dictionary\cr
  998. \+ & & & Make actions\cr
  999. \+ & & & Print diagnostics\cr
  1000. \+ & Construct output file\cr
  1001. \smallskip
  1002. \+ & & & Text translation && |zcode.c|\cr
  1003. \+ & & & Z-code database\cr
  1004. \+ & & & Reserved words table\cr
  1005. \+ & Abbreviations optimiser\cr
  1006. \smallskip
  1007. \+ & & & Symbols table maker && |symbols.c|\cr
  1008. \smallskip
  1009. \+ & & & Preprocessor stack && |inputs.c|\cr
  1010. \+ & & & Character-level parsing\cr
  1011. \+ & & & Error reporting\cr
  1012. \smallskip
  1013. \+ & & & File handling && |files.c|\cr
  1014. \+ & & & Fatal errors\cr
  1015. \+ & & & Debugging information file\cr
  1016. \+ & & & Memory management\cr
  1017. \smallskip
  1018. \+ & & & & Comments & |header.h|\cr
  1019. \+ & & & & |#define|s\cr
  1020. \+ & & & & Integer types\cr
  1021. \+ & & & & Structures\cr
  1022. \+ & & & & Extern declarations\cr}$$
  1023. \smallskip\hrule
  1024. \endinsert
  1025. Inform runs in two passes, like an assembler.  Mostly it does the same
  1026. things on pass 2 as pass 1 (but is able to sort out forward references);
  1027. but there are exceptions (the dictionary is insertion-sorted and hashed
  1028. on pass 1, then strung together in the right order on pass 2, for instance).
  1029.  
  1030. It tokenises one line at a time (and does not make elaborate parse trees,
  1031. which is why it is not good at hanging elses).  Lines are divided
  1032. up between directives, assembler opcodes and statements.  Statements
  1033. are normally converted back into sequences of assembler lines, which
  1034. are held on the `preprocessor stack' to be processed next (before
  1035. the next statement from the source).  Some complex statements even
  1036. compile to simpler ones and so on down.  In this way the original
  1037. source becomes a stream of assembly language.
  1038.  
  1039. Objects and classes are stored in a compressed format similar to their
  1040. final format, to save on memory.
  1041.  
  1042. Only one error is allowed through per original source statement (which
  1043. prevents assembly-language errors caused by poor error recovery in
  1044. some cases).
  1045.  
  1046. The modification history of Inform 1 to 5 is as follows.  Note that some of
  1047. the earlier remarks are archaic and out-of-date, representing features now
  1048. superceded.  Apologies to those whose corrections went in without their
  1049. names being recorded!
  1050. \smallskip
  1051. \hrule
  1052. \medskip
  1053. \noindent{\bf Inform 1}
  1054. \beginlines
  1055. |     The first archive release (0.5) was on April 30th 1993.               |
  1056. \endlines
  1057. \medskip
  1058. \noindent{\bf Inform 2}
  1059. \beginlines
  1060. |     The second archive release (0.6) had the following improvements:      |
  1061. |                                                                           |
  1062. |     One #ifdef ARCHIMEDES altered to correct a bug in non-Archimedes      |
  1063. |     version                                                               |
  1064. |     Checking on the MAX_ACTIONS limit put in ("Curses" exceeded 100!)     |
  1065. |     Checking on MAX_STATIC_STRINGS put in; -m information extended        |
  1066. |     -x (hash printing) option introduced                                  |
  1067. |     -a (list assembly lines only) option, and ATRACE/NOATRACE introduced  |
  1068. |     Void prototypes explicitly declared (void)                            |
  1069. |     Defunct Inform directives "STRING" and "SET" removed                  |
  1070. |     Opcode data now made static, and faster opcode-parsing routine put in |
  1071. |     Preprocessor stack rewritten, and now checking for overflow           |
  1072. |     Showdict produces more useful output                                  |
  1073. |     Filename extension #defines added                                     |
  1074. |     Command line parsing improved                                         |
  1075. |     Some ASCII assumptions removed                                        |
  1076. |     Typedefs added to force integers to be 32-bits long                   |
  1077. |     Memory management heavily reformed, at the expense of a certain charm |
  1078. |                                                                           |
  1079. |     USE_TEMPORARY_FILES version: if this is #defined, scratch files       |
  1080. |       amounting to at most about 100K and 50K respectively are used to    |
  1081. |       hold the code and static strings areas; this saves about another    |
  1082. |       150K.                                                               |
  1083. |       (At worst three files are simultaneously open under this regime.)   |
  1084. |       The temporary file names are #define'd below.  They are             |
  1085. |         automatically deleted.                                            |
  1086. \endlines
  1087. \medskip
  1088. \noindent{\bf Inform 3}
  1089. \beginlines
  1090. |   The third release (1.0) is generally tidied and reorganised: most       |
  1091. |   of the sillier variable and routine names have been made more           |
  1092. |   comprehensible.                                                         |
  1093. |   It is also 3 to 6 times faster; thanks due to Dilip Sequeira for        |
  1094. |   profiling output, and also David Moore for his... comments.             |
  1095. |       (November 1993)                                                     |
  1096. |                                                                           |
  1097. |   Program improvements in the third release:                              |
  1098. |                                                                           |
  1099. |     @xx string indirection via the synonyms table added                   |
  1100. |     Objects allowed to have multiple internal names                       |
  1101. |     New constant form #n$word... added                                    |
  1102. |     And #r$routine...                                                     |
  1103. |     New high-level commands "write" and "give" for easier object amending |
  1104. |     Fatal errors fractionally more informative                            |
  1105. |     Non-fatal errors quite a lot more informative, and better worded      |
  1106. |     Grievous bug in stack long slot routines fixed                        |
  1107. |     The checksum and length words are now properly set (though few        |
  1108. |       interpreters need them)                                             |
  1109. |     Error checking on exceeding MAX_VERBS                                 |
  1110. |     -e (economy mode) added: causes abbreviations to be worked out,       |
  1111. |       slowly (this is why it is only an option)                           |
  1112. |     #SWITCHES directive added                                             |
  1113. |     -i (ignore switches) and -o (print offsets) added                     |
  1114. |     Checking added on whether routines have too many local variables (the |
  1115. |       Z-machine crashes in a very strange way if so!)                     |
  1116. |     Minor bug in printing object tree fixed                               |
  1117. |     Two unused bytes spare at end of property defaults table are now      |
  1118. |       zeroed                                                              |
  1119. |     Temporary files now deleted after use                                 |
  1120. |     Checking on excessively long variable names added                     |
  1121. |     STATUSLINE directive added (for games with hours/minutes on the       |
  1122. |       status line)                                                        |
  1123. |     The former SMALL_MEMORY compilation option is now mandatory.          |
  1124. |       (Previously, Inform could be compiled so that it read source files  |
  1125. |       into an enormous buffer, rather than reading them twice through a   |
  1126. |       bit at a time.  This could only be useful on machines with huge     |
  1127. |       memory and very slow filing systems, of which there are few, and it |
  1128. |       complicated the code.)                                              |
  1129. |     The way input file names are processed has been reformed: they are    |
  1130. |       now not altered if they contain a '.' or a '/'                      |
  1131. |     INCLUDE directive added, so that Inform #includes files like C        |
  1132. |     Old -p (both passes) directive renamed -b, and new -p (percentage     |
  1133. |       breakdown)                                                          |
  1134. |     Warnings added: variables not used; checking that Main behaves        |
  1135. |       properly; small bug in line counting fixed; checking on number of   |
  1136. |       function arguments                                                  |
  1137. |     Meta-verbs added                                                      |
  1138. |     -f (frequencies) and -t (assembly trace) switches added               |
  1139. |     Small bug to do with stubbed routines removed                         |
  1140. |     Possibly unused bytes (due to word alignment) in data, now zeroed     |
  1141. |       (so that different machines will not produce different game files)  |
  1142. |     -f now calculates bytes yielded by abbreviations                      |
  1143. |     New SERIAL directive for machines without access to today's date      |
  1144. |     Now handles more complicated multiple expressions within the same     |
  1145. |       command                                                             |
  1146. |     New STRING command added for writing to the synonyms table            |
  1147. |     New FONT command for proportional fonts control                       |
  1148. |     New DEFAULT and STUB directives, for stubbing undeclared CONSTANTs    |
  1149. |       and code                                                            |
  1150. |     Checking on no. of attributes and properties added, and               |
  1151. |       property-counting                                                   |
  1152. |                                                                           |
  1153. |   Speed improvements in the third release:                                |
  1154. |                                                                           |
  1155. |     The following have been rewritten in the interests of speed and       |
  1156. |       not being O(n^2) for the sake of it: the line reader and tokeniser, |
  1157. |       management of local variables, the dictionary builder, the text     |
  1158. |       translator, the line parser and the symbols table (courtesy of hash |
  1159. |       coding by Dilip).                                                   |
  1160. |                         Curses    Dejavu       (compiling times (seconds) |
  1161. |                                                 on my machine)            |
  1162. |        Release 2...        300        45       (including 1-2 seconds for |
  1163. |        Tokeniser & locals  205        26        printing statistics)      |
  1164. |        Dictionary           89        19                                  |
  1165. |        Symbols hashing      74        17                                  |
  1166. |        Tokeniser II         69        16                                  |
  1167. |        Abbreviations        55        16                                  |
  1168. |        Hashing reserveds    49        14                                  |
  1169. |                                                                           |
  1170. |   Compatibility improvements in the third release:                        |
  1171. |                                                                           |
  1172. |     The sort_number routine has been rewritten at the suggestion of Jon   |
  1173. |       Drukman in order to defend against compilers determined to sign     |
  1174. |       chars; and so have some structure definitions and variable types    |
  1175. |     Subtraction of pointers is now done by an easily altered macro (the   |
  1176. |       point being that you can't always subtract by casting to int, if    |
  1177. |       int is 16 bit or if you have a dire MSDOS-like memory map)          |
  1178. |     File naming improved slightly                                         |
  1179. |     The two points where ASCII is used now go through translate_to_ascii  |
  1180. |     Some stupid alterations made for VAX C compatibility                  |
  1181. |       (in the idiot world of VAX C, # commands must start on column 1,    |
  1182. |       x=-1 is read as x-=1, typedef isn't ANSI, the word "signed" is      |
  1183. |       rejected, values like MAX_INT are wrongly set and string consts     |
  1184. |       don't concatenate)                                                  |
  1185. |     A general rewrite has been made to sort out 16-bit from 32-bit        |
  1186. |       integers: Inform now properly works when int is 16 bit by default.  |
  1187. |     VAX version now working (so presumably Inform does not rely on the    |
  1188. |       order of bytes in a word)                                           |
  1189. |     Long constants explicitly declared so (to keep Borland C++ happy)     |
  1190. |     Because some C compilers (especially PC ones) don't like large static |
  1191. |       arrays there's now an ALLOCATE_BIG_ARRAYS option (#define PC forces |
  1192. |       it) which uses calloc to allocate memory from the heap for them.    |
  1193. |     Altogether Inform is going to need about 200K of workspace, and       |
  1194. |       that's that: in a big flat memory machine, this will split about    |
  1195. |       equally between static arrays and dynamic allocation.  With         |
  1196. |       ALLOCATE_BIG_ARRAYS set it will be almost entirely dynamically      |
  1197. |       allocated.                                                          |
  1198. |     If PROMPT_INPUTS is defined (and the VAX and PC versions force this), |
  1199. |       Inform gets file names and options by prompting for keyboard input, |
  1200. |       rather than using a Unix-style command line.                        |
  1201. |     If TIME_UNAVAILABLE is defined, Inform doesn't try to use strftime    |
  1202. |       and doesn't enter today's date for the serial number: the           |
  1203. |       programmer will have to use a SERIAL directive in Inform, instead.  |
  1204. |                                                                           |
  1205. |     Improvements made for Release 3a:  (Dec 7th 1993)                     |
  1206. |                                                                           |
  1207. |      The AMIGA port option added (following Christopher Wichura)          |
  1208. |      #define US_POINTERS option added                                     |
  1209. |      A few constants (eg. MAX_BANK_SIZE) slightly increased, as "Curses"  |
  1210. |        needed it when very close indeed to maximum possible size          |
  1211. |     A few void routines which weren't explicitly called (void) now are    |
  1212. |     The use of local text buffers by routines has been reformed, so that  |
  1213. |       although there's now about 6K more of array allocation, the stack   |
  1214. |       needed during runs of Inform is very much smaller (previously       |
  1215. |       machines with less than 32K stack couldn't manage).                 |
  1216. |     The tokeniser now recognises tab characters (outside string literals) |
  1217. |       as spaces (Inform previously gave errors when it found these).      |
  1218. |     The begin_pass routines are now more legible                          |
  1219. \endlines
  1220. \medskip
  1221. \noindent{\bf Inform 4}
  1222. \beginlines
  1223. |     Miscellaneous improvements made for Release 4:  (January 20th 1994)   |
  1224. |                                                                           |
  1225. |     Checking on file I/O errors (previously Inform only checked errors    |
  1226. |     which occurred on opening files, so never noticed disc space          |
  1227. |     running out)                                                          |
  1228. |     Lamentable wrong-verify-code bug in R3a (caused by misplaced #endif)  |
  1229. |       fixed, and checksum calculation rewritten in a truly paranoid way   |
  1230. |       for better portability to machines signing char's                   |
  1231. |     "p[syns]=0x80" made to work when char's are signed (-128 to 127); a   |
  1232. |       few redundant initialisations of variables removed                  |
  1233. |     Minor tracing bug in R3a (only) fixed                                 |
  1234. |     Source code reformatted to 79 columns wide for troglodyte monitors    |
  1235. |     New typedef of "zip" (for char / unsigned char) to simplify the       |
  1236. |       the US_POINTERS option                                              |
  1237. |     Heavy reorganisation and division into seven separately-compiled      |
  1238. |       files; variables sorted into extern and static throughout           |
  1239. |     Optimisation on void-context function calls (saving about 300 bytes   |
  1240. |       on a v-3 file of size 128K!)                                        |
  1241. |     Conditional compilation added: #IFDEF, #IFNDEF, #IFNOT, #ENDIF        |
  1242. |     Slow and memory-intensive abbreviations optimiser added: -u switch    |
  1243. |     Text transcription (-r) added                                         |
  1244. |     Property and attribute "alias" introduced (using code suggested by    |
  1245. |       Art Dyer)                                                           |
  1246. |     Properties and attributes formally separated as types, and a warning  |
  1247. |       introduced for the common accident of missing out a comma in a      |
  1248. |       property list                                                       |
  1249. |     Warning put in for over-long property data (in Version 3 files)       |
  1250. |     Property operators ".", ".&", ".#" added                              |
  1251. |     Direct array and property assignments (eg., a->2=3;) added            |
  1252. |     Expression evaluator tracing improved (and "etrace full" added)       |
  1253. |     Expressions generally reformed, and complicated conditions added      |
  1254. |     Braces made optional for simple if clauses                            |
  1255. |     Negative constants now tokenised correctly and allowed                |
  1256. |     Unary minus, ++ and -- added; x+-1 optimised to x-1                   |
  1257. |     "Children" and other in-lined object functions added                  |
  1258. |     Recondite bug in expressions with nested function calls fixed         |
  1259. |     Preprocessor stack fully rewritten in a cleverer way (and it worked   |
  1260. |       first time!)                                                        |
  1261. |     New-style "for", "objectloop" added (they didn't, though); bug in the |
  1262. |       old "do...until" code fixed                                         |
  1263. |     Assignments can now take the form of a comma-separated-list           |
  1264. |     Braces made optional for arbitrary (nested) new-style constructs      |
  1265. |     Fixed miscellaneous bugs and finally rewrote the expression evaluator |
  1266. |       in a tokenised way, losing about 50 calls to strcmp per operator -  |
  1267. |       which made no noticeable difference to run time but I feel better   |
  1268. |     my_malloc and my_calloc given the correct int type - size_t           |
  1269. |     Rare bug with large constant initial values for global variables when |
  1270. |       int is 2-byte, fixed                                                |
  1271. |     Microsoft Visual C/C++ port added (following Toby Nelson)             |
  1272. |     Line tracing format made more legible (at long last)                  |
  1273. |     strcmp no longer used with possibly null strings (which is allowed    |
  1274. |       by ANSI to crash the machine, and does under Unix)                  |
  1275. |                                                                           |
  1276. |   New Version-5 features in Release 4:                                    |
  1277. |                                                                           |
  1278. |     -v3 and -v5 switches, and VERSION directive, added to switch between  |
  1279. |       producing version 3 (Standard) and version 5 (Advanced) games       |
  1280. |     Rewritten statistics routines; changes to some array limits           |
  1281. |     New Advanced opcodes added                                            |
  1282. |     Optimisation of calls in v-5 code to make use of variant opcodes      |
  1283. |     STYLE command for bold-face, underlining, reverse video               |
  1284. |     READ command replaces the old v-3 opcode of the same name, and        |
  1285. |       emulates it (with an optional status-line-routine) in version 5     |
  1286. |     Dictionary routines rewritten for either 6- or 9-character accuracy   |
  1287. |     New constants #dict_par1, -2, -3 and #version_number                  |
  1288. |     SAVE, RESTORE commands replace the old v-3 opcodes, so as to emulate  |
  1289. |       them in v-5                                                         |
  1290. |     #IFV3 and #IFV5 directives added                                      |
  1291. |     Different file extensions/prefixes for version 5 files                |
  1292. |     BOX command added                                                     |
  1293. |                                                                           |
  1294. \endlines
  1295. \medskip
  1296. \noindent{\bf Inform 5}
  1297. \beginlines
  1298. |     Many minor improvements and bug fixes; object classes; inheritance;   |
  1299. |     embedded routines in object definitions; cosmetic improvements        |
  1300. |                                                                           |
  1301. |     June 1st 1994; revised June 12th (5.1), and again June 19th (5.2)     |
  1302. |                                                                           |
  1303. |     A few corrections by Christopher Wichura for the AMIGA option,        |
  1304. |       and Amiga makefile commented above - 25/1                           |
  1305. |     Variable name in grow_branch() changed on advice of David Ingram      |
  1306. |       (it was called opcode, which was also a typedef'd name) - 14/2      |
  1307. |     Check on exceeding MAX_ROUTINES put in (finally!) - 26/2              |
  1308. |     Minor bug to do with property data exceeding 10 bytes fixed - 13/3    |
  1309. |     Assembler slightly rewritten, and the new opcode naming system        |
  1310. |       introduced: a few minor changes, numerous (unuseful) additions - "  |
  1311. |     Versions 4 and 6 (-v4, -v6) added for completeness - 16/3             |
  1312. |     Some minor tidying up of code suggested by Bob Newell, and the        |
  1313. |       USE_TEMPORARY_FILES option finally made to work on PCs - 17/3       |
  1314. |     Bob's Quick C port added - 17/3                                       |
  1315. |     Nasty (but extremely unlikely) bug to do with data area fixed, and    |
  1316. |       memory allocation for this made more flexible - 30/3                |
  1317. |     Really miserable, vile bug in the expression evaluator to do with     |
  1318. |       exactly the case  function(a-1,b)  fixed - 14/4                     |
  1319. |     Errors added for duplicated and misplaced "else"s - rather important  |
  1320. |       since Inform handles hanging elses slightly naively - 15/4          |
  1321. |     Charles Briscoe-Smith's Atari ST port added - 20/4                    |
  1322. |     John Kennedy's OS/2 port added                                        |
  1323. |     Robin Watts' Archimedes throwback code added                          |
  1324. |     Bob Newell's fix for the } brace underflow bug added (about time too) |
  1325. |     Robert Pelak's Macintosh port added - 26/4                            |
  1326. |     Testing on size of quoted strings added (previously Inform could      |
  1327. |       crash if they were more than 2K long) - 27/4                        |
  1328. |     -j (list objects as made) switch added - 27/4                         |
  1329. |     Better reporting of output file opening errors - 27/4                 |
  1330. |     Code generator fixed to produce only safe calls to get_prop_len       |
  1331. |       (calls with non-existent properties crash some interpreters) - 1/5  |
  1332. |     Code for drawing quotation boxes made smaller and better - 1/5        |
  1333. |     Updated the gcc makefile on Dilip's advice - 2/5                      |
  1334. |     Put error check in for misplaced "switches" directive, after such a   |
  1335. |       mistake confused me for ages - 17/5                                 |
  1336. |     Embedded routines in object declarations added - 18/5                 |
  1337. |     ##Action form added - 18/5                                            |
  1338. |     Forward references to constants now understood (a thorny problem      |
  1339. |       because of the long/short storage dilemma) - 18/5                   |
  1340. |     Classes and inheritance, embedded routines, fake actions added        |
  1341. |     Dictionary routines fixed to allow e.g. "y2" and "pipe-dream" - 19/5  |
  1342. |     -n (print property/attribute numbers as allocated) added              |
  1343. |     <Action ...> added; dictionary address constants reformed - 20/5      |
  1344. |     "Nearby" declarations, and object locations defaulted to "nothing"    |
  1345. |     Bare strings understood as print_ret                                  |
  1346. |     <<Action...>> added - 21/5                                            |
  1347. |     Additive properties; "name" made additive; more logical punctuation   |
  1348. |       of object definitions - 26/5                                        |
  1349. |                                                                           |
  1350. |     At this point the code sat in the incoming directory at ftp.gmd.de    |
  1351. |       for a while and was discovered and looted, after which the          |
  1352. |       following improvements were made, producing Inform 5.2:             |
  1353. |                                                                           |
  1354. |     Old "inform.c" file divided about equally into two, making new file   |
  1355. |       "express.c" for the expression evaluator - a long overdue change    |
  1356. |     Minor bug (to do with 32 properties being exceeded in V5) fixed       |
  1357. |     Memory allocation tracing (-m) and freeing improved                   |
  1358. |     The old ALLOCATE_BIG_ARRAYS option is now mandatory                   |
  1359. |     Memory $ commands (on the command line) added: memory consumption     |
  1360. |       reduced: symbols table memory allocation reformed                   |
  1361. |     Two minor, convoluted bugs in line counting for error reports fixed   |
  1362. |     Temporary files not left lying around after errors have occurred      |
  1363. |     Grammar table extensions added                                        |
  1364. |                                                                           |
  1365. |     Revision 5.3 (as appeared in Acorn User magazine's cover disc)        |
  1366. |                                                                           |
  1367. |     Bob Newell's Quick C port revised, and his compatibility improvements |
  1368. |       incorporated (with the result that some ints are now int32s, and    |
  1369. |       array typing is more careful with double indirection: this explains |
  1370. |       why several apparent char *'s come from int32 ** structures)        |
  1371. |     The #inclusions of the header now written in more orthodox C form     |
  1372. |     Bug in reporting the missing-comma-after-] error, noticed by          |
  1373. |       Teo Kwang Liak, fixed                                               |
  1374. |     Header for Amiga version corrected by Christopher Wichura             |
  1375. |                                                                           |
  1376. |     Revision 5.4                                                          |
  1377. |                                                                           |
  1378. |     Archimedes temporary-file prefixing added                             |
  1379. |     Three memory settings moved int -> int32, one cast in symbols fixed,  |
  1380. |       the huge printf divided into two, some %d's made %ld (at suggestion |
  1381. |       of Robert Pelak and Bob Newell)                                     |
  1382. |     Tab characters ignored when quoted strings split across lines         |
  1383. |       (this overlooked case pointed out by Andrew McMurry)                |
  1384. |     tracing_mode now set to 0 (as it should have been before)             |
  1385. |     @@decimal-number syntax added to text translation, so that untypeable |
  1386. |       chars (e.g. accented letters, graphic chars) can be put in text     |
  1387. |     Error added for spurious code after #include line                     |
  1388. |     Opcode names standardised by agreement with Mark Howell; with         |
  1389. |       the very last transuranic opcode added                              |
  1390. |     -n (property number) tracing improved, in the course of...            |
  1391. |     ...fixing an unfortunate bug in additivity of property inheritance    |
  1392. |       which resulted in some copies of Advent crashing                    |
  1393. |     The * syntax for "-g debug on this routine only" added                |
  1394. |     Really foolish bug in tokeniser (first token buffer 1 byte too short  |
  1395. |       with lines beginning with long-named function calls) fixed          |
  1396. |     Extensive support for the Infix debugger added                        |
  1397. |     String literals longer than 509 chars, the ANSI safe limit, divided   |
  1398. |       (at request of Brad Jones)                                          |
  1399. |     Constant form 'word' now allowed in object/class property defns       |
  1400. |     'scope=' token support added, and 'name=' consequently renumbered     |
  1401. |     Bug in input routines which didn't allow '"' fixed                    |
  1402. |     Error messages generally revised and clarified                        |
  1403. |     Bug to do with crashing on a long initial token which isn't a string  |
  1404. |       removed, and error messages protected against excessive length      |
  1405. |                                                                           |
  1406. |     Slight updates in releasing 5.4 (Oct 1994):                           |
  1407. |     Minor variable definition mishap fixed                                |
  1408. |     More ANSI printing of hex addresses which overflow 16-bit ints        |
  1409. |     Bug to do with default property values on 16-bit-int machines fixed   |
  1410. |     The Sibelius Bug fixed (this caused some if statements not to put     |
  1411. |       braces properly around single statements, when the first character  |
  1412. |       of the corresponding source line was a TAB).  (This bug is so known |
  1413. |       because Bob Newell had a sudden flash of inspiration and fixed it   |
  1414. |       on his laptop while killing time in a hotel in Minot, North Dakota, |
  1415. |       where he was staying to record a radio programme of Scandinavian    |
  1416. |       music, including Sibelius' Concerto for Violin and Orchestra in D   |
  1417. |       minor.)                                                             |
  1418. \endlines
  1419. \hrule
  1420. \smallskip
  1421. \end
  1422.