paul@17 | 1 | #!/usr/bin/env python |
paul@17 | 2 | |
paul@17 | 3 | """ |
paul@17 | 4 | RSVP instruction classes. |
paul@17 | 5 | |
paul@54 | 6 | Copyright (C) 2007, 2008 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@54 | 22 | from micropython.inspect import Const, Instance |
paul@54 | 23 | |
paul@17 | 24 | class Instruction: |
paul@17 | 25 | |
paul@17 | 26 | "A generic instruction." |
paul@17 | 27 | |
paul@21 | 28 | def __init__(self, attr=None): |
paul@17 | 29 | self.attr = attr |
paul@17 | 30 | |
paul@17 | 31 | def __repr__(self): |
paul@26 | 32 | if self.attr is not None: |
paul@26 | 33 | return "%s(%r)" % (self.__class__.__name__, self.attr) |
paul@26 | 34 | else: |
paul@26 | 35 | return "%s()" % self.__class__.__name__ |
paul@17 | 36 | |
paul@21 | 37 | # Instructions operating on the value stack. |
paul@21 | 38 | |
paul@26 | 39 | class LoadConst(Instruction): "Load the constant from the specified location." |
paul@44 | 40 | class Duplicate(Instruction): "Duplicate the top of stack." |
paul@44 | 41 | class Pop(Instruction): "Pop the top of stack." |
paul@21 | 42 | |
paul@21 | 43 | # Access within an invocation frame. |
paul@21 | 44 | |
paul@44 | 45 | class LoadName(Instruction): "Load the object from the given local attribute/variable." |
paul@44 | 46 | class StoreName(Instruction): "Store the object in the given local attribute/variable." |
paul@21 | 47 | |
paul@21 | 48 | # Access to address-relative data. |
paul@21 | 49 | |
paul@26 | 50 | class MakeObject(Instruction): "Make a new object." |
paul@26 | 51 | # ... DropObject not defined: Assume garbage collection. |
paul@26 | 52 | class LoadAttr(Instruction): "Load the object from the given attribute." |
paul@28 | 53 | class LoadAttrIndex(Instruction): "Load the object for the attribute with the given index." |
paul@28 | 54 | class StoreAttr(Instruction): "Store an object in the given attribute." |
paul@28 | 55 | class StoreAttrIndex(Instruction): "Store an object in the attribute with the given index." |
paul@21 | 56 | |
paul@21 | 57 | # Access to invocation frames in preparation. |
paul@21 | 58 | |
paul@26 | 59 | class MakeFrame(Instruction): "Make a new invocation frame." |
paul@26 | 60 | class ReserveFrame(Instruction): "Reserve the given number of entries for the invocation frame." |
paul@26 | 61 | class DropFrame(Instruction): "Drop an invocation frame." |
paul@26 | 62 | class StoreFrame(Instruction): "Store an argument at the given frame location." |
paul@26 | 63 | class StoreFrameIndex(Instruction): "Store an argument for the parameter with the given index." |
paul@21 | 64 | |
paul@21 | 65 | # Invocation-related instructions. |
paul@21 | 66 | |
paul@45 | 67 | class Jump(Instruction): "Jump unconditionally." |
paul@45 | 68 | class JumpIfFalse(Instruction): "Jump if the last evaluation gave a false result." |
paul@45 | 69 | class JumpIfTrue(Instruction): "Jump if the last evaluation gave a true result." |
paul@45 | 70 | class LoadCallable(Instruction): "Load the target of an invocation." |
paul@45 | 71 | class LoadContext(Instruction): "Load the context of an invocation." |
paul@45 | 72 | class CheckContext(Instruction): "Check the context of an invocation against the target." |
paul@45 | 73 | class RaiseException(Instruction): "Raise an exception." |
paul@45 | 74 | class Return(Instruction): "Return a value from a subprogram." |
paul@45 | 75 | class CheckException(Instruction): "Check the raised exception against another." |
paul@17 | 76 | |
paul@17 | 77 | # vim: tabstop=4 expandtab shiftwidth=4 |