paul@187 | 1 | Object contexts:
|
paul@187 | 2 |
|
paul@187 | 3 | Object Context
|
paul@187 | 4 | ------ -------
|
paul@187 | 5 | function overridable
|
paul@187 | 6 | method defining/originating class
|
paul@187 | 7 | class null
|
paul@187 | 8 | instance self
|
paul@187 | 9 | module null
|
paul@187 | 10 |
|
paul@186 | 11 | Assignment types:
|
paul@186 | 12 |
|
paul@186 | 13 | Assignment of stored value to... Effect on context
|
paul@186 | 14 | -------------------------------- -----------------
|
paul@186 | 15 | local preserved
|
paul@186 | 16 | global (module) preserved
|
paul@187 | 17 | class overridden (if overridable)
|
paul@186 | 18 | instance preserved
|
paul@186 | 19 |
|
paul@187 | 20 | Assignment to a namespace preserves the context except for some class
|
paul@187 | 21 | assignments
|
paul@187 | 22 |
|
paul@187 | 23 | Assigning to classes:
|
paul@187 | 24 |
|
paul@187 | 25 | Assignment of... Effect on context
|
paul@187 | 26 | ---------------- -----------------
|
paul@187 | 27 | function (overridable context) overridden by class (becomes method)
|
paul@187 | 28 | method (existing context) preserved
|
paul@187 | 29 | class (null context) preserved
|
paul@187 | 30 | instance (self context) preserved
|
paul@187 | 31 | module (null context) preserved
|
paul@187 | 32 |
|
paul@187 | 33 | With run-time restrictions on assignment targets:
|
paul@187 | 34 |
|
paul@187 | 35 | Assignment of stored value to... Effect on context Optimised instruction Unoptimised instruction
|
paul@187 | 36 | -------------------------------- ----------------- --------------------- -----------------------
|
paul@187 | 37 | local preserved StoreName
|
paul@187 | 38 | global (module) preserved StoreAddress StoreAttrIndex
|
paul@187 | 39 | instance preserved StoreAttr StoreAttrIndex
|
paul@519 | 40 | class -> class StoreAddressContext StoreAttrIndex
|
paul@187 | 41 |
|
paul@519 | 42 | Assignment of new class attributes is only permitted during initialisation
|
paul@557 | 43 | unless attribute usage observations are employed to detect possible attribute
|
paul@557 | 44 | assignments
|
paul@186 | 45 |
|
paul@678 | 46 | Remember that once a function is assigned to a class, it will have that class
|
paul@678 | 47 | as context (as an unbound method)
|
paul@678 | 48 |
|
paul@186 | 49 | Access types:
|
paul@186 | 50 |
|
paul@194 | 51 | Access to stored value from... Effect on context Optimised instruction Unoptimised instruction
|
paul@194 | 52 | ------------------------------ ----------------- --------------------- -----------------------
|
paul@186 | 53 | local preserved LoadName
|
paul@194 | 54 | global (module) preserved LoadAddress LoadAttrIndex
|
paul@194 | 55 | class preserved LoadAddress LoadAttrIndex
|
paul@223 | 56 | class via instance -> instance LoadAddressContext(Cond) LoadAttrIndexContext(Cond)
|
paul@194 | 57 | instance preserved LoadAttr LoadAttrIndex
|
paul@186 | 58 |
|
paul@186 | 59 | Access to a namespace may not preserve the stored context
|
paul@189 | 60 |
|
paul@189 | 61 | Access to class attributes via instances:
|
paul@189 | 62 |
|
paul@189 | 63 | Access to stored value with... Effect on context
|
paul@189 | 64 | ------------------------------ -----------------
|
paul@223 | 65 | compatible class as context -> instance
|
paul@189 | 66 | incompatible class as context preserved
|
paul@189 | 67 | null context preserved
|
paul@189 | 68 | other context (instance) preserved
|
paul@189 | 69 |
|
paul@194 | 70 | Optimisation possibilities for class attribute access via instances:
|
paul@193 | 71 |
|
paul@193 | 72 | Class Class attribute Context of attribute Instruction
|
paul@193 | 73 | ----- --------------- -------------------- -----------
|
paul@193 | 74 | known constant preserved LoadAddress
|
paul@223 | 75 | known constant -> instance LoadAddressContext
|
paul@194 | 76 | known not constant preserved LoadAddress (attribute may always be preserved)
|
paul@223 | 77 | known not constant -> instance LoadAddressContext (attribute may always be overridden)
|
paul@194 | 78 | known not constant not known LoadAddressContextCond (perform context check)
|
paul@194 | 79 | not known not known preserved LoadAttrIndex (attribute may have preserved context in all classes)
|
paul@676 | 80 | * not known not known -> instance LoadAttrIndexContext (attribute may have overridden context in all classes)
|
paul@194 | 81 | not known not known not known LoadAttrIndexContextCond (perform context check for class attribute access)
|
paul@193 | 82 |
|
paul@676 | 83 | * Since knowing that an instance will replace the context might also mean
|
paul@676 | 84 | knowing the nature of the attribute, LoadAttrIndexContext is not likely to
|
paul@676 | 85 | be useful in practice.
|
paul@676 | 86 |
|
paul@189 | 87 | Since the object table encodes sufficient information (an instance must be
|
paul@189 | 88 | compatible to access the class attribute, and compatibility information is
|
paul@193 | 89 | stored), an explicit compatibility test may not always be required at
|
paul@193 | 90 | run-time
|
paul@642 | 91 |
|
paul@642 | 92 | Definite compile-time knowledge about instance usage is likely to be
|
paul@642 | 93 | restricted to literal constants: in general, no assertions can be made about
|
paul@642 | 94 | an accessor never being a class, module or constant and therefore being an
|
paul@642 | 95 | instance
|