paul@201 | 1 | #!/usr/bin/env python |
paul@201 | 2 | |
paul@201 | 3 | """ |
paul@201 | 4 | Program code and data representations. |
paul@253 | 5 | |
paul@659 | 6 | Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk> |
paul@253 | 7 | |
paul@253 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@253 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@253 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@253 | 11 | version. |
paul@253 | 12 | |
paul@253 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@253 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@253 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@253 | 16 | details. |
paul@253 | 17 | |
paul@253 | 18 | You should have received a copy of the GNU General Public License along with |
paul@253 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@201 | 20 | """ |
paul@201 | 21 | |
paul@237 | 22 | class Context: |
paul@237 | 23 | |
paul@237 | 24 | """ |
paul@237 | 25 | A representation of a context used in a program, providing the special |
paul@237 | 26 | context value types. |
paul@237 | 27 | """ |
paul@237 | 28 | |
paul@237 | 29 | def __init__(self, truth_value, repr): |
paul@237 | 30 | self.truth_value = truth_value |
paul@237 | 31 | self.repr = repr |
paul@237 | 32 | |
paul@237 | 33 | def __repr__(self): |
paul@237 | 34 | return self.repr |
paul@237 | 35 | |
paul@237 | 36 | def __nonzero__(self): |
paul@237 | 37 | return self.truth_value |
paul@237 | 38 | |
paul@243 | 39 | __shortrepr__ = __repr__ |
paul@243 | 40 | |
paul@237 | 41 | # A representation of a context that is replaced upon certain assignment |
paul@237 | 42 | # operations. |
paul@237 | 43 | |
paul@237 | 44 | ReplaceableContext = Context(0, "Replace") |
paul@237 | 45 | |
paul@237 | 46 | # A representation of a context that is employed by classes so that |
paul@237 | 47 | # instantiators have enough slots in the invocation frame, yet does not cause |
paul@237 | 48 | # testing of the context or adjustment of the frame. |
paul@237 | 49 | |
paul@237 | 50 | PlaceholderContext = Context(0, "Placeholder") |
paul@237 | 51 | |
paul@201 | 52 | # vim: tabstop=4 expandtab shiftwidth=4 |