micropython

Annotated docs/assignment.txt

223:09ae448806d1
2009-05-24 Paul Boddie Added a StoreAddressContext instruction for class attribute initialisation. Fixed the mechanism behind LoadAttrIndexContextCond and LoadAddressContextCond since it failed to provide the appropriate instance context for instance accesses. Added a LoadFunction instruction in order to distinguish between constants which have no context information and those which do.
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@223 40
  class                             -> class            StoreAddressContext
paul@187 41
paul@223 42
  Class assignments are not permitted except during initialisation and hence
paul@223 43
  employ no unoptimised instruction
paul@186 44
paul@186 45
Access types:
paul@186 46
paul@194 47
  Access to stored value from...    Effect on context   Optimised instruction     Unoptimised instruction
paul@194 48
  ------------------------------    -----------------   ---------------------     -----------------------
paul@186 49
  local                             preserved           LoadName
paul@194 50
  global (module)                   preserved           LoadAddress               LoadAttrIndex
paul@194 51
  class                             preserved           LoadAddress               LoadAttrIndex
paul@223 52
  class via instance                -> instance         LoadAddressContext(Cond)  LoadAttrIndexContext(Cond)
paul@194 53
  instance                          preserved           LoadAttr                  LoadAttrIndex
paul@186 54
paul@186 55
  Access to a namespace may not preserve the stored context
paul@189 56
paul@189 57
Access to class attributes via instances:
paul@189 58
paul@189 59
  Access to stored value with...    Effect on context
paul@189 60
  ------------------------------    -----------------
paul@223 61
  compatible class as context       -> instance
paul@189 62
  incompatible class as context     preserved
paul@189 63
  null context                      preserved
paul@189 64
  other context (instance)          preserved
paul@189 65
paul@194 66
Optimisation possibilities for class attribute access via instances:
paul@193 67
paul@193 68
  Class       Class attribute   Context of attribute  Instruction
paul@193 69
  -----       ---------------   --------------------  -----------
paul@193 70
  known       constant          preserved             LoadAddress
paul@223 71
  known       constant          -> instance           LoadAddressContext
paul@194 72
  known       not constant      preserved             LoadAddress              (attribute may always be preserved)
paul@223 73
  known       not constant      -> instance           LoadAddressContext       (attribute may always be overridden)
paul@194 74
  known       not constant      not known             LoadAddressContextCond   (perform context check)
paul@194 75
  not known   not known         preserved             LoadAttrIndex            (attribute may have preserved context in all classes)
paul@223 76
  not known   not known         -> instance           LoadAttrIndexContext     (attribute may have overridden context in all classes)
paul@194 77
  not known   not known         not known             LoadAttrIndexContextCond (perform context check for class attribute access)
paul@193 78
paul@189 79
  Since the object table encodes sufficient information (an instance must be
paul@189 80
  compatible to access the class attribute, and compatibility information is
paul@193 81
  stored), an explicit compatibility test may not always be required at
paul@193 82
  run-time