micropython

Change of rsvp.py

134:12c97a4d751c
rsvp.py
     1.1 --- a/rsvp.py	Sun Aug 24 19:20:45 2008 +0200
     1.2 +++ b/rsvp.py	Mon Aug 25 02:04:10 2008 +0200
     1.3 @@ -58,7 +58,7 @@
     1.4  
     1.5      "A really simple virtual processor."
     1.6  
     1.7 -    def __init__(self, memory, objtable, paramtable, clstable, pc=None, debug=0):
     1.8 +    def __init__(self, memory, objtable, paramtable, pc=None, debug=0):
     1.9  
    1.10          """
    1.11          Initialise the processor with a 'memory' (a list of values containing
    1.12 @@ -68,7 +68,6 @@
    1.13          self.memory = memory
    1.14          self.objtable = objtable
    1.15          self.paramtable = paramtable
    1.16 -        self.clstable = clstable
    1.17          self.pc = pc or 0
    1.18          self.debug = debug
    1.19  
    1.20 @@ -252,10 +251,10 @@
    1.21  
    1.22      def LoadAttrIndex(self):
    1.23          context, ref = self.value
    1.24 -        code = self.load(ref) # + 0 (the classcode)
    1.25 -        element = self.objtable[code + self.operand]
    1.26 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.27 +        element = self.objtable[classcode + self.operand]
    1.28          found_code, class_attr, replace_context, offset = element
    1.29 -        if found_code == code:
    1.30 +        if found_code == classcode:
    1.31              if class_attr:
    1.32                  loaded_context, loaded_ref = self.load(offset) # offset is address of class attribute
    1.33                  if replace_context:
    1.34 @@ -270,10 +269,10 @@
    1.35  
    1.36      def StoreAttrIndex(self):
    1.37          context, ref = self.value
    1.38 -        code = self.load(ref) # + 0 (the classcode)
    1.39 -        element = self.objtable[code + self.operand]
    1.40 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.41 +        element = self.objtable[classcode + self.operand]
    1.42          found_code, class_attr, replace_context, offset = element
    1.43 -        if found_code == code:
    1.44 +        if found_code == classcode:
    1.45              if class_attr:
    1.46                  # NOTE: This should cause an attribute or type error.
    1.47                  # Class attributes cannot be changed at run-time.
    1.48 @@ -301,10 +300,10 @@
    1.49  
    1.50      def StoreFrameIndex(self):
    1.51          frame = self.invocation_sp_stack[-1] # different from the current frame after MakeFrame
    1.52 -        code = self.load(ref) # + 0 (the functioncode)
    1.53 -        element = self.objtable[code + self.operand]
    1.54 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.55 +        element = self.objtable[classcode + self.operand]
    1.56          found_code, offset = element
    1.57 -        if found_code == code:
    1.58 +        if found_code == classcode:
    1.59              self.frame_stack[frame + offset] = self.value
    1.60          else:
    1.61              # NOTE: This should cause an argument error.
    1.62 @@ -312,25 +311,52 @@
    1.63  
    1.64      def LoadCallable(self):
    1.65          context, ref = self.value
    1.66 -        self.callable = self.load(ref + 1)
    1.67 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.68 +        self.callable = codeaddr, codedetails
    1.69  
    1.70      def StoreCallable(self):
    1.71          context, ref = self.value
    1.72 -        self.save(ref + 1, self.callable)
    1.73 +        # NOTE: Should improve the representation and permit direct saving.
    1.74 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.75 +        self.save(ref, (classcode, attrcode) + self.callable)
    1.76  
    1.77      def LoadContext(self):
    1.78          context, ref = self.value
    1.79          self.value = None, context
    1.80  
    1.81      def CheckFrame(self):
    1.82 +        operand = self.operand
    1.83 +        frame = self.invocation_sp_stack[-1]
    1.84          context, ref = self.value
    1.85 -        nargs, ndefaults = self.load(ref + 2)
    1.86 -        if not (nargs - ndefaults <= self.operand <= nargs):
    1.87 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
    1.88 +
    1.89 +        # Support sliding of the frame to exclude any inappropriate context.
    1.90 +
    1.91 +        if context is None:
    1.92 +            frame = frame[1:]
    1.93 +            operand -= 1
    1.94 +        else:
    1.95 +            if contexttype == self.typetype:
    1.96 +                frame = frame[1:]
    1.97 +                operand -= 1
    1.98 +
    1.99 +        nargs, ndefaults = codedetails
   1.100 +        if not (nargs - ndefaults <= operand <= nargs):
   1.101              raise Exception, "CheckFrame %r" % (nargs - ndefaults, self.operand, nargs)
   1.102 +
   1.103          # NOTE: Support population of defaults.
   1.104 -        # NOTE: Support sliding of the frame to exclude any inappropriate context.
   1.105  
   1.106 -    def CheckSelf(self): pass
   1.107 +    def CheckSelf(self):
   1.108 +        context, ref = self.value
   1.109 +        target_context, target_ref = self.source
   1.110 +        classcode, attrcode, codeaddr, codedetails = self.load(ref)
   1.111 +        target_classcode, target_attrcode, target_codeaddr, target_codedetails = self.load(target_context)
   1.112 +        element = self.objtable[target_classcode + attrcode]
   1.113 +        found_code, class_attr, replace_context, offset = element
   1.114 +        if found_code == target_classcode:
   1.115 +            self.status = 1
   1.116 +        else:
   1.117 +            self.status = 0
   1.118  
   1.119      def JumpWithFrame(self):
   1.120          self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame