1%% -*- Mode: Texinfo -*-
2\input texinfo
3@c %**start of header (This is for running Texinfo on a region.)
4@setfilename oo2c-v2.info
5@settitle New Features of oo2c v2
6@setchapternewpage off
7@set xref-automatic-section-title
8
9@ignore
10@ifinfo
11@format
12START-INFO-DIR-ENTRY
13* New Features of oo2c v2: (oo2c-v2.info).
14END-INFO-DIR-ENTRY
15@end format
16@end ifinfo
17@end ignore
18
19@finalout
20
21@titlepage
22@title New Features of oo2c v2
23@subtitle $Revision: 1.7 $ covering oo2c-2.1.9
24@author Michael van Acken @email{mva@@users.sf.net}
25@end titlepage
26@page
27
28@contents
29
30@ifinfo
31@node Top, Introduction, (dir), (dir)
32@top New Features of oo2c v2
33
34@end ifinfo
35
36@menu
37* Introduction::
38* Programs::
39* Library Modules::
40* Doc Comments::
41* Built-in Type STRING::
42* Exceptions::
43* Parametric Types::
44* Initialization Functions::
45* Example Module::
46* Document History::
47@end menu
48
49@node Introduction, Programs, Top, Top
50@chapter Introduction
51
52@code{oo2c} v2 is a complete rewrite of the compiler and associated
53tools.  Some highlights are
54
55@itemize @bullet
56@item
57Reduced internal complexity, at the expense of more computational
58overhead.  This goes hand in hand with the ability to add experimental
59language features to the compiler.
60@item
61A simplified internal SSA code representation that eliminates the need
62to keep track the block structure of nested statements.  This reduces
63the complexity of most code transformations.  On the other hand,
64producing the target code becomes more difficult.
65@item
66A broader range of code transformations, including loop rewriting and
67partial redundancy elimination on top of the existing ones (common
68subexpression elimination, loop invariant code motion, constant
69propagation, algebraic transformations, and dead code elimination).
70@item
71A large set of regression tests, increasing the reliability and
72stability of compiler releases.
73@item
74More built-in support for building and installing third party
75packages.
76@item
77Writing @code{FOREIGN} modules to interface with external libraries
78has become easier.  A simple @code{#include} pulls in all the run-time
79type and module meta data a module needs to provide to the run-time
80system.
81@end itemize
82
83The v2 compiler implements most, but not all, of the features of its
84predecessor.  Most programs should compile without changes, although
85some of the more esoteric features and library modules have been
86dropped.  The following sections summarize the omissions and
87additions.  For the most part, the language extensions are
88experimental in nature and should not be considered final.
89
90
91@node Programs, Library Modules, Introduction, Top
92@chapter Programs
93
94The biggest change to the behavior of the programs @code{oo2c},
95@code{oob}, @code{ooef}, and @code{oowhereis} is the introduction of
96so called repositories to structure source code, intermediate, and
97executable files.  A @dfn{repository} is a path to a directory
98@var{r} with @file{@var{r}/src/} holding the source code,
99@file{@var{r}/pkginfo.xml} any repository meta data,
100@file{@var{r}/sym/} the symbol files, and so on.  When looking for a
101particular module, all configured repositories are searched.  Output
102files for a particular module (symbol file, C files, objects files,
103and so on) are placed into the repository that holds the module's
104source code.
105
106The tool @code{oocn} is gone.  Part of its functionality have been
107moved into the compiler @code{oo2c}: converting a module's public
108interface and its documentation strings to HTML and listing all uses
109of a particular object.  Some of the command line options of
110@code{oo2c} have been replaced, and it has a whole new set of commands
111dealing with packages: build, install, uninstall, etc.  Packages allow
112to install a set of library modules, module documentation,
113executables, and auxiliary files from the meta data of a
114@file{pkginfo.xml} file.
115
116Please refer to the man page of @code{oo2c} for the details.
117
118
119@node Library Modules, Doc Comments, Programs, Top
120@chapter Library Modules
121
122With the switch from oo2c v1 to v2 a number of highly specialized and
123rarely used library modules were dropped, while at the same time whole
124families of modules were included that were distributed separately in
125the past.
126
127Replaced by other modules: @code{Filenames} (use @code{OS:Path}
128instead), @code{Integers} (use @code{Object:BigInt}), @code{Kernel}
129and @code{Types} (functionality covered by @code{RT0}), and @code{Rts}
130(see @code{OS:ProcessManagement}).
131
132Removed without replacement: @code{ComplexMath}, @code{JulianDay},
133@code{LComplexMath}, @code{LocNumConv}, @code{LocNumStr},
134@code{LocStrings}, @code{LocText}, @code{LocTextRider},
135@code{Locales}, @code{LongInts}, @code{LowLReal}, @code{LowReal},
136@code{OakFiles}, @code{OakIn}, @code{OakMath}, @code{OakMathL},
137@code{OakStrings}, @code{Reals}, @code{Signal}, and @code{Strings2}.
138
139New modules:
140@table @code
141@item ADT:*
142A set of abstract data types, most importantly @code{ArrayList} and
143@code{Dictionary}.  Also provides a framework for serializing
144arbitrary graphs of objects.
145
146@item IO:*
147IO modules for files and sockets, providing an interface that is
148closer to the I/O capabilities provided by @code{libc}.  Also mappers
149based on the new classes, and an abstraction for the @samp{select()}
150function.
151
152@item OS:*
153Various low-level modules dealing with file systems, file names, and
154processes.
155@end table
156
157Preliminary modules (their interface might change significantly in the
158future, although their general functionality will continue to be part
159of the core distribution):
160@table @code
161@item URI:*
162Data types representing Uniform Resource Identifiers (both
163hierarchical and opaque), plus an URI parser.
164
165@item XML:*
166A call-back based XML 1.0 parser.  Also includes support for XML
167namespaces and validation.
168@end table
169
170
171@node Doc Comments, Built-in Type STRING, Library Modules, Top
172@chapter Doc Comments
173
174Documentation describing the public interface of a module can embedded
175into the source code using @dfn{doc comments}.  Such comments start
176with a special delimiter @samp{(**}, like @samp{(**Some
177explanation. *)}, and refer to the declaration preceding them.
178Within doc comments, a subset of the GNU Texinfo command set can be
179used to mark up the text.
180
181The following sections summarise the commands implemented by the OOC
182parser.  Please refer to the Texinfo manual for a more thorough
183description of the their syntax and intended use.
184
185@menu
186* Inline Commands::
187* Block Commands::
188* Glyphs::
189@end menu
190
191@node Inline Commands, Block Commands, Doc Comments, Doc Comments
192@section Inline Commands
193
194Inline commands take a single argument in curly braces like
195@samp{@@code@{ABS()@}}.
196
197@subsubheading Font and style commands:
198
199@table @code
200@item @@asis
201used with @code{@@table} for entries without added highlighting
202@item @@cite
203name of a book (with no cross reference link available)
204@item @@code
205syntactic tokens
206@item @@command
207command names
208@item @@dfn
209introductory or defining use of a technical term
210@item @@emph
211emphasis; produces @emph{italics} in printout
212@item @@file
213file name
214@item @@kbd
215input to be typed by users
216@item @@samp
217literal example or sequence of characters
218@item @@strong
219stronger emphasis than @code{@@emph}; produces @strong{bold} in printout
220@item @@var
221meta-syntactic variables (for example, formal procedure parameters)
222@end table
223
224@subsubheading References:
225
226@table @code
227@item @@email
228an email address
229@item @@url
230indicate a uniform resource locator (URL)
231@item @@uref
232reference to a uniform resource locator (URL)
233@end table
234
235@subsubheading Referencing Oberon declarations:
236
237@table @code
238@item @@omodule
239module name
240@item @@oconst
241name of a constant
242@item @@ofield
243designator referring to a record field
244@item @@oparam
245parameter name
246@item @@oproc
247designator referring to a procedure (normal or type-bound)
248@item @@otype
249type name
250@item @@ovar
251variable name
252@end table
253
254Designators can contain arbitrary @samp{.member} parts, referring to
255members of modules, procedures, or records.  For example,
256@samp{@@oparam@{MyModule.MyPointer.MyProc.param@}} would refer to the
257parameter @samp{param} of the type-bound procedure @samp{MyProc} from
258module @samp{MyModule} that has @samp{MyPointer} as its receiver type.
259Unless prefixed by a @samp{*}, names and designators must refer to
260existing declarations and the class of the indicated object must match
261the command name.  If the designator is prefixed with a @samp{*}, then
262the designator is not checked by the compiler.  In this case, it must
263begin with a fully qualified module name and use the canonical
264designator for the indicated object.  This variant should only be used
265to refer to an object from another module if the module is not part of
266the @code{IMPORT} list.
267
268@node Block Commands, Glyphs, Inline Commands, Doc Comments
269@section Block Commands
270
271Block commands start with the command @samp{@@cmd} on a line of its
272own, often followed by one or more arguments, and end with @samp{@@end
273cmd}, also on a line of its own.
274
275@subsubheading Lists and tables:
276
277@table @code
278@item @@enumerate
279enumerated lists, using numbers or letters
280@item @@itemize
281itemised lists with and without bullets
282@item @@table
283two-column tables with highlighting
284@item @@item, @@itemx
285used with the above lists and tables for each entry
286@end table
287
288@subsubheading Paragraph formatting:
289
290@table @code
291@item @@example
292example that is not part of the running text (fixed font)
293@item @@noindent
294prevents paragraph indentation
295@end table
296
297@subsubheading Pre- and post-conditions:
298
299@table @code
300@item @@precond
301pre-conditions of a procedure
302@item @@postcond
303post-conditions of a procedure
304@end table
305
306@node Glyphs,  , Block Commands, Doc Comments
307@section Glyphs
308
309@table @code
310@item @@@@
311the character @samp{@@}
312@item @@@{
313the character @samp{@{}
314@item @@@}
315the character @samp{@}}
316@item @@dots@{@}
317ellipsis @samp{@dots{}}
318@item @@bullet@{@}
319a @samp{@bullet{}}, typically used with @code{@@itemize}
320@item @@minus@{@}
321a minus sign, @samp{@minus{}}
322@item @@result@{@}
323result of evaluating an expression, @samp{@result{}}
324@item -@code{-}-
325an em-dash for text `---'
326@end table
327
328
329
330@node Built-in Type STRING, Exceptions, Doc Comments, Top
331@chapter Built-in Type STRING
332
333The predefined identifier @code{STRING} is an alias for the type
334@samp{Object.String}, which implements Unicode strings.  The semantics
335of this type are defined for the most part by the regular module
336@samp{Object}@footnote{The module @samp{Object} does not need to be
337imported to use @code{STRING}.  It is part of the run-time system and
338as such included into every program.}, with two exceptions: the
339compiler converts string constants to instances of @code{STRING}
340automatically, and the operator @samp{+} performs string
341concatenation.
342
343String constants are assignment compatible with variables of type
344@samp{Object.Object}.  Such an assignment automatically converts the
345constant into an instance of @code{STRING}.  That is, a string
346constant can be used instead of a @code{STRING} in an assignment, for
347a procedure argument passed to a value parameter, and as a function
348result.  The string object is created once, as part of the module's
349initialization code, @emph{not} each time its surrounding code is
350evaluated.
351
352The operator @samp{+} is defined for string operands and returns the
353concatenation of its operands.  The result is of type @code{STRING}.
354
355Please note that comparison of string values is done by means of the
356type-bound procedure @samp{String.Equals}.  The definition of the
357operators @samp{=} and @samp{#} has @emph{not} been changed.  That is,
358they test for object identity by comparing the strings' pointer
359values.
360
361@node Exceptions, Parametric Types, Built-in Type STRING, Top
362@chapter Exceptions
363
364There are four user visible parts to exceptions:
365
366@itemize @bullet
367@item
368The module @samp{Exception}, defining the types @samp{Exception},
369@samp{Checked}, and @samp{Unchecked} and implementing the required
370run-time support.
371@item
372A new statement, @code{TRY}, to transfer control to exception handlers
373if a statement sequence raises an exception.
374@item
375A new predefined procedure, @code{RAISE}, to raise an exception.
376@item
377An extended syntax for procedures and procedure types, to declare
378which checked (or unchecked) exception can be raised by a procedure.
379@end itemize
380
381@menu
382* TRY and RAISE ::
383* Checked vs Unchecked Exceptions::
384* Implementation Notes::
385@end menu
386
387@node TRY and RAISE , Checked vs Unchecked Exceptions, Exceptions, Exceptions
388@section @code{TRY} and @code{RAISE}
389
390Exceptions behave pretty much like their counterparts in Python or
391Java.  The statement
392
393@example
394TRY
395  S
396CATCH T1(t1):
397  C1
398CATCH T2(t2):
399  C2
400END;
401@end example
402
403is roughly equivalent to
404
405@enumerate
406@item
407Push exception handler for this @code{TRY} block
408(@samp{Exception.PushContext}).
409
410@item
411Evaluate @var{S}, followed by @samp{Exception.PopContext}.  If there
412are any @code{RETURN} or @code{EXIT} statements within @var{S} that
413would cause control flow to leave the @code{TRY} statement, then they
414also do an implicit @samp{PopContext} as part of the non-local exit.
415
416@item
417If an exception is raised during @var{S}, then do
418
419@example
420Exception.PopContext;
421temp := Exception.Current();
422WITH temp: T1 DO
423  t1 := temp;
424  C1;
425| temp: T2 DO
426  t2 := temp;
427  C2;
428ELSE
429  Exception.ActivateContext;
430END;
431Exception.Clear;
432@end example
433@end enumerate
434
435An exception is raised by calling the predefined procedure @code{RAISE} with
436an instance of @samp{Exception}.  This passes control to the nearest
437@code{CATCH} clause whose type is an extension of the raised exception, if
438such a clause exist.  Otherwise, the exception is written to @var{stderr}
439and the program is aborted.
440
441Within a @code{CATCH}, the optional name given in parenthesis refers to the
442current exception that triggered the @code{CATCH}.  Its type is the one
443from the @code{CATCH} clause.  The variable is read-only.
444
445Within the module body no exceptions can be passed up, because there
446is no caller.  As a consequence, any exception that is not caught
447explicitly is written to @var{stderr} and aborts the program.  For
448checked exceptions, the compiler emits a warning if they are not caught
449in the module body.
450
451@node Checked vs Unchecked Exceptions, Implementation Notes, TRY and RAISE , Exceptions
452@section Checked vs Unchecked Exceptions
453
454There are two kinds of exceptions, checked and unchecked.  The
455compiler enforces a stricter set of restrictions on the usage of
456checked exceptions.  During program run-time, there is no difference
457between the two.
458
459A @dfn{checked} exception @var{E} must either be caught within a
460procedure, or the procedure must declare that it may pass an exception
461of type @var{E} up to its caller.  For example,
462
463@example
464PROCEDURE P() RAISES E;
465@end example
466
467@noindent
468declares that evaluation of @samp{P} may raise an exception of type @var{E},
469or an extension thereof.
470
471An exception is of the ``checked'' variant if it is an extension of
472the class @samp{Exception.Checked}.  The base class
473@samp{Exception.Exception} is also treated as ``checked''.
474
475On the other hand, an @dfn{unchecked} exception can be raised anytime,
476without the need to declare or catch it.  It is possible to add an
477unchecked exception to the @samp{RAISES} list of a procedure
478declaration for documentation purposes.  In this case, it is
479@emph{not} a compile time error if the caller does not catch this
480exception, and does not declare to pass it on.  An exception is
481``unchecked'' if it is an extension of the class
482@samp{Exception.Unchecked}.
483
484Please note that the record type of the exception class,
485@samp{Exception.ExceptionDesc}, is no longer exported.  This means
486that it is not possible to extend it directly.  Applications must use
487either @samp{Exception.CheckedDesc} or @samp{Exception.UncheckedDesc}
488to create specialized exception classes.
489
490
491@node Implementation Notes,  , Checked vs Unchecked Exceptions, Exceptions
492@section Implementation Notes
493
494A @code{TRY} block is mapped to C's @samp{setjmp()} function by
495@code{oo2c}.  The amount of data stored by this function depends on
496the target architecture and may differ by a factor of ten or more.
497For example, on a @samp{ix86} processor, only 72 bytes are stored,
498while on a @samp{PPC} this is 768 bytes.  As a consequence, the work
499done by the program within a @code{TRY} should be large enough to
500amortize the costs of the @code{TRY} for all possible targets.
501
502On some systems@footnote{At the time of writing, this means all
503systems running with GNU @code{libc} and implementing the
504@samp{backtrace()} function.}, raising an exception also stores
505information about the top 20 activation frames on the call stack.
506This means that raising an exception can be moderately expensive as
507well.  Therefore they should only be used to report exceptional
508conditions that are rarely triggered.
509
510
511@node Parametric Types, Initialization Functions, Exceptions, Top
512@chapter Parametric Types
513
514A parametric type can be seen as a type definition with a certain
515degree of freedom.  The freedom comes in form of type parameters
516acting as placeholders for type arguments that are provided when the
517parametric type is used in a particular context.  There are two
518restrictions on type parameters and type arguments: the parameter must
519be based on a record pointer, and the argument must be an extension of
520the parameter's base type.
521
522Take for example the type @samp{ArrayList}.  The element type of the
523list can be any type derived from @samp{Object}, like
524@samp{MyElementType}, which is provided when creating an
525@samp{ArrayList} variable:
526
527@example
528TYPE
529  ArrayList*(E: Object.Object) = POINTER TO ArrayListDesc(E);
530  ArrayListDesc*(E: Object.Object) = RECORD
531    @dots{}
532  END;
533@dots{}
534VAR myList: ArrayList(MyElementType);
535@end example
536
537@noindent
538The compiler statically detects any uses of @samp{myList} or of its
539methods that are incompatible with the declared element type
540@samp{MyElementType}.
541
542The implementation of parametric types extends the syntax in three
543places:
544
545@itemize @bullet
546@item
547A type declaration can have a list of type parameters.
548@item
549Usage of a parametric type can provide a list of type arguments.
550@item
551For a type-bound procedure of a parametric type, the receiver
552declaration must provide the names of local aliases for the type
553parameters of the base type.  These names act as type variables within
554the procedure.
555@end itemize
556@noindent
557(For the details, please refer to the EBNF grammar at the end of this
558section.)
559
560A type declared with a type parameter list like
561@samp{T(t1:B1,t2:B2,@dots{},tn:Bn)} is called a @dfn{parametric type}.
562The formal type @var{Bi} of a type parameter declaration is called
563its type bound.  The type bound must be a record pointer.  A type name
564@var{ti} is visible to the end of the type declaration.
565
566For a qualified type expression of the form
567@samp{T(A1,A2,@dots{},An)},
568
569@enumerate a
570@item
571the type @var{T} must be a parametric type,
572
573@item
574it must have the same number of type arguments as there are type
575parameters, and
576
577@item
578each actual type parameter @var{Ai} is either an extension of the
579corresponding type bound @var{Bi}, or @var{Ai} is a type variable
580whose bound is an extension of @var{Bi}.
581@end enumerate
582
583If @var{T} is a parametric type as defined above, then the type
584expression @samp{T} (without any type arguments) is equivalent to the
585qualified type `@samp{T(B1,B2,@dots{},Bn)}, where each type argument
586equals the corresponding type bound.  @var{Bi} and @samp{Ai} can be
587forward references to types that are defined later.
588
589A type-bound procedure of a parametric type must define a list of type
590names after its receiver type, for example
591
592@example
593PROCEDURE (r: P(T1,T2,@dots{})) TBProc(@dots{});
594@end example
595
596Each name is a type alias for the corresponding type parameter of the
597procedure's @emph{base record} type.  Within a type-bound procedure, a
598variable @samp{v: Ti}, with @var{Ti} declared with a type bound
599@samp{Ti: Bi}, can for the most part be used like it had been declared
600as @samp{v: Bi}.  The exceptions are that it can only be assigned
601values of type @var{Ti} (or @code{NIL}), and that @code{NEW} is not
602applicable to such a variable.
603
604Two qualified types are considered to be the same type, if they have
605the same base type and if their corresponding type arguments are of
606the same type.
607
608@code{NIL} is assignment compatible with a parametric type if it is
609assignment compatible with the type's base type.
610
611@samp{NEW()} is applicable to a variable of parametric type if its
612base type is a pointer.
613
614@noindent
615Syntax:
616@example
617TPSection  = ident @{"," ident@} ":" Qualident.
618TypePars   = "(" [TPSection @{";" TPSection@}] ")".
619TypeDecl   = IdentDef [TypePars] "=" Type ";".
620
621QualType   = Qualident ["(" [QualType @{"," QualType@}] ")"].
622Type       = QualType|ArrayType|RecordType|PointerType|ProcType.
623RecordType = "RECORD" ["("QualType")"] @dots{} "END".
624FormalPars = ["(" [FPSection @{";" FPSection@}] ")" [":" QualType]].
625
626AliasList = "(" [ident @{"," ident@}] ")".
627Receiver = "(" ["VAR"] ident ":" ident  [AliasList] ")".
628@end example
629
630@emph{Note}: Polymorphic procedures, where free type parameters are
631added to a formal parameter list to place an additional restriction on
632the acceptable argument lists of calls, are currently not supported.
633
634
635
636@node Initialization Functions, Example Module, Parametric Types, Top
637@chapter Initialization Functions
638
639The compiler provides a common notation to define an initialization
640procedure for an object, to redefine the initialization procedure
641within an extended type, and to call this procedure automatically when
642creating an object.  For this, a class may provide a type-bound
643procedure @code{INIT}, like
644
645@example
646PROCEDURE (l: List) INIT*(initialSize: LONGINT);
647@end example
648
649Such a procedure has the special property that a call to it always
650binds to the procedure bound to the @emph{static} type of the
651receiver, @emph{not} the dynamic one.  In this it behaves like a call
652to a normal procedure, where the actual code to be evaluated is known
653at compile time.
654
655@code{INIT} must not return a result, and it must be exported.  Its
656formal parameters do not need to match the parameter list inherited
657from the base type, if one exists.  If the base type provides an
658@samp{INIT} procedure, but there is no super call like
659@samp{l.INIT^(@dots{})}, then the compiler produces a warning.
660
661As a shortcut to create an object is to use @samp{NEW()} as a
662function, passing the type of the the new object as its first
663argument.  @samp{v := NEW(T,a1,a2,@dots{})} is equivalent to
664
665@example
666VAR temp: T;
667@dots{}
668NEW(temp);
669temp.INIT(a1,a2,@dots{});
670v := temp;
671@end example
672
673The initialization call is omitted if @samp{T} does not define an
674@samp{INIT} procedure.
675
676@emph{Note}: The definition of @samp{NEW(v)} when called as a
677procedure has not changed.  That is, with this use of @samp{NEW} the
678@samp{INIT()} procedure is @emph{not} called implicitly for the new
679object.
680
681@emph{Possible changes}: Right now, the type argument of @samp{NEW()}
682must be a record pointer.  This might be relaxed to any pointer type
683in the future.
684
685
686
687@node Example Module, Document History, Initialization Functions, Top
688@appendix Example Module
689
690The modules below exercise most of the features described above:
691strings, parametric types, exceptions, and initialization functions.
692
693@smallexample
694MODULE Example:Map;
695(**A simple parametric map type using linked lists. *)
696
697IMPORT Object, E := Exception;
698
699TYPE
700  Key* = Object.Object;
701  Value* = Object.Object;
702
703TYPE
704  Entry(K: Key; V: Value) = POINTER TO EntryDesc(K, V);
705  EntryDesc(K: Key; V: Value) = RECORD
706    key: K;
707    value: V;
708    next: Entry(K, V);
709  END;
710
711TYPE
712  Map*(K: Key; V: Value) = POINTER TO MapDesc(K, V);
713  MapDesc(K: Key; V: Value) = RECORD
714    name: STRING;
715    entries: Entry(K, V);
716  END;
717
718PROCEDURE (map: Map(K,V)) Put*(key: K; value: V);
719VAR
720  entry: Entry(K, V);
721BEGIN
722  NEW(entry);
723  entry.key := key;
724  entry.value := value;
725  entry.next := map.entries;
726  map.entries := entry;
727END Put;
728
729PROCEDURE (map: Map(K, V)) Get*(key: K): V
730RAISES E.Exception;
731VAR
732  entry: Entry(K, V);
733BEGIN
734  entry := map.entries;
735  WHILE entry # NIL DO
736    IF key.Equals(entry.key) THEN
737      RETURN entry.value;
738    END;
739    entry := entry.next;
740  END;
741  RAISE(NEW(E.Exception,
742            "Map '"+map.name +"' undefined for '"+key.ToString()+"'"));
743END Get;
744
745PROCEDURE (map: Map(K, V)) INIT*(name: STRING);
746BEGIN
747  map.name := name;
748  map.entries := NIL;
749END INIT;
750
751END Example:Map.
752@end smallexample
753
754@smallexample
755MODULE TestMap;
756
757IMPORT
758  Example:Map, Object, Object:Boxed, E := Exception, Out;
759
760TYPE
761  Key = STRING;
762  Value = Object.Object;
763
764PROCEDURE ShowEntry(map: Map.Map(Key, Value); key: Key);
765VAR
766  value: Value;
767BEGIN
768  TRY
769    value := map.Get(key);
770    Out.Object("The value for "+key+" is "+value.ToString());
771  CATCH E.Exception(e):
772    Out.Object("Exception: "+e.GetMessage());
773  END;
774  Out.Ln
775END ShowEntry;
776
777PROCEDURE Test;
778VAR
779  map: Map.Map(Key, Value);
780BEGIN
781  map := NEW(Map.Map(Key,Value), "my map");
782
783  map.Put("one",  Boxed.NewLongReal(1.0));
784  map.Put("pi",   Boxed.NewLongReal(3.14159265358979));
785  map.Put("true", Boxed.NewBoolean(TRUE));
786  map.Put("a rose", "a rose");
787
788  ShowEntry(map, "a rose");
789  ShowEntry(map, "one");
790  ShowEntry(map, "two");
791END Test;
792
793BEGIN
794  Test;
795END TestMap.
796@end smallexample
797
798
799@node Document History,  , Example Module, Top
800@appendix Document History
801
802@table @emph
803@item 1.7
804A type variable can be used on the right hand side of a type test or
805type guard.  Introduced with @code{oo2c-2.1.9}.
806
807@item 1.5
808Adds information regarding ``checked'' vs ``unchecked'' exceptions,
809which were introduced with @code{oo2c-2.0.13}.  Covers
810@code{oo2c-2.0.15}.
811
812@item 1.4
813First release.  Covers @code{oo2c-2.0.12}.
814@end table
815
816@bye
817