05.08.2014 Views

here - Stefan-Marr.de

here - Stefan-Marr.de

here - Stefan-Marr.de

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4.2. SOM: Simple Object Machine<br />

1 SOMInterpreter = (<br />

2 | frame universe currentByteco<strong>de</strong> |<br />

3<br />

4 currentObject = ( ^ ( frame outerContext ) currentObject )<br />

5<br />

6 doPopField = (<br />

7 self currentObject<br />

8 fieldAtIn<strong>de</strong>x : currentByteco<strong>de</strong> fieldIn<strong>de</strong>x<br />

9 put : frame pop )<br />

10<br />

11 doPushField = (<br />

12 frame push :<br />

13 ( self currentObject<br />

14 fieldAtIn<strong>de</strong>x : currentByteco<strong>de</strong> fieldIn<strong>de</strong>x ))<br />

15<br />

16 doSend = (<br />

17 | receiver |<br />

18 receiver := frame stackElementAtIn<strong>de</strong>x :<br />

19 currentByteco<strong>de</strong> selector numArgs + 1.<br />

20 ^ self performSend : currentByteco<strong>de</strong> selector<br />

21 to: receiver<br />

22 lookupCls : receiver class )<br />

23<br />

24 doSuperSend = (<br />

25 | receiver superClass |<br />

26 receiver := frame stackElementAtIn<strong>de</strong>x :<br />

27 currentByteco<strong>de</strong> selector numArgs + 1.<br />

28 " Determine super in the context of the correct method ."<br />

29 superClass := frame outerContext method hol<strong>de</strong>r superClass .<br />

30 ^ self performSend : currentByteco<strong>de</strong> selector<br />

31 to: receiver<br />

32 lookupCls : superClass )<br />

33<br />

34 performSend : selector to: receiver lookupCls : cls = (<br />

35 ^ self send : selector toClass : cls )<br />

36<br />

37 send : selector toClass : cls = (<br />

38 ( cls lookupInvokable : selector )<br />

39 ifNotNilDo : [: invokable | invokable invokeInFrame : frame ]<br />

40 ifNil : [ self sendDoesNotUn<strong>de</strong>rstand : selector ] )<br />

41 " ... ")<br />

Listing 4.5: Basics of the SOM Interpreter<br />

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!