method dispatch in oforth
play

Method Dispatch in Oforth M. Franck Bensusan presented by M. Anton - PowerPoint PPT Presentation

Method Dispatch in Oforth M. Franck Bensusan presented by M. Anton Ertl, TU Wien Methods and classes in Oforth Object Class new: A A Class new: A1 A1 method: foo "Foo for A1 :" . self . ; Object Class new: B B method: foo Duck


  1. Method Dispatch in Oforth M. Franck Bensusan presented by M. Anton Ertl, TU Wien

  2. Methods and classes in Oforth Object Class new: A A Class new: A1 A1 method: foo "Foo for A1 :" . self . ; Object Class new: B B method: foo • Duck typing "Foo for B :" . self . ; Send any message to any object A method: bar • Classes are never closed "Bar for A :" . self . ; • Dispatch matrix grows A virtual: foo2 in both directions "to be redefined" abort ; • virtual: can be overridden A1 method: foo2 method: cannot "Redefined: " . self . ; A1 new foo B new foo A new dup bar foo2 A1 new dup bar foo2

  3. Method dispatch test $1, TOS jne LcallMethodInteger Method virtual table (MVT) test TOS, TOS One per method selector je LcallMethodNull class index used for access class A A object movl (TOS), r0 index=5 $nnnnn005 attribute a andl 0x00000FFF, r0 attribute b cmpl IDClass, r0 foo MVT of foo je LcallMethodClass MVT pointer size=10 polymorphic polymorphic movl virtualTable(r1), r2 polymorphic polymorphic cmp (r2),r0 foo for class 5 (A) polymorphic jl reallocMVT foo for class 7 (B) movl (r2, r0, 4), r3 jmp *r3

  4. MVT initialization • initially 0 slots • grows on method call • new slots initially polymorphic • polymorphic looks up method linear search of methods per class and all superclasses stores result in MVT

  5. Optimization • self calls to method: s • Method calls to literal objects • Object method: s

Recommend


More recommend