JaM Introduction JaM is a simple stack-based interactive system with graphics utilities. JaM is intended to be a flexible system, giving the user rather direct control over the primitives. It is not intended to be a fault tolerant system for beginning users. This manual is written in the same spirit: the intent is to explain only those aspects of JaM which are not properties of programming languages in general. It gives explainations of all but the most obscure intrinsic functions and a sampling of the most useful external utilities. JaM has three major components: a virtual memory, a set of primitives which perform stack manipulations much like a very powerful, flexible Hewlett-Packard calculator, and a graphics package. All functions in JaM make use of the operand stack. This stack contains objects: integers, reals, booleans, character strings, commands, streams, dictionaries, arrays, and special stack markers. Execution proceedes by getting a token from the input stream, converting it into an object, checking whether or not it is executable and executing it. Non-executable objects are pushed onto the stack. During execution, operands may be retrieved from the stack and results are returned on the stack. This means that all input is given in postfix notation. The graphics package is a group of functions, some written in JaM, others written directly in Cedar, which must be loaded in addition to the basic JaM system. Basic Operation JaM execution proceedes simply by transforming the input stream into a series of objects and processing them sequentially. There are two types of objects: nouns which are automatically placed on the operand stack, and verbs which are immediately executed. The JaM scanner parses the input stream into a series of tokens separated by tabs, carriage returns, spaces and commas. There are three types of tokens: numbers, strings and identifiers. Numbers and strings are converted directly into the corresponding objects and placed on the operand stack. Identifiers are looked up in the current dictionary (explained later) and the resulting object is processed according to whether it is a noun or a verb. Syntactically, a string is a sequence of characters enclosed in parentheses. It may contain anything except unbalanced parentheses (even carriage returns). Any token which is neither a number nor a string is an identifier. The system has a total of three major stacks: the operand stack, the dictionary or context stack, and the execution stack. The dictionary stack is used for keeping track of identifiers during execution. This stack functions as a series of nested contexts, much like the blocks of a block structured language. A dictionary is esentially a table of fixed size for associating identifiers with their values. When the scanner comes across an identifier, it tries to look it up in the dictionary on the top of the dictionary stack. If the lookup is successful, the value found in the dictionary is the next object returned by the scanner. Otherwise, the identifier is looked up in each of the other dictionaries on the dictionary stack in sequence, until a value is found. The execution stack is used for keeping track of nested function calls. It contains the information necessary to implement recursive function invocations. It need not be the direct concern of the user since he cannot refer to it directly. How to Start Type the command jamimager'' to the CommandTool. This will create a JaM typescript for you to interact with the JaM interpreter and a JaMImager viewer for the graphics utilites. JaM gives you a prompt *'' in the typescript viewer. Initially, the operand stack is empty and the dictionary stack contains only one dictionary, the system dictionary. All the JaM intrinsic functions are defined in this dictionary. There are a number of other functions which JaM assumes exist and expects the user to define. These will be explained later when we discuss the relevent details of the system. Commands and Utilities This discussion is organized by function. All commands relating to a particular topic are given together along with an explanation of the particular aspect of the system to which they relate. The exact placement of arguments and results of each function on the stack is given by a diagram. For example: .add _ Z Add two real numbers. The symbols in angle brackets, , , , represent objects on the stack. An arrow (_) separates the condition of the operand stack before the command is executed from the condition after. Only the top-most objects on the stack are shown, the others are assumed to remain unchanged. A comment may describe the command following the symbol Z. A double vertical bar (||) will be used to mean the bottom of the stack. There are various error conditions which can occur when trying to execute a command. These are discussed in a separate section (see Error Handling) because there are special functions relating to this topic. Arithmetic and Bit Manipulation There are three types of numeric objects: reals, integers, and long integers. Integers and reals are 32 bits. Implicit type conversion is performed on numeric objects, but it is also possible to do these conversions explicitly (see Type Conversion). .add _ Z Add two real numbers. .sub _ Z Subtrct two real numbers. .mul _ Z Multiply two real numbers. .div _ Z Real division. .idiv _ Z Integer division. .neg _ <x> Z .cos _ Z (x in degrees) .sin _ Z .atan _ Z (180 < p < 180) .exp _ Z (result always of real type) .log _ Z .sqrt _ <)x> Z .bitor _

Z (The integer p is the bitwise or of 32 bit integers x and y.) .bitxor _

Z (p is the 32 bit exclusive or of x and y.) .bitand _

Z (p is the 32 bit logical and of x and y.) .bitnot _

Z (p is the 32 bit bitwise complement of x.) .bitshift _

