paul@17 | 1 | #!/usr/bin/env python |
paul@17 | 2 | |
paul@17 | 3 | """ |
paul@17 | 4 | RSVP instruction classes. |
paul@17 | 5 | |
paul@17 | 6 | Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> |
paul@17 | 7 | |
paul@17 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@17 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@17 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@17 | 11 | version. |
paul@17 | 12 | |
paul@17 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@17 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@17 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@17 | 16 | details. |
paul@17 | 17 | |
paul@17 | 18 | You should have received a copy of the GNU General Public License along with |
paul@17 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@17 | 20 | """ |
paul@17 | 21 | |
paul@17 | 22 | class Instruction: |
paul@17 | 23 | |
paul@17 | 24 | "A generic instruction." |
paul@17 | 25 | |
paul@21 | 26 | def __init__(self, attr=None): |
paul@17 | 27 | self.attr = attr |
paul@17 | 28 | |
paul@17 | 29 | def __repr__(self): |
paul@26 | 30 | if self.attr is not None: |
paul@26 | 31 | return "%s(%r)" % (self.__class__.__name__, self.attr) |
paul@26 | 32 | else: |
paul@26 | 33 | return "%s()" % self.__class__.__name__ |
paul@17 | 34 | |
paul@21 | 35 | # Instructions operating on the value stack. |
paul@21 | 36 | |
paul@26 | 37 | class LoadConst(Instruction): "Load the constant from the specified location." |
paul@21 | 38 | |
paul@21 | 39 | # Access within an invocation frame. |
paul@21 | 40 | |
paul@26 | 41 | class LoadName(Instruction): "Load the object from the given local attribute." |
paul@26 | 42 | class StoreName(Instruction): "Store the object in the given local attribute." |
paul@21 | 43 | |
paul@21 | 44 | # Access to address-relative data. |
paul@21 | 45 | |
paul@26 | 46 | class MakeObject(Instruction): "Make a new object." |
paul@26 | 47 | # ... DropObject not defined: Assume garbage collection. |
paul@26 | 48 | class LoadAttr(Instruction): "Load the object from the given attribute." |
paul@26 | 49 | class StoreAttr(Instruction): "Store the object in the given attribute." |
paul@21 | 50 | |
paul@21 | 51 | # Access to invocation frames in preparation. |
paul@21 | 52 | |
paul@26 | 53 | class MakeFrame(Instruction): "Make a new invocation frame." |
paul@26 | 54 | class ReserveFrame(Instruction): "Reserve the given number of entries for the invocation frame." |
paul@26 | 55 | class DropFrame(Instruction): "Drop an invocation frame." |
paul@26 | 56 | class StoreFrame(Instruction): "Store an argument at the given frame location." |
paul@26 | 57 | class StoreFrameIndex(Instruction): "Store an argument for the parameter with the given index." |
paul@21 | 58 | |
paul@21 | 59 | # Invocation-related instructions. |
paul@21 | 60 | |
paul@19 | 61 | class Jump(Instruction): pass |
paul@21 | 62 | class LoadCallable(Instruction): pass |
paul@21 | 63 | class Return(Instruction): pass |
paul@17 | 64 | |
paul@17 | 65 | # vim: tabstop=4 expandtab shiftwidth=4 |