Structure.st
changeset 616 b5c07da2df11
parent 429 ffc4e2ab5581
child 654 da9ab8a701fd
equal deleted inserted replaced
615:34672ab134f7 616:b5c07da2df11
    14 	instanceVariableNames:'superclass flags methodDictionary otherSupers instSize i1 i2 i3
    14 	instanceVariableNames:'superclass flags methodDictionary otherSupers instSize i1 i2 i3
    15 		i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 i21
    15 		i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 i21
    16 		i22 i23 i24 i25 i26 i27 i28 i29 i30 i31 i32 i33 i34 i35 i36 i37
    16 		i22 i23 i24 i25 i26 i27 i28 i29 i30 i31 i32 i33 i34 i35 i36 i37
    17 		i38 i39 i40 i41 i42 i43 i44 i45 i46 i47 i48 i49 i50'
    17 		i38 i39 i40 i41 i42 i43 i44 i45 i46 i47 i48 i49 i50'
    18 	classVariableNames:'OneInstance DummyClass ReadAccessMethods WriteAccessMethods
    18 	classVariableNames:'OneInstance DummyClass ReadAccessMethods WriteAccessMethods
    19 		OtherMethods'
    19 		OtherMethods OtherSelectors'
    20 	poolDictionaries:''
    20 	poolDictionaries:''
    21 	category:'Programming-Support'
    21 	category:'Programming-Support'
    22 !
    22 !
    23 
    23 
    24 !Structure  class methodsFor:'documentation'!
    24 !Structure class methodsFor:'documentation'!
    25 
    25 
    26 copyright
    26 copyright
    27 "
    27 "
    28  COPYRIGHT (c) 1996 by Claus Gittinger
    28  COPYRIGHT (c) 1996 by Claus Gittinger
    29               All Rights Reserved
    29               All Rights Reserved
    37 "
    37 "
    38 !
    38 !
    39 
    39 
    40 documentation
    40 documentation
    41 "
    41 "
    42     are you tired of using arrays or identityDictionaries, when
    42     This is an experimental class, stressing the metaObject capabilities.
    43     multiple values have to be returned from some method, AND
    43 
    44     you dont want to add many stupid dummy data-holder classes to
    44     Structures are objects which are class-less,
    45     avoid the above ?
    45     only holding some values, and provide a protocol to access
    46     (for example, the value as returned by Method>>who) 
    46     those fields. In addition, they support the array-protocol,
    47 
    47     so they can be used as backward compatible replacements in
    48     Here is a goody to return an object which is class-less,
       
    49     only holding some values, and provides a protocol to access
       
    50     those fields. In addition, it supports the array-protocol,
       
    51     so it can be used as a backward compatible replacement in
       
    52     places where arrays were returned.
    48     places where arrays were returned.
    53     
    49     (However, we recommend using private classes, since they are easier
    54     For example, in Method>>who, instead of returning:
    50      to understand and aintain).
    55         ^ Array with:cls with:selector
    51 
    56     you can also return:
    52     For example, some structure object can be create with:
    57         ^ Structure with:#containingClass->cls with:#selector->selector
    53         ^ Structure with:#foo->'someFooValue' with:#bar->'someBarValue'
    58 
    54 
    59     and access these values either as:
    55     and access these values either as:
    60         retVal at:1     -> returns the cls
    56         retVal at:1     -> returns the foo instvar value
    61         retVal at:2     -> returns the selector
    57         retVal at:2     -> returns the bar instvar value
    62     or (much more convenient and readable) as:
    58     or (much more convenient and readable) as:
    63         retVal containingClass
    59         retVal foo
    64         retVal selector
    60         retVal bar
    65 
    61 
    66     implementation note:
    62     Implementation note:
    67         this is a very tricky (but fully legal) implementation,
    63         this is a very tricky (but fully legal) implementation,
    68         creating an objects which is its own class. 
    64         creating an object which is its own class. 
    69         Therefore, no additional overhead by extra objects is involved.
    65         Therefore, no additional overhead by extra (class) objects is involved.
    70         
    66         These are very lightweight objects.
       
    67 
    71         Another prove that smalltalk is a powerful & flexible programming language.
    68         Another prove that smalltalk is a powerful & flexible programming language.
    72         However, some smalltalk systems crash if your try this ;-)
    69         However, some smalltalk systems crash if your try this ;-)
    73 
    70 
    74     CAVEAT:
    71     CAVEAT:
       
    72         tricky implementation - not the full object protocol is supported;
    75         a maximum of 50 instance variables is allowed.
    73         a maximum of 50 instance variables is allowed.
       
    74 
       
    75     [WARNING:]
       
    76         this is an experimental goody - for our amusement and not meant
       
    77         to be used in real applications.
       
    78         It may be removed without notice and/or no longer maintained in the furure.
    76 
    79 
    77     [author:]
    80     [author:]
    78         Claus Gittinger
    81         Claus Gittinger
    79 
    82 
    80     [see also:]
    83     [see also:]
   112                                                                 [exEnd]
   115                                                                 [exEnd]
   113 
   116 
   114 "
   117 "
   115 ! !
   118 ! !
   116 
   119 
   117 !Structure  class methodsFor:'initialization'!
   120 !Structure class methodsFor:'initialization'!
   118 
   121 
   119 initialize
   122 initialize
   120     OneInstance isNil ifTrue:[
   123     OneInstance isNil ifTrue:[
   121         OneInstance := self basicNew.
   124         OneInstance := self basicNew.
   122 
   125 
   123         DummyClass := Behavior shallowCopy.
   126         DummyClass := Behavior shallowCopy.
   124         DummyClass flags:(Behavior flagBehavior bitOr:Behavior flagPointers).
   127         DummyClass flags:(Behavior flagBehavior bitOr:Behavior flagPointers).
   125 
   128 
   126         ReadAccessMethods := (1 to:50) 
   129         ReadAccessMethods := (1 to:50) 
   127                                 collect:[:i | 
   130                                 collect:[:i | |m|
   128                                         (self compiledMethodAt:('i', i printString) asSymbol)
   131                                             m := self compiledMethodAt:('i', i printString) asSymbol.
       
   132                                             (m notNil and:[m isLazyMethod]) ifTrue:[m makeRealMethod].
       
   133                                             m
   129                                 ].
   134                                 ].
   130         WriteAccessMethods := (1 to:50) 
   135         WriteAccessMethods := (1 to:50) 
   131                                 collect:[:i | 
   136                                 collect:[:i | |m|
   132                                         (self compiledMethodAt:('i', i printString,':') asSymbol)
   137                                             m := self compiledMethodAt:('i', i printString , ':') asSymbol.
       
   138                                             (m notNil and:[m isLazyMethod]) ifTrue:[m makeRealMethod].
       
   139                                             m
   133                                 ].
   140                                 ].
   134 
   141 
   135         OtherMethods := Array new:6.
   142         OtherMethods := OrderedCollection new.
   136         OtherMethods at:1 put:(self compiledMethodAt:#doesNotUnderstand:).
   143         OtherMethods 
   137         OtherMethods at:2 put:(Object compiledMethodAt:#class).
   144             add:(self compiledMethodAt:#doesNotUnderstand:);
   138         OtherMethods at:3 put:(Object compiledMethodAt:#at:).
   145             add:(Object compiledMethodAt:#class);
   139         OtherMethods at:4 put:(Object compiledMethodAt:#at:put:).
   146             add:(Object compiledMethodAt:#identityHash);
   140         OtherMethods at:5 put:(Object compiledMethodAt:#basicAt:).
   147             add:(Object compiledMethodAt:#at:);
   141         OtherMethods at:6 put:(Object compiledMethodAt:#basicAt:put:).
   148             add:(Object compiledMethodAt:#at:put:);
       
   149             add:(Object compiledMethodAt:#basicAt:);
       
   150             add:(Object compiledMethodAt:#basicAt:put:);
       
   151             add:(Object compiledMethodAt:#printString);
       
   152             add:(Object compiledMethodAt:#printOn:);
       
   153             add:(Object compiledMethodAt:#addDependent:);
       
   154             add:(Object compiledMethodAt:#removeDependent:);
       
   155             add:(Object compiledMethodAt:#dependents);
       
   156             add:(Object compiledMethodAt:#dependents:);
       
   157             add:(Object compiledMethodAt:#perform:);
       
   158             add:(Object compiledMethodAt:#perform:with:).
       
   159         OtherMethods := OtherMethods asArray.
       
   160 
       
   161         OtherSelectors := #(#doesNotUnderstand: 
       
   162                             #class #identityHash
       
   163                             #at: #at:put: #basicAt: #basicAt:put: 
       
   164                             #printString #printOn:
       
   165                             #addDependent: #removeDependent: #dependents #dependents:
       
   166                             #perform: #perform:with:).
   142     ].
   167     ].
   143 
   168 
   144     "
   169     "
   145      OneInstance := nil.
   170      OneInstance := nil.
   146      self initialize.
   171      self initialize.
   147     "
   172     "
   148 
   173 
   149     "Modified: 21.9.1996 / 16:01:48 / cg"
   174     "Modified: 21.9.1996 / 16:01:48 / cg"
   150 ! !
   175 ! !
   151 
   176 
   152 !Structure  class methodsFor:'instance creation'!
   177 !Structure class methodsFor:'instance creation'!
   153 
   178 
   154 newWith:names
   179 newWith:names
   155     "return a new structure containing fields as passed in the names collection.
   180     "return a new structure containing fields as passed in the names collection.
   156      The argument must be a sequenceable collection of symbols.
   181      The argument must be a sequenceable collection of symbols.
   157      The new structures values are all initialized to nil."
   182      The new structures values are all initialized to nil."
   168 newWith:names values:values
   193 newWith:names values:values
   169     "return a new structure containing fields as passed in the names collection.
   194     "return a new structure containing fields as passed in the names collection.
   170      The argument must be a sequenceable collection of symbols.
   195      The argument must be a sequenceable collection of symbols.
   171      The new structures values are set to corresponding values from the second argument, values."
   196      The new structures values are set to corresponding values from the second argument, values."
   172 
   197 
   173     |cls arr sels mthds dummyClass|
   198     |cls arr sels mthds dummyClass nInsts|
       
   199 
       
   200     nInsts := names size.
   174 
   201 
   175     sels := names collect:[:nm | nm asSymbol].
   202     sels := names collect:[:nm | nm asSymbol].
   176     sels := sels , (names collect:[:nm | (nm , ':') asSymbol]).
   203     sels := sels , (names collect:[:nm | (nm , ':') asSymbol]).
   177     sels := sels , #(#doesNotUnderstand: #class #at: #at:put: #basicAt: #basicAt:put:).
   204     sels := sels , OtherSelectors.
   178 
   205 
   179     mthds := ReadAccessMethods copyTo:names size. 
   206     mthds := ReadAccessMethods copyTo:nInsts. 
   180     mthds := mthds , (WriteAccessMethods copyTo:names size).
   207     mthds := mthds , (WriteAccessMethods copyTo:nInsts).
   181     mthds := mthds , OtherMethods.
   208     mthds := mthds , OtherMethods.
   182 
   209 
   183     "/ create a prototype object as an array ...
   210     "/ create a prototype object as an array ...
   184 
   211     "/ the object will be its own class, and have the indexable flag bit set;
   185     arr := Array new:(names size + 5).
   212     "/ therefore, the first 5 instVars must correspond to Behavior instvars,
       
   213     "/ the remaining ones will be the indexed instvars.
       
   214 
       
   215     arr := Array new:(nInsts + 5).
   186     arr at:1 put:nil.                                                   "/ superclass
   216     arr at:1 put:nil.                                                   "/ superclass
   187     arr at:2 put:(Behavior flagBehavior bitOr:Behavior flagPointers).   "/ flags
   217     arr at:2 put:(Behavior flagBehavior bitOr:Behavior flagPointers).   "/ flags
   188     arr at:3 put:(MethodDictionary withKeys:sels andValues:mthds).      "/ selectors & methods
   218     arr at:3 put:(MethodDictionary withKeys:sels andValues:mthds).      "/ selectors & methods
   189     arr at:4 put:nil.                                                   "/ other supers
   219     arr at:4 put:nil.                                                   "/ other supers
   190     arr at:5 put:5.                                                     "/ instSize 
   220     arr at:5 put:5.                                                     "/ instSize 
   273     "
   303     "
   274      Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world'
   304      Structure with:#foo->'foo' with:#bar->'bar' with:#baz->'baz' with:#hello->'hello' with:#world->'world'
   275     "
   305     "
   276 ! !
   306 ! !
   277 
   307 
       
   308 !Structure class methodsFor:'special'!
       
   309 
       
   310 primAddSelector:newSelector withMethod:newMethod
       
   311     "must reinit myself when methods are accepted."
       
   312 
       
   313     |val|
       
   314 
       
   315     val := super primAddSelector:newSelector withMethod:newMethod.
       
   316     OneInstance := nil.
       
   317     self initialize.
       
   318     ^ val
       
   319 ! !
       
   320 
   278 !Structure methodsFor:'accessing'!
   321 !Structure methodsFor:'accessing'!
   279 
   322 
   280 flags
   323 flags
   281     "return the flags - required class protocol"
   324     "return the flags - required class protocol"
   282 
   325 
   292 
   335 
   293     "Created: 13.5.1996 / 21:19:23 / cg"
   336     "Created: 13.5.1996 / 21:19:23 / cg"
   294 !
   337 !
   295 
   338 
   296 i1
   339 i1
   297     "return the first instance variable"
   340     "prototype method to return the first instance variable"
   298 
   341 
   299     ^ i1
   342     ^ i1
   300 
   343 
   301     "Created: 13.5.1996 / 21:19:25 / cg"
   344     "Created: 13.5.1996 / 21:19:25 / cg"
   302 !
   345 !
   303 
   346 
   304 i10
   347 i10
   305     "return i10"
   348     "prototype method to return the 10th instance variable"
   306 
   349 
   307     ^ i10
   350     ^ i10
   308 
   351 
   309     "Created: 13.5.1996 / 21:19:27 / cg"
   352     "Created: 13.5.1996 / 21:19:27 / cg"
   310 !
   353 !
   311 
   354 
   312 i10:something
   355 i10:something
   313     "set i10"
   356     "prototype method to set the 10th instance variable"
   314 
   357 
   315     i10 := something.
   358     i10 := something.
   316 
   359 
   317     "Created: 13.5.1996 / 21:19:27 / cg"
   360     "Created: 13.5.1996 / 21:19:27 / cg"
   318 !
   361 !
   324 
   367 
   325     "Created: 13.5.1996 / 21:19:27 / cg"
   368     "Created: 13.5.1996 / 21:19:27 / cg"
   326 !
   369 !
   327 
   370 
   328 i11:something
   371 i11:something
   329     "set i11"
   372     "prototype method to set the 11th instance variable"
   330 
   373 
   331     i11 := something.
   374     i11 := something.
   332 
   375 
   333     "Created: 13.5.1996 / 21:19:27 / cg"
   376     "Created: 13.5.1996 / 21:19:27 / cg"
   334 !
   377 !
   460 
   503 
   461     "Created: 13.5.1996 / 21:19:29 / cg"
   504     "Created: 13.5.1996 / 21:19:29 / cg"
   462 !
   505 !
   463 
   506 
   464 i1:something
   507 i1:something
   465     "set i1"
   508     "prototype method to set the 1st instance variable"
   466 
   509 
   467     i1 := something.
   510     i1 := something.
   468 
   511 
   469     "Created: 13.5.1996 / 21:19:25 / cg"
   512     "Created: 13.5.1996 / 21:19:25 / cg"
   470 !
   513 !
   471 
   514 
   472 i2
   515 i2
   473     "return i2"
   516     "prototype method to return the 2nd instance variable"
   474 
   517 
   475     ^ i2
   518     ^ i2
   476 
   519 
   477     "Created: 13.5.1996 / 21:19:25 / cg"
   520     "Created: 13.5.1996 / 21:19:25 / cg"
   478 !
   521 !
   636 
   679 
   637     "Created: 21.9.1996 / 16:06:22 / cg"
   680     "Created: 21.9.1996 / 16:06:22 / cg"
   638 !
   681 !
   639 
   682 
   640 i2:something
   683 i2:something
   641     "set i2"
   684     "prototype method to set the 2nd instance variable"
   642 
   685 
   643     i2 := something.
   686     i2 := something.
   644 
   687 
   645     "Created: 13.5.1996 / 21:19:25 / cg"
   688     "Created: 13.5.1996 / 21:19:25 / cg"
   646 !
   689 !
   647 
   690 
   648 i3
   691 i3
   649     "return i3"
   692     "prototype method to return the 3rd instance variable"
   650 
   693 
   651     ^ i3
   694     ^ i3
   652 
   695 
   653     "Created: 13.5.1996 / 21:19:25 / cg"
   696     "Created: 13.5.1996 / 21:19:25 / cg"
   654 !
   697 !
   804 
   847 
   805     "Created: 21.9.1996 / 16:06:22 / cg"
   848     "Created: 21.9.1996 / 16:06:22 / cg"
   806 !
   849 !
   807 
   850 
   808 i3:something
   851 i3:something
   809     "set i3"
   852     "prototype method to set the 3rd instance variable"
   810 
   853 
   811     i3 := something.
   854     i3 := something.
   812 
   855 
   813     "Created: 13.5.1996 / 21:19:25 / cg"
   856     "Created: 13.5.1996 / 21:19:25 / cg"
   814 !
   857 !
   815 
   858 
   816 i4
   859 i4
   817     "return i4"
   860     "prototype method to return the 4th instance variable"
   818 
   861 
   819     ^ i4
   862     ^ i4
   820 
   863 
   821     "Created: 13.5.1996 / 21:19:25 / cg"
   864     "Created: 13.5.1996 / 21:19:25 / cg"
   822 !
   865 !
   823 
   866 
       
   867 i40
       
   868     "return the value of the instance variable 'i40' (automatically generated)"
       
   869 
       
   870     ^ i40!
       
   871 
   824 i40:something
   872 i40:something
   825     "set i40"
   873     "prototype method"
   826 
   874 
   827     i40 := something.
   875     i40 := something.
   828 
   876 
   829     "Created: 21.9.1996 / 16:06:22 / cg"
   877     "Created: 21.9.1996 / 16:06:22 / cg"
   830 !
   878 !
   831 
   879 
   832 i41
   880 i41
   833     "return i41"
   881     "prototype method"
   834 
   882 
   835     ^ i41
   883     ^ i41
   836 
   884 
   837     "Created: 21.9.1996 / 16:06:23 / cg"
   885     "Created: 21.9.1996 / 16:06:23 / cg"
   838 !
   886 !
   839 
   887 
   840 i41:something
   888 i41:something
   841     "set i41"
   889     "prototype method"
   842 
   890 
   843     i41 := something.
   891     i41 := something.
   844 
   892 
   845     "Created: 21.9.1996 / 16:06:23 / cg"
   893     "Created: 21.9.1996 / 16:06:23 / cg"
   846 !
   894 !
   847 
   895 
   848 i42
   896 i42
   849     "return i42"
   897     "prototype method"
   850 
   898 
   851     ^ i42
   899     ^ i42
   852 
   900 
   853     "Created: 21.9.1996 / 16:06:23 / cg"
   901     "Created: 21.9.1996 / 16:06:23 / cg"
   854 !
   902 !
   855 
   903 
   856 i42:something
   904 i42:something
   857     "set i42"
   905     "prototype method"
   858 
   906 
   859     i42 := something.
   907     i42 := something.
   860 
   908 
   861     "Created: 21.9.1996 / 16:06:23 / cg"
   909     "Created: 21.9.1996 / 16:06:23 / cg"
   862 !
   910 !
   863 
   911 
   864 i43
   912 i43
   865     "return i43"
   913     "prototype method"
   866 
   914 
   867     ^ i43
   915     ^ i43
   868 
   916 
   869     "Created: 21.9.1996 / 16:06:23 / cg"
   917     "Created: 21.9.1996 / 16:06:23 / cg"
   870 !
   918 !
   871 
   919 
   872 i43:something
   920 i43:something
   873     "set i43"
   921     "prototype method"
   874 
   922 
   875     i43 := something.
   923     i43 := something.
   876 
   924 
   877     "Created: 21.9.1996 / 16:06:23 / cg"
   925     "Created: 21.9.1996 / 16:06:23 / cg"
   878 !
   926 !
   879 
   927 
   880 i44
   928 i44
   881     "return i44"
   929     "prototype method"
   882 
   930 
   883     ^ i44
   931     ^ i44
   884 
   932 
   885     "Created: 21.9.1996 / 16:06:23 / cg"
   933     "Created: 21.9.1996 / 16:06:23 / cg"
   886 !
   934 !
   887 
   935 
   888 i44:something
   936 i44:something
   889     "set i44"
   937     "prototype method"
   890 
   938 
   891     i44 := something.
   939     i44 := something.
   892 
   940 
   893     "Created: 21.9.1996 / 16:06:23 / cg"
   941     "Created: 21.9.1996 / 16:06:23 / cg"
   894 !
   942 !
   895 
   943 
   896 i45
   944 i45
   897     "return i45"
   945     "prototype method"
   898 
   946 
   899     ^ i45
   947     ^ i45
   900 
   948 
   901     "Created: 21.9.1996 / 16:06:23 / cg"
   949     "Created: 21.9.1996 / 16:06:23 / cg"
   902 !
   950 !
   903 
   951 
   904 i45:something
   952 i45:something
   905     "set i45"
   953     "prototype method"
   906 
   954 
   907     i45 := something.
   955     i45 := something.
   908 
   956 
   909     "Created: 21.9.1996 / 16:06:23 / cg"
   957     "Created: 21.9.1996 / 16:06:23 / cg"
   910 !
   958 !
   911 
   959 
   912 i46
   960 i46
   913     "return i46"
   961     "prototype method"
   914 
   962 
   915     ^ i46
   963     ^ i46
   916 
   964 
   917     "Created: 21.9.1996 / 16:06:23 / cg"
   965     "Created: 21.9.1996 / 16:06:23 / cg"
   918 !
   966 !
   919 
   967 
   920 i46:something
   968 i46:something
   921     "set i46"
   969     "prototype method"
   922 
   970 
   923     i46 := something.
   971     i46 := something.
   924 
   972 
   925     "Created: 21.9.1996 / 16:06:23 / cg"
   973     "Created: 21.9.1996 / 16:06:23 / cg"
   926 !
   974 !
   927 
   975 
   928 i47
   976 i47
   929     "return i47"
   977     "prototype method"
   930 
   978 
   931     ^ i47
   979     ^ i47
   932 
   980 
   933     "Created: 21.9.1996 / 16:06:23 / cg"
   981     "Created: 21.9.1996 / 16:06:23 / cg"
   934 !
   982 !
   935 
   983 
   936 i47:something
   984 i47:something
   937     "set i47"
   985     "prototype method"
   938 
   986 
   939     i47 := something.
   987     i47 := something.
   940 
   988 
   941     "Created: 21.9.1996 / 16:06:23 / cg"
   989     "Created: 21.9.1996 / 16:06:23 / cg"
   942 !
   990 !
   943 
   991 
   944 i48
   992 i48
   945     "return i48"
   993     "prototype method"
   946 
   994 
   947     ^ i48
   995     ^ i48
   948 
   996 
   949     "Created: 21.9.1996 / 16:06:23 / cg"
   997     "Created: 21.9.1996 / 16:06:23 / cg"
   950 !
   998 !
   951 
   999 
   952 i48:something
  1000 i48:something
   953     "set i48"
  1001     "prototype method"
   954 
  1002 
   955     i48 := something.
  1003     i48 := something.
   956 
  1004 
   957     "Created: 21.9.1996 / 16:06:23 / cg"
  1005     "Created: 21.9.1996 / 16:06:23 / cg"
   958 !
  1006 !
   959 
  1007 
   960 i49
  1008 i49
   961     "return i49"
  1009     "prototype method"
   962 
  1010 
   963     ^ i49
  1011     ^ i49
   964 
  1012 
   965     "Created: 21.9.1996 / 16:06:23 / cg"
  1013     "Created: 21.9.1996 / 16:06:23 / cg"
   966 !
  1014 !
   967 
  1015 
   968 i49:something
  1016 i49:something
   969     "set i49"
  1017     "prototype method"
   970 
  1018 
   971     i49 := something.
  1019     i49 := something.
   972 
  1020 
   973     "Created: 21.9.1996 / 16:06:24 / cg"
  1021     "Created: 21.9.1996 / 16:06:24 / cg"
   974 !
  1022 !
   975 
  1023 
   976 i4:something
  1024 i4:something
   977     "set i4"
  1025     "prototype method to set the 4th instance variable"
   978 
  1026 
   979     i4 := something.
  1027     i4 := something.
   980 
  1028 
   981     "Created: 13.5.1996 / 21:19:25 / cg"
  1029     "Created: 13.5.1996 / 21:19:25 / cg"
   982 !
  1030 !
   983 
  1031 
   984 i5
  1032 i5
   985     "return i5"
  1033     "prototype method to return the 5th instance variable"
   986 
  1034 
   987     ^ i5
  1035     ^ i5
   988 
  1036 
   989     "Created: 13.5.1996 / 21:19:26 / cg"
  1037     "Created: 13.5.1996 / 21:19:26 / cg"
   990 !
  1038 !
   991 
  1039 
   992 i50
  1040 i50
   993     "return i50"
  1041     "prototype method"
   994 
  1042 
   995     ^ i50
  1043     ^ i50
   996 
  1044 
   997     "Created: 21.9.1996 / 16:06:24 / cg"
  1045     "Created: 21.9.1996 / 16:06:24 / cg"
   998 !
  1046 !
   999 
  1047 
  1000 i50:something
  1048 i50:something
  1001     "set i50"
  1049     "prototype method"
  1002 
  1050 
  1003     i50 := something.
  1051     i50 := something.
  1004 
  1052 
  1005     "Created: 21.9.1996 / 16:06:24 / cg"
  1053     "Created: 21.9.1996 / 16:06:24 / cg"
  1006 !
  1054 !
  1007 
  1055 
  1008 i5:something
  1056 i5:something
  1009     "set i5"
  1057     "prototype method to set the 5th instance variable"
  1010 
  1058 
  1011     i5 := something.
  1059     i5 := something.
  1012 
  1060 
  1013     "Created: 13.5.1996 / 21:19:26 / cg"
  1061     "Created: 13.5.1996 / 21:19:26 / cg"
  1014 !
  1062 !
  1015 
  1063 
  1016 i6
  1064 i6
  1017     "return i6"
  1065     "prototype method to return the 6th instance variable"
  1018 
  1066 
  1019     ^ i6
  1067     ^ i6
  1020 
  1068 
  1021     "Created: 13.5.1996 / 21:19:26 / cg"
  1069     "Created: 13.5.1996 / 21:19:26 / cg"
  1022 !
  1070 !
  1023 
  1071 
  1024 i6:something
  1072 i6:something
  1025     "set i6"
  1073     "prototype method to set the 6th instance variable"
  1026 
  1074 
  1027     i6 := something.
  1075     i6 := something.
  1028 
  1076 
  1029     "Created: 13.5.1996 / 21:19:26 / cg"
  1077     "Created: 13.5.1996 / 21:19:26 / cg"
  1030 !
  1078 !
  1031 
  1079 
  1032 i7
  1080 i7
  1033     "return i7"
  1081     "prototype method to return the 7th instance variable"
  1034 
  1082 
  1035     ^ i7
  1083     ^ i7
  1036 
  1084 
  1037     "Created: 13.5.1996 / 21:19:26 / cg"
  1085     "Created: 13.5.1996 / 21:19:26 / cg"
  1038 !
  1086 !
  1039 
  1087 
  1040 i7:something
  1088 i7:something
  1041     "set i7"
  1089     "prototype method to set the 7th instance variable"
  1042 
  1090 
  1043     i7 := something.
  1091     i7 := something.
  1044 
  1092 
  1045     "Created: 13.5.1996 / 21:19:26 / cg"
  1093     "Created: 13.5.1996 / 21:19:26 / cg"
  1046 !
  1094 !
  1047 
  1095 
  1048 i8
  1096 i8
  1049     "return i8"
  1097     "prototype method to return the 8th instance variable"
  1050 
  1098 
  1051     ^ i8
  1099     ^ i8
  1052 
  1100 
  1053     "Created: 13.5.1996 / 21:19:26 / cg"
  1101     "Created: 13.5.1996 / 21:19:26 / cg"
  1054 !
  1102 !
  1055 
  1103 
  1056 i8:something
  1104 i8:something
  1057     "set i8"
  1105     "prototype method to set the 8th instance variable"
  1058 
  1106 
  1059     i8 := something.
  1107     i8 := something.
  1060 
  1108 
  1061     "Created: 13.5.1996 / 21:19:26 / cg"
  1109     "Created: 13.5.1996 / 21:19:26 / cg"
  1062 !
  1110 !
  1063 
  1111 
  1064 i9
  1112 i9
  1065     "return i9"
  1113     "prototype method to return the 9th instance variable"
  1066 
  1114 
  1067     ^ i9
  1115     ^ i9
  1068 
  1116 
  1069     "Created: 13.5.1996 / 21:19:26 / cg"
  1117     "Created: 13.5.1996 / 21:19:26 / cg"
  1070 !
  1118 !
  1071 
  1119 
  1072 i9:something
  1120 i9:something
  1073     "set i9"
  1121     "prototype method to set the 9th instance variable"
  1074 
  1122 
  1075     i9 := something.
  1123     i9 := something.
  1076 
  1124 
  1077     "Created: 13.5.1996 / 21:19:27 / cg"
  1125     "Created: 13.5.1996 / 21:19:27 / cg"
  1078 !
  1126 !
  1136 doesNotUnderstand:aMessage
  1184 doesNotUnderstand:aMessage
  1137     "catch unimplemented messages - pass some to the superclass.
  1185     "catch unimplemented messages - pass some to the superclass.
  1138      Notice that although this method calls super messages,
  1186      Notice that although this method calls super messages,
  1139      actual instances will have no valid superClass."
  1187      actual instances will have no valid superClass."
  1140 
  1188 
  1141     |sel args names sz s|
  1189     |sel args names sz s idx|
  1142 
  1190 
  1143     "/ instance protocol
  1191     "/ instance protocol
  1144 
  1192 
  1145     sel := aMessage selector.
  1193     sel := aMessage selector.
  1146     args := aMessage arguments.
  1194     args := aMessage arguments.
  1147 
  1195 
  1148     sel == #displayString ifTrue:[
  1196     sel == #displayString ifTrue:[
  1149        s := WriteStream on:''.
  1197        s := WriteStream on:''.
  1150        s nextPutAll:'Structure('.
  1198        s nextPutAll:'Structure('.
  1151         names := self allInstVarNames.
  1199         names := self allInstVarNames.
  1152         names keysAndValuesDo:[:idx :nm |
  1200         names notNil ifTrue:[
  1153             s nextPutAll:nm; nextPutAll:'->'.
  1201             names keysAndValuesDo:[:idx :nm |
  1154             s nextPutAll:(self at:idx) displayString.
  1202                 s nextPutAll:nm; nextPutAll:'->'.
  1155             s space
  1203                 s nextPutAll:(self at:idx) displayString.
       
  1204                 s space
       
  1205             ].
  1156         ].
  1206         ].
  1157         s nextPutAll:')'.
  1207         s nextPutAll:')'.
  1158         ^ s contents
  1208         ^ s contents
  1159     ].
       
  1160 
       
  1161     sel == #printString ifTrue:[
       
  1162          ^ super printString
       
  1163     ].
       
  1164 
       
  1165     sel == #printOn: ifTrue:[
       
  1166          ^ super printOn:(args at:1)
       
  1167     ].
  1209     ].
  1168 
  1210 
  1169     sel == #basicInspect ifTrue:[
  1211     sel == #basicInspect ifTrue:[
  1170         ^ InspectorView openOn:self
  1212         ^ InspectorView openOn:self
  1171     ].
  1213     ].
  1210 
  1252 
  1211     (sel := aMessage selector) == #name ifTrue:[
  1253     (sel := aMessage selector) == #name ifTrue:[
  1212         ^ 'Structure'
  1254         ^ 'Structure'
  1213     ].
  1255     ].
  1214 
  1256 
  1215     sel == #instSize ifTrue:[
       
  1216         ^ instSize
       
  1217     ].
       
  1218 
       
  1219     sel == #isVariable ifTrue:[
  1257     sel == #isVariable ifTrue:[
  1220          ^ false
  1258          ^ false
  1221     ].
  1259     ].
  1222 
  1260 
  1223     sel == #isClass ifTrue:[
  1261     sel == #isClass ifTrue:[
  1231     sel == #isBehavior ifTrue:[
  1269     sel == #isBehavior ifTrue:[
  1232          ^ false
  1270          ^ false
  1233     ].
  1271     ].
  1234 
  1272 
  1235     sel == #respondsTo: ifTrue:[
  1273     sel == #respondsTo: ifTrue:[
  1236         (args at:1) printNL.
       
  1237          ^ false
  1274          ^ false
       
  1275     ].
       
  1276 
       
  1277     sel == #whichClassIncludesSelector: ifTrue:[
       
  1278          ^ nil
  1238     ].
  1279     ].
  1239 
  1280 
  1240     sel == #evaluatorClass ifTrue:[
  1281     sel == #evaluatorClass ifTrue:[
  1241         ^ Compiler
  1282         ^ Compiler
  1242     ].
  1283     ].
  1252     sel == #allClassVarNames ifTrue:[
  1293     sel == #allClassVarNames ifTrue:[
  1253         ^ #()
  1294         ^ #()
  1254     ].
  1295     ].
  1255 
  1296 
  1256     sel == #allInstVarNames ifTrue:[
  1297     sel == #allInstVarNames ifTrue:[
       
  1298         methodDictionary isNil ifTrue:[
       
  1299             'oops - nil ethodDict' printCR.
       
  1300             ^ #()
       
  1301         ].
       
  1302 
  1257         sz := super basicSize.
  1303         sz := super basicSize.
  1258         names := Array new:sz.
  1304         names := Array new:sz.
  1259 
  1305 
  1260         methodDictionary copy keysAndValuesDo:[:sel :mthd|
  1306         methodDictionary keysAndValuesDo:[:sel :mthd|
  1261             |index|
  1307             |index mysel|
       
  1308 
  1262             (sel endsWith:$:) ifFalse:[
  1309             (sel endsWith:$:) ifFalse:[
  1263                 (sel ~~ #class) ifTrue:[
  1310                 (sel ~~ #class) ifTrue:[
  1264                     "/
  1311                     "/
  1265                     "/ which method is it ?
  1312                     "/ which method is it ?
  1266                     "/
  1313                     "/
  1267                     1 to:20 do:[:i |
  1314                     idx := 1.
  1268                         |mysel|
  1315                     [idx <= sz] whileTrue:[
  1269 
  1316                         mysel := ('i' , idx printString) asSymbol.
  1270                         mysel := ('i' , i printString) asSymbol.
       
  1271                         mthd == (Structure compiledMethodAt:mysel) ifTrue:[
  1317                         mthd == (Structure compiledMethodAt:mysel) ifTrue:[
  1272                             index := i
  1318                             names at:idx put:sel.
  1273                         ]
  1319                             idx := sz.   "/ break
       
  1320                         ].
       
  1321                         idx := idx + 1.
  1274                     ].
  1322                     ].
  1275 
       
  1276                     index isNil ifTrue:[
       
  1277                         'oops' printNL.
       
  1278                         ^ nil
       
  1279                     ].
       
  1280 
       
  1281                     names at:index put:sel.                
       
  1282                 ]
  1323                 ]
  1283             ]
  1324             ]
  1284         ].
  1325         ].
  1285         "/ must now sort by index ...
       
  1286         
  1326         
  1287          ^ names
  1327          ^ names
  1288     ].
  1328     ].
  1289 
  1329 
  1290     aMessage printNL.
  1330     'Structure [warning]: return nil for: ' print.
  1291     'args ' print. args printNL.
  1331     aMessage print.
       
  1332     ' args ' print. args printCR.
  1292 
  1333 
  1293     ^ nil.
  1334     ^ nil.
  1294 
  1335 
  1295     "Created: 13.5.1996 / 20:22:22 / cg"
  1336     "Created: 13.5.1996 / 20:22:22 / cg"
  1296     "Modified: 13.5.1996 / 21:12:54 / cg"
  1337     "Modified: 13.5.1996 / 21:12:54 / cg"
  1297 ! !
  1338 ! !
  1298 
  1339 
  1299 !Structure  class methodsFor:'documentation'!
  1340 !Structure class methodsFor:'documentation'!
  1300 
  1341 
  1301 version
  1342 version
  1302     ^ '$Header: /cvs/stx/stx/libcomp/Structure.st,v 1.5 1996-11-08 14:37:23 cg Exp $'
  1343     ^ '$Header: /cvs/stx/stx/libcomp/Structure.st,v 1.6 1997-10-09 11:51:58 ca Exp $'
  1303 ! !
  1344 ! !
  1304 Structure initialize!
  1345 Structure initialize!