Z (The integer x is shifted left by y places. If y > 0 then the y low order bits are set to zero. If y < 0 then the y high order bits are set to zero and y is shifted right. If |y| > 32 then p is set to zero.) Boolean and Relational Commands The following commands deal with boolean objects. They have two possible values represented here by .true'' and .false''. For integer comparisons, implicit type conversion occurs before comparison. If one argument is integer and the other is long integer or real, the integer is converted to that type. Similarly, long integers may be converted to real type. Strings may also be compared using lexicographic ordering. It is not legal to compare integers with strings. .true _ <.true> Z .false _ <.false> Z .eq _ <.true> if x = y, otherwise <.false> Z .gt _ <.true> if x > y numerically or lexicographically, else <.false> Z .lt _ <.true> if x < y numerically or lexicographically, else <.false> Z .not _ <~ x> Z .and _ Z .or _ Z .xor _ Z Stack Manipulation Commands It is often useful to manipulate the operand stack. It is probably not good practice, however, to try to use the stack for all temporary storage. Define local variables instead (see Dictionary Related Commands). Overuse of stack manipulation makes programs hard to read and difficult to debug. With this warning in mind, the following diagrams should make these commands clear. .pop _ Z .copy ... _ ... ... Z (i must be of type integer) .index ... _ Z ( is an integer less than n) .count || ... _ ... Z .roll ... _ ... ... Z (i and j are of type integer. Since we started counting from 1, not 0, by k mod i, we really mean i when i divides k.) .dup _ Z .exch _ Z .clrstk || ... _ || Z clears the stack /clr || ... _ || Z Clears the stack by first counting the stack and then popping each element off the stack. Defined in basic.jam. Stack Marking and Mark Manipulation Commands There is a special object called a stack mark. Its main purpose is for keeping variable numbers of arguments on the stack. The .loop and .rept commands (see below) use this concept internally to allow arbitrary execution inside the loop without losing track of the original condition of the operand stack. .mark _ Z (mark type object put on stack) .cnttomrk ... _ ... Z .clrtomrk ... _ Z Execution Control Commands JaM has much of the execution control machinery found in Algol-like languages. This includes looping'', if-else'' and select'' constructions. There is no go to'' command, however, as this would not easily fit into the stack oriented structure of JaM. The constructions just mentioned do fit in with the stack oriented structure because they can operate on executable objects in the operand stack. For example, the .if command expects a boolean object and any other object on the operand stack. If the boolean equals .true, then the other object is executed, otherwise the .if command pops the object from the stack. .exec _ Z Remove x from the operand stack and execute it as if it just came from the input stream. However x got on the stack, it is the result of some kind of execution. This means that x is effectively evaluated twice as with the eval'' function in Lisp. To reverse this effect, see Type Conversion .if _ Z if b = .true then execute x /if _ Z utility equivalent to: .cvx .if'' .ifelse _ Z if b = .true then execute x else execute y /ifelse _ Z utility equivalent to: .ifelse .cvx .exec'' .rept _ Z execute x i times .loop _ Z execute x forever .for _ Z Execute xk(ki)/jl+1 times, with i on top of the stack the first time and i+j, i+2j, ... on top thereafter. .exit _ Z Exit from current .rept, .loop, .dictforall, or .arrayforall loop. This clears the operand and execution stack down to the marks placed upon entering the current loop. .stop _ Z Clears the execution stack, terminating all unfinished execution. To see how this affects error conditions, refer to Error Handling. Dictionary Related Commands Variables are stored in special objects called dictionaries. Dictionary objects are general symbol tables useful for all kinds off storage. They have a fixed maximum size specified at the time of their creation. As mentioned earlier, there is a stack of dictionaries maintained by the system. The dictionaries in this stack are used like levels of static nesting for variable definitions in an Algol-like language. Dictionaries may be named and retrieved for later use just like other objects in JaM. There are a few things to watch out for when dealing with dictionaries. Some of the system commands and utilities assume that there is space left in the current dictionary (the one at the top of the dictionary stack) to define temporary variables. For this reason, you should be careful about creating small dictionaries. Another problem is what to do when dictionaries get filled up. There are about four choices: push another dictionary onto the dictionary stack with .begin, remove the offending dictionary with .end, delete entries to make room, or clear the dictionary. This problem is particularly severe for users who just start defining variables without ever worrying about dictionaries. The system dictionay has a capacity of 256 entries, most of which are already filled up with system command definitions. When the system dictionary gets filled up, whatever you do, don't clear it! In the following table, refer to keys or variables and refers to the corresponding values. .curdict _ Z pushes the top of the dictionary stack onto the operand stack .dict _ Z creates new dictionary d with capacity of i entries .def _ Z Associate the value v with the key k in the current dictionary. To define a function, make v executable. /def _ Z Equivalent to: .def $help.put''. The $help dictionary contains informative messages about certain functions. It provides a convenient way to document programs. To access this dictionary, see Input/Output Commands. This utility resides in the file basic.jam /xdef _ Z Equivalent to: .cvx /def''. .del _ Z deletes the key k from the dictionary d .load _ Z Retrieve the value associated with the key k in the current dictionary. If v is an executable string,this allows its definition to be printed. (See Type Conversion and Input/Output Commands). .store _ Z Finds a definition of k in the current dictionary and replaces that definition with the value v. If no definition of k exists, this functions as .def .put _ Z associates value v with key k in dictionary d .get _ Z retrieves the value v associated with k in dictionary d .known _ Z <.true> if key k is in dictionary d, <.false> otherwise .where _ Z <.true> if k is found in some dictionary d, <.false> otherwise /dir _ Z Utility from basic.jam which prints all key, value pairs in the dictionary d /kdir _ Z utility which prints all the keys in the dictionary d ?? _ Z This is a utility from basic.jam equivalent to $help /kdir. This prints all functions on which help is available. This usually includes most of the external utility functions whic have been loaded. .clrdict _ Z Clear all entries from dictionary d .dictforall _ Z Put on the stack, and then execute . This is done for every k, v pair in dictionary d .begin _ Z Push d on the top of the dictionary stack. (This makes d the current dictionary) .end .end _ Z Pop current dictionary off the top of the dictionary stack. .sysdict _ Z .length _ Z the current number of entries in the dictionary d .maxlength _ Z the total capacity of dictionary d .attachdict _ Z attaches dictionary d2 to dictionary d1, so that searches within dictionary d1 will find elements of dictionary d2. .detachdict _ Z detaches dictionary d2 from dictionary d1. .attachedforall _ Z Puts dictionary di on the stack and executes x for each dictionary di attached to dictionary d. .detachall _ Z Removes all attached dictionaries to dictionary d. Array Related Commands Array objects are linear arrays of objects indexed starting at zero. They have fixed lengths determined when they are created. There are commands for creating arrays, storing into them, retrieving objects from them, etc. Most commands either expect array objects on the operand stack or return array objects. Arrays can also be made executable. (See Type Conversion) .array _ Z Creates a new array a of i objects. [ _ Z Mark the operand stack for use by the ]'' utility. ] _ Z Put all the objects down to the first stack mark into an array a and return it on the operand stack. [ obj1 obj2 ... obji ]'' forms an i-element array. .subarray _ Z a( is the subarray of a starting at position i and of length j. If i+j > length(a) this causes a range error. .aput _ Z Store v in the i-th position of a, if 0 < i < length(a). .aget _ Z Get v from the i-th position of a, if 0 < i < length(a). .aload _ ... Z (where a is of length i) .astore ... _ Z (a is of length i) .arrayforall _ Z Puts a[i] on the stack and executes x for each object a[i] in a. .abind _ Z Binds names in array a with values in dictionary d. .afind _ Z Searches array a for element x and returns ok as .true if ai = x, otherwise ok is .false and does not appear on the stack. .length _ Z Replaces array a with its length. Input/Output Commands This catagory of commands deals primarily with string and stream objects. Files are represented in JaM as special objects called streams. Commands for reading and writing files accept string type aruments and return string results. There is always an input stream and an output stream. By default, these are both identified with the terminal. When writing strings to a file (stream), keep in mind that carriage returns can be part of strings and no implicit carriage returns are ever written to an output stream. Either the input stream or the output stream can be directed to any file. It is also possible to convert streams to strings and manipulate them that way. (see Type Conversion) .print _ Z Print the string s on the current output stream = _ Z Utility function from the file basic.jam which converts x to a string and prints it, followed by a carriage return. (Uses .cvis -- see Type Conversion). /stk _ Z Print the the contents of the operand stack without destroying it. This uses .print to print the entries. == _ Z Utility function from the file basic.jam. It functions like = for printable strings, but it prints useful information about non-printable objects and even uses a reverse dictionary to decipher commands. /pstk _ Z Prints the operand stack like /stk, except it uses ==. This may not be good for debugging since == does a dictionary look up which could cause an error. ? _ Z Looks up the string s in the $help dictionary and prints the informative message it finds there. The string s should be one of the system commands and utility funcions or something defined using the /def utility (see Dictionary Related Commands). ?? _ Z Print all the keys in the $help dictionary (the commands on which help is available). .stream _ Z This command creates a byte stream with the access characteristics represented by = .false for read or .true for write. Byte streams are the proper type of streams for most text files. The created stream is left on the operand stack. If access is greater than one, it becomes the current output stream. (uses .searchrules) .killstream _ Z Kill the stream t. For output streams this restores the destination of .print to the terminal. .run _ Z The file is read as a byte stream and executed. This is how to read bravo files of JaM function definitions. A * prompt is printed each time the scanner comes to a carriage return. (uses .searchrules) .loadbcd _ Z Load Cedar bcd'' (binary file) and start. This is like .run except it runs a Cedar program. (uses .searchrules) .readitem _ Z <.true> if the stream s is not empty, <.false> otherwise. (An item is one byte for a bytestream or keystream and one word for a wordstream. Bytes are returned as integers, e.g. ascii codes for characters.) .writeitem _ Z The item s (see above) is appended to the stream t. .writebytes _ Z Write bytes in string s to stream t. .searchrules _ Z Search rules for finding files. /cr _ Z Prints a carriage return. /sp _ Z Prints a space. /tab _ Z Prints a tab character. /lp _ Z Prints a left parenthesis. /rp _ Z Prints a right parenthesis. /quote _ Z Prints a quotation mark, ". Type Conversion Commands There are several different types of objects in JaM. String objects have a fixed length once they are created. It is possible to change existing strings (see Scanner and String Manipulation Commands) but their length remains constant. There are two numeric types: integer and real. When the scanner finds a string without any decimal point, it tries to make it an integer, then if it's too big, a long integer. Strings too long to be long integers are converted to reals. Strings containing decimal points naturaly become real type objects. It is not possible to enter numbers in exponential notation; however, one can type 6.7 10 -11 .exp .mul to get 6.7X 1011. Type conversion commands allow the user to determine the types of objects and convert from one object type to another. Type mismatches cause run-time errors. These errors cause special error routines to be executed, which are user definable. .type _ Z Deliver the type of on top of the operand stack. Current types include: .nil, .int (32 bits), .real (32 bits), .atom, .rope, .stream, .cmd, .op, .array, .dict, .mark, .other. .length _ Z Length i of: string (in characters), array (in elements), dictionary (in entries). .cvs _ Z Convert to string equivalent. Applies to numbers, strings, executable strings, and streams. .cvis _ Z This is like .cvs, except for booleans and integers it destroys the string s, reusing the space for the result. If the string s is too short, JaM calls the function .sizechk to handle the error. You must define this yourself. .cvrs _ Z This is exactly like .cvs, except if n is a number it comes out in base r. .cvos _ Z The number n is converted to a string giving its octal representation. .cvirs _ Z This is like .cvrs except numbers come out in base r. .cvi _ Z (converts numbers to type integer) .cvr _ Z (converts numbers to real type) .cvx _ Z Conversts strings or arrays to executable form. They become verbs. This is the way to get an executable string or array on the operand stack as is required by the execution control commands. .cvlit _ Z This converts strings and arrays into literal form (makes them nouns). This undoes the effect of .cvx. .commandname _ Z Returns the name of command x as a string s. The most important type conversion is the conversion to executable. This is necessary every time a function is defined. There are two main executable forms in JaM: strings and arrays. Strings are a lot easier to use, but arrays are a lot faster. When a string is expected, the scanner must extract the objects from the string and each identifier must be looked up in the dictionary stack. When arrays are executed, they are already sequences of objects. In addition, all the identifiers have been looked up ahead of time. Executable strings are simpler to use because it is easier to change the definitions of the functions they call and they are easier to read and print. The use of the functions .cvx, .load, and .exec when defining executable arrays can be very confusing. Recursive functions are also more difficult with arrays. The following examples illustrate the difference in format: (average) (.add 2 .div) .cvx .def (average) [ (.add) .load 2 (.div) .load ] .cvx .def When using executable arrays, it is necessary to .load each function to get its definition (see Dictionary Related Commands). There is a utility called /compile to make this a little easier. Use ? (explained under Input/Output Commands) to find out about this. String Manipulation Commands This section had the JaM scanner commands and they are now obsolete. .length _ Z Replaces the string s with its length in characters. .substring _ Z is the j character substring of s starting at positon i. We must have 0 < i < length(s). .search _ Z <.true> if there is a substring of t matching s, with b and a respectively the parts of t before and after the first occurrence of s, and <.false> if no substring of t matches s. .asearch _ Z <.true> if a starting substring of t matches s -- a is the rest of t, <.false> otherwise. Graphics Commands The graphics commands are not part of the basic JaM system. The basic graphics commands are enabled by loading JamGraphics.bcd. There are useful extensions to these basic graphics commands in various files of utilities. The basic primitives are implemented in Cedar and provide for a display context stack. This is maintained so that transformations and other state information can easily be saved and restored. The .pushdc, .popds and .initdc commands control this stack. State information concerning the graphics device is held in an entity called the display context. Most transformation, clipping, and painting commands alter this state. Most drawing commands both use this state and alter it. One of the more important components of the state is the current definition of the coordinate system. Points in the graphics display are refered to by pairs of real numbers. JaM maintains a transformation matrix for converting these numbers to the coordinates used by the display divice. The translation matrix affects only the placement of new objects on the display. Changing the transformation matrix with a transformation command affects the placement of already existing objects. The state information also contains the position of a special point called the current draw position. The line drawing commands use the draw position to define one endpoint of the line. The draw position is also used to control the placement of text within the display. The file Graphics.jam contains definitions useful to the beginning user. There are also other definitions which are intended more for demonstration purposes. A sampling of functions from Graphics.jam will be included in the following table along with the basic commands from JamGraphics.bcd in terms of which they are defined. The commands whose names start with a period come from JamGraphics.bcd and the other commands come from Graphics.jam. It is possible to look at the definitions of the commands from Graphics.jam using .load == (see Dictionary Related Commands and Input/Output Commands). This allows you to see exactly what these commands do and examine how the more basic graphics commands are used. There are several concepts common to many graphics commands. First of all, parametric cubic splines are used to specify curves. Cubic splines in turn are specified either in terms of the x and y coordinates of points, or by the coefficients of the actual parametric equations. Usually, the coordinates come from the mouse. A cubic spline segment may be specified by four points called its B ezier points. They have a specific mathematical relationship to the spline; informally, the spline passes through the first and fourth point, goes near the other two, and is always contained within the convex quadrilateral defined by the four points. Many commands facilitate the building of paths made up of curves and straight lines. The path does not actually show up on the screen until a command is given to fill in the area enclosed by the path. There are commands which control how the area is filed in. In particular, some commands set up a clipping box which is intersected with the region to be filled in. There is also a painting function which controls the texture (halftone, etc.) of the shaded region. .initdc _ Z Initializes the stack of display contents. .pushdc _ Z Pushes a copy of the current display context onto the display contents stack. .popdc _ Z Replaces the current display context with that on top of the display context stack. .translate _ Z The origin of the new coordinate system is set to the location of (x,y) in the old system. .scale _ Z The coordinate system is expanded by sx in the x direction and sy in the y direction. The entire display is enlarged and lines are thickened. (Lines are normally about one unit wide). .rotate _ see comment Z The coordinate system is rotated clockwise by q degrees. .sixpoint _ Z Transform the coordinate system so that the first three points are mapped into the the last three. .concat _ Z Postmultiply the current transformation matrix by another transformation matrix. .drawto _ Z Draw a line from the current draw position to the point (x,y). This moves the draw position too. .rdrawto _ Z A line is drawn from the current draw position to the sum of that position and the vector (x,y). This moves the draw position as well. .moveto _ Z The current draw position becomes the point (x,y). .getpos _ Z Put the current draw position on the stack. .rmoveto _ Z The vector (x,y) is added to the current draw position. .drawboxarea _ Z A filled box is drawn with the given lower left corner and upper right corner. The draw position is left at the lower left corner. .drawcubic _ Z A cubic is drawn with the given coeficients in its parametric equation. .beziertocubic _ Z Four B ezier control points are converted to the parametric form of a cubic. .cubictobezier _ Z The parametric form of a cubic is converted to its four B ezier control points. .startpath _ Z A path is started for the area generation machinery. Subsequent .enter, etc. commands will add to the path. The interior of the path is determined by a winding number technique. .starteopath _ Z A path is started for the area generation machinery except that even/odd parity is used to determine interior. There is a difference only in paths which cross themselves. .enterpoint _ Z This command which must be preceded by .startpath, enters the point (x,y) in the current path. Successive .enterpoint's create polygonal paths. path _ Z Enter a path defined by i calls to the .touch function. This is equivalent to i repititions of: .touch .enterpoint''. .enterrect _ Z The rectangle defined by the given lower left and upper right corners is entered into the current path. rect rect _ Z The rectangle defined by to calls to the .touch function (see below) is entered into the current path. .entercubic _ Z The given cubic (represented in parametric form) is entered in the current path. .enterspline ... _ Z Creates an open ended curve through the n given points and enters it in the current path. This curve is a natural spline consisting of n cubics. .entercspline ... _ Z This is the same as enterspline, except a closed curve is formed. spline _ Z This command from the file graphics.jam is equivalent to .enterspline except the i points come from i calls to the .touch function (see below). cspline _ Z This command from the file graphics.jam is equivalent to spline except a closed curve is formed. .newboundary _ Z A new boundary is started on the current path. If the new part of the path is inside a previous boundary in the same path, it designates a hole in the center exactly when it winds in the opposite direction. .drawarea _ Z Fill the interior of the boundaries comprising the current path. The current path is then deleted. .drawscreenarea _ Z Fill in the whole screen using the current texture and painting function. .erase .erase _ Z Erase all area inside the current clipping regions. .cliparea _ Z Set the clipping region to the interiors of the boundaries comprising the current path. .clippedcliparea .clippedcliparea _ Z Set the clipping region equal to its intersection with the interiors of the boundaries comprising the current path clip _ Z Start a new polygonal path defined by i calls to the .touch function (described below) and make this the current clipping region (from graphics.jam). cclip _ Z Execute the clip command except use the intersection of the new region with the old clipping region (from graphics.jam). clips _ Z The new clipping region is the union of i rectangles each defined by to calls to .touch (see below). Each rectangle is defined by two .touch's: one at its lower left corner and the other at its upper right. blob _ Z Start a new path and enter a closed spline defined by i .touch's (like cspline) and fill it in using .drawarea (from graphics.jam). cblob _ Z Draw a blob defined by i .touch's as the blob command does except intersect it with the current clipping region (from graphics.jam). poly _ Z Draw a polygonal line defined by i calls to the .touch function (from graphics.jam). .dot _ Z Put down a dot at the coordinates specified. dot _ Z This command from graphics.jam is like .dot except it copies its arguments. area _ Z Fills in polygonal area defined by i calls to .touch, putting a dot at each .touch (from graphics.jam). .texture _ Z The integer n is viewed as a sixteen bit octal number. It defines a 4X4 bit pattern which is tessellated when filling in areas. By default, n=1 is used. This causes areas to be filled in solid black. .paint _ Z This function interacts with the .texture setting to determine how pixels are reset when filling in areas. The integer n is in the range 0...3, but is more convenient to use the identifiers defined in the file graphics.jam. Pixels for which the texture bit is 1 are: set to 1 (black) if n=0 (paint), inverted if n=1 (invert), set to 1 and all other pixels are set to 0 if n=2 (replace), and set to 0 (white) if n=3 (erase). The default is paint. .touch _ Z Returns the current corrdinates of the mouse when the red'' button is pushed. Execution is halted while waiting for the user to push the button. .mouse _ Z Returns the current coordinates of the mouse in the current coordinate system. Execution does not halt. No buttons need be pushed. .redup _ Z This is a user definable function which is executed every time the red'' mouse button is released. When this happens, execution is interrupted and the coordinates of the mouse are put on top of the stack. Then the function executed. All of these default to .pop .pop so they originally function as no-ops. .reddown _ Z similar comment .yellowup _ Z similar comment .yellowdown _ Z similar comment .blueup _ Z similar comment .bluedown _ Z similar comment .setfont _ Z Set the font for the character drawing commands, using n point type. There is no default font, so this command is required before any characters can be drawn. .drawchar _ Z Draw a character at the current draw position and update the draw position to reflect the width of the character. .erasechar _ Z Erase a character at the current draw position and update the draw position by the negative of the width of the character. .drawstring _ Z Draw the string s at the current draw position and update the draw position to reflect the length of the string. .getstringbox _ Z Return the four corners or the bounding box of the given string. .getcharbox _ Z Return the four corners or the bounding box of the given character. text _ Z Put the lines of text from the string s into the screen starting at the point (x,y). Lines are separated by carriage returns and are spaced dy below each other with a left margin at x (from graphics.jam). .displayoff _ Z Blank out the whole screen including the text window. .displayon _ Z Reverse the effect of the previous command. Error Handling Run time error handling routines in JaM are user definable. When such an error is detected, the appropriate function (identifier, whose value is to be executed) is called. The default definitions of these functions are found in the file errordefs.jam. Not having these defaults loaded will cause an infinite string of errors when JaM tries to call the error handling routines. These defaults may be changed, but typically they stop execution and print the stack after displaying a short message regarding the type of error. When writing new error handling routines one must keep in mind that the operand stack and execution stack must remain intact when the error handling routine is called. One version of these routines prints the stack using /stk (see Input/Output Commands) and puts the user in a loop which reads lines from .mystream (the input stream) and executes them. This terminates when an empty line is found. Hitting carriage return causes JaM to attempt to continue execution. At various stages in this routine it is possible to get an additional (nested) error. This could be a little awkward. In this case it is a good idea to use the .stop command. The error handling routines are: .stkundflow _ Z Called when there is an attempt to get something from an empty stack. .undefkey _ Z Called when an identifier cannot be found in a dictionary. .longname _ Z A rare error caused by excessively huge file names. .badname _ Z Called when a string which was supposed to be a file name cannot be found in the directory. .typecheck _ Z Called when some argument of a function is of the wrong type. The offending primitive command is left on the stack along with its other arguments. .dictfull _ Z Called when an attempt is made to define something into a full dictionary. This may mean a system utility has tried to define its own temporary varible into a full user dictionary. .syntaxerr _ Z Called when the scanner finds an unmatched )''. .overflow _ Z Arithmetic overflow. .stkovrflow _ Z Rare, considering JaM's virtual memory. Look for infinite recursion, etc. .rangechk _ Z Something out of range, usually in an array or string manipulation command. .sizechk _ Z Occurs only in the .cvis and .cvirs commands (see Type Conversion). Warning -- this routine has been neglected in some versions of the file errordefs.jam. The Edit Package This package can help reduce some of the inconvenience of continually having to change a bravo file when one is debugging programs in JaM. It is possible to make minor changes in function definitions without having to exit JaM and .run an external file again. This helps prevent the virtual memory from being filled up with garbage and it can save a lot of time. The editor is necessarily rather primitive, however, and it is desirable for safety to have programs saved on external files. For these reasons, this package should not be overused. To use this package, run edit.jam (see .run under Input/Output Commands). The commands are: /edit _ Z Tell the editor to edit the value of the key k (usually a function name). and its value are printed in the format of /p (see below). Subsequent calls to /p and /r refer to k. /p _ Z Print the function definition being edited. The format is: (name)(definition). /r _ Z The first occurance of the string s in the definition being edited is replaced by the string r. If s is not found, a message is printed and the definition is unchanged. To see the effect of your change, use /p. Programming and Use of JaM Because JaM is quite different from other programming languages, it is appropriate to give hints on how to program and put JaM to good use. The JaM input language has very little syntax. This attribute is both good and bad. The lack of syntax is good because a uniform representation is attained. The lack of syntax is bad because the code is hopelessly unreadable. In JaM it is almost true that any line of code can do anything (given the appropriate redefinitions of identifiers). Because of this property of JaM code, it is desirable to do several things when programming. First, document each funtion as it is written (use /def and /xdef under Dictionary Related Commands). Second, use naming conventions for functions that all belong to a given class (for example, intrinsic commands are started with .''). The latter convention will allow a person reading the code to tell what catagory a function is in by its name and may help him avoid accidentally redefining intrinsic functions. Since JaM is a stack orientated machine, the user must mentally keep track of the contents of the stack. It is easier to program JaM if each routine performs only one function and is very short. Normally a JaM routine should be at most one or two lines long. For example, suppose we wish to use the absolute value of a given number. Then, rather than introduce the code in line, it is desirable to write an "abs" function and then use that function e.g. (abs)(.dup 0 .lt (.neg) .cvx .if) .cvx .def Also if complex paramerters are being passed to JaM control statements, it is better to name the parameters rather than have lines and lines full of parentheses. îJaMManual.Tioga Copyright (C) 1984, Xerox Corporation. All rights reserved. This was converted from "JaMmanual.tex" last edited by Leo Guibas, December 28, 1980 2:17 PM Last Edited by Rick Beach, January 9, 1985 4:32:53 pm PST Ê$M– "Cedar" style–÷(look.w) "annotation look" {"CREAM" family 10 bp size bold face } ScreenRule (look.w) "annotatiion look" {"CREAM10" family 10 bp size bold face } PrintRule (command) "for JaM command descriptions" {block 100 pt tabStops 100 pt restIndent}StyleRule˜Jšœ™šœ<™œRœ˜ž—šœ˜Mšœ„œ»˜ÅMšœà˜àMšœ‡˜‡Mšœð˜ð—šœ ˜ Mšœ œ+œ)œ@œœ›œbœ˜Ô—šœ˜Mšœ±˜±IcommandšÐbfœÏiœŸœÐfmœŸœŸœÏmœ˜,Mšœ ŸœŸœŸœŸœ. œ€¡œÒÏbœ=˜ú—šœ˜šœê¢œ˜ûNšžœŸœŸœ œŸœŸœ¡œ˜,NšžœŸœŸœ œŸœŸœ¡œ˜0NšžœŸœŸœ œŸœ¡œ˜0NšžœŸœŸœ œŸœŸœ¡œ˜%NšžœŸœŸœ œŸœŸœ¡œ˜(NšžœŸœ œŸœ¡œ˜NšžœŸœ œŸœ¡œŸœ ˜%NšžœŸœ œŸœ¡œ˜NšžœŸœŸœ œŸœŸœŸœ¡œ Ÿœ¡œ˜0NšžœŸœŸœ œŸÐiuœ¡œ˜2NšžœŸœŸœ œÐdiŸœ¡œ˜NšžœŸœ œ¡Ÿœ¡œ˜NšžœŸœŸœ œŸœ¡œŸœ&ŸœŸœ˜TNšžœŸœŸœ œŸœ¡œŸœŸœŸœ˜BNšžœŸœŸœ œŸœ¡œŸœŸœŸœ˜ANšžœŸœ œŸœ¡œŸœ%Ÿœ˜?Nš"žœŸœŸœ œŸœ¡œŸœŸœ ŸœŸœ%ŸœŸœ%Ÿœ¡œ Ÿœ˜í——M˜šœ˜šœgœ œâ˜ÝNš ž œœ¡œ˜Nš ž œœ¡œ˜NšžœŸœŸœ œœŸœŸœ œ¡œ˜5NšžœŸœŸœ œœŸœŸœ)œ¡œ˜QNšžœŸœŸœ œœŸœŸœ)œ¡œ˜QNšžœŸœ œŸœ¡œ˜NšžœŸœŸœ œŸœ¡œŸœ¡œ˜NšžœŸœŸœ œŸœ¡œŸœ¡œ˜NšžœŸœŸœ œŸœ¡œŸœ¡œ˜——šœ˜šœ¸¢œª˜ýNš žœŸœ œ¡œ˜Nš*žœŸÏdœŸ¥œŸœŸ¤œŸœ œŸ¥œŸ¥œŸ¤œŸ¥œŸ¥œŸ¤œ¡œŸœ˜^NšžœŸ¤œŸ¤¥œŸ¥œŸœ œŸ¤œ¡œŸœŸœ˜GNšžœŸ¥œŸ¥œŸ¤œ œŸ¥œŸ¥œŸ¤œŸœ¡œ˜5Nš.žœŸœŸœŸ¤œ œ¥¤¥¤œŸ¤œŸ¥œ¥¤¥¤œ¡œŸœŸœCŸœŸœŸœŸœ Ÿœ˜ÄNšžœŸœ œŸœŸœ¡œ˜Nš žœŸœ œŸœ¡œ˜NšœŸ¥œŸ¥œŸ¤œ œ¡œ˜4NšžœŸ¥œŸ¥œŸ¤œ œ¡œh œ˜‘——šœ,˜,šœœœ£˜³Nš ž œœ¡œ!˜2Nš!ž œœŸ¥œŸ¥œŸ¤œ œœŸ¥œŸ¥œŸ¤œŸœ¡œ˜BNš œœŸ¥œŸ¥œŸ¤œ œœ¡œ˜.——šœ˜š œüœ§œdœ3œ(˜óNšžœŸœ œ¡œ ŸœZŸœPŸœd¢˜¶NšžœŸœŸœ œ¡œŸœœŸ˜+NšžœŸœŸœ œ¡œœ˜4NšžœŸœŸœŸœ œ¡œŸœœŸœŸ˜ANšžœŸœŸœŸœ œ¡œœ˜ENšžœŸœŸœ œ¡œ ŸœŸœ˜#Nš žœŸœ œ¡œ Ÿœ˜ Nš$žœŸœŸœŸœŸœ œ¡œ Ÿ¡œŸœŸœŸ¡œŸœ(ŸœŸœŸœŸœ˜‚Nšž œ¡œœœ œ œk˜³Nšž œ¡œy¢œ˜’——šœ˜MšœÕ˜ÕMšœžœ˜¢MšœÛœ'œø˜„šœŸœ"Ÿœ%˜bNšž œ¡œ?˜aNšžœŸœ œŸœ¡œŸœŸœ˜FNšžœŸœŸœ œ¡œŸœŸœ8Ÿœ ˜zNšžœŸœŸœŸœ œ¡œŸœŸœ œŸœŸœœ œ—¢œ$ ˜§NšžœŸœŸœŸœ œ¡œ œ˜4NšžœŸœŸœ œ¡œŸœŸ˜8NšžœŸœ œŸœ¡œ-Ÿœ!ŸœJ¢œ¢œ˜ÖNšžœŸœŸœ œ¡œŸœGŸœŸœ˜ªNšžœŸœŸœŸœ œ¡œŸœ ŸœŸ˜ANšžœŸœŸœ œŸœ¡œŸœŸœŸ˜LNšžœŸœŸœ œ¡œœ ŸœŸœœ ˜JNšžœŸœ œ¡œŸœœŸœŸœœ ˜QNš žœŸœ œ¡œ œ5Ÿ˜ZNš žœŸœ œ¡œ6Ÿ˜DNšžœŸœ œ¡œ œ œ˜ÓNš œŸœ œ¡œÏw!œŸ˜5Nšž œŸœŸœ œ¡œŸœŸœ"ŸœŸœŸœŸ˜xNšžœŸœ œ¡œŸœ2Ÿœ˜aNšžœ œ¡œ=˜JNšž œ¡œ˜#NšžœŸœ œŸœ¡œ2Ÿ˜FNš œŸœ œŸœ¡œ¦ œŸ˜:Nšž œŸ¥œŸ¥œ œ¡œŸ¥œŸ¥œ%Ÿ¥œ"Ÿ¥œ˜ŽNšž œŸ¥œŸ¥œ œ¡œŸ¥œŸ¥œ˜ENšžœŸœŸœ œ¡œŸ¤œŸœŸ¤œŸœ˜|Nš ž œŸœ œ¡œ2Ÿœ˜G——šœ˜šœã¢œ˜óNšžœŸœ œŸœ¡œŸœŸœ ˜7Nš ž œœ¡œ*œ ˜CNšž œŸœ¡œAŸœ'Ÿ¥œŸ¥œŸ¤œ Ÿœ˜¥Nšž œŸœŸœŸœ œŸ¡œ¡œŸ¡œŸœŸœŸœŸœ Ÿœ˜ŒNšžœŸœŸœŸœ œ¡œŸœŸœŸœ¡œ Ÿœ˜NNšžœŸœŸœ œŸœ¡œŸœ ŸœŸœ¡œ Ÿœ˜ONšžœŸœ œŸ¥œŸ¥œŸ¤¥œŸœ¡œ ŸœŸœ˜?Nš%žœŸ¥œŸ¥œŸ¤¥œŸœ œŸœŸ¥œŸ¥œŸ¤¥œ¡œŸœŸœ˜_Nšž œŸœŸœ œ¡œŸœŸœŸœŸœŸœŸœ˜YNšžœŸœŸœ œ¡œŸœŸœ˜GNš$žœŸœŸœ œŸœŸœ¡œŸœ Ÿœ ŸœœŸ¤œŸœ ŸœœŸœ˜™NšžœŸœ œŸœ¡œŸœ˜6——šœ˜Mšœdœ‚˜éšœ½¢œ˜ÍNš žœŸœ œ¡œŸœ˜?NšžœŸœ œ¡œ! œŸœAœ¢œ˜£Nšž œ¡œOœ˜tNš œ œ¡œ! œœ˜×Nš ž œ¡œ œœ,œ6˜¥NšžœŸœ œ¡œŸœœKŸœZœ¢œ˜‚Nšž œ¡œœ6˜^NšžœŸ œŸœ œŸœ¡œUŸœœ œÌ œ˜óNšž œŸœ œ¡œŸœ7œ˜tNšžœ  œ¡œVœœK œ˜àNš žœ  œ¡œ<œ' œ˜ŒNšž œŸœ œ¡œœŸœœ¡˜óNšž œŸœŸœ œ¡œ Ÿœ'Ÿœ˜JNšž œŸœŸœ œ¡œŸœ Ÿœ˜