1.1 --- a/micropython/raw.py Fri Jun 28 21:17:02 2013 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,77 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -Classes used to help with the generation of raw image data.
1.8 -
1.9 -Copyright (C) 2009, 2010, 2011, 2012 Paul Boddie <paul@boddie.org.uk>
1.10 -
1.11 -This program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU General Public License as published by the Free Software
1.13 -Foundation; either version 3 of the License, or (at your option) any later
1.14 -version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 -details.
1.20 -
1.21 -You should have received a copy of the GNU General Public License along with
1.22 -this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -"""
1.24 -
1.25 -class RawObject:
1.26 -
1.27 - "The basis for serialised program objects."
1.28 -
1.29 - def __init__(self, item):
1.30 - self.item = item
1.31 -
1.32 - def set_location(self, location, objtable, with_builtins):
1.33 - self.item.location = location
1.34 - return location + 1
1.35 -
1.36 - def finalise_location(self, with_builtins):
1.37 - pass
1.38 -
1.39 - def finalise_body_location(self, with_builtins):
1.40 - pass
1.41 -
1.42 - def is_generated(self, with_builtins):
1.43 - return with_builtins or self.item.module.name not in ("__builtins__", "native") or self.item.astnode.doc is not None
1.44 -
1.45 -class UntranslatableInstruction(Exception):
1.46 - pass
1.47 -
1.48 -class RSVPTranslator:
1.49 -
1.50 - "A class which provides the basis for the translation of RSVP instructions."
1.51 -
1.52 - def get_method(self, instruction):
1.53 -
1.54 - "Return the handler method for the given 'instruction'."
1.55 -
1.56 - instruction_name = instruction.__class__.__name__
1.57 - method = getattr(self, instruction_name, None)
1.58 - if method is None:
1.59 - raise UntranslatableInstruction, instruction_name
1.60 - return method
1.61 -
1.62 - def perform(self, instruction):
1.63 -
1.64 - "Perform the 'instruction', returning the next PC value or None."
1.65 -
1.66 - self.get_method(instruction)()
1.67 -
1.68 - def translate(self, code):
1.69 -
1.70 - "Translate the given 'code'."
1.71 -
1.72 - self.output_code = []
1.73 -
1.74 - for instruction in code:
1.75 - self.perform(instruction)
1.76 -
1.77 - def new_op(self, op):
1.78 - self.output_code.append(op)
1.79 -
1.80 -# vim: tabstop=4 expandtab shiftwidth=4