home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / smalltk / doc / manual.txt < prev    next >
Text File  |  1991-10-12  |  31KB  |  862 lines

  1. --  --
  2.  
  3.  
  4.  
  5.  
  6.  Little Smalltalk Users Manual - Version Three
  7.  
  8.  Tim Budd
  9.  
  10.  Department of Computer Science
  11.  Oregon State University
  12.  Corvallis, Oregon
  13.  97331 USA
  14.  
  15.  ABSTRACT
  16.  
  17.  
  18.  Version three of Little Smalltalk was designed specifically to be easy to port to
  19.  new machines and operating systems. This document provides the basic information
  20.  needed to use Version Three of Little Smalltalk, plus information needed by those
  21.  wishing to undertake the job of porting the system to a new operating environment.
  22.  
  23.  
  24.  The first version of Little Smalltalk, although simple, small and fast, was in a number of very
  25. critical ways very Unix specific. Soon after the publication of the book A Little Smalltalk, requests
  26. started flooding in asking if there existed a port to an amazingly large number of different machines,
  27. such as the IBM PC, the Macintosh, the Acorn, the Atari, and even such systems as DEC VMS.
  28. Clearly it was beyond our capabilities to satisfy all these requests, however in an attempt to meet them
  29. partway in the summer of 1988 I designed a second version of Little Smalltalk, which was specifically
  30. designed to be less Unix specific and more amenable to implementation of different systems.
  31.  
  32.  This document describes is divided into two parts. In part one I describe the basic features of the
  33. user interface. This is essential information for anybody wishing to use the system. In part two we
  34. give the basic information needed by anybody wishing to undertake the task of porting version three
  35. Little Smalltalk to a new machine.
  36.  
  37. 1. Getting Started
  38.  
  39.  How you get started depends upon what kind of system you are working on. Currently there are
  40. two styles of interface supported. A line-oriented, tty style stdin interface is available, which runs
  41. under Unix and other systems. There is also a window based system which runs under X-windows and
  42. on the Mac.
  43.  
  44. 1.1. The stdin/stdout interface
  45.  
  46.  Using the stdin/stdout interface, there is a prompt (the ``>'' caracter) typed to indicate the system
  47. is waiting for input. Expressions are read at the keyboard and evaluated following each carrage return.
  48. The result of the expression is then printed.
  49.  
  50.  > 5 + 7
  51.  12
  52.  
  53. Global variables can be created simply by assigning to a name. The value of an assignment statement
  54. is the value of the right hand side.
  55.  
  56.   x <- 3
  57.  3
  58.  
  59. Multiple expressions can appear on the same line separated by periods. Only the last expression is
  60. printed.
  61.  
  62.  
  63.  
  64.  
  65. --  --
  66.  
  67.  - 2 -
  68.  
  69.  
  70.  
  71.   y <- 17. 3 + 4
  72.  7
  73.  
  74.  
  75. 1.2. The windowing interface
  76.  
  77.  The windowing interface is built on top of guido van rossums standard window package, and runs
  78. on top of systems that support standard windows. These include X-11 and the Macintosh.
  79.  
  80.  When you start up the system, there will be a single window titled ``workspace''. You can enter
  81. expressions in the workspace, then select either the menu items ``do it'' or ``print it''. Both will evalu-
  82. ate the expression; the latter, in addition, will print the result.
  83.  
  84.  A number of other memu commands are also available. These permit you to save the current
  85. image, exit the system, or start the browser.
  86.  
  87.  The browser is an interface permiting you to easily view system code. Selecting a class in the
  88. first pane of the browser brings up a second pane in which you can select methods, selecting a method
  89. brings up a third pane in which you can view and edit text. Selecting ``compile'' following the editing
  90. of text will attempt to compile the method. If no errors are reported, the method is then available for
  91. execution.
  92.  
  93. 2. Exploring and Creating
  94.  
  95.  This section describes how to discover information about existing objects and create new objects
  96. using the Little Smalltalk system (version three). In Smalltalk one communicates with objects by pass-
  97. ing messages to them. Even the addition message + is treated as a message passed to the first object 5,
  98. with an argument represented by the second object. Other messages can be used to discover information
  99. about various objects. The most basic fact you can discover about an object is its class. This is given
  100. by the message class, as in the following examples:
  101.  
  102.  > 7 class 
  103.  Integer
  104.  > nil class
  105.  UndefinedObject
  106.  
  107.  
  108.  Occasionally, especially when programming, one would like to ask whether the class of an object
  109. matches some known class. One way to do this would be to use the message = =, which tells whether
  110. two expressions represent the same object:
  111.  
  112.  > ( 7 class = = Integer)
  113.  True
  114.  > nil class = = Object
  115.  False
  116.  
  117.  
  118.  An easier way is to use the message isMemberOf:;
  119.  
  120.  > 7 isMemberOf: Integer
  121.  True
  122.  > nil isMemberOf: Integer
  123.  False
  124.  
  125.  
  126.  Sometimes you want to know if an object is an instance of a particular class or one if its subc-
  127. lasses; in this case the appropriate message is isKindOf:.
  128.  
  129.  > 7 isMemberOf: Number
  130.  False
  131.  > 7 isKindOf: Number
  132.  True
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. --  --
  140.  
  141.  - 3 -
  142.  
  143.  
  144.  All objects will respond to the message display by telling a little about themselves. Many just
  145. give their class and their printable representation:
  146.  
  147.  > 7 display
  148.  (Class Integer) 7
  149.  > nil display
  150.  (Class UndefinedObject) nil
  151.  
  152.  
  153. Others, such as classes, are a little more verbose:
  154.  
  155.  > Integer display
  156.  Class Name: Integer
  157.  SuperClass: Number
  158.  Instance Variables:
  159.  no instance variables
  160.  Subclasses:
  161.  
  162.  
  163. The display shows that the class Integer is a subclass of class Number (that is, class Number is the
  164. superclass of Integer). There are no instance variables for this class, and it currently has no subclasses.
  165. All of this information could be obtained by means of other messages, although the display form is the
  166. easiest. [ Note: at the moment printing subclasses takes a second or two. I'm not sure why.]
  167.  
  168.  > List variables display
  169.  links
  170.  > Integer superClass
  171.  Number
  172.  > Collection subClasses display
  173.  IndexedCollection
  174.  Interval
  175.  List
  176.  
  177. About the only bit of information that is not provided when one passes the message display to a class
  178. is a list of methods the class responds to. There are two reasons for this omission; the first is that this
  179. list can often be quite long, and we don't want to scroll the other information off the screen before the
  180. user has seen it. The second reason is that there are really two different questions the user could be
  181. asking. The first is what methods are actually implemented in a given class. A list containing the set
  182. of methods implemented in a class can be found by passing the message methods to a class. As we
  183. saw with the message subClasses shown above, the command display prints this information out one
  184. method to a line:
  185.  
  186.  > True methods display
  187.  #ifTrue:ifFalse:
  188.  #not
  189.  
  190.  
  191.  A second question that one could ask is what message selectors an instance of a given class will
  192. respond to, whether they are inherited from superclasses or are defined in the given class. This set is
  193. given in response to the message respondsTo. [ NOTE: again form some reason I'm not sure of this
  194. command seems to take a long time to execute ].
  195.  
  196.  
  197.  
  198.  
  199. --  --
  200.  
  201.  - 4 -
  202.  
  203.  
  204.  
  205.  > True respondsTo display
  206.  #class
  207.  #==
  208.  #hash
  209.  #isNil
  210.  #display
  211.  #=
  212.  #basicSize
  213.  #isMemberOf:
  214.  #notNil
  215.  #print
  216.  #basicAt:put:
  217.  #isKindOf:
  218.  #basicAt:
  219.  #printString
  220.  #or:
  221.  #and:
  222.  #ifFalse:ifTrue:
  223.  #ifTrue:
  224.  #ifFalse:
  225.  #not
  226.  #ifTrue:ifFalse:
  227.  
  228.  
  229.  Alternatively, one can ask whether instances of a given class will respond to a specific message
  230. by writing the message selector as a symbol:
  231.  
  232.  > String respondsTo: #print
  233.  True
  234.  > String respondsTo: #+
  235.  False
  236.  
  237.  
  238.  The inverse of this would be to ask what classes contain methods for a given message selector.
  239. Class Symbol defines a method to yield just this information:
  240.  
  241.  > #+ respondsTo display
  242.  Integer
  243.  Number
  244.  Float
  245.  
  246.  
  247.  The method that will be executed in response to a given message selector can be displayed by
  248. means of the message viewMethod:
  249.  
  250.  > Integer viewMethod: #gcd:
  251.  gcd: value
  252.   (value = 0) ifTrue: [ \(ua self ].
  253.   (self negative) ifTrue: [ \(ua self negated gcd: value ].
  254.   (value negative) ifTrue: [ \(ua self gcd: value negated ].
  255.   (value > self) ifTrue: [ \(ua value gcd: self ].
  256.   \(ua value gcd: (self rem: value)
  257.  
  258.  
  259.  Some Smalltalk systems make it very difficult for you to discover the bytecodes that a method
  260. gets translated into. Since the primary goal of Little Smalltalk is to help the student to discover how a
  261. modern very high level language is implemented, it makes sense that the system should help you as
  262. much as possible discover everything about its internal structure. Thus a method, when presented with
  263. the message display, will print out its bytecode representation.
  264.  
  265.  
  266.  
  267.  
  268. --  --
  269.  
  270.  - 5 -
  271.  
  272.  
  273.  
  274.  > Char methodNamed: #isAlphabetic ; display
  275.  Method #isAlphabetic
  276.   isAlphabetic
  277.    \(ua (self isLowercase) or: [ self isUppercase ]
  278.  
  279.  literals
  280.  Array ( #isLowercase #isUppercase )
  281.  bytecodes
  282.  32 2 0
  283.  129 8 1
  284.  144 9 0
  285.  250 15 10
  286.  9 0 9
  287.  32 2 0
  288.  129 8 1
  289.  145 9 1
  290.  242 15 2
  291.  245 15 5
  292.  241 15 1
  293.  
  294.  
  295.  Bytecodes are represented by four bit opcodes and four bit operands, with occasional bytes
  296. representing data (more detail can be found in the book). The three numbers written on each line for
  297. the bytecodes represent the byte value followed by the upper four bits and the lower four bits.
  298.  
  299.  
  300.  If you have written a new class and want to print the class methods on a file you can use the
  301. message fileOut:, after first creating a file to write to. Both classes and individual methods can be filed
  302. out, and several classes and/or methods can be placed in one file. [ NOTE - file out doesn't work yet ].
  303.  
  304.  > f \(<- File new
  305.  > f name: 'foo.st'
  306.  > f open: 'w'
  307.  > Foo fileOut: f
  308.  > Bar fileOut: f
  309.  > Object fileOutMethod: #isFoo to: f
  310.  > f close
  311.  
  312.  
  313. The file ``newfile'' will now have a printable representation of the methods for the class Foo. These
  314. can subsequently be filed back into a different smalltalk image.
  315.  
  316.  > f \(<- File new
  317.  > f name: 'foo.st'
  318.  > f open: 'r'
  319.  > f fileIn
  320.  > 2 isFoo
  321.  False
  322.  
  323.  
  324.  Finally, once the user has added classes and variables and made whatever other changes they
  325. want, the message saveImage, passed to the pseudo variable smalltalk, can be used to save an entire
  326. object image on a file. If the writing of the image is successful, a message will be displayed.
  327.  
  328.  > smalltalk saveImage
  329.  Image name? newimage
  330.  image newimage created
  331.  > 
  332.  
  333.  
  334.  Typing control-D causes the interpreter to exit.
  335.  
  336.  
  337.  
  338.  
  339. --  --
  340.  
  341.  - 6 -
  342.  
  343.  
  344.  When the smalltalk system is restarted, an alternative image, such as the image just created, can
  345. be specified by giving its name on the argument line:
  346.  
  347.  st newimage
  348.  
  349.  
  350.  Further information on Little Smalltalk can be found in the book.
  351.  
  352. 3. New Methods, New Classes
  353.  
  354. 3.1. Stdin/Stdout Interface
  355.  
  356.  New functionality can be added using the message addMethod. When passed to an instance of
  357. Class, this message drops the user into a standard Unix Editor. A body for a new method can then be
  358. entered. When the user exits the editor, the method body is compiled. If it is syntactically correct, it is
  359. added to the methods for the class. If it is incorrect, the user is given the option of re-editing the
  360. method. The user is first prompted for the name of the group to which the method belongs.
  361.  
  362.  > Integer addMethod
  363.   ... drop into editor and enter the following text
  364.  % x
  365.   \(ua ( x + )
  366.   ... exit editor
  367.  compiler error: invalid expression start )
  368.  edit again (yn) ?
  369.   ...
  370.  
  371.  
  372.  In a similar manner, existing methods can be editing by passing their selectors, as symbols to the
  373. message editMethod:.
  374.  
  375.  > Integer editMethod: #gcd:
  376.   ... drop into editor working on the body of gcd:
  377.  
  378.  
  379.  The name of the editor used by these methods is taken from a string pointed to by the global
  380. variable editor. Different editors can be selected merely by redefining this value:
  381.  
  382.  editor \(<- 'emacs'
  383.  
  384.  
  385.  Adding a new subclass is accomplished by sending the message
  386. addSubClass:instanceVariableNames: to the superclass object. The the first argument is a symbol
  387. representing the name, the second is a string containing the names of any instance variables.
  388.  
  389.  > Object addSubClass: #Foo instanceVariableNames: 'x y'
  390.  Object
  391.   Foo display
  392.  Class Name: Foo
  393.  SuperClass: Object
  394.  Instance Variables:
  395.  x 
  396.  y
  397.  
  398. Once defined, addMethod and editMethod: can be used to provide functionality for the new class.
  399.  
  400.  New classes can also be added using the fileIn mechanism.
  401.  
  402. 3.2. The Windowing Interface
  403.  
  404.  Using the windowing interface, new classes are created by selecting the menu item add class in
  405. the first browser window. New Methods are selected by choosing new method in a subsequent window.
  406.  
  407.  
  408.  
  409.  
  410.  
  411. --  --
  412.  
  413.  - 7 -
  414.  
  415.  
  416. 4. Incompatibilities with the Book
  417.  
  418.  It is unfortunately the case that during the transition from version 1 (the version described in the
  419. book) and version 3, certain changes to the user interface were required. I will describe these here.
  420.  
  421.  The first incompatibility comes at the very beginning. In version 1 there were a great number of
  422. command line options. These have all been eliminated in version three. In version three the only com-
  423. mand line option is the file name of an image file.
  424.  
  425.  The interface to the editor has been changed. In version one this was handled by the system, and
  426. not by Smalltalk code. This required a command format that was clearly not a Smalltalk command, so
  427. that they could be distinguished. The convention adopted was to use an APL style system command:
  428.  
  429.  )e filename
  430.  
  431. In version three we have moved these functions into Smalltalk code. Now the problem is just the
  432. reverse, we need a command that is a Smalltalk command. In addition, in version one entire classes
  433. were edited at once, whereas in version three only individual methods are edited. As we have already
  434. noted, the new commands to add or edit methods are as follows:
  435.  
  436.  classname addMethod
  437.  classname editMethod: methodname
  438.  
  439.  
  440.  The only other significant syntactic change is the way primitive methods are invoked. In version
  441. one these were either named or numbered, something like the following:
  442.  
  443.  <primitive 37 a b>
  444.  <IntegerAdd a b>
  445.  
  446. In version three we have simply eliminated the keyword primitive, so primitives now look like:
  447.  
  448.  <37 a b>
  449.  
  450.  
  451.  There are far fewer primitives in version three, and much more of the system is now performed
  452. using Smalltalk code.
  453.  
  454.  In addition to these syntactic changes, there are various small changes in the class structure. I
  455. hope to have a document describing these changes at some point, but as of right now the code itself is
  456. the best description.
  457.  
  458. 5. Implementors Information
  459.  
  460.  The remainder of this document contains information necessary for those wishing to examine or
  461. change the source code for the Little Smalltalk system.
  462.  
  463. 5.1. Finding Your Way Around
  464.  
  465.  In this section we describe the files that constitute version three of the Little Smalltalk system.
  466.  
  467. memory.c
  468.  This is the memory manager, the heart of the Little Smalltalk system. Although it uses a straight-
  469.  forward reference counting scheme, a fair amount of design effort has gone into making it as fast
  470.  as possible. By modifying it's associated description file (memory.h) a number of operations can
  471.  be specified either as macros or as function calls. The function calls generally perform more
  472.  error checking, and should be used during initial development. Using macros, on the other hand,
  473.  can improve performance dramatically. At some future date we hope to make available both
  474.  reference counting and garbage collection versions of the memory manager.
  475.  
  476. names.c
  477.  The only data structures used internally in the Little Smalltalk system are arrays and name tables.
  478.  A name table is simply an instance of class Dictionary in which keys are symbols. Name tables
  479.  are used to implement the dictionary of globally accessible values, symbols, and to implement
  480.  method tables. This module provides support for reading from name tables.
  481.  
  482.  
  483.  
  484.  
  485. --  --
  486.  
  487.  - 8 -
  488.  
  489.  
  490. news.c
  491.  This module contains several small utility routines which create new instances of various standard
  492.  classes.
  493.  
  494. interp.c
  495.  This module implements the actual bytecode interpreter. It is the heart of the system, where most
  496.  execution time is spent.
  497.  
  498. primitive.c
  499.  This module contains the code that is executed to perform primitive operations. Only the stan-
  500.  dard primitives (see the section on primitives) are implemented in this module. File primitives
  501.  and system specific primitives are implemented in another module, such as unixio.c for the Unix
  502.  system and macio.c for the Macintosh version.
  503.  
  504. unixio.c,filein.c
  505.  These two modules contains I/O routines.
  506.  
  507. lex.c,parser.c
  508.  The files lex.c and parser.c are the lexical analyzer and parser, respectively, for compiling the tex-
  509.  tual representation of methods into bytecodes. In the current version parsing is done using a sim-
  510.  ple (although large) recursive descent parser.
  511.  
  512. st.c 
  513.  The file st.c is the front end for the Unix version of Little Smalltalk. On the Macintosh version it
  514.  is replaced by the pair of files macmain.c and macevent.c.
  515.  
  516. initial.c
  517.  This module contains code that reads the module form of Smalltalk code, creating an object
  518.  image. This is not part of the Smalltalk bytecode interpreter, but is used in building the initial
  519.  object image (see next section).
  520.  
  521.  There are description files ( .h files, in standard C convention) which describe many of the
  522. modules described above. In addition, there is a very important file called env.h (for ``environment'').
  523. This file describes the characteristics of the operating system/machine you are running on. The general
  524. structure of this file is that the user provides one definition for their system, for example
  525.  
  526.  # define LIGHTC
  527.  
  528. to indicate using the Lightspeed C compiler on the macintosh, for example. Following this are block of
  529. code which, based on this one definition, define other terms representing the specific attributes of this
  530. system. Where ever possible new code should be surrounded by ifdef directives based on words defined
  531. in this manner. The next section describes this in more detail.
  532.  
  533. 5.2. Defining System Characteristics
  534.  
  535.  There are many ways in which compilers and operating systems differ from each other. A fair
  536. amount of work has been expanded in making sure the software will operate on most machines, which
  537. requires that different code fragments be used on different systems. In large part these are controlled
  538. by a single ``meta-define'' in the file env.h. Setting this one value then causes the expansion of another
  539. code segment, which then defines many more options.
  540.  
  541.  In the event that you are attempting to port the software to a system that has not previously been
  542. defined, you will need to decide which set of options to enable. The next two sections contain informa-
  543. tion you may need in making this determination.
  544.  
  545. Define Options
  546.  
  547.  Many options are specified merely by giving or not giving a DEFINE statement in the file env.h.
  548. The following table presents the meaning for each of these values:
  549.  
  550. ALLOC
  551.  Defined If there is an include file called alloc.h which defines calloc, malloc, and the like.
  552.  
  553.  
  554.  
  555.  
  556.  
  557. --  --
  558.  
  559.  - 9 -
  560.  
  561.  
  562. BINREADWRITE
  563.  Defined if the fopen specification for binary files must include the "b" modifier. This is true on
  564.  many MS-DOS inspired systems.
  565.  
  566. NOENUMS
  567.  Defined if enumerated datatypes are not supported. If defined, these will be replaced by #define
  568.  constants.
  569.  
  570. NOTYPEDEF
  571.  Defined if the typedef construct is not supported. If defined, these will be replaced by #define
  572.  constructs.
  573.  
  574. NOVOID
  575.  Defined if the void keyword is not recognized. If defined, expect lint to complain a lot about
  576.  functions returning values which are sometimes (or always) ignored.
  577.  
  578. SIGNALS
  579.  Used if both the <signals.h> package and the <longjmp.h> package are available, and if the rou-
  580.  tine used to set signals is signal. Incompatible with SSIGNALS.
  581.  
  582. SSIGNALS
  583.  Used if both the <signals.h> package and the <longjmp.h> package are available, and if the rou-
  584.  tine used to set signals is ssignal. Incompatible with SIGNALS.
  585.  
  586. STRING
  587.  Used if the string functions (strcpy, strcat and the like) are found in <string.h>. This switch is
  588.  incompatible with STRINGS.
  589.  
  590. STRINGS
  591.  Used if the string functions (strcpy, strcat and the like) are found in <strings.h>. This switch is
  592.  incompatible with STRING.
  593.  
  594. In addition, several routines can optionally be replaced by macros for greater efficiency. See the file
  595. memory.h for more information.
  596.  
  597. 5.3. Building an Initial Object Image
  598.  
  599.  There are two programs used in the Little Smalltalk system. The first is the actual bytecode
  600. interpreter. The use of this program is described in detail in other documents (see ``Exploring and
  601. Creating''). The Little Smalltalk system requires, to start, a snapshot representation of memory. This
  602. snapshot is called an object image, and the purpose of the second program, the initial object image
  603. maker, is to construct an initial object image. In theory, the this program need only be run once, by the
  604. system administrator, and thereafter all users can access the same standard object image.
  605.  
  606.  The object image format is binary. However, since the format for binary files will undoubtedly
  607. differ from system to system, the methods which will go into the initial image are distributed in textual
  608. form, called module form. Several modules are combined to create an object image. The following
  609. describes the modules distributed on the standard tape, in the order they should be processed, and their
  610. purposes.
  611.  
  612. basic.st
  613.  This module contains the basic classes and methods which should be common to all implementa-
  614.  tions of Little Smalltalk.
  615.  
  616. mag.st
  617.  This module contains methods for those objects having magnitude, which are the basic subclasses
  618.  of Magnitude.
  619.  
  620. collect.st
  621.  This module contains methods for the collection subclasses.
  622.  
  623. file.st 
  624.  This module contains the classes and methods used for file operations. Although all implementa-
  625.  tions should try to support these operations, it may not always be possible on all systems.
  626.  
  627.  
  628.  
  629. --  --
  630.  
  631.  - 10 -
  632.  
  633.  
  634. unix.st
  635.  This module contains unix - specific commands, which may differ from those used under other
  636.  operating systems.
  637.  
  638. mult.st
  639.  This module contains code for the multiprocessing scheduler.
  640.  
  641. init.st 
  642.  This module contains code which is run to initialize the initial object image. These methods
  643.  disappear after they have been executed. (or should; they don't really yet).
  644.  
  645. test.st 
  646.  This file contains various test cases.
  647.  
  648. 5.4. Object Memory
  649.  
  650.  There are several datatypes, not directly supported by C, that are used in the Little Smalltalk sys-
  651. tem. The first of these is the datatype byte. A byte is an eight bit unsigned (hence positive) quantity.
  652. On many systems the appropriate datatype is unsigned char, however on other systems this declaration
  653. is not recognized and other forms may be required. To aid in coverting to and from bytes the macro
  654. byteToInt() is used, which converts a byte value into an integer. In addition, the routines byteAt and
  655. byteAtPut are used to get and put bytes from byte strings.
  656.  
  657.  The other datatype is that used to represent object points. On most machines in which a short is
  658. 16 bits, the datatype short should suffice. Much more information on the memory module can be found
  659. in the file memory.h.
  660.  
  661. 5.5. The Bottom End
  662.  
  663.  The opposite extreme from the front end are those messages that originate within the Smalltalk
  664. bytecode interpreter and must be communicated to the user. We can divide these into two different
  665. classes of communications, editing operations and input/output operations. The following sections will
  666. treat each of these individually.
  667.  
  668. 5.5.1. Editing
  669.  
  670.  We have already mentioned that commands entered by the user are converted into methods, and
  671. passed to the same method compiler as all other methods. Before the user can create a new method,
  672. however, there must be some mechanism for allowing the user to enter the method.
  673.  
  674.  One approach would be to read the method from the standard input, just as commands are read.
  675. While easy to implement, this approach would soon prove unsatisfactory, since for every error the user
  676. would need to reenter the entire method. So some form of update, or editing, must be provided.
  677. Again, the Unix interface and the Macintosh interface solve this problem in radically different ways.
  678.  
  679. 5.5.1.1. Editing Under Unix
  680.  
  681.  A request to edit or add a method is given by sending either the message addMethod or edit-
  682. Method: to a class. The methods for these messages in turn call upon a common routine to perform
  683. the actual editing work.
  684.  
  685.  
  686.  
  687.  
  688. --  --
  689.  
  690.  - 11 -
  691.  
  692.  
  693.  
  694.  addMethod
  695.   self doEdit: ''
  696.  
  697.  editMethod: name
  698.   self doEdit: ( methods at: name
  699.    ifAbsent: [ 'no such method ' print. \(ua nil ] ) text
  700.  
  701.  doEdit: startingText  | text |
  702.   text \(<- startingText.
  703.   [ text \(<- text edit.
  704.    (self addMethodText: text)
  705.    ifTrue: [ false ]
  706.    ifFalse: [ smalltalk inquire: 'edit again (yn) ? ' ]
  707.     ] whileTrue
  708.  
  709.  
  710.  The Unix and MS-DOS versions of the system provide a method edit as part of the functionality
  711. of class String. When edit is passed to a string, an editing environment is established. The user per-
  712. forms editing tasks in that environment, and then exits the editing environment. Under Unix, this func-
  713. tionality is implemented using the file system.
  714.  
  715.  edit | file text |
  716.   file \(<- File new; 
  717.    scratchFile;
  718.    open: 'w';
  719.    print: self;
  720.    close.
  721.   (editor, ' ', file name) unixCommand.
  722.   file open: 'r'.
  723.   text \(<- file asString.
  724.   file close; delete.
  725.   \(ua text
  726.  
  727.  
  728.  A file is created, and the contents of the string written to it. Then a standard Unix editor (given
  729. by the global variabled editor) is invoked to process the file. After the user exits the editor, the con-
  730. tents of the file are read back as a string, the file is closed and deleted, and the string returned. The
  731. command unixCommand is implemented as a primitive, which invokes the system() system call:
  732.  
  733.  unixCommand
  734.   \(ua <150 self>
  735.  
  736.  
  737.  Although the edit message is used by the system only for editing methods, it is general enough
  738. for any editing application and there is no reason why the user cannot use it for other purposes. By the
  739. way, the unixCommand message is also used to implement file deletes.
  740.  
  741.  delete
  742.   ('rm ', name) unixCommand
  743.  
  744.  
  745.  On MS-Dos systems this command should be changed to DEL.
  746.  
  747.  
  748. 5.5.1.2. Editing on the Macintosh
  749.  
  750.  The Macintosh version takes an entirely different approach to the editing of methods. As in the
  751. Unix version, the user requests editing using the commands editMethod: and addNewMethod. And, as
  752. in the Unix version, these in turn invoke a common method.
  753.  
  754.  
  755.  
  756.  
  757. --  --
  758.  
  759.  - 12 -
  760.  
  761.  
  762.  
  763.  addMethod
  764.   self doEdit: ( self printString, ': new method') text: ''
  765.  
  766.  
  767.  editMethod: name
  768.   self doEdit: (self printString, ': ', name)
  769.    text: (methods at: name
  770.      ifAbsent: ['no such method' print. \(ua nil ]) text
  771.  
  772.  
  773.  Here, however, when the user asks to edit a method, a new editing window is created.
  774.  
  775.  doEdit: title text: text | w |
  776.   w \(<- EditWindow new; 
  777.    acceptTask: [ self addMethodText: w getString ] ;
  778.    title: title; create; print: text; showWindow
  779.  
  780.  
  781.  The edit window is initialized with the current text of the method. Thereafter, the user can edit
  782. this using the standard Macintosh cut and paste conventions. The user signifies they are satisfied with
  783. the result by entering the command accept, which causes the acceptTask: block to be executed. This
  784. block gets the text of the window (given by the message getString) and passes it to addMethodText:,
  785. which compiles the method, entering it in the method table if there are no errors.
  786.  
  787. 5.5.2. Input/Output commands
  788.  
  789.  Under the Unix system all input/output operations are performed using the file system and the
  790. global variables stdin, stdout and stderr. Thus the message error:, in class Smalltalk, merely prints a
  791. message to the standard error output and exits.
  792.  
  793.  The macintosh version, although using the same file routines, does not have any notion of stan-
  794. dard input or standard output. Thus error messages (such as from error:) result in alert boxes being
  795. displayed.
  796.  
  797.  There are also error messages that come from inside the Smalltalk interpreter itself. These are of
  798. two types, as follows:
  799.  
  800. 1. System errors. These are all funnelled through the routine sysError(). System errors are caused
  801.  by dramatically wrong conditions, and should generally cause the system to abort after printing
  802.  the message passed as argument to sysError().
  803.  
  804. 2. Compiler errors. As we noted earlier, the method compiler is used to parse expressions typed
  805.  directly at the keyboard, so these message can also arise in that manner. These are all funnelled
  806.  through the routines compilError() and compilWarn(). These should print their arguments (two
  807.  strings), in an appropriate location on the users screen. Execution continues normally after call.
  808.  
  809. 5.6. Primitives
  810.  
  811.  Primitives are the means whereby actions that cannot be described directed in Smalltalk are per-
  812. formed. In version three of the Little Smalltalk system, primitives are divided into three broad
  813. categories.
  814.  
  815. 1. Primitives numbered less than 119 are all standard, and both the meaning and the implementation
  816.  of these should be the same in all implementations of Little Smalltalk. These are largely just
  817.  simple actions, such as mathematical operations.
  818.  
  819. 2. Primitives numbered 120-139 are reserved for file operations. Although the meaning of these
  820.  primitives should remain constant across all implementations, their implementation may differ.
  821.  
  822. 3. Primitives number 150-255 are entirely implementation specific, and thus in porting to a new sys-
  823.  tem the implementor is free to give these any meaning desired. For example under the Unix ver-
  824.  sion there is, at present, only one such primitive, used to perform the system() call. On the other
  825.  hand, the Macintosh version has dozens of primitives used to implement graphics functions,
  826.  
  827.  
  828.  
  829. --  --
  830.  
  831.  - 13 -
  832.  
  833.  
  834.  windowing function, editing and the like.
  835.  
  836. 6. Distribution of New Implementations
  837.  
  838.  The Little Smalltalk system is entirely public domain, and any user is free to redistribute it in any
  839. fashion they wish. As a service to the Smalltalk community, I would appreciate it if new implementors
  840. could send me a listing of changes they make, so that they can be incorporated into one standard distri-
  841. bution. Correspondence should be addressed to:
  842.  
  843.  Tim Budd
  844.  Department of Computer Science
  845.  Oregon State University
  846.  Corvallis, Oregon
  847.  97331 USA
  848.  
  849.  
  850.  Copies of the most recent distribution can also be obtained by writing to this address. In mailing
  851. out distributions, there is a small charge for media and mailing costs.
  852.  
  853. 7. New Features
  854.  
  855.  If you type ``smalltalk echo'' all input will be echoed (tty interface only). Typing smalltalk echo
  856. again undoes this. This is useful for reading from scripts.
  857.  
  858.  
  859.  
  860.  
  861. --  --
  862.