1.1 --- a/rsvp.py Sat Aug 23 22:32:17 2008 +0200
1.2 +++ b/rsvp.py Sun Aug 24 03:06:00 2008 +0200
1.3 @@ -32,7 +32,7 @@
1.4 * Invocation frame pointer stack
1.5 * Exception handler stack
1.6 * Registers: current value, boolean status value, source value, result,
1.7 - current exception
1.8 + current exception, current callable
1.9
1.10 The memory contains constants, global variable references and program code.
1.11
1.12 @@ -87,6 +87,7 @@
1.13 self.value = None
1.14 self.status = None
1.15 self.source = None
1.16 + self.callable = None
1.17 self.result = None
1.18 self.exception = None
1.19
1.20 @@ -289,13 +290,7 @@
1.21 self.invocation_sp_stack.append(len(self.frame_stack))
1.22 self.frame_stack.extend([None] * self.operand)
1.23
1.24 - def JumpWithFrame(self):
1.25 - self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame
1.26 - context, ref = self.value
1.27 - return self.jump(ref.code_location, self.pc + 1) # return to the instruction after this one
1.28 -
1.29 def DropFrame(self):
1.30 - result = self.pull()
1.31 self.local_sp_stack.pop()
1.32 frame = self.invocation_sp_stack.pop()
1.33 self.frame_stack = self.frame_stack[:frame] # reset stack before call
1.34 @@ -315,15 +310,35 @@
1.35 # NOTE: This should cause an argument error.
1.36 raise Exception, "StoreFrameIndex % r" % element
1.37
1.38 - def CheckFrame(self): pass
1.39 + def LoadCallable(self):
1.40 + context, ref = self.value
1.41 + self.callable = self.load(ref + 1)
1.42 +
1.43 + def StoreCallable(self):
1.44 + context, ref = self.value
1.45 + self.save(ref + 1, self.callable)
1.46 +
1.47 + def LoadContext(self):
1.48 + context, ref = self.value
1.49 + self.value = None, context
1.50 +
1.51 + def CheckFrame(self):
1.52 + context, ref = self.value
1.53 + nargs, ndefaults = self.load(ref + 2)
1.54 + if not (nargs - ndefaults <= self.operand <= nargs):
1.55 + raise Exception, "CheckFrame %r" % (nargs - ndefaults, self.operand, nargs)
1.56 + # NOTE: Support population of defaults.
1.57 + # NOTE: Support sliding of the frame to exclude any inappropriate context.
1.58
1.59 def CheckSelf(self): pass
1.60
1.61 - def LoadCallable(self): pass
1.62 + def JumpWithFrame(self):
1.63 + self.local_sp_stack.append(self.invocation_sp_stack[-1]) # adopt the invocation frame
1.64 + return self.jump(self.callable, self.pc + 1) # return to the instruction after this one
1.65
1.66 - def LoadContext(self):
1.67 - context, ref = self.value
1.68 - self.push((None, context))
1.69 + def ExtendFrame(self):
1.70 + frame = self.local_sp_stack[-1]
1.71 + frame.extend([None] * self.operand)
1.72
1.73 def Return(self):
1.74 self.pc = self.pull_pc()
1.75 @@ -372,4 +387,7 @@
1.76 # LoadBoolean is implemented in the generated code.
1.77 # StoreBoolean is implemented by testing against the True value.
1.78
1.79 + def InvertBoolean(self):
1.80 + self.status = not self.status
1.81 +
1.82 # vim: tabstop=4 expandtab shiftwidth=4