Пример #1
0
def GetInterpreter():
    """\
    Get the interpreter for TPCL code. Here we can add any
    variables that we need to and make any changes that are
    neccessary for the propert interpretation of TPCL code.
    
    The interpreter follows the singletone pattern, so we
    get it once and set global variables once. Note that we
    must be careful, then, of bleed-over from other uses.
    """
    global interp
    global base_env
    if not interp:
        interp = scheme.make_interpreter()
        base_env = interp.get_environment()
    return interp
Пример #2
0
def GetInterpreter():
    """\
    Get the interpreter for TPCL code. Here we can add any
    variables that we need to and make any changes that are
    neccessary for the propert interpretation of TPCL code.
    
    The interpreter follows the singletone pattern, so we
    get it once and set global variables once. Note that we
    must be careful, then, of bleed-over from other uses.
    """
    global interp
    global base_env
    if not interp:
        interp = scheme.make_interpreter()
        base_env = interp.get_environment()
    return interp
Пример #3
0
    def calculate(self):
        """\
		calculate() -> Interpretor, Design

		Calculates all the properties on a design. 
		Returns the Interpretor (used to create the design and the actual design).
		"""
        if hasattr(self, "_calculate"):
            return self._calculate
        i = scheme.make_interpreter()

        # Step 1 -------------------------------------

        ranks = self.rank()
        print "The order I need to calculate stuff in is,", ranks

        # Step 2 -------------------------------------

        # The design object
        class Design(dict):
            pass

        design = Design()
        scheme.environment.defineVariable(scheme.symbol.Symbol("design"), design, i.get_environment())

        # Step 3 -------------------------------------
        for rank in ranks.keys():
            for property_id in ranks[rank]:
                property = Property(property_id)

                # Where we will store the values as calculated
                bits = []

                # Get all the components we contain
                for component_id, amount in self.components:
                    # Create the component object
                    component = Component(component_id)

                    # Calculate the actual value for this design
                    value = component.property(property_id)
                    if value:
                        print "Now evaluating", value
                        value = i.eval(scheme.parse("""( %s design)""" % value))

                        print "The value calculated for component %i was %r" % (component_id, value)

                        for x in range(0, amount):
                            bits.append(value)

                print "All the values calculated where", bits
                bits_scheme = "(list"
                for bit in bits:
                    bits_scheme += " " + str(bit).replace("L", "")
                bits_scheme += ")"
                print "In scheme that is", bits_scheme

                print """(let ((bits %s)) (%s design bits))""" % (bits_scheme, property.calculate)
                total = i.eval(
                    scheme.parse("""(let ((bits %s)) (%s design bits))""" % (bits_scheme, property.calculate))
                )
                value, display = scheme.pair.car(total), scheme.pair.cdr(total)

                print "In total I got '%i' which will be displayed as '%s'" % (value, display)
                design[property.name] = (property_id, value, display)

                def t(design, name=property.name):
                    return design[name][1]

                i.install_function("designtype." + property.name, t)

        print "The final properties we have are", design.items()
        self._calculate = (i, design)
        return i, design
Пример #4
0
	def calculate(self):
		"""\
		calculate() -> Interpretor, Properties

		Calculates all the properties on a design. 
		Returns the Interpretor and the object with the Properties.
		"""
		i = scheme.make_interpreter()

		# Step 1 -------------------------------------
		ranks = self.rank()
		print "The order I need to calculate stuff in is,", ranks

		# Step 2 -------------------------------------
		# The object which will store the properties calculated
		class Properties(dict):
			pass

		properties = Properties()
		scheme.environment.defineVariable(scheme.symbol.Symbol('design'), properties, i.get_environment())

		# Step 3 -------------------------------------
		for rank in ranks.keys():
			for property_id in ranks[rank]:
				property = self.cache.properties[property_id]

				# Where we will store the values as calculated
				bits = []
		
				# Get all the components we contain
				for component_id, amount in self.design.components:
					# Create the component object
					component = self.cache.components[component_id] 

					# Calculate the actual value for this design
					value = get(component.properties, property_id)
					if value:
						print "Now evaluating", value
						value = i.eval(scheme.parse("""(%s design)""" % value))

						print "The value calculated for component %i was %r" % (component_id, value)
					
						for x in range(0, amount):
							bits.append(value)

				print "All the values calculated where", bits
				bits_scheme = "(list"
				for bit in bits:
					bits_scheme += " " + str(bit).replace('L', '')
				bits_scheme += ")"
				print "In scheme that is", bits_scheme
				
				total = i.eval(scheme.parse("""(let ((bits %s)) (%s design bits))""" % (bits_scheme, property.calculate)))
				value, display = scheme.pair.car(total), scheme.pair.cdr(total)

				print "In total I got '%i' which will be displayed as '%s'" % (value, display)
				properties[property.name] = (property_id, value, display)

				def t(properties, name=property.name):
					return properties[name][1]
				
				i.install_function('designtype.'+property.name, t)
				
		print "The final properties we have are", properties.items()
		return i, properties
Пример #5
0
    def calculate(self):
        """\
		calculate() -> Interpretor, Design

		Calculates all the properties on a design. 
		Returns the Interpretor (used to create the design and the actual design).
		"""
        if hasattr(self, '_calculate'):
            return self._calculate
        i = scheme.make_interpreter()

        # Step 1 -------------------------------------

        ranks = self.rank()
        print "The order I need to calculate stuff in is,", ranks

        # Step 2 -------------------------------------

        # The design object
        class Design(dict):
            pass

        design = Design()
        scheme.environment.defineVariable(scheme.symbol.Symbol('design'),
                                          design, i.get_environment())

        # Step 3 -------------------------------------
        for rank in ranks.keys():
            for property_id in ranks[rank]:
                property = Property(property_id)

                # Where we will store the values as calculated
                bits = []

                # Get all the components we contain
                for component_id, amount in self.components:
                    # Create the component object
                    component = Component(component_id)

                    # Calculate the actual value for this design
                    value = component.property(property_id)
                    if value:
                        print "Now evaluating", value
                        value = i.eval(scheme.parse("""( %s design)""" %
                                                    value))

                        print "The value calculated for component %i was %r" % (
                            component_id, value)

                        for x in range(0, amount):
                            bits.append(value)

                print "All the values calculated where", bits
                bits_scheme = "(list"
                for bit in bits:
                    bits_scheme += " " + str(bit).replace('L', '')
                bits_scheme += ")"
                print "In scheme that is", bits_scheme

                print """(let ((bits %s)) (%s design bits))""" % (
                    bits_scheme, property.calculate)
                total = i.eval(
                    scheme.parse("""(let ((bits %s)) (%s design bits))""" %
                                 (bits_scheme, property.calculate)))
                value, display = scheme.pair.car(total), scheme.pair.cdr(total)

                print "In total I got '%i' which will be displayed as '%s'" % (
                    value, display)
                design[property.name] = (property_id, value, display)

                def t(design, name=property.name):
                    return design[name][1]

                i.install_function('designtype.' + property.name, t)

        print "The final properties we have are", design.items()
        self._calculate = (i, design)
        return i, design