-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Mirror API to explore SOMns object model and metaclass system
Signed-off-by: Stefan Marr <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class ObjectModel usingPlatform: platform = Value ( | ||
| private ObjectMirror = platform mirrors ObjectMirror. | ||
private ClassMirror = platform mirrors ClassMirror. | ||
private Thing = platform kernel Thing. | | ||
)( | ||
public class Snake = ()() | ||
|
||
private printInstanceAndSuperclassOf: classMirror = ( | ||
classMirror name print. ' is instance of ' print. | ||
classMirror classMirror name println. | ||
classMirror name print. ' is subclass of ' print. | ||
classMirror superclassName println. | ||
) | ||
|
||
public main: args = ( | ||
| snake snakeMirror obj objMirror thing thingMirror | | ||
snake := Snake new. | ||
snakeMirror := (ObjectMirror reflecting: snake). | ||
'snake is instance of ' print. | ||
snakeMirror className println. | ||
|
||
printInstanceAndSuperclassOf: snakeMirror classMirror. | ||
printInstanceAndSuperclassOf: snakeMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: snakeMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: snakeMirror classMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: snakeMirror classMirror classMirror classMirror classMirror classMirror. | ||
|
||
'' println. '' println. | ||
'Superclass hierarchy:' println. | ||
'' println. | ||
|
||
obj := Object new. | ||
objMirror := (ObjectMirror reflecting: obj). | ||
'obj is instance of ' print. | ||
objMirror className println. | ||
|
||
printInstanceAndSuperclassOf: objMirror classMirror. | ||
printInstanceAndSuperclassOf: objMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: objMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: objMirror classMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: objMirror classMirror classMirror classMirror classMirror classMirror. | ||
|
||
'' println. '' println. | ||
'In SOMns there is still Thing:' println. | ||
'' println. | ||
|
||
thing := Thing new. | ||
thingMirror := (ObjectMirror reflecting: thing). | ||
'thing is instance of ' print. | ||
thingMirror className println. | ||
|
||
printInstanceAndSuperclassOf: thingMirror classMirror. | ||
printInstanceAndSuperclassOf: thingMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: thingMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: thingMirror classMirror classMirror classMirror classMirror. | ||
printInstanceAndSuperclassOf: thingMirror classMirror classMirror classMirror classMirror classMirror. | ||
|
||
^ 0 | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters