home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mod201j.zip / modula2.exe / os2api / som.def < prev    next >
Text File  |  1995-04-01  |  78KB  |  2,211 lines

  1. DEFINITION MODULE SOM;
  2.  
  3. (***************************************************************************
  4.   OS/2 2.x/3.0 System Object Model.
  5.                01.04.95 01:28 : exception types corrected
  6.  
  7.   Copyright (c) 1994, 1995 by Juergen Neuhoff
  8. ****************************************************************************)
  9.  
  10. (*$XL+       Modula-2 language extensions: '_' allowed for symbol names *)
  11. (*$CDECL+    C-style procedures                                         *)
  12. (*$A         default alignment for record fields                        *)
  13.  
  14.  
  15. IMPORT SYSTEM;
  16.  
  17. TYPE
  18.   BYTE                = SYSTEM.BYTE;
  19.   WORD                = SYSTEM.WORD;
  20.   DWORD               = SYSTEM.DWORD;
  21.   LONGWORD            = SYSTEM.LONGWORD; (* same as DWORD *)
  22.   ADDRESS             = SYSTEM.ADDRESS;
  23.  
  24. TYPE (* basic type names *)
  25.   integer1            = SHORTINT;
  26.   integer2            = INTEGER;
  27.   uinteger2           = CARDINAL;
  28.   integer4            = LONGINT;
  29.   uinteger4           = LONGCARD;
  30.   float4              = SHORTREAL;
  31.   float8              = LONGREAL;
  32.   PSTRING             = POINTER TO ARRAY [0..MAX(LONGCARD)-1] OF CHAR;
  33.   zString             = PSTRING;
  34.   fString             = PSTRING;
  35.   somId               = POINTER TO PSTRING;
  36.   somToken            = ADDRESS;     (* Uninterpretted value   *)
  37.   somMToken           = ADDRESS;     (* Method token           *)
  38.   somDToken           = ADDRESS;     (* Data token             *)
  39.   somClassInfo        = somToken;
  40.   SOMTokBuf           = somToken;
  41.   somMOffset          = integer4;
  42.   somDOffset          = integer4;
  43.   somMData            = integer4;
  44.   size_t              = LONGCARD;
  45.   uchar_t             = SHORTCARD;
  46.   long                = LONGINT;
  47.   PSOMObject          = POINTER TO SOMObject;
  48.   PSOMClass           = POINTER TO SOMClass;
  49.   PSOMClassMgr        = POINTER TO SOMClassMgr;
  50.   PSOMAny             = PSOMObject;
  51.  
  52.  
  53. TYPE (* -- For building lists of class objects *)
  54.   somClassList        = RECORD
  55.     cls                 : PSOMClass;
  56.     next                : POINTER TO somClassList;
  57.                         END;
  58.   somClasses          = POINTER TO somClassList;
  59.  
  60. TYPE
  61.   somMethodProc       = SYSTEM.LONGWORD;  (* pointer to method procedure *)
  62.  
  63. TYPE
  64.   somTP_somClassInitFunc = PROCEDURE( PSOMClass );
  65.  
  66. TYPE (* Method Table *)
  67.   somMethodTabStruct  = RECORD
  68.     classObject         : PSOMClass;
  69.     entries             : ARRAY [0..0] OF somMethodProc;
  70.                         END;
  71.   somMethodTab        = somMethodTabStruct;
  72.  
  73. TYPE (* -- For building lists of method tables *)
  74.   somMethodTabList    = RECORD
  75.     mtab                : POINTER TO somMethodTab;
  76.     next                : POINTER TO somMethodTabList;
  77.                         END;
  78.   somMethodTabs       = POINTER TO somMethodTabList;
  79.  
  80. TYPE (* -- Generic ClassData structure *)
  81.   somClassDataStructure     = RECORD
  82.     classObject               : PSOMClass;
  83.     tokens                    : ARRAY [0..0] OF somToken;
  84.                               END;
  85.   somClassDataStructurePtr  = POINTER TO somClassDataStructure;
  86.  
  87. TYPE (* -- Generic Auxiliary Class Data Structure *)
  88.   somCClassDataStructure    = RECORD
  89.     parentMtab                : somMethodTabs;
  90.     instanceDataToken         : somDToken;
  91.     ptrs                      : ARRAY [0..0] OF somMethodProc;
  92.                               END;
  93.   somCClassDataStructurePtr = POINTER TO somCClassDataStructure;
  94.  
  95. CONST
  96.   SOM_DynamicMethod      = 1;
  97.   SOM_StaticMethod       = 0;
  98.  
  99. TYPE (* Old style name support *)
  100.   somMethodPtr           = somMethodProc;
  101.  
  102. TYPE (* OS/2-style type synonyms *)
  103.   FLOAT4                 = float4;
  104.   FLOAT8                 = float8;
  105.   SOMID                  = somId;
  106.   SOMTOKEN               = somToken;
  107.   SOMMTOKEN              = somMToken;
  108.   SOMDTOKEN              = somDToken;
  109.   SOMMETHODTAB           = somMethodTab;
  110.   SOMMETHODPTR           = somMethodPtr;
  111.   SOMCLASSDATASTRUCT     = somClassDataStructure;
  112.   SOMCLASSDATA           = somClassDataStructure;
  113.   SOMMETHODPROC          = somMethodProc;
  114.   SOMMETHOD              = somMethodProc;
  115.   INT                    = LONGINT;
  116.   INTEGER4               = LONGINT;
  117.   INTEGER2               = INTEGER;
  118.   INTEGER1               = SHORTINT;
  119.  
  120. TYPE (* pointer type names *)
  121.   PsomClassList          = POINTER TO somClassList;
  122.   PsomMethodTab          = POINTER TO somMethodTab;
  123.   PsomMethodTabList      = POINTER TO somMethodTabList;
  124.   PsomClassDataStructure = POINTER TO somClassDataStructure;
  125.   PPSTRING               = POINTER TO PSTRING;
  126.  
  127. CONST (* error severity codes, which are added to the base error number *)
  128.   SOM_Ok              = 0H;
  129.   SOM_Warn            = 1H;
  130.   SOM_Ignore          = 2H;     (* don't do anything *)
  131.   SOM_Fatal           = 9H;     (* terminate the program *)
  132.   SOM_Template        = 5H;     (* used to identify msg templates *)
  133.  
  134.  
  135. CONST (* error base *)
  136.   SOM_EB              = 20000;
  137.  
  138. CONST (* error numbers *)
  139.  
  140.   (*
  141.    * The somDescendedFrom method was passed a NULL class argument.
  142.    *)
  143.   SOMERROR_CCNullClass    = SOM_EB + SOM_Warn + 1*10;
  144.  
  145.   (*
  146.    * The internal buffer used in somPrintf overflowed.
  147.    *)
  148.   SOMERROR_SompntOverflow = SOM_EB + SOM_Fatal + 2*10;
  149.  
  150.   (*
  151.    * somFindMethodOk failed to find the indicated method.
  152.    *)
  153.   SOMERROR_MethodNotFound = SOM_EB + SOM_Fatal + 3*10;
  154.  
  155.   (*
  156.    * Method table overflow in somAddStaticMethod
  157.    *)
  158.   SOMERROR_StaticMethodTableOverflow = SOM_EB + SOM_Fatal + 4*10;
  159.  
  160.   (*
  161.    * The somDefaultMethod was called, probably means a defined method
  162.    *  was not added before it was invoked
  163.    *)
  164.   SOMERROR_DefaultMethod  = SOM_EB + SOM_Fatal + 5*10;
  165.  
  166.   (*
  167.    *   The specified method was not defined on the target object.
  168.    *)
  169.   SOMERROR_MissingMethod  = SOM_EB + SOM_Fatal + 6*10;
  170.  
  171.   (*
  172.    *    Attempt to load, create or use a version of a class object
  173.    *    implementation that is incompatible with the using program.
  174.    *)
  175.   SOMERROR_BadVersion     = SOM_EB + SOM_Fatal + 7*10;
  176.  
  177.   (*
  178.    *   somCheckId was given a NULL id to check.
  179.    *)
  180.   SOMERROR_NullId         = SOM_EB + SOM_Fatal + 8*10;
  181.  
  182.   (*
  183.    *   Memory exhausted
  184.    *)
  185.   SOMERROR_OutOfMemory    = SOM_EB + SOM_Fatal + 9*10;
  186.  
  187.   (*
  188.    *   somObjectTest found problems with the object it was testing
  189.    *)
  190.   SOMERROR_TestObjectFailure         = SOM_EB + SOM_Fatal + 10*10;
  191.  
  192.   (*
  193.    *   somTest detected a failure, only generated by test code
  194.    *)
  195.   SOMERROR_FailedTest     = SOM_EB + SOM_Fatal + 11*10;
  196.  
  197.   (*
  198.    *   somFindClass could not find the requested class.
  199.    *)
  200.   SOMERROR_ClassNotFound  = SOM_EB + SOM_Warn + 12*10;
  201.  
  202.   (*
  203.    *   Old style method name used, change to appropriate name
  204.    *)
  205.   SOMERROR_OldMethod      = SOM_EB + SOM_Warn + 13*10;
  206.  
  207.   (*
  208.    *   Calling somEnvironmentNew did not create the root class
  209.    *)
  210.   SOMERROR_CouldNotStartup = SOM_EB + SOM_Fatal + 14*10;
  211.  
  212.   (*
  213.    *    somUnloadClassFile argument was not a registered class
  214.    *)
  215.   SOMERROR_NotRegistered  = SOM_EB + SOM_Fatal + 15*10;
  216.  
  217.   (*
  218.    *   Call to somOverrideSMethod for a method that was not defined in a
  219.    *   parent class
  220.    *)
  221.   SOMERROR_BadOverride    = SOM_EB + SOM_Fatal + 16*10;
  222.  
  223.   (*
  224.    *   The method raising the error message is not implemented yet
  225.    *)
  226.   SOMERROR_NotImplementedYet = SOM_EB + SOM_Fatal + 17*10;
  227.  
  228.   (*
  229.    *   The method raising the error message should have been overridden
  230.    *)
  231.   SOMERROR_MustOverride   = SOM_EB + SOM_Fatal + 18*10;
  232.  
  233.   (*
  234.    *   An argument to a core SOM method failed a validity test
  235.    *)
  236.   SOMERROR_BadArgument    = SOM_EB + SOM_Fatal + 19*10;
  237.  
  238.   (*
  239.    *   During class object create, the parent class object could not be found.
  240.    *)
  241.   SOMERROR_NoParentClass  = SOM_EB + SOM_Fatal + 21*10;
  242.  
  243.   (*
  244.    *   During class object create, the metaclass object could not be found.
  245.    *)
  246.   SOMERROR_NoMetaClass    = SOM_EB + SOM_Fatal + 22*10;
  247.  
  248.   (*
  249.    *   An attempt to index an out-of-range buffer entry
  250.    *)
  251.   SOMERROR_Indexrange     = SOM_EB + SOM_Fatal + 23*10;
  252.  
  253.   (*
  254.    *   An attempt to delete a character from an empty buffer
  255.    *)
  256.   SOMERROR_Underflow      = SOM_EB + SOM_Fatal + 24*10;
  257.  
  258.   (*
  259.    *   Internal logic error during buffer manipulation
  260.    *)
  261.   SOMERROR_Logic          = SOM_EB + SOM_Fatal + 25*10;
  262.  
  263.   (*
  264.    *
  265.    *)
  266.   SOMERROR_6              = SOM_EB + SOM_Fatal + 26*10;
  267.  
  268.   (*
  269.    *
  270.    *)
  271.   SOMERROR_7              = SOM_EB + SOM_Fatal + 27*10;
  272.  
  273.  
  274. VAR (* control variables for printing debug messages *)
  275.   SOM_TraceLevel         : INT;      (* 0-none, 1-user, 2-core&user *)
  276.   SOM_WarnLevel          : INT;      (* 0-none, 1-all *)
  277.   SOM_AssertLevel        : INT;      (* 0-none, 1-user, 2-core&user *)
  278.  
  279.  
  280.  
  281. VAR (* SOM Version Numbers *)
  282.   SOM_MajorVersion       : LONGINT;
  283.   SOM_MinorVersion       : LONGINT;
  284.  
  285. TYPE (* Procedure types for replacable SOM functions *)
  286.   somTD_classInitRoutine =
  287.     PROCEDURE( PSOMClass, PSOMClass );
  288.   somTD_SOMOutCharRoutine =
  289.     PROCEDURE( CHAR ) : INT;
  290.   somTD_SOMLoadModule =
  291.     PROCEDURE
  292.     ( ARRAY OF CHAR, (* ClassName *)
  293.       ARRAY OF CHAR, (* FileName *)
  294.       ARRAY OF CHAR, (* FunctionName *)
  295.       INTEGER4,      (* MajorVersion *)
  296.       INTEGER4,      (* MinorVersion *)
  297.       VAR somToken   (* ModHandle *)
  298.     ) : INT;
  299.   somTD_SOMDeleteModule =
  300.     PROCEDURE( somToken ) : INT;
  301.   somTD_SOMClassInitFuncName =
  302.     PROCEDURE() : zString;
  303.   somTD_SOMMalloc =
  304.     PROCEDURE( size_t ) : ADDRESS;
  305.   somTD_SOMCalloc =
  306.     PROCEDURE
  307.     ( size_t,        (* ElementCount *)
  308.       size_t         (* ElementSize *)
  309.     ) : ADDRESS;
  310.   somTD_SOMRealloc =
  311.     PROCEDURE( ADDRESS, size_t ) : ADDRESS;
  312.   somTD_SOMFree =
  313.     PROCEDURE( ADDRESS );
  314.   somTD_SOMError =
  315.     PROCEDURE
  316.     ( INT,            (* Code  *)
  317.       ARRAY OF CHAR,  (* FileName *)
  318.       INT             (* LineNumber *)
  319.     );
  320.  
  321. (*************************************************************************
  322.    Misc. procedures:
  323. *************************************************************************)
  324.  
  325. (*
  326.  *  Create and initialize the SOM environment
  327.  *
  328.  *  Can be called repeatedly
  329.  *
  330.  *  Will be called automatically when first object (including a class
  331.  *  object) is created, if it has not already been done.
  332.  *
  333.  *  Returns the SOMClassMgrObject
  334.  *)
  335. PROCEDURE somEnvironmentNew( ) : PSOMClassMgr;
  336.  
  337.  
  338. (*************************************************************************
  339.  *  String Manager functions
  340. *************************************************************************)
  341.  
  342. (*
  343.  * makes sure that the id is registered and in normal form, returns
  344.  * the id
  345.  *)
  346. PROCEDURE somCheckId( Ident : somId ) : somId;
  347.  
  348. (*
  349.  * Same as somCheckId except returns 1 (true) if this is the first
  350.  * time the string associated with this id has been registered,
  351.  * returns 0 (false) otherwise
  352.  *)
  353. PROCEDURE somRegisterId( Id : somId ) : INT;
  354.  
  355. PROCEDURE somIdFromString( Str : ARRAY OF CHAR ) : somId;
  356.  
  357. PROCEDURE somStringFromId( Ident : somId ) : zString;
  358.  
  359. (*
  360.  * Returns 1 (TRUE) if identifiers represent same string values
  361.  * Returns 0 (FALSE) if identifiers represent unequal string values
  362.  *)
  363. PROCEDURE somCompareIds( Ident1, Ident2 : somId ) : INT;
  364.  
  365. (*
  366.  * Returns the total number of ids that have been registered so far,
  367.  * you can use this to advise the SOM runtime concerning expected
  368.  * number of ids in later executions of your program, via a call to
  369.  * somSetExpectedIds defined below
  370.  *)
  371. PROCEDURE somTotalRegIds() : LONGCARD;
  372.  
  373. (*
  374.  * Tells the SOM runtime how many unique ids you expect to use during
  375.  * the execution of your program, this can improve space and time
  376.  * utilization slightly, this routine must be called before the SOM
  377.  * environment is created to have any effect
  378.  *)
  379. PROCEDURE somSetExpectedIds( NunIds : LONGCARD );
  380.  
  381. (*
  382.  * Returns the unique key for this id, this key will be the same as the
  383.  * key in another id if and only if the other id refers to the same
  384.  * name as this one
  385.  *)
  386. PROCEDURE somUniqueKey( Ident : somId ) : LONGCARD;
  387.  
  388. (*
  389.  * Tells the id manager that strings for any new ids that are
  390.  * registered will never be freed or otherwise modified. This allows
  391.  * the id manager to just use a pointer to the string in the
  392.  * unregistered id as the master copy of the ids string. Thus saving
  393.  * space
  394.  * Under normal use (where ids are static varibles) the string
  395.  * associated with an id would only be freed if the code module in
  396.  * which it occured was unloaded
  397.  *)
  398. PROCEDURE somBeginPersistentIds();
  399.  
  400. (*
  401.  * Tells the id manager that strings for any new ids that are
  402.  * registered may be freed or otherwise modified.  Therefore the id
  403.  * manager must copy the strings inorder to remember the name of an
  404.  * id.
  405.  *)
  406. PROCEDURE somEndPersistentIds();
  407.  
  408.  
  409.  
  410. (*************************************************************************
  411.   Global Class Manager Object.
  412. **************************************************************************)
  413.  
  414. VAR
  415.   SOMClassMgrObject      : PSOMClassMgr;
  416.  
  417.  
  418.  
  419. (*************************************************************************
  420.   Basic offset based method resolution, this is used in every method
  421.   class that uses offset resolution.
  422.   It returns the appropriate method procedure for the method
  423.   identified by <mdata>, Mdata id the 32 bit value stored in the
  424.   class data structure in the entry with the methods name. I.e., if
  425.   a object, obj, of class, Foo, has a method, bar, then:
  426.   somResolve(obj, FooClassData.bar)
  427.   will return the appropriate method procedure for bar.
  428.   The way that <mdata> identifies a method and the algorithm used by
  429.   somResolve to locate the appropriate method procedure is not part
  430.   of the visible SOM architecture and is subject to change in
  431.   subsequent releases.
  432. **************************************************************************)
  433.  
  434. PROCEDURE somResolve
  435. ( obj            : PSOMAny;
  436.   mdata          : somMToken
  437. )                : somMethodProc;
  438.  
  439. PROCEDURE somParentResolve
  440. ( parentMtab     : PsomMethodTabList;
  441.   mdata          : somMToken
  442. )                : somMethodProc;
  443.  
  444. PROCEDURE somParentNumResolve
  445. ( parentMtabs    : PsomMethodTabList;
  446.   parentNum      : LONGINT;
  447.   mToken         : somMToken
  448. )                : somMethodProc;
  449.  
  450. PROCEDURE somClassResolve
  451. ( classObject    : PSOMClass;
  452.   mdata          : somMToken
  453. )                : somMethodProc;
  454.  
  455. PROCEDURE somResolveByName
  456. ( obj            : PSOMObject;
  457.   methodName     : ARRAY OF CHAR
  458. )                : somMethodProc;
  459.  
  460. PROCEDURE somDataResolve
  461. ( obj            : PSOMAny;
  462.   dataId         : somDToken
  463. )                : ADDRESS;
  464.  
  465. PROCEDURE somIsObj
  466. ( obj            : somToken
  467. )                : BOOLEAN;
  468.  
  469.  
  470.  
  471. (*************************************************************************
  472.    Method Stubs -- Signature Support
  473. **************************************************************************)
  474.  
  475. (*
  476.  *
  477.  * This section defines the structures used to pass method signature
  478.  * ingo to the runtime. This supports selection of generic apply stubs
  479.  * and runtime generation of redispatchstubs when these are needed. The
  480.  * information is registered with the runtime when methods are defined.
  481.  *
  482.  * When calling somAddStaticMethod, if the redispatchStub is -1, then a
  483.  * pointer to a struct of type somApRdInfo is passed as the applyStub.
  484.  * Otherwise, the passed redispatchstub and applystub are taken as given.
  485.  * When calling somAddDynamicMethod, an actual apply stub must be passed.
  486.  * Redispatch stubs for dynamic methods are not available, nor is
  487.  * automated support for dynamic method apply stubs. The following
  488.  * atructures only appropriate in relation to static methods.
  489.  *
  490.  * In SOMr2, somAddStaticMethod can be called with an actual redispatchstub
  491.  * and applystub *ONLY* if the method doesn't return a structure. Recall
  492.  * that no SOMr1 methods returned structures, so SOMr1 binaries obey this
  493.  * restriction. The reason for this rule is that SOMr2 *may* use thunks,
  494.  * and thunks need to know if a structure is returned. We therefore assume
  495.  * that if no signature information is provided for a method through the
  496.  * somAddStaticMethod interface, then the method returns a scalar.
  497.  *
  498.  * If a structure is returned, then a -1 *must* be passed to
  499.  * somAddStaticMethod as a redispatchstub. In any case, if a -1 is passed,
  500.  * then this means that the applystub actually points to a structure of type
  501.  * somApRdInfo. This structure is used to hold and access signature
  502.  * information encoded as follows.
  503.  *
  504.  * If the somApRdInfo pointer is NULL, then, if the runtime was built with
  505.  * SOM_METHOD_STUBS defined, a default signature is assumed (no arguments,
  506.  * and no structure returned); otherwise, the stubs are taken as
  507.  * somDefaultMethod (which produces a runtime error when used) if dynamic
  508.  * stubs are not available.
  509.  *
  510.  * If the somApRdInfo pointer is not NULL, then the structure it points to can
  511.  * either include (non-null) redispatch and applystubs (the method is then
  512.  * assumed to return a structure), or null stubs followed by information needed
  513.  * to generate necessary stubs dynamically.
  514.  *)
  515.  
  516. TYPE
  517.   somRdAppType = LONGCARD;      (* method signature code -- see def below *)
  518.   somFloatMap  = ARRAY [0..12] OF LONGCARD; (* float map -- see def below *)
  519.  
  520. TYPE
  521.   somMethodInfoStruct = RECORD
  522.     callType            : somRdAppType;
  523.     va_listSize         : LONGINT;
  524.     float_map           : POINTER TO somFloatMap;
  525.                         END;
  526.   somMethodInfo       = somMethodInfoStruct;
  527.  
  528. TYPE
  529.   somApRdInfoStruct   = RECORD
  530.     rdStub              : POINTER TO somMethodProc;
  531.     apStub              : POINTER TO somMethodProc;
  532.     stubInfo            : POINTER TO somMethodInfo;
  533.                         END;
  534.   somApRdInfo         = POINTER TO somApRdInfoStruct;
  535.  
  536. (*
  537.  * Values for somRdAppType are generated by summing one from column A and one
  538.  * from column B of the following constants:
  539.  *)
  540.  
  541. CONST (* Column A: return type *)
  542.   SOMRdRetsimple      =  0; (* Return type is a non-float fullword *)
  543.   SOMRdRetfloat       =  2; (* Return type is (single) float *)
  544.   SOMRdRetdouble      =  4; (* Return type is double *)
  545.   SOMRdRetlongdouble  =  6; (* Return type is long double *)
  546.   SOMRdRetaggregate   =  8; (* Return type is struct or union *)
  547.   SOMRdRetbyte        = 10; (* Return type is a byte *)
  548.   SOMRdRethalf        = 12; (* Return type is a (2 byte) halfword *)
  549.  
  550. CONST (* Column B: are there any floating point scalar arguments? *)
  551.   SOMRdNoFloatArgs    = 0;
  552.   SOMRdFloatArgs      = 1;
  553.  
  554. (* A somFloatMap is only needed on RS/6000 *)
  555. (*
  556.  * This is an array of offsets for up to the first 13 floating point arguments.
  557.  * If there are fewer than 13 floating point arguments, then there will be
  558.  * zero entries following the non-zero entries which represent the float args.
  559.  * A non-zero entry signals either a single- or a double-precision floating point
  560.  * argument. For a double-precision argument, the entry is the stack
  561.  * frame offset. For a single-precision argument the entry is the stack
  562.  * frame offset + 1. For the final floating point argument, add 2 to the
  563.  * code that would otherwise be used.
  564.  *)
  565. CONST
  566.   SOMFMSingle         = 1; (* add to indicate single-precision *)
  567.   SOMFMLast           = 2; (* add to indicate last floating point arg *)
  568.  
  569. TYPE
  570.   somSharedMethodData = somToken;
  571.  
  572. TYPE
  573.   somMethodDataStruct = RECORD
  574.     id                  : somId;
  575.     type                : LONGCARD;      (* 0=static, 1=dynamic *)
  576.     descriptor          : somId;         (* for use with IR interfaces *)
  577.     mToken              : somMToken;     (* NULL for dynamic methods *)
  578.     method              : somMethodPtr;  (* depends on resolution context *)
  579.     shared              : POINTER TO somSharedMethodData;
  580.                         END;
  581.   somMethodData       = somMethodDataStruct;
  582.   somMethodDataPtr    = POINTER TO somMethodDataStruct;
  583.   SOMMETHODDATA       = somMethodData;
  584.   PsomMethodData      = POINTER TO somMethodData;
  585.  
  586.  
  587. PROCEDURE somApply
  588. (
  589.   somSelf             : PSOMObject;
  590.   VAR retVal          : ADDRESS;
  591.   mdPtr               : somMethodDataPtr;
  592.   VAR ap              : ARRAY OF LONGWORD
  593. )                     : BOOLEAN;
  594.  
  595. (* This routine replaces direct use of applyStubs in SOMr1. The reason
  596.  * for the replacement is that the SOMr1 style of applyStub is not
  597.  * generally available in SOMr2, which uses a fixed set of applyStubs,
  598.  * according to method information in the somMethodData. In particular,
  599.  * neither the redispatch stub nor the apply stub found in the method
  600.  * data structure are necessarily useful as such. The method somGetRdStub
  601.  * is the way to get a redispatch stub, and the above function is the
  602.  * way to call an apply stub. If an appropriate apply stub for the
  603.  * method indicated by md is available, then this is invoked and TRUE is
  604.  * returned; otherwise FALSE is returned.
  605.  *
  606.  * The va_list passed to somApply *must* include the target object,
  607.  * somSelf, as its first entry, and any single precision floating point
  608.  * arguments being passed to the the method procedure must be
  609.  * represented on the va_list using double precision values. retVal cannot
  610.  * be NULL.
  611.  *)
  612.  
  613.  
  614. (*************************************************************************
  615.    somBuildClass is a convenience procedure that automates construction
  616.    of a new class object. The following structures are required for its use.
  617. **************************************************************************)
  618.  
  619. TYPE (* to specify a new static method *)
  620.   somStaticMethodStruct    = RECORD
  621.     classData                : POINTER TO somMToken;
  622.     methodId                 : POINTER TO somId;
  623.     methodDescriptor         : POINTER TO somId;
  624.     method                   : somMethodProc;
  625.     redispatchStub           : somMethodProc;
  626.     applyStub                : somMethodProc;
  627.                              END;
  628.   somStaticMethod_t        = somStaticMethodStruct;
  629.  
  630. TYPE (* to specify an overridden method *)
  631.   somOverideMethodStruct   = RECORD
  632.     methodId                 : POINTER TO somId;
  633.     method                   : somMethodProc;
  634.                              END;
  635.   somOverrideMethod_t      = somOverideMethodStruct;
  636.  
  637. TYPE (* to specify non-internal data *)
  638.   somNonInternalDataStruct = RECORD
  639.     classData                : POINTER TO somDToken;
  640.     basisForDataOffset       : POINTER TO CHAR;
  641.                              END;
  642.   somNonInternalData_t     = somNonInternalDataStruct;
  643.  
  644. TYPE (* to specify a "procedure" method *)
  645.   somProcMethodsStruct     = RECORD
  646.     classData                : POINTER TO somMethodProc;
  647.     pEntry                   : somMethodProc;
  648.                              END;
  649.   somProcMethods_t         = somProcMethodsStruct;
  650.  
  651. TYPE (* to specify a varargs function *)
  652.   somVarargsFuncsStruct    = RECORD
  653.     classData                : POINTER TO somMethodProc;
  654.     vEntry                   : somMethodProc;
  655.                              END;
  656.   somVarargsFuncs_t        = somVarargsFuncsStruct;
  657.  
  658. (*
  659.  * The address of the class's ClassData structure is passed to
  660.  * somBuildClass, to allow somBuildClass to initialize it. This
  661.  * structure should have the external name, <className>ClassData.
  662.  * The tokens array should have (numStaticMethods + numNonInternalData)
  663.  * entries, and the classObject should be NIL (if it is not NIL,
  664.  * then a new class will not be built).
  665.  *
  666.  * somClassDataStructure    = RECORD
  667.  *   classObject              : PSOMClass;
  668.  *   tokens                   : ARRAY [0..0] OF somToken;
  669.  *                            END;
  670.  * somClassDataStructurePtr = POINTER TO somClassDataStructure;
  671.  *)
  672.  
  673. (*
  674.  * The address of the class's auxiliary ClassData structure is passed to
  675.  * somBuildClass, to allow somBuildClass to initialize it. This
  676.  * structure (whose actual typedef is located in this file) should
  677.  * have the external name, <className>CClassData. The wrappers array
  678.  * should have numVarargsFuncs entries.
  679.  *
  680.  *  somCClassDataStructure  = RECORD
  681.  *    parentMtab              : PsomMethodTabList;
  682.  *    instanceDataToken       : somDToken;
  683.  *    wrappers                : ARRAY [0..0] OF somMethodProc;
  684.  *                            END;
  685.  *)
  686.  
  687. TYPE (* The Static Class Info Structure passed to somBuildClass *)
  688.   somStaticClassInfoStruct  = RECORD
  689.     layoutVersion             : INTEGER4; (* this is layout version 2 *)
  690.     numStaticMethods          : INTEGER4; (* count of smt entries *)
  691.     numStaticOverrides        : INTEGER4; (* count of omt entries *)
  692.     numNonInternalData        : INTEGER4; (* count of nit entries *)
  693.     numProcMethods            : INTEGER4; (* count of pmt entries *)
  694.     numVarargsFuncs           : INTEGER4; (* count of vft entries *)
  695.     majorVersion              : INTEGER4;
  696.     minorVersion              : INTEGER4;
  697.     instanceDataSize          : INTEGER4;
  698.     maxMethods                : INTEGER4;
  699.     numParents                : INTEGER4;
  700.     classId                   : somId;
  701.     explicitMetaId            : somId;
  702.     implicitParentMeta        : INTEGER4;
  703.     parents                   : POINTER TO somId;
  704.     cds                       : POINTER TO somClassDataStructure;
  705.     ccds                      : POINTER TO somCClassDataStructure;
  706.     smt                       : POINTER TO somStaticMethod_t;
  707.     omt                       : POINTER TO somOverrideMethod_t;
  708.     nitReferenceBase          : POINTER TO CHAR;
  709.     nit                       : POINTER TO somNonInternalData_t;
  710.     pmt                       : POINTER TO somProcMethods_t;
  711.     vft                       : POINTER TO somVarargsFuncs_t;
  712.     cif                       : POINTER TO somTP_somClassInitFunc;
  713.     dataAlignment             : INTEGER4;  (* only layout versions > 1:
  714.                                               the desired alignment for
  715.                                               instance data
  716.                                            *)
  717.                               END;
  718.   somStaticClassInfo        = somStaticClassInfoStruct;
  719.   somStaticClassInfoPtr     = POINTER TO somStaticClassInfoStruct;
  720.  
  721. PROCEDURE somBuildClass
  722. ( inherit_vars              : LONGINT;
  723.   VAR sci                   : somStaticClassInfo;
  724.   majorVersion              : LONGINT;
  725.   minorVersion              : LONGINT
  726. )                           : PSOMClass;
  727.  
  728.  
  729. (*************************************************************************
  730.   Used to make class object creation an atomic operation, this is
  731.   called by the generated <class name>NewClass routine.  You should
  732.   never call this routine directly. Kept for backwards compatability.
  733. **************************************************************************)
  734.  
  735. PROCEDURE somConstructClass
  736. ( classInitRoutine      : somTD_classInitRoutine;
  737.   parentClass           : PSOMClass;
  738.   metaClass             : PSOMClass;
  739.   cds                   : PsomClassDataStructure
  740. );
  741.  
  742.  
  743. (*************************************************************************
  744.   Replaceable character output handler.
  745.   Points to the character output routine to be used in development
  746.   support.  Initialized to <somOutChar>, but may be reset at anytime.
  747.   Should return 0 (false) if an error occurs and 1 (true) otherwise.
  748. **************************************************************************)
  749.  
  750. VAR
  751.   SOMOutCharRoutine     : somTD_SOMOutCharRoutine;
  752.  
  753. (*************************************************************************
  754.   Pointers to routines used to do dynamic code loading and deleting
  755. **************************************************************************)
  756.  
  757. VAR
  758.   SOMLoadModule         : somTD_SOMLoadModule;
  759.   SOMDeleteModule       : somTD_SOMDeleteModule;
  760.   SOMClassInitFuncName  : somTD_SOMClassInitFuncName;
  761.  
  762.  
  763. (*************************************************************************
  764.   Replaceable SOM Memory Management Interface
  765.  
  766.   External procedure variables SOMCalloc, SOMFree, SOMMalloc, SOMRealloc
  767.   have the same interface as standard C-library analogs,
  768.   and they may be used under Modula-2 as well.
  769. **************************************************************************)
  770.  
  771. VAR
  772.   SOMCalloc             : somTD_SOMCalloc;
  773.   SOMFree               : somTD_SOMFree;
  774.   SOMMalloc             : somTD_SOMMalloc;
  775.   SOMRealloc            : somTD_SOMRealloc;
  776.  
  777.  
  778. (**************************************************************************
  779.   Replaceable SOM Error handler
  780. ***************************************************************************)
  781.  
  782. VAR
  783.   SOMError              : somTD_SOMError;
  784.  
  785.  
  786. (**************************************************************************
  787.   Externals used in the implementation of SOM, but not part of the
  788.   SOM API.
  789. **************************************************************************)
  790.  
  791. PROCEDURE somTestCls
  792. ( obj                   : PSOMAny;
  793.   classObj              : PSOMClass;
  794.   fileName              : ARRAY OF CHAR;
  795.   lineNumber            : INT
  796. )                       : PSOMAny;
  797.  
  798. PROCEDURE somTest
  799. ( condition             : BOOLEAN;
  800.   severity              : INT;
  801.   fileName              : ARRAY OF CHAR;
  802.   lineNum               : INT;
  803.   msg                   : ARRAY OF CHAR
  804. );
  805.  
  806. PROCEDURE somAssert
  807. ( condition             : BOOLEAN;
  808.   ecode                 : INT;
  809.   fileName              : ARRAY OF CHAR;
  810.   lineNum               : INT;
  811.   msg                   : ARRAY OF CHAR
  812. );
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822. (*************************************************************************
  823.    Additional types for new 'SOMClass' method parameters.
  824. **************************************************************************)
  825.  
  826. TYPE
  827.   _IDL_SEQUENCE_SOMClass    = RECORD
  828.     _maximum                  : LONGCARD;
  829.     _length                   : LONGCARD;
  830.     _buffer                   : POINTER TO PSOMClass;
  831.                               END;
  832.   SOMClass_SOMClassSequence = _IDL_SEQUENCE_SOMClass;
  833.  
  834. TYPE (* a structure to describe a class-related offset *)
  835.   SOMClass_somOffsetInfo    = RECORD
  836.     cls                       : PSOMClass;
  837.     offset                    : LONGINT;
  838.                               END;
  839.  
  840. TYPE (* a sequence of class-related offsets *)
  841.   _IDL_SEQUENCE_SOMClass_somOffsetInfo = RECORD
  842.     _maximum                             : LONGCARD;
  843.     _length                              : LONGCARD;
  844.     _buffer                              : POINTER TO SOMClass_somOffsetInfo;
  845.                                          END;
  846.   SOMClass_somOffsets                  = _IDL_SEQUENCE_SOMClass_somOffsetInfo;
  847.  
  848.  
  849. (*************************************************************************
  850.   'SOMObject' Class API for Modula-2
  851. **************************************************************************)
  852.  
  853. (*
  854.  * SOMObject is the root class for all SOM classes. It defines the
  855.  * essential behavior common to all SOM objects. As SOMObject has
  856.  * no own instance data (except for a pointer to its metaclass object),
  857.  * it contributes nothing to the size of derived classes.
  858.  * All SOM classes are expected to derive from SOMObject. Three methods
  859.  * would typically be overwritten by any subclass that has instance data-
  860.  * somInit, somUninit, and somDumpSelfInt. See the descriptions of these
  861.  * methods for further information.
  862.  *
  863.  * Note:
  864.  *
  865.  * Currently no further SOM support beyond the mere usage of SOM classes
  866.  * is supported by this compiler version. No special SOM emitters
  867.  * or language bindings has been implemented. SOM is supposed to
  868.  * represent a language independent object management. But due to the
  869.  * poor SOM documentation and its closeness to the C-language this
  870.  * claim can hardly be substantiated. Nevertheless is the limited
  871.  * support by this Modula-2 compiler enough for using any SOM-based
  872.  * library such as the OS/2 2.x Workplace Shell.
  873.  *
  874.  *)
  875.  
  876.  
  877. CONST
  878.   SOMObject_MajorVersion     = 1;
  879.   SOMObject_MinorVersion     = 1;
  880.  
  881.  
  882. (* A procedure to create the SOMObject Class *)
  883. PROCEDURE SOMObjectNewClass
  884. ( majorVersion          : INTEGER4;
  885.   minorVersion          : INTEGER4
  886. )                       : PSOMClass;
  887.  
  888.  
  889. (* The static interface to SOMObject and its instances *)
  890. TYPE
  891.   SOMObjectClassDataStructure = RECORD
  892.     classObject                 : PSOMClass;
  893.     somInit                     : somMethodProc;
  894.     somUninit                   : somMethodProc;
  895.     somFree                     : somMethodProc;
  896.     somMissingMethod            : somMethodProc;
  897.     somGetClassName             : somMethodProc;
  898.     somGetClass                 : somMethodProc;
  899.     somIsA                      : somMethodProc;
  900.     somRespondsTo               : somMethodProc;
  901.     somIsInstanceOf             : somMethodProc;
  902.     somGetSize                  : somMethodProc;
  903.     somDumpSelf                 : somMethodProc;
  904.     somDumpSelfInt              : somMethodProc;
  905.     somPrintSelf                : somMethodProc;
  906.     somFreeObj                  : somMethodProc;
  907.     somDispatchV                : somMethodProc;
  908.     somDispatchL                : somMethodProc;
  909.     somDispatchA                : somMethodProc;
  910.     somDispatchD                : somMethodProc;
  911.     somDispatch                 : somMethodProc;
  912.     somClassDispatch            : somMethodProc;
  913.                                 END;
  914. VAR
  915.   SOMObjectClassData          : SOMObjectClassDataStructure;
  916.  
  917. TYPE
  918.   (*$SOM+ *)
  919.   SOMObject           = RECORD
  920.     mtab                : POINTER TO somMethodTabStruct;
  921.     (* body             : ARRAY [0..0] OF integer1; *)
  922.                         END;
  923.   (*$SOM- *)
  924.  
  925.  
  926. PROCEDURE( Self : PSOMObject ) somInit( );
  927. (*
  928.  *  Initializes <Self>.  As instances of <SOMObject> do not have any
  929.  *  instance data there is nothing to initialize and you need not call
  930.  *  this method.  It is provided to induce consistency among
  931.  *  subclasses that require initialization.
  932.  *
  933.  *  <somInit> is called automatically as a side effect of object
  934.  *  creation (ie, by <somNew>).  If this effect is not desired, you
  935.  *  can supply your own version of <somNew> (in a user-written metaclass)
  936.  *  which does not invoke <somInit>.
  937.  *
  938.  *  When overriding this method you should always call the parent class
  939.  *  version of this method BEFORE doing your own initialization.
  940.  *)
  941.  
  942.  
  943. PROCEDURE( Self : PSOMObject ) somUninit( );
  944. (*
  945.  *  Un-initializes self.  As instances of <SOMObject> do not have any
  946.  *  instance data there is nothing to un-initialize and you need not
  947.  *  call this method.  It is provided to induce consistency among
  948.  *  subclasses that require un-initialization.
  949.  *
  950.  *  Use this method to clean up anything necessary such as dynamically
  951.  *  allocated storage. However this method does not release the actual
  952.  *  storage assigned to the object instance. This method is provided as
  953.  *  a complement to <somFree> which also releases the storage
  954.  *  associated with a dynamically allocated object. Usually you would
  955.  *  just call <somFree> which will always call <somUninit>. However, in
  956.  *  cases where <somRenew> (see the definition of <SOMClass>) was used
  957.  *  to create an object instance, <somFree> cannot be called and you
  958.  *  must call <somUninit> explicitly.
  959.  *
  960.  *  When overriding this method you should always call the parentclass
  961.  *  version of this method AFTER doing your own un-initialization.
  962.  *)
  963.  
  964.  
  965. PROCEDURE( Self : PSOMObject ) somFree( );
  966. (*
  967.  *  Releases the storage associated with <self>, assuming that <self>
  968.  *  was created by <somNew> (or another class method that used
  969.  *  <somNew>).  No future references should be made to <self>.  Will
  970.  *  call <somUninit> on <self> before releasing the storage.
  971.  *
  972.  *  This method must only be called on objects created by <somNew> (see
  973.  *  the definition of <somClass>) and never on objects created by
  974.  *  <somRenew>.
  975.  *
  976.  *  It should not be necessary to override this method. (Override
  977.  *  <somUninit> instead.)
  978.  *)
  979.  
  980.  
  981. PROCEDURE( Self : PSOMObject ) somGetClass( ) : PSOMClass;
  982. (*
  983.  *  Returns this object's class object.
  984.  *)
  985.  
  986.  
  987. PROCEDURE( Self : PSOMObject ) somGetClassName( ) : zString;
  988. (*
  989.  *  Returns a pointer to this object's class's name, as a NULL
  990.  *  terminated string.
  991.  *
  992.  *  It should not be necessary to override this method as it just
  993.  *  invokes the class object's method (<somGetName>) to get the name.
  994.  *)
  995.  
  996.  
  997. PROCEDURE( Self : PSOMObject ) somGetSize( ) : INTEGER4;
  998. (*
  999.  *  Returns the size of this instance in bytes.
  1000.  *)
  1001.  
  1002.  
  1003. PROCEDURE( Self : PSOMObject ) somIsA
  1004. (
  1005.   aClassObj     : PSOMClass
  1006. )               : BOOLEAN;
  1007. (*
  1008.  *  Returns 1 (true) if <self>'s class is a descendent class of
  1009.  *  <aClassObj> and 0 (false) otherwise.  Note: a class object is
  1010.  *  considered to be descended from itself for the purposes of this
  1011.  *  method.
  1012.  *)
  1013.  
  1014.  
  1015. PROCEDURE( Self : PSOMObject ) somIsInstanceOf
  1016. (
  1017.   aClassObj     : PSOMClass
  1018. )               : BOOLEAN;
  1019. (*
  1020.  *  Returns 1 (true) if <self> is an instance of the specified
  1021.  *  <aClassObj> and 0 (false) otherwise.
  1022.  *)
  1023.  
  1024.  
  1025. PROCEDURE( Self : PSOMObject ) somRespondsTo
  1026. (
  1027.   mId : somId
  1028. )     : BOOLEAN;
  1029. (*
  1030.  *  Returns 1 (true) if the indicated method is supported by this
  1031.  *  object's class and 0 (false) otherwise.
  1032.  *)
  1033.  
  1034.  
  1035. PROCEDURE( Self : PSOMObject ) somPrintSelf( ) : PSOMObject;
  1036. (*
  1037.  *  Uses <SOMOutCharRoutine> to write a brief string with identifying
  1038.  *  information about this object.  The default implementation just gives
  1039.  *  the object's class name and its address in memory.
  1040.  *  <self> is returned.
  1041.  *)
  1042.  
  1043.  
  1044. PROCEDURE( Self : PSOMObject ) somDumpSelf
  1045. (
  1046.   level : INT
  1047. );
  1048. (*
  1049.  *  Uses <SOMOutCharRoutine> to write a detailed description of this object
  1050.  *  and its current state.
  1051.  *
  1052.  *  <level> indicates the nesting level for describing compound objects
  1053.  *  it must be greater than or equal to zero.  All lines in the
  1054.  *  description will be preceeded by <2*level> spaces.
  1055.  *
  1056.  *  This routine only actually writes the data that concerns the object
  1057.  *  as a whole, such as class, and uses <somDumpSelfInt> to describe
  1058.  *  the object's current state.  This approach allows readable
  1059.  *  descriptions of compound objects to be constructed.
  1060.  *
  1061.  *  Generally it is not necessary to override this method, if it is
  1062.  *  overriden it generally must be completely replaced.
  1063.  *)
  1064.  
  1065.  
  1066. PROCEDURE( Self : PSOMObject ) somDumpSelfInt
  1067. (
  1068.   level : INT
  1069. );
  1070. (*
  1071.  *  Uses <SOMOutCharRoutine> to write out the current state of this object.
  1072.  *  Generally this method will need to be overridden.  When overriding
  1073.  *  it, begin by calling the parent class form of this method and then
  1074.  *  write out a description of your class's instance data. This will
  1075.  *  result in a description of all the object's instance data going
  1076.  *  from its root ancestor class to its specific class.
  1077.  *)
  1078.  
  1079.  
  1080. (*
  1081.  *  The following somDispatchX methods make it easier for very dynamic
  1082.  *  domains to bind to the SOM object protocol boundry.
  1083.  *
  1084.  *  These methods determine the appropriate method procedure and then
  1085.  *  call it with the arguments specified.  The default implementation
  1086.  *  of these methods provided in this class simply lookup the method by
  1087.  *  name and call it.  However, other classes may choose to implement
  1088.  *  any form of lookup they wish.  For example, one could provide an
  1089.  *  implementation of these methods that used the CLOS form of method
  1090.  *  resolution. For domains that can do so it will generally be much
  1091.  *  faster to invoke their methods directly rather than going through a
  1092.  *  dispatch method.  However, all methods are reachable through the
  1093.  *  dispatch methods.  SOM provides a small set of external procedures
  1094.  *  that wrap these method calls so that the caller need never do method
  1095.  *  resolution.
  1096.  *
  1097.  *  These methods are declared to take a variable length argument list,
  1098.  *  but like all such methods the SOM object protocol boundry requires
  1099.  *  that the variable part of the argument list be assembled into the
  1100.  *  standard, platform-specific, data structure for variable argument
  1101.  *  lists before the method is actually invoked.  This can be very
  1102.  *  useful in domains that need to construct the argument list at
  1103.  *  runtime. As they can invoke methods without being able to put the
  1104.  *  constructed arguments in the normal form for a call.  This is
  1105.  *  helpful because such an operation is usually impossible in most
  1106.  *  high level languages and platform-specific assembler language
  1107.  *  routines would have to be used.
  1108.  *
  1109.  *  Note: It was decided to have different methods for different return
  1110.  *  value shapes. This avoids the memory mangement problems that would
  1111.  *  arise in some domains if an additional parameter was required to
  1112.  *  carry the return value.
  1113.  *
  1114.  *  Note: SOM does not support return values except for the four
  1115.  *  families shown below. Within a family (such as integer) SOM only
  1116.  *  supports the largest member.
  1117.  *)
  1118.  
  1119. PROCEDURE( Self : PSOMObject ) somDispatchV
  1120. (
  1121.   methodId      : somId;
  1122.   descriptor    : somId;
  1123.   ap            : ARRAY OF BYTE
  1124. );
  1125. (*
  1126.  *  Does not return a value.
  1127.  *)
  1128.  
  1129.  
  1130. PROCEDURE( Self : PSOMObject ) somDispatchL
  1131. (
  1132.   methodId      : somId;
  1133.   descriptor    : somId;
  1134.   ap            : ARRAY OF BYTE
  1135. )               : INTEGER4;
  1136. (*
  1137.  *  Returns a 4 byte quanity in the normal manner that integer data is
  1138.  *  returned. This 4 byte quanity can, of course, be something other
  1139.  *  than an integer.
  1140.  *)
  1141.  
  1142.  
  1143. PROCEDURE( Self : PSOMObject ) somDispatchA
  1144. (
  1145.   methodId      : somId;
  1146.   descriptor    : somId;
  1147.   ap            : ARRAY OF BYTE
  1148. )               : ADDRESS;
  1149. (*
  1150.  *  Returns a data structure address in the normal manner that such data is
  1151.  *  returned.
  1152.  *)
  1153.  
  1154.  
  1155. PROCEDURE( Self : PSOMObject ) somDispatchD
  1156. (
  1157.   methodId      : somId;
  1158.   descriptor    : somId;
  1159.   ap            : ARRAY OF BYTE
  1160. )               : FLOAT8;
  1161. (*
  1162.  *  Returns a 8 byte quanity in the normal manner that floating point
  1163.  *  data is returned.
  1164.  *)
  1165.  
  1166.  
  1167.  
  1168. PROCEDURE( Self : PSOMObject ) somDispatch
  1169. (
  1170.   VAR retValue  : somToken;
  1171.   methodId      : somId;
  1172.   ap            : ARRAY OF BYTE
  1173. )               : BOOLEAN;
  1174. (*
  1175.  *  The procedure that supports this method accepts as input a pointer to
  1176.  *  memory area to be loaded with the result of dispatching a method, a
  1177.  *  methodId indicating the id of the method to be dispatched, and a
  1178.  *  va_list containing method arguments. If an appropriate apply stub
  1179.  *  is available for the indicated method, the procedure that
  1180.  *  implements somDispatch for SOMClass instances invokes this apply stub
  1181.  *  for the method, and then returns TRUE; otherwise, FALSE is returned.
  1182.  *  For static methods, method resolution necessary to select the method
  1183.  *  procedure to be used by the apply stub is performed using the method
  1184.  *  table of the target object, Self.
  1185.  *)
  1186.  
  1187.  
  1188. PROCEDURE( Self : PSOMObject ) somClassDispatch
  1189. (
  1190.   clsObj        : PSOMClass;
  1191.   VAR retValue  : somToken;
  1192.   methodId      : somId;
  1193.   ap            : ARRAY OF BYTE
  1194. )               : BOOLEAN;
  1195. (*
  1196.  *  The procedure that supports this method accepts as input a class
  1197.  *  object, a pointer to
  1198.  *  memory area to be loaded with the result of dispatching a method, a
  1199.  *  methodId indicating the id of the method to be dispatched, and a
  1200.  *  va_list containing method arguments. If an appropriate apply stub
  1201.  *  is available for the indicated method, the procedure that
  1202.  *  implements somDispatch for SOMClass instances invokes this apply stub
  1203.  *  for the method, and then returns TRUE; otherwise, FALSE is returned.
  1204.  *  For static methods, method resolution necessary to select the method
  1205.  *  procedure to be used by the apply stub is performed using the instance
  1206.  *  method table of clsObj.
  1207.  *)
  1208.  
  1209.  
  1210.  
  1211. (*************************************************************************
  1212.   'SOMClass' Class API for Modula-2
  1213. **************************************************************************)
  1214.  
  1215. (*
  1216.  *  SOMClass is the root class for all SOM metaclasses. it defines the
  1217.  *  essential behavior common to all SOM classes. In particular, it has
  1218.  *  two generic methods for manufacturing object instances (somNew and
  1219.  *  somRenew), and a suite of methods for constructing classes.
  1220.  *  It also has methods that can be used to dynamically obtain (or augment)
  1221.  *  information about a class and its methods at run time.
  1222.  *
  1223.  *  The instances of this class are class objects.
  1224.  *  When the SOM environment is created one
  1225.  *  instance of this class with the external name
  1226.  *  <SOMClassClassData.classObject> is created. This class object is
  1227.  *  unique in that it is its own class object.
  1228.  *  SOMClass can be subclassed just like any SOM class. The subclasses
  1229.  *  of SOMClass are new metaclasses and can generate class objects with
  1230.  *  different implementations than those produced by SOMClass object.
  1231.  *)
  1232.  
  1233. CONST
  1234.   SOMClass_MajorVersion  = 1;
  1235.   SOMClass_MinorVersion  = 1;
  1236.  
  1237. (* A procedure to create the SOMClass Class *)
  1238. PROCEDURE SOMClassNewClass
  1239. (
  1240.   majorVersion : INTEGER4;
  1241.   minorVersion : INTEGER4
  1242. )              : PSOMClass;
  1243.  
  1244. (* The static interface to SOMClass and its instances *)
  1245. TYPE
  1246.   SOMClassClassDataStructure    = RECORD
  1247.     classObject                   : PSOMClass;
  1248.     somNew                        : somMToken;
  1249.     somRenew                      : somMToken;
  1250.     somInitClass                  : somMToken;
  1251.     somClassReady                 : somMToken;
  1252.     somGetName                    : somMToken;
  1253.     somGetParent                  : somMToken;
  1254.     somDescendedFrom              : somMToken;
  1255.     somCheckVersion               : somMToken;
  1256.     somFindMethod                 : somMToken;
  1257.     somFindMethodOk               : somMToken;
  1258.     somSupportsMethod             : somMToken;
  1259.     somGetNumMethods              : somMToken;
  1260.     somGetInstanceSize            : somMToken;
  1261.     somGetInstanceOffset          : somMToken;
  1262.     somGetInstancePartSize        : somMToken;
  1263.     somGetMethodIndex             : somMToken;
  1264.     somGetNumStaticMethods        : somMToken;
  1265.     somGetPClsMtab                : somMToken;
  1266.     somGetClassMtab               : somMToken;
  1267.     somAddStaticMethod            : somMToken;
  1268.     somOverrideSMethod            : somMToken;
  1269.     somAddDynamicMethod           : somMToken;
  1270.     somGetMethodOffset            : somMToken;
  1271.     somGetApplyStub               : somMToken;
  1272.     somFindSMethod                : somMToken;
  1273.     somFindSMethodOk              : somMToken;
  1274.     somGetMethodDescriptor        : somMToken;
  1275.     somGetNthMethodInfo           : somMToken;
  1276.     somSetClassData               : somMToken;
  1277.     somGetClassData               : somMToken;
  1278.     somNewNoInit                  : somMToken;
  1279.     somRenewNoInit                : somMToken;
  1280.     somGetInstanceToken           : somMToken;
  1281.     somGetMemberToken             : somMToken;
  1282.     somSetMethodDescriptor        : somMToken;
  1283.     somGetMethodData              : somMToken;
  1284.     somOverrideMtab               : somMToken;
  1285.     somGetMethodToken             : somMToken;
  1286.     somGetParents                 : somMToken;
  1287.     somGetPClsMtabs               : somMToken;
  1288.     somInitMIClass                : somMToken;
  1289.     somGetVersionNumbers          : somMToken;
  1290.     somLookupMethod               : somMToken;
  1291.     _get_somInstanceDataOffsets   : somMToken;
  1292.     somRenewNoZero                : somMToken;
  1293.     somRenewNoInitNoZero          : somMToken;
  1294.     somAllocate                   : somMToken;
  1295.     somDeallocate                 : somMToken;
  1296.     somGetRdStub                  : somMToken;
  1297.     somGetNthMethodData           : somMToken;
  1298.                                   END;
  1299. VAR
  1300.   SOMClassClassData             : SOMClassClassDataStructure;
  1301.  
  1302. TYPE
  1303.   (*$SOM+ *)
  1304.   SOMClass = RECORD( SOMObject ) END;
  1305.   (*$SOM- *)
  1306.  
  1307.  
  1308. PROCEDURE( Self : PSOMClass ) somAddStaticMethod
  1309. (
  1310.   methodId         : somId;
  1311.   methodDescriptor : somId;
  1312.   method           : somMethodProc;
  1313.   redispatchStub   : somMethodProc;
  1314.   applyStub        : somMethodProc
  1315. )                  : somMToken;
  1316. (*
  1317.  *  Adds/overrides the indicated method, returns the value that
  1318.  *  should be used to set the method slot in the class data structure
  1319.  *  for this method name.
  1320.  *
  1321.  *  <methodDescriptor> is a somId for a string describing the calling
  1322.  *  sequence to this method as described in <somcGetNthMethodInfo>
  1323.  *  defined in the SOMObject class definition.
  1324.  *
  1325.  *  <method> is the actual method procedure for this method
  1326.  *
  1327.  *  <redispatchStub> is a procedure with the same calling sequence as
  1328.  *  <method> that re-dispatches the method to one of this class's
  1329.  *  dispatch functions.
  1330.  *
  1331.  *  <applyStub> is a procedure that takes a standard variable argument
  1332.  *  list data structure applies it to its target object by calling
  1333.  *  <method> with arguments derived from the data structure.  Its
  1334.  *  calling sequence is the same as the calling sequence of the
  1335.  *  dispatch methods defined in SOMObject.  This stub is used in the
  1336.  *  support of the dispatch methods used in some classes.  In classes
  1337.  *  where the dispatch functions do not need such a function this
  1338.  *  parameter may be null.
  1339.  *)
  1340.  
  1341.  
  1342. PROCEDURE( Self : PSOMClass ) somClassReady( );
  1343. (*
  1344.  *  This method is invoked when all of the static initialization for
  1345.  *  the class has been finished.  The default implementation simply
  1346.  *  registers the newly constructed class with the SOMClassMgr.
  1347.  *  Metaclasses may override this method to augment the class construction
  1348.  *  sequence in any way that they wish.
  1349.  *)
  1350.  
  1351.  
  1352. PROCEDURE( Self : PSOMClass ) somInitClass
  1353. (
  1354.   className         : ARRAY OF CHAR;
  1355.   parentClass       : PSOMObject;
  1356.   instanceSize      : INTEGER4;
  1357.   maxStaticMethods  : INT;
  1358.   majorVersion      : INTEGER4;
  1359.   minorVersion      : INTEGER4
  1360. );
  1361. (*
  1362.  *  Initializes <self>.
  1363.  *  <parentClass> is the parent (or parent class) of this class, it may
  1364.  *  be NULL in which case it defaults to SOMObject (actually
  1365.  *  SOMObjectClassData.classObject the class object for SOMObject).
  1366.  *  If a parent class is specifed then it must have already been created
  1367.  *  as a pointer to its class object is required.
  1368.  *
  1369.  *  <instanceSize> should be just the space needed for this class, it
  1370.  *  is not necessary to consider the parent class's (if any) space
  1371.  *  requirements.
  1372.  *
  1373.  *  <maxStaticMethods> should be just the static methods defined by
  1374.  *  this class, it is not necessary to consider the parent class's
  1375.  *  methods (if any), even if they are overriden in this class.
  1376.  *
  1377.  *  <majorVersion> indicates the major version number for this
  1378.  *  implementation of the class definition, and <minorVersion>
  1379.  *  indicates the minor version number.
  1380.  *)
  1381.  
  1382.  
  1383. PROCEDURE( Self : PSOMClass ) somOverrideSMethod
  1384. (
  1385.   methodId : somId;
  1386.   method   : somMethodProc
  1387. );
  1388. (*
  1389.  *  This method can be used instead of <somAddStaticMethod> or
  1390.  *  <somAddDynamicMethod> when it is known that the class' parent
  1391.  *  class already supports this method.  This call does not require the
  1392.  *  method descriptor and stub methods that the others do.
  1393.  *)
  1394.  
  1395.  
  1396. PROCEDURE( Self : PSOMClass ) somNew( ) : ADDRESS;
  1397. (*
  1398.  *  Make an instance of this class.  When applied to SOMClass, or any
  1399.  *  other metaclass object, this will produce a new class object;
  1400.  *  when applied to a regular class object, this will produce an
  1401.  *  instance of that class.  The somInit method of the newly created
  1402.  *  object is then invoked automatically.
  1403.  *)
  1404.  
  1405.  
  1406. PROCEDURE( Self : PSOMClass ) somNewNoInit( ) : ADDRESS;
  1407. (*
  1408.  *  Equivalent to somNew except that somInit is not automatically invoked.
  1409.  *)
  1410.  
  1411.  
  1412. PROCEDURE( Self : PSOMClass ) somRenew
  1413. (
  1414.   VAR obj : ARRAY OF BYTE
  1415. )         : ADDRESS;
  1416. (*
  1417.  *  Make an instance of this class, but use the space pointed to by
  1418.  *  <obj> rather than allocating new space for the object.  Note: no
  1419.  *  test is made to insure that <obj> points to enough space.  <obj>
  1420.  *  is returned, but it is now a pointer to a valid, initialized,
  1421.  *  object (the somInit method of the "renewed" object is invoked
  1422.  *  automatically).
  1423.  *)
  1424.  
  1425.  
  1426. PROCEDURE( Self : PSOMClass ) somRenewNoInit
  1427. (
  1428.   VAR obj : ARRAY OF BYTE
  1429. )         : ADDRESS;
  1430. (*
  1431.  *  Equivalent to somRenew except that somInit is not automatically invoked.
  1432.  *)
  1433.  
  1434.  
  1435. PROCEDURE( Self : PSOMClass )  somGetApplyStub
  1436. (
  1437.   methodId : somId
  1438. )          : somMethodProc;
  1439. (*
  1440.  *  Returns the apply stub associated with the specified method. NULL
  1441.  *  is returned if the method is not supported by this class.  An apply
  1442.  *  stub is a procedure that is called with a fixed calling sequence,
  1443.  *  namely (SOMObject *self, somId methodId, somId descriptor, ap_list
  1444.  *  ap) where <ap> is a varargs data structure that contains the actual
  1445.  *  argument list to be passed to the method.  The apply stub fowards
  1446.  *  the call to its associated method and then returns any result
  1447.  *  produced by the method.
  1448.  *)
  1449.  
  1450.  
  1451. PROCEDURE( Self : PSOMClass ) somGetClassData( ) : PsomClassDataStructure;
  1452. (*
  1453.  *  Returns a pointer to the static <className>ClassData structure.
  1454.  *)
  1455.  
  1456.  
  1457. PROCEDURE( Self : PSOMClass ) somGetClassMtab
  1458. ( ) : PsomMethodTab;
  1459. (*
  1460.  *  Returns a pointer to the method table of this class.
  1461.  *)
  1462.  
  1463.  
  1464. PROCEDURE( Self : PSOMClass ) somGetInstanceToken( ) : somDToken;
  1465. (*
  1466.  *  Returns a token that identifies the introduced portion of this class
  1467.  *  within itself or any derived class.  This token can be subsequently
  1468.  *  passed to the run-time somDataResolve function to locate the instance
  1469.  *  data introduced by this class.
  1470.  *)
  1471.  
  1472.  
  1473. PROCEDURE( Self : PSOMClass ) somGetMemberToken
  1474. (
  1475.   memberOffset  : INTEGER4;
  1476.   instanceToken : somDToken
  1477. )               : somDToken;
  1478. (*
  1479.  *  Returns a token that represents the data member at offset
  1480.  *  "memberOffset" within the introduced portion of the class identified
  1481.  *  by instanceToken.  The instance token must have been obtained from a
  1482.  *  previous invocation of somGetInstanceToken.  The returned member
  1483.  *  token can be subsequently passed to the run-time somDataResolve
  1484.  *  function to locate the data member.
  1485.  *)
  1486.  
  1487.  
  1488. PROCEDURE( Self : PSOMClass ) somGetInstanceOffset( ) : INTEGER4;
  1489. (*
  1490.  *  Returns the offset in the body part of this [class] object for the
  1491.  *  instance data introduced by this class, as the distance in bytes along
  1492.  *  the class' "left-hand" derivation path.
  1493.  *)
  1494.  
  1495.  
  1496. PROCEDURE( Self : PSOMClass ) somGetInstancePartSize( ) : INTEGER4;
  1497. (*
  1498.  *  Returns the size in bytes of the instance data introduced by this
  1499.  *  class.  This does not include the instance data space required for
  1500.  *  this class' ancestor or descendent classes.
  1501.  *)
  1502.  
  1503.  
  1504. PROCEDURE( Self : PSOMClass ) somGetInstanceSize( ) : INTEGER4;
  1505. (*
  1506.  *  Returns the total size of an instance of <self>.
  1507.  *  All instances of <self> have the same size.
  1508.  *)
  1509.  
  1510.  
  1511. PROCEDURE( Self : PSOMClass ) somGetMethodDescriptor
  1512. (
  1513.   methodId : somId
  1514. )          : somId;
  1515. (*
  1516.  *  Returns the method descriptor for the indicated method.  If
  1517.  *  this object does not support the indicated method then NULL is
  1518.  *  returned.
  1519.  *)
  1520.  
  1521.  
  1522. PROCEDURE( Self : PSOMClass ) somGetName( ) : zString;
  1523. (*
  1524.  *  Returns this object's class name as a NULL terminated string.
  1525.  *)
  1526.  
  1527.  
  1528. PROCEDURE( Self : PSOMClass ) somGetNumMethods( ) : INT;
  1529. (*
  1530.  *  Returns the number of methods currently supported by this class,
  1531.  *  including inherited methods (both static and dynamic).
  1532.  *)
  1533.  
  1534.  
  1535. PROCEDURE( Self : PSOMClass ) somGetNumStaticMethods( ) : INT;
  1536. (*
  1537.  *  Returns the number of static methods that this class has.  This is
  1538.  *  used by a child class in initializing its method table.
  1539.  *)
  1540.  
  1541.  
  1542. PROCEDURE( Self : PSOMClass ) somGetParent( ) : PSOMClass;
  1543. (*
  1544.  *  Returns the parent class of self (along its "left-hand" derivation
  1545.  *  path), if one exists and NULL otherwise.
  1546.  *)
  1547.  
  1548.  
  1549. PROCEDURE( Self : PSOMClass ) somGetPClsMtab( ) : PsomMethodTabList;
  1550. (*
  1551.  *  Returns a pointer to the method table list of this class's parent class
  1552.  *  (along its "left-hand" derivation path).  If this class is a root
  1553.  *  class (SOMObject), NULL is returned.
  1554.  *)
  1555.  
  1556.  
  1557. PROCEDURE( Self : PSOMClass ) somSetClassData
  1558. (
  1559.   cds : PsomClassDataStructure
  1560. );
  1561. (*
  1562.  *  Sets the class' pointer to the static <className>ClassData structure.
  1563.  *)
  1564.  
  1565.  
  1566. PROCEDURE( Self : PSOMClass ) somCheckVersion
  1567. (
  1568.   majorVersion : INTEGER4;
  1569.   minorVersion : INTEGER4
  1570. )              : INT;
  1571. (*
  1572.  *  Returns 1 (true) if the implementation of this class is
  1573.  *  compatible with the specified major and minor version number and
  1574.  *  false (0) otherwise.  An implementation is compatible with the
  1575.  *  specified version numbers if it has the same major version number
  1576.  *  and a minor version number that is equal to or greater than
  1577.  *  <minorVersion>.  The major, minor version number pair (0,0) is
  1578.  *  considered to match any version.  This method is usually called
  1579.  *  immediately after creating the class object to verify that a
  1580.  *  dynamically loaded class definition is compatible with a using
  1581.  *  application.
  1582.  *)
  1583.  
  1584.  
  1585. PROCEDURE( Self : PSOMClass ) somDescendedFrom
  1586. (
  1587.   aClassObj     : PSOMClass
  1588. )               : BOOLEAN;
  1589. (*
  1590.  *  Returns 1 (true) if <self> is a descendent class of <aClassObj> and
  1591.  *  0 (false) otherwise.  Note: a class object is considered to be
  1592.  *  descended itself for the purposes of this method.
  1593.  *)
  1594.  
  1595.  
  1596. PROCEDURE( Self : PSOMClass ) somSupportsMethod
  1597. (
  1598.   mId : somId
  1599. )     : BOOLEAN;
  1600. (*
  1601.  *  Returns 1 (true) if the indicated method is supported by this
  1602.  *  class and 0 (false) otherwise.
  1603.  *)
  1604.  
  1605.  
  1606. PROCEDURE( Self : PSOMClass ) somFindMethod
  1607. (
  1608.   methodId : somId;
  1609.   VAR m    : somMethodProc
  1610. )          : BOOLEAN;
  1611. (*
  1612.  *  Finds the method procedure associated with <methodId> for this
  1613.  *  class and sets <m> to it.  1 (true) is returned when the
  1614.  *  method procedure is directly callable and 0 (false) is returned
  1615.  *  when the method procedure is a dispatch function.
  1616.  *
  1617.  *  If the class does not support the specified method then
  1618.  *  <m> is set to NULL and the return value is meaningless.
  1619.  *
  1620.  *  Returning a dispatch function does not guarantee that a
  1621.  *  class supports the specified method; the dispatch may fail.
  1622.  *)
  1623.  
  1624.  
  1625. PROCEDURE( Self : PSOMClass ) somFindMethodOk
  1626. (
  1627.   methodId : somId;
  1628.   VAR m    : somMethodProc
  1629. )          : BOOLEAN;
  1630. (*
  1631.  *  Just like <somFindMethod> except that if the method is not
  1632.  *  supported then an error is raised and execution is halted.
  1633.  *)
  1634.  
  1635.  
  1636. PROCEDURE( Self : PSOMClass ) somFindSMethod
  1637. (
  1638.   methodId : somId
  1639. )          : somMethodProc;
  1640. (*
  1641.  *  Finds the indicated method, which must be a static method defined
  1642.  *  for this class, and returns a pointer to its method procedure.
  1643.  *
  1644.  *  If the method is not defined (as a static method or at all) for
  1645.  *  this class then a NULL pointer is returned.
  1646.  *)
  1647.  
  1648.  
  1649. PROCEDURE( Self : PSOMClass ) somFindSMethodOk
  1650. (
  1651.   methodId : somId
  1652. )          : somMethodProc;
  1653. (*
  1654.  *  Just like <somFindSMethod> except that an error is raised if the
  1655.  *  method is not defined for this class.
  1656.  *)
  1657.  
  1658.  
  1659. PROCEDURE( Self : PSOMClass ) somOverrideMtab( );
  1660. (*
  1661.  *  Overrides the method table pointers to point to the redispatch stubs.
  1662.  *  All the methods except somDispatch methods are overriden.
  1663.  *)
  1664.  
  1665.  
  1666. PROCEDURE( Self : PSOMClass ) somGetMethodToken
  1667. (
  1668.   methodId      : somId
  1669. )               : somMToken;
  1670. (*
  1671.  *  Returns the specified method's access token. This token can then
  1672.  *  be passed to method resolution routines, which use the token
  1673.  *  to select a method pointer from a method table.
  1674.  *)
  1675.  
  1676.  
  1677.  
  1678. PROCEDURE( Self : PSOMClass ) somGetPClsMtabs( ) : PsomMethodTabList;
  1679. (*
  1680.  *  A list of the method tables of this class's parent classes.
  1681.  *  If this class is a root class (SOMObject), NULL is returned.
  1682.  *)
  1683.  
  1684.  
  1685. PROCEDURE( Self : PSOMClass ) somInitMIClass
  1686. (
  1687.   inherit_vars      : LONGINT;
  1688.   className         : ARRAY OF CHAR;
  1689.   VAR parentClasses : SOMClass_SOMClassSequence;
  1690.   dataSize          : LONGINT;
  1691.   dataAlignment     : LONGINT;
  1692.   maxStaticMethods  : LONGINT;
  1693.   majorVersion      : LONGINT;
  1694.   minorVersion      : LONGINT
  1695. );
  1696. (*
  1697.  *  These methods implement the second phase of dynamic class creation:
  1698.  *  inheritance of interface and possibly implementation (instance
  1699.  *  variables) by suitable initialization of <self> (a class object).
  1700.  *  This primarily involves
  1701.  *  allocation of a method table for instances, and copying parent method
  1702.  *  table entries into the new table. In addition, the locations of
  1703.  *  instance variable groups are recorded (for those classes from which
  1704.  *  instance variables are inherited).
  1705.  *
  1706.  *  Implementation is always inherited when using somInitClass; this is the
  1707.  *  old single inheritance initialization method kept for binary
  1708.  *  compatability.
  1709.  *
  1710.  *  For somInitMIClass, the inherit_vars argument controls whether abstract
  1711.  *  or implementation inheritance is used. Inherit_vars is a 32 bit
  1712.  *  bit-vector. Implementation is inherited from parent i if the bit
  1713.  *  (1 SHL i) is on, or (i >= 32).
  1714.  *
  1715.  *  On a class-by-class basis, for each class ancestor, implementation
  1716.  *  inheritance always takes precidence over abstract inheritance. This is
  1717.  *  necessary to guarantee that procedures supporting parent method calls
  1718.  *  (available on non-abstract parents) are always supported by parent
  1719.  *  instance variables.
  1720.  *
  1721.  *  --  for somInitClass.
  1722.  *  <parentClass> is a pointer to the parent class of <self>
  1723.  *  or
  1724.  *  -- for somInitMIClass.
  1725.  *  <parentClasses> is a SOMClassSequence containing pointers to the
  1726.  *  parent classes. somInitMIClass makes a copy of this, so it may
  1727.  *  be freed upon return to the caller if this is desired.
  1728.  *
  1729.  *  <dataSize> is the space needed for the instance variables
  1730.  *  introduced by this class.
  1731.  *
  1732.  *  <dataAlignment> specifies the desired byte alignment for instance
  1733.  *  data introduced by this class. A value of 0 selects a system-wide default;
  1734.  *  any other argument is taken as the desired byte alignment multiple. Thus,
  1735.  *  for example, even if a byte multiple of 8 is needed for double precision
  1736.  *  values on a given system (so 8 is the default), a class whose instance data
  1737.  *  doesn't require this can indicate otherwise. If A is the next memory address
  1738.  *  available for holding instance data, the address that will be used is
  1739.  *  A + (A mod byte-alignment).
  1740.  *
  1741.  *  <maxStaticMethods> is the maximum number of static methods that will be
  1742.  *  added to the initialized class using addStaticMethod.
  1743.  *
  1744.  *  <majorVersion> indicates the major version number for this
  1745.  *  implementation of the class definition, and <minorVersion>
  1746.  *  indicates the minor version number.
  1747.  *)
  1748.  
  1749.  
  1750. PROCEDURE( Self : PSOMClass ) somGetVersionNumbers
  1751. (
  1752.   VAR majorVersion : LONGINT;
  1753.   VAR minorVersion : LONGINT
  1754. );
  1755. (*
  1756.  *  Returns for the class its major and minor version numbers in the
  1757.  *  corresponding output parameters.
  1758.  *)
  1759.  
  1760.  
  1761. PROCEDURE( Self : PSOMClass ) somLookupMethod
  1762. (
  1763.   methodId      : somId
  1764. )               : somMethodPtr;
  1765. (*
  1766.  *  Like <somFindSMethodOK> except that dynamic methods are allowed.
  1767.  *)
  1768.  
  1769.  
  1770.  
  1771. PROCEDURE( Self : PSOMClass ) somRenewNoZero
  1772. (
  1773.   VAR obj       : ARRAY OF BYTE
  1774. )               : ADDRESS;
  1775. (*
  1776.  *  Equivalent to somRenew except that object memory is not set to zeros.
  1777.  *)
  1778.  
  1779.  
  1780. PROCEDURE( Self : PSOMClass ) somRenewNoInitNoZero
  1781. (
  1782.   VAR obj       : ARRAY OF BYTE
  1783. )               : ADDRESS;
  1784. (*
  1785.  *  Equivalent to somRenewNoInit except that object memory is not set to zeros.
  1786.  *  [Initialization / Termination Group]
  1787.  *)
  1788.  
  1789.  
  1790. PROCEDURE( Self : PSOMClass ) somAllocate
  1791. (
  1792.   size          : LONGINT
  1793. )               : PSTRING;
  1794. (*
  1795.  *  Allocates memory, and returns a pointer to it. The default implementation
  1796.  *  for somAllocate (used by SOMClass) is to access default memory allocation
  1797.  *  through the external procedure variable, SOMMalloc.
  1798.  *)
  1799.  
  1800.  
  1801. PROCEDURE( Self : PSOMClass ) somDeallocate
  1802. (
  1803.   memptr        : PSTRING
  1804. );
  1805. (*
  1806.  *  Deallocates memory originally allocated using somAllocate. The default
  1807.  *  implementation for somDeallocate (used by SOMClass) is to access default
  1808.  *  memory deallocation from the external procedure variable, SOMFree.
  1809.  *)
  1810.  
  1811.  
  1812. PROCEDURE( Self : PSOMClass ) somGetRdStub
  1813. (
  1814.   methodId      : somId
  1815. )               : somMethodProc;
  1816. (*
  1817.  *  Returns a redispatch stub for the indicated method, if possible.
  1818.  *  If not possible (because a valid redispatch stub has not been
  1819.  *  registered, and there is insufficient information to dynamically
  1820.  *  construct one), then a NULL is returned.
  1821.  *)
  1822.  
  1823.  
  1824. PROCEDURE( Self : PSOMClass ) somGetNthMethodData
  1825. (
  1826.   n             : LONGINT;
  1827.   VAR md        : somMethodData
  1828. )               : BOOLEAN;
  1829. (*
  1830.  *  loads *md with the method data associated with the the nth method,
  1831.  *  or NULL if there is no such method. Returns true is successful;
  1832.  *  false otherwise.
  1833.  *)
  1834.  
  1835.  
  1836.  
  1837. (*************************************************************************
  1838.   'SOMClassMgr' Class API for Modula-2
  1839. **************************************************************************)
  1840.  
  1841. (*
  1842.  * One instance of SOMClassMgr is created during SOM initialization.
  1843.  * It acts as a run-time registry for all SOM class objects that have been
  1844.  * created or dynamically loaded by the current process. Each SOM class
  1845.  * automatically registers itself with the SOMClassMgr instance
  1846.  * ( pointed to by the global variable, SOMClassMgrObject) during the
  1847.  * final stage of its initialization.
  1848.  *)
  1849.  
  1850. CONST
  1851.   SOMClassMgr_MajorVersion  = 1;
  1852.   SOMClassMgr_MinorVersion  = 1;
  1853.  
  1854.  
  1855. (* A procedure to create the SOMClassMgr Class *)
  1856. PROCEDURE SOMClassMgrNewClass
  1857. ( majorVersion : INTEGER4;
  1858.   minorVersion : INTEGER4
  1859. )              : PSOMClass;
  1860.  
  1861.  
  1862. (* The static interface to SOMClassMgr and its instances *)
  1863. TYPE
  1864.   SOMClassMgrClassDataStructure   = RECORD
  1865.     classObject                     : PSOMClass;
  1866.     somFindClsInFile                : somMToken;
  1867.     somFindClass                    : somMToken;
  1868.     somClassFromId                  : somMToken;
  1869.     somRegisterClass                : somMToken;
  1870.     somUnregisterClass              : somMToken;
  1871.     somLocateClassFile              : somMToken;
  1872.     somLoadClassFile                : somMToken;
  1873.     somUnloadClassFile              : somMToken;
  1874.     somGetInitFunction              : somMToken;
  1875.     somMergeInto                    : somMToken;
  1876.     somGetRelatedClasses            : somMToken;
  1877.     somSubstituteClass              : somMToken;
  1878.     _get_somInterfaceRepository     : somMToken;
  1879.     _set_somInterfaceRepository     : somMToken;
  1880.     _get_somRegisteredClasses       : somMToken;
  1881.                                     END;
  1882. VAR
  1883.   SOMClassMgrClassData            : SOMClassMgrClassDataStructure;
  1884.  
  1885. TYPE
  1886.   (*$SOM+ *)
  1887.   SOMClassMgr = RECORD( SOMObject ) END;
  1888.   (*$SOM- *)
  1889.  
  1890. TYPE
  1891.   PPSOMClass = POINTER TO PSOMClass;
  1892.  
  1893. PROCEDURE( Self : PSOMClassMgr ) somLoadClassFile
  1894. (
  1895.   classId      : somId;
  1896.   majorVersion : INTEGER4;
  1897.   minorVersion : INTEGER4;
  1898.   file         : ARRAY OF CHAR
  1899. )              : PSOMClass;
  1900. (*
  1901.  *  Loads the class' code and initializes the class object.
  1902.  *)
  1903.  
  1904.  
  1905. PROCEDURE( Self : PSOMClassMgr ) somLocateClassFile
  1906. (
  1907.   classId      : somId;
  1908.   majorVersion : INTEGER4;
  1909.   minorVersion : INTEGER4
  1910. )              : zString;
  1911. (*
  1912.  *  Real implementation supplied by subclasses.  Default implementation
  1913.  *  returns the class name as the file name.   Subclasses may use
  1914.  *  version number info to assist in deriving the file name.
  1915.  *)
  1916.  
  1917.  
  1918. PROCEDURE( Self : PSOMClassMgr ) somRegisterClass
  1919. (
  1920.   classObj      : PSOMClass
  1921. );
  1922. (*
  1923.  *  Lets the class manager know that the specified class is installed
  1924.  *  and tells it where the class object is.
  1925.  *)
  1926.  
  1927.  
  1928. PROCEDURE( Self : PSOMClassMgr ) somUnloadClassFile
  1929. (
  1930.   classObj     : PSOMClass
  1931. )              : INT;
  1932. (*
  1933.  *  Releases the class' code and unregisters all classes in the
  1934.  *  same affinity group (see somGetRelatedClasses below).
  1935.  *)
  1936.  
  1937.  
  1938. PROCEDURE( Self : PSOMClassMgr ) somUnregisterClass
  1939. (
  1940.   classObj     : PSOMClass
  1941. )              : INT;
  1942. (*
  1943.  *  Free the class object and removes the class from the SOM registry.
  1944.  *  If the class caused dynamic loading to occur, it is also unloaded
  1945.  *  (causing its entire affinity group to be unregistered as well).
  1946.  *)
  1947.  
  1948.  
  1949. PROCEDURE( Self : PSOMClassMgr ) somGetInitFunction( ) : zString;
  1950. (*
  1951.  *  Supplies the name of the initialization function in the class' code
  1952.  *  file.  Default implementation returns SOM.SOMClassInitFuncName().
  1953.  *)
  1954.  
  1955.  
  1956. PROCEDURE( Self : PSOMClassMgr ) somGetRelatedClasses
  1957. (
  1958.   classObj     : PSOMClass
  1959. )              : PPSOMClass;
  1960. (*
  1961.  *  Returns an array of class objects that were all registered during
  1962.  *  the dynamic loading of a class. These classes are considered to
  1963.  *  define an affinity group.  Any class is a member of at most one
  1964.  *  affinity group. The affinity group returned by this call is the
  1965.  *  one containing the class identified by classObj.  The first element
  1966.  *  in the array is the class that caused the group to be loaded, or the
  1967.  *  special value -1 which means that the SOMClassMgr is currently in the
  1968.  *  process of unregistering and deleting the affinity group (only
  1969.  *  SOMClassMgr subclasses would ever see this value).
  1970.  *  The remainder of the array (elements one thru n) consists of
  1971.  *  pointers to class objects ordered in reverse chronological sequence
  1972.  *  to that in which they were originally registered.  This list includes
  1973.  *  the given argument, classObj, as one of its elements, as well as the
  1974.  *  class, if any, returned as element[0] above.  The array is terminated
  1975.  *  by a NULL pointer as the last element.  Use SOMFree to release the
  1976.  *  array when it is no longer needed.  If the supplied class was not
  1977.  *  dynamically loaded, it is not a member of any affinity
  1978.  *  group and NULL is returned.
  1979.  *)
  1980.  
  1981.  
  1982. PROCEDURE( Self : PSOMClassMgr ) somClassFromId
  1983. (
  1984.   classId : somId
  1985. )         : PSOMClass;
  1986. (*
  1987.  *  Finds the class object, given its Id, if it already exists.
  1988.  *  Does not load the class.  Returns NULL if the class object does
  1989.  *  not yet exist.
  1990.  *)
  1991.  
  1992.  
  1993. PROCEDURE( Self : PSOMClassMgr ) somFindClass
  1994. (
  1995.   classId      : somId;
  1996.   majorVersion : INTEGER4;
  1997.   minorVersion : INTEGER4
  1998. )              : PSOMClass;
  1999. (*
  2000.  *  Returns the class object for the specified class.  This may result
  2001.  *  in dynamic loading.  Uses somLocateClassFile to obtain the name of
  2002.  *  the file where the class' code resides, then uses somFindClsInFile.
  2003.  *)
  2004.  
  2005.  
  2006. PROCEDURE( Self : PSOMClassMgr ) somFindClsInFile
  2007. (
  2008.   classId      : somId;
  2009.   majorVersion : INTEGER4;
  2010.   minorVersion : INTEGER4;
  2011.   file         : ARRAY OF CHAR
  2012. )              : PSOMClass;
  2013. (*
  2014.  *  Returns the class object for the specified class.  This may result
  2015.  *  in dynamic loading.  If the class already exists <file> is ignored,
  2016.  *  otherwise it is used to locate and dynamically load the class.
  2017.  *  Values of 0 for major and minor version numbers bypass version checking.
  2018.  *)
  2019.  
  2020.  
  2021. PROCEDURE( Self : PSOMClassMgr ) somMergeInto
  2022. (
  2023.   targetObj : PSOMClassMgr
  2024. );
  2025. (*
  2026.  *  Merges the SOMClassMgr registry information from the receiver to
  2027.  *  <targetObj>.  <targetObj> is required to be an instance of SOMClassMgr
  2028.  *  or one of its subclasses.  At the completion of this operation,
  2029.  *  the <targetObj> should be able to function as a replacement for the
  2030.  *  receiver.  At the end of the operation the receiver object (which is
  2031.  *  then in a newly uninitialized state) is freed.  Subclasses that
  2032.  *  override this method should similarly transfer their sections of
  2033.  *  the object and pass this method to their parent as the final step.
  2034.  *  If the receiving object is the distinguished instance pointed to
  2035.  *  from the global variable SOMClassMgrObject, SOMCLassMgrObject is
  2036.  *  then reassigned to point to <targetObj>.
  2037.  *)
  2038.  
  2039.  
  2040. PROCEDURE( Self : PSOMClassMgr ) somSubstituteClass
  2041. (
  2042.   origClassName : ARRAY OF CHAR;
  2043.   newClassName  : ARRAY OF CHAR
  2044. )               : LONGINT;
  2045. (*
  2046.  *  This method causes the somFindClass, somFindClsInFile, and
  2047.  *  somClassFromId methods to return the class named newClassName
  2048.  *  whenever they would have normally returned the class named
  2049.  *  origClassName.  This effectively results in class <newClassName>
  2050.  *  replacing or substituting itself for class <origClassName>.
  2051.  *  Some restrictions are enforced to insure that this works well.
  2052.  *  Both class <origClassName> and class <newClassName> must
  2053.  *  have been already registered before issuing this method, and newClass
  2054.  *  must be an immediate child of origClass.  In addition (although not
  2055.  *  enforceable), no instances should exist of either class at the time
  2056.  *  this method is invoked.  A return value of zero indicates success;
  2057.  *  a non-zero value indicates an error was detected.
  2058.  *)
  2059.  
  2060.  
  2061. (*************************************************************************
  2062.    Types, records, constants and procedures in support
  2063.    of CORBA extensions to the SOM run-time
  2064. **************************************************************************)
  2065.  
  2066.  
  2067. TYPE (* in SOM, a CORBA object is a SOM object *)
  2068.   CORBAObject            = SOMObject;
  2069.  
  2070. TYPE
  2071.   Object                 = CORBAObject;
  2072.  
  2073. TYPE (* CORBA 5.7, p.89 *)
  2074.   boolean                = BOOLEAN;
  2075.   octet                  = SHORTCARD;
  2076.   string                 = PSTRING;
  2077.  
  2078. TYPE (* CORBA 7.5.1, p. 129 *)
  2079.   Identifier             = string;
  2080.  
  2081. TYPE (* CORBA 4.13, p. 80 *)
  2082.   exception_type         = LONGCARD;
  2083.   completion_status      = LONGCARD;
  2084.   StExcep                = RECORD
  2085.     minor                  : LONGCARD;
  2086.     completed              : completion_status;
  2087.                            END;
  2088.   Environment            = RECORD
  2089.     _major                 : exception_type;
  2090.     exception              : RECORD
  2091.       _exception_name        : POINTER TO CHAR;
  2092.       _params                : ADDRESS;
  2093.                              END;
  2094.     _somdAnchor            : ADDRESS;
  2095.                            END;
  2096.   PEnvironment           = POINTER TO Environment;
  2097.  
  2098. CONST (* for exception_type *)
  2099.   NO_EXCEPTION           = 0;
  2100.   USER_EXCEPTION         = 1;
  2101.   SYSTEM_EXCEPTION       = 2;
  2102.  
  2103. CONST (* for completion_status *)
  2104.   YES                    = 0;
  2105.   NO                     = 1;
  2106.   MAYBE                  = 2;
  2107.  
  2108. TYPE (* CORBA 7.6.1, p.139 plus 5.7, p.89 enum Data Type Mapping *)
  2109.   TCKind                 = LONGCARD;
  2110. CONST
  2111.   TypeCode_tk_null       =   1;
  2112.   TypeCode_tk_void       =   2;
  2113.   TypeCode_tk_short      =   3;
  2114.   TypeCode_tk_long       =   4;
  2115.   TypeCode_tk_ushort     =   5;
  2116.   TypeCode_tk_ulong      =   6;
  2117.   TypeCode_tk_float      =   7;
  2118.   TypeCode_tk_double     =   8;
  2119.   TypeCode_tk_boolean    =   9;
  2120.   TypeCode_tk_char       =  10;
  2121.   TypeCode_tk_octet      =  11;
  2122.   TypeCode_tk_any        =  12;
  2123.   TypeCode_tk_TypeCode   =  13;
  2124.   TypeCode_tk_Principal  =  14;
  2125.   TypeCode_tk_objref     =  15;
  2126.   TypeCode_tk_struct     =  16;
  2127.   TypeCode_tk_union      =  17;
  2128.   TypeCode_tk_enum       =  18;
  2129.   TypeCode_tk_string     =  19;
  2130.   TypeCode_tk_sequence   =  20;
  2131.   TypeCode_tk_array      =  21;
  2132.   TypeCode_tk_pointer    = 101; (* SOM extension *)
  2133.   TypeCode_tk_self       = 102; (* SOM extension *)
  2134.   TypeCode_tk_foreign    = 103; (* SOM extension *)
  2135.  
  2136. CONST (* Short forms of tk_<x> enumerators *)
  2137.   tk_null                = TypeCode_tk_null;
  2138.   tk_void                = TypeCode_tk_void;
  2139.   tk_short               = TypeCode_tk_short;
  2140.   tk_long                = TypeCode_tk_long;
  2141.   tk_ushort              = TypeCode_tk_ushort;
  2142.   tk_ulong               = TypeCode_tk_ulong;
  2143.   tk_float               = TypeCode_tk_float;
  2144.   tk_double              = TypeCode_tk_double;
  2145.   tk_boolean             = TypeCode_tk_boolean;
  2146.   tk_char                = TypeCode_tk_char;
  2147.   tk_octet               = TypeCode_tk_octet;
  2148.   tk_any                 = TypeCode_tk_any;
  2149.   tk_TypeCode            = TypeCode_tk_TypeCode;
  2150.   tk_Principal           = TypeCode_tk_Principal;
  2151.   tk_objref              = TypeCode_tk_objref;
  2152.   tk_struct              = TypeCode_tk_struct;
  2153.   tk_union               = TypeCode_tk_union;
  2154.   tk_enum                = TypeCode_tk_enum;
  2155.   tk_string              = TypeCode_tk_string;
  2156.   tk_sequence            = TypeCode_tk_sequence;
  2157.   tk_array               = TypeCode_tk_array;
  2158.   tk_pointer             = TypeCode_tk_pointer;
  2159.   tk_self                = TypeCode_tk_self;
  2160.   tk_foreign             = TypeCode_tk_foreign;
  2161.  
  2162. TYPE
  2163.   TypeCode               = ADDRESS;
  2164.  
  2165. TYPE (* CORBA 5.7, p.89 *)
  2166.   any                    = RECORD
  2167.     _type                  : TypeCode;
  2168.     _value                 : ADDRESS;
  2169.                            END;
  2170.  
  2171. PROCEDURE somExceptionId
  2172. ( VAR ev                 : Environment
  2173. )                        : PSTRING;
  2174.  
  2175. PROCEDURE somExceptionValue
  2176. ( VAR ev                 : Environment
  2177. )                        : ADDRESS;
  2178.  
  2179. PROCEDURE somExceptionFree
  2180. ( VAR ev                 : Environment
  2181. );
  2182.  
  2183. PROCEDURE somSetException
  2184. ( VAR ev                 : Environment;
  2185.   major                  : exception_type;
  2186.   exception_name         : ARRAY OF CHAR;
  2187.   VAR params             : ARRAY OF BYTE
  2188. );
  2189.  
  2190. PROCEDURE somGetGlobalEnvironment
  2191. ( )                      : PEnvironment;
  2192.  
  2193.  
  2194. (* aliased function name per CORBA 5.19, p.99 *)
  2195. PROCEDURE exception_id
  2196. ( VAR ev                 : Environment
  2197. )                        : PSTRING;
  2198.  
  2199. (* aliased function name per CORBA 5.19, p.99 *)
  2200. PROCEDURE exception_value
  2201. ( VAR ev                 : Environment
  2202. )                        : ADDRESS;
  2203.  
  2204. (* aliased function name per CORBA 5.19, p.99 *)
  2205. PROCEDURE exception_free
  2206. ( VAR ev                 : Environment
  2207. );
  2208.  
  2209.  
  2210. END SOM.
  2211.