Advertisement
Guest User

zil.doc

a guest
Sep 9th, 2020
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.43 KB | None | 0 0
  1. The Zork Implementation Language
  2.  
  3. The Zork Implementation Language, ZIL, is designed as a MUDDLEish
  4. language which is readily compiled into Z code, using the ZIL compiler
  5. (ZILCH) and assembler (ZAP). Before discussing the control structures
  6. in the language, the basic Z instruction set will be reviewed.
  7.  
  8. Z Instruction Set
  9.  
  10. Z instructions may have one of the following properties: it may
  11. have side effects only, it may return a value, or it may be a predicate.
  12. A few predicates also return a value. Z instructions act on one of
  13. four classes of operands: integers (+/- 32K), variables, character
  14. strings, and tables. The latter are implemented similarly to MUDDLE
  15. vectors, in that they are random-access structures; however, tables
  16. do not have an intrinsic length property. All Z operands are limited
  17. to those which can be expressed in 16-bits.
  18.  
  19. In the following description, each instruction is followed by
  20. a few characters describing their properties: S(ide effects), V(alue),
  21. P(redicate), F(low of control). Instructions in parentheses are
  22. compiler pseudo-operations, most of which alter the flow of control.
  23. All other instructions are from the Z instruction set directly.
  24. Also following are the number of arguments each operation is allowed,
  25. expressed as a number or a range of numbers. No operation may have
  26. more than 4 arguments. No called routine may have more than 3 arguments.
  27. Finally, a description of the operation is listed.
  28.  
  29. Truth
  30.  
  31. In Z, 'false' is represented by a zero. Anything else is true.
  32. The expression <COND (.A ...)> is equivalent exactly to <NOT <==? .A 0>>.
  33. Note that this may cause some errors; be careful testing the results
  34. of operations which might return an integer or a 'false'.
  35.  
  36. Variables
  37.  
  38. Variables in ZIL are the equivalent of MUDDLE ATOMs. Variables
  39. bound in the argumentlist of a routine will generate local references.
  40. All others will be assumed to be global references. The compiler will
  41. list all external (global) variables used in each routine compiled. At
  42. the end of compilation, errors will be generated for all external
  43. variables which are not defined at top level in the ZIL file.
  44.  
  45. The forms .FOO and ,FOO are used, as in MUDDLE, to represent local
  46. and global variables.
  47.  
  48. Tables
  49.  
  50. User-defined tables are random-access VECTOR-like structures which
  51. may hold any number of legal ZORK objects. They may be accessed by
  52. individual byte or by element (2-byte pair). As any ZORK object can
  53. be represented in two-bytes, the most common type of table is the two-
  54. byte table. Operations are defined which GET and PUT either bytes
  55. or elements from/into tables. Please not that byte/element numbers
  56. start at 0, rather than 1. For many uses, the 0th element may want
  57. to contain the table's length, but this is not required if the length
  58. is known or only known offsets are used. REST and BACK work on these
  59. structures although these REST and BACK BYTES!, not elements. Be
  60. warned. Although the Z interpreter has no bounds checking facility,
  61. ZIL has. In addition, ZIL will insure that, for example, a GET is not
  62. pointing at an 'odd' element of a TABLE (i.e. an element's second byte).
  63.  
  64. Properties
  65.  
  66. Object properties are retrieved/stored with GETP and PUTP. Any
  67. legal object may be a property. Attempts to PUTP a non-existent
  68. property is an error. Also, it is an error to PUTP a two-byte object
  69. into a one-byte slot, or vice versa. Some properties have a length
  70. of greater than two bytes (room exits, for example). These may not
  71. be accessed by GETP, PUTP, but rather must be accessed through GETPT,
  72. which returns a TABLE with the property value. The property may be
  73. examined and altered thereafter with GET(B) and PUT(B). The instruction
  74. PTSIZE, when given a property TABLE, returns the length of the property
  75. value, in bytes.
  76.  
  77. Routines
  78.  
  79. Arbitrary routines may be defined in ZIL using the ROUTINE function.
  80. The argument syntax is very similar to MUDDLE's: required arguments
  81. are included as ATOMs, optional arguments follow an "OPTIONAL" statement
  82. and may include default values (i.e. (C 10)), and auxiliary variables
  83. follow an "AUX" statement, including default values. In all cases the
  84. default value must be a constant! The Z interpreter does not support
  85. the concept of optional/required/auxiliary variables: this concept is
  86. included in the ZIL language to enhance clarity of code. When a routine
  87. calls another routine, the arguments are checked for number and an error
  88. is generated if the wrong number of arguments is passed. Routines take
  89. a maximum of three arguments and always return a value. AGAIN and RETURN
  90. will work at top level within a routine (unlike MUDDLE).
  91.  
  92. MUDDLE-like PROGs and REPEATs exist in ZIL; the binding
  93. specification is ignored by ZIL and all locals should be bound at top
  94. level in the routine. RETURN to a repeat causes the REPEAT to terminate;
  95. the same is true for PROG. As with MUDDLE, REPEAT is a PROG with an
  96. AGAIN at the end. Note that PROG and REPEAT do not return values!
  97.  
  98. Values
  99.  
  100. Only some Z instructions return values explicitly (these are labelled
  101. with a 'V' below. All instructions (including pseudo-ops) may be made
  102. to return a value, if the value is requested (i.e. a SET). All instructions
  103. which are side-effects only return 1 (TRUE). Instructions which are
  104. predicates return 1 (TRUE) or 0 (FALSE). Control-type pseudo-ops return
  105. values as they would in MUDDLE.
  106.  
  107.  
  108. ZIL Instructions
  109.  
  110. Arithmetic Operators
  111.  
  112. + V 2-n Adds integers
  113. - V 2-n Subtracts integers
  114. * V 2-n Multiplies integers
  115. / V 2-n Divides integers
  116. MOD V 2 Argument 1 MOD Argument 2
  117. RANDOM V 1 Returns a random number between
  118. 1 and argument, inclusive
  119.  
  120. BAND V 2 <ANDB argument-1 argument-2>
  121. BOR V 2 <ORB argument-1 argument-2>
  122. BCOM V 1 2's complement
  123. BTST P 2 <N==? <ANDB argument-1 argument-2> 0>
  124.  
  125. 0? P 1 <==? argument 0>
  126. EQUAL? P 2-4 <OR <==? argument-1 argument-2>
  127. <==? argument-1 argument-3>
  128. <==? argument-1 argument-4>>
  129. [==? may be used for the two argument case]
  130. G? P 2 <G? argument-1 argument-2>
  131. (G=?) P 2 <G=? argument-1 argument-2>
  132. L? P 2 <L? argument-1 argument-2>
  133. (L=?) P 2 <L=? argument-1 argument-2>
  134.  
  135. Object Oriented Operations
  136.  
  137. MOVE S 2 Put argument-1 into argument-2
  138. REMOVE S 1 Make argument have no container
  139. FSET S 2 Set flag (argument-2) in argument-1
  140. FCLEAR S 2 Clear flag (argument-2) in argument-1
  141. FSET? P 2 Is flag (argument-2) set in argument-1?
  142. GETP V 2 Return property (argument-2) of argument-1
  143. NEXTP V 2 Return next property of argument-1 starting
  144. at property-2. A value of 0 indicates the
  145. last property. NEXTP given a second argument
  146. of 0 will return the first property of the
  147. object. NEXTP is intended for the rare case
  148. of mapping through a property table
  149. GETPT V 2 Return pointer to property (argument-2) of
  150. argument-1
  151. PUTP S 3 Set property (argument-2) of argument-1
  152. to argument-3
  153. IN? P 2 Is argument-1 contained in argument-2?
  154. LOC? PV 1 Returns location of argument.
  155. Is location not 0? (i.e. is it not contained
  156. in another object?)
  157. FIRST? PV 1 Returns the first content of argument
  158. Is content not 0? (i.e. is there not one
  159. object inside the object?)
  160. NEXT? PV 1 Returns the next sibling of argument
  161. (i.e. the next object also contained
  162. in object's container) Is there a
  163. next sibling?
  164.  
  165. Variable and Stack Operations
  166.  
  167. SET S 2 Set a variable (argument-1) to a value
  168. (argument-2).
  169. (SETG) S 2 Sets a global variable. These are
  170. not distinguished from SETs by Z; however,
  171. this is useful for MUDDLE-like debugging.
  172. VALUE V 1 Returns the VALUE (MUDDLE-style) of its
  173. argument.
  174.  
  175. Looping Operations
  176.  
  177. IGRTR? SP 2 1) <SET variable <+ variable 1>>
  178. 2) <G? variable argument-2>
  179. DLESS? SP 2 1) <SET variable <- variable 1>>
  180. 2) <L? variable argument-2>
  181.  
  182. APPLY FV 1-4 Call a routine (argument-1) with from 0-3
  183. arguments
  184. RETURN F 1 Return argument as the value of a called
  185. ROUTINE, PROG, or REPEAT
  186. RTRUE F 0 Return TRUE as the value of a called routine
  187. RFALSE F 0 Return FALSE as the value of a called routine
  188.  
  189. Table Operations
  190.  
  191. GET V 2 Returns the nth (argument-2) element of
  192. argument-1
  193. PUT V 3 Set the nth (argument-2) element of argument-1
  194. to argument-3
  195. GETB V 2) Like NTH and PUT, but return the nth byte
  196. PUTB V 3) of a table, rather than the nth word of a table
  197. SIZEPT V 1 Returns the size of a property table, which
  198. was returned by GETPT.
  199.  
  200. REST V 2 Rest the table (argument-1) by argument-2
  201. BYTES! To rest a table by one element, the
  202. second argument should be 2.
  203. BACK V 2 Inverse of REST.
  204.  
  205. I/O Operations
  206.  
  207. PRINTC S 1 Prints an integer as its ASCII equivalent
  208. PRINTD S 1 Prints the short description of an object
  209. PRINTI S 1 Prints a string
  210. PRINTN S 1 Prints an integer
  211. PRINTR SF 1 Prints a string, then RTRUE.
  212. PRINT S 1 Print a non-immediate string (i.e. the
  213. result of a table lookup)
  214. READ S 2 Dont ask
  215.  
  216. Compiler Pseudo Operations
  217.  
  218. AND 1-n Like MUDDLE's AND
  219. OR 1-n Like MUDDLE's OR
  220. COND 1-n Like MUDDLE's COND
  221. NOT 1 Like MUDDLE's NOT
  222. PROG 2-n Like MUDDLE's PROG, but the AUX list is
  223. ignored
  224. REPEAT 2-n Like MUDDLE's REPEAT, but the AUX list is
  225. ignored
  226. ROUTINE 3-n Like MUDDLE's DEFINE; understands
  227. required arguments, optional arguments,
  228. and auxiliary variables. No routine
  229. can have more than three arguments
  230. maximum. Also a named activation cannot
  231. be used.
  232.  
  233. Pseudo Variables (for ease of use to MUDDLErs)
  234.  
  235. T Truth (1)
  236. <> False (0)
  237.  
  238. Variable Naming Conventions
  239.  
  240. ZIL makes use of 'lexical blocking' in some variable names
  241. by prefixing <prefix> <question mark> to the name of the variable.
  242. These prefixes are used to prevent naming conflicts of common words.
  243. The global values of the prefixed names are used. The prefixes are:
  244.  
  245. V?<name> The verb <name>
  246.  
  247. P?<name> The property <name>
  248.  
  249. Thus, to determine if the current verb (PRSA) is WALK,
  250. one might say <COND (<==? ,PRSA ,V?WALK> ....)>.
  251.  
  252. [The following are parser-internal]
  253.  
  254. PR?<name> The preposition <name>
  255.  
  256. A?<name> The adjective <name>
  257.  
  258. B?<name> The buzz-word <name>
  259.  
  260. ACT?<name> The action <name>
  261.  
  262. W?<name> The pointer to the vocabulary entry for <name>
  263.  
  264. Structure-creating Pseudo-Ops
  265.  
  266. TABLE
  267.  
  268. TABLE creates a user-defined table. The syntax is
  269. <TABLE <element> [<element> ...]>.
  270.  
  271. ITABLE
  272.  
  273. ITABLE creates a user-defined table of a specified length in
  274. bytes. Optionally, it makes the length the 0th element of the table.
  275.  
  276. <ITABLE <length in bytes> <specifier> <filler>>
  277.  
  278. Specifier may be 1) NONE - no length is put in the table 2) BYTE -
  279. a one-byte entry is added to the table with the length, or 3) WORD -
  280. a one-word (two-byte) entry is added to the table with the length.
  281. Filler may be any legal object, defaulting to FALSE (0).
  282.  
  283. SYNTAX
  284.  
  285. SYNTAX creates syntaxes for the parser. The syntax is:
  286.  
  287. <SYNTAX [<optional preposition>
  288. OBJECT
  289. <specifier>
  290. <optional preposition>
  291. OBJECT
  292. <specifier>]
  293. =
  294. <name of routine>
  295. [<name of preact routine>]>
  296.  
  297. where the first and second noun clause specifiers are optional
  298. as is the preact routine. The bare minimum expression would be, for
  299. example, <SYNTAX LOOK = LOOK>. The prepositions should be ATOMs.
  300. Specifiers are of the following forms:
  301.  
  302. 1. (FIND <flag name>) - parens included, the 'gwim' flag name
  303. where flag name is an ATOM
  304. or
  305.  
  306. 2. (<where to look> [<where to look> ...]) - parens included, the
  307. places to look for the object, if there
  308. is ambiguity. The legal places to look
  309. are:
  310. HELD - top-level on WINNER
  311. CARRIED - second-level on WINNER
  312. ON-GROUND - top-level in HERE
  313. IN-ROOM - second-level in HERE
  314.  
  315. BUZZ
  316.  
  317. BUZZ creates buzz-words. Syntax is <BUZZ <buzz word> [<buzz word> ...]>.
  318.  
  319. SYNONYM
  320.  
  321. SYNONYM is used to equate a number of vocabulary words with another.
  322. The syntax is <SYNONYM <existing word> <new word> [<new word> ...]>.
  323.  
  324. OBJECT
  325.  
  326. OBJECT is used to create Zork objects/rooms. The syntax is as follows:
  327.  
  328. <OBJECT <name> [(<property> <value> [<value> ...]) ...]>
  329.  
  330. where <name> and <property> are ATOMs. Property may be a user-defined
  331. property name or a special property known to ZIL. The special properties
  332. and their legal values are:
  333.  
  334. Property Value
  335.  
  336. IN Name of an object, its container
  337. FLAGS Any number of ATOMs, flag names
  338. ACTION ATOM, name of routine associated with object
  339. SYNONYM Any number of ATOMs, names for the object
  340. ADJECTIVE Any number of ATOMs, adjectives for the object
  341. PER ATOM, name of an exit routine. The following
  342. should be used for exit routines.
  343. (<direction> PER <routine name>).
  344. TO Used for all unconditional and conditional exits.
  345. The following forms are recognized:
  346. (<direction> TO <room name>)
  347. - unconditional exit
  348. (<direction> TO <room name> IF <flag name>)
  349. - conditional exit
  350. (<direction> TO <room name> IF <flag name> ELSE <str>)
  351. - conditional exit with string to print if fails
  352. (<direction> TO <room name> IF <object name> IS OPEN)
  353. - door exit
  354. If the value of a direction name is a STRING, this
  355. is an NEXIT.
  356.  
  357. The properties SYNONYM and ADJECTIVE must be defined for all referencable
  358. objects, even if empty.
  359.  
  360. PROPDEF
  361.  
  362. PROPDEF is used to define defaults for user-defined properties.
  363. The syntax is <PROPDEF <property name> <default value>>. The default
  364. for a user-defined property not given a PROPDEF specification is FALSE
  365. (0).
  366.  
  367. -- READ FURTHER AT YOUR OWN RISK --
  368.  
  369. **NOTE**
  370. The following stack and variable operations are not useful in writing
  371. ZIL code and are included only for completeness. They should be used
  372. only in extreme circumstances. Ask me first...
  373.  
  374.  
  375. INC S 1 Increment a variable (argument)
  376. DEC S 1 Decrement a variable (argument)
  377. [The previous two operations should be
  378. done as <SET variable <+ variable 1>>
  379. as it is more MDLishly readable; the two
  380. compile equivalently.]
  381. PUSH S 1 Push argument onto the stack
  382. POP S 1 Pop the top of the stack into a variable
  383. (argument)
  384. FSTACK S 0 Flush the top of the stack
  385. RSTACK S 0 Return the top of the stack
  386.  
  387. Flow of Control Operations
  388.  
  389. JUMP F 1 Jump to a label within the current routine
  390. (can only be used with TAG)
  391. RSTACK F 0 Return top of stack as the value of a called
  392. routine
  393. (TAG) - 1 Generate a label for JUMP (foo!)
  394.  
  395. **END OF NOTE**
  396.  
  397.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement