Beispiel #1
0
def checkValidKey(s):
    if s in keyRenamings:
        return keyRenamings[s]
    if type(s) is type("s"):
        if len(s) == 1 or s in allKeyNames:
            return s
    Errors.badKeyName(s)
def checkValidKey(s):
    if s in keyRenamings:
        return keyRenamings[s]
    if type(s) is type("s"):
        if len(s) == 1 or s in allKeyNames:
            return s
    Errors.badKeyName(s)
Beispiel #3
0
 def __add__(self, e):
     Errors.checkEvent(e, "event addition")
     #       print("Event merge: " + str(self) + " " + str(e))
     if self.value is None:
         return e
     else:
         return self
Beispiel #4
0
 def __sub__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP3):
         return subP3(self, y)
     if isinstance(y, Factory.SFact):
         return Factory.Lift0F(self, p3Type) - y
     Errors.errorOnStaticTypes("Sub", "SP3", y)
Beispiel #5
0
 def __sub__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP2):
         return subP2(self, y)
     if isinstance( y, Factory.SFact):
         return Factory.Lift0F(self, p2Type) - y
     Errors.errorOnStaticTypes("Sub", "SP2", y)
Beispiel #6
0
 def __radd__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP3):
         return addP3(self, y)
     if isinstance(y, Factory.SFact):
         return y + self
     Errors.errorOnStaticTypes("Add", "SP3", y)
Beispiel #7
0
 def __radd__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP3):
         return addP3(self, y)
     if isinstance(y, Factory.SFact):
         return y + self
     Errors.errorOnStaticTypes("Add", "SP3", y)
Beispiel #8
0
 def __rmul__(self, y):
     if y is zero:
         return zero
     if isinstance(y, type(1)) or isinstance(y,type(1.0)):
         return scaleP2(y, self)
     if getPtype(y).includes(numType):
         return scaleP2(y, self)
     Errors.errorOnStaticTypes("Mul", "SP2", y)
Beispiel #9
0
 def __sub__(self, y):
     if y is zero:
         return self
     if isinstance(y, SHPR):
         return subHPR(self, y)
     if isinstance(y, Factory.SFact):
         return Factory.Lift0F(self, hprType) - y
     Errors.errorOnStaticTypes("Sub", "SHPR", y)
Beispiel #10
0
 def __add__(self, y):
     if y is zero:
         return self
     if isinstance(y, SHPR):
         return addHPR(self, y)
     if isinstance(y, Factory.SFact):
         return y + self
     Errors.errorOnStaticTypes("Add", "SHPR", y)
Beispiel #11
0
 def __rmul__(self, y):
     if y is zero:
         return zero
     if isinstance(y, type(1)) or isinstance(y, type(1.0)):
         return scaleP2(y, self)
     if getPtype(y).includes(numType):
         return scaleP2(y, self)
     Errors.errorOnStaticTypes("Mul", "SP2", y)
Beispiel #12
0
 def __rmul__(self, y):
     if y is zero:
         return zero.rmul(self, y)
     if isinstance(y, type(1)) or isinstance(y, type(1.5)):
         return scaleP3(y, self)
     #print(getPtype(y))
     if getPtype(y).includes(numType):
         return scaleP3(y, self)
     Errors.errorOnStaticTypes("Mul", "SP3", y)
Beispiel #13
0
 def __div__(self, y):
     if y is zero:
         print("Universal Explosion")
         return zero
     if isinstance(y, type(1)) or isinstance(y,type(1.0)):
         return scaleP3((1.0/y), self)
     if getPtype(y).includes(numType):
         return scaleP3((1.0/y), self)
     Errors.errorOnStaticTypes("Div", "SP2", y)
Beispiel #14
0
 def __rmul__(self, y):
     if y is zero:
         return zero.rmul(self, y)
     if isinstance(y, type(1)) or isinstance(y, type(1.5)):
         return scaleP3(y, self)
     #print(getPtype(y))
     if getPtype(y).includes(numType):
         return scaleP3(y, self)
     Errors.errorOnStaticTypes("Mul", "SP3", y)
Beispiel #15
0
 def __div__(self, y):
     if y is zero:
         print("Universal Explosion")
         return zero
     if isinstance(y, type(1)) or isinstance(y, type(1.0)):
         return scaleP3((1.0 / y), self)
     if getPtype(y).includes(numType):
         return scaleP3((1.0 / y), self)
     Errors.errorOnStaticTypes("Div", "SP2", y)
Beispiel #16
0
 def __add__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP2):
         return addP2(self, y)
     if isinstance(y, Factory.SFact):
         return y + self
     Errors.errorOnStaticTypes("Add", "SP2", y)
     sys.exit()
Beispiel #17
0
 def __add__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP2):
         return addP2(self, y)
     if isinstance(y, Factory.SFact):
         return y + self
     Errors.errorOnStaticTypes("Add", "SP2", y)
     sys.exit()
Beispiel #18
0
def checkType(obj, attr, value, expected):
    got = getPtype(value)
    #print(str(expected.includes(got)) + " " + str(got) + " " + str(expected))
    if got.includes(expected):
        return
    if hasattr(obj, '_name'):
        name = obj._name
    else:
        name = repr(obj)
    Errors.typeError(expected, got, name, attr)
Beispiel #19
0
 def fn(*args):
     #print(str(len(types)) + " " + str(len(args)))
     Errors.checkNumArgs(len(types), len(args), "ProxyObject", name)
     for arg in args:
         #(print("lift: " + str(arg)))
         if isinstance(arg, SFact):
             return LiftF(name, f, args, types=types, outType=outType)
     if len(types) is not 0:
         for i in range(len(args)):
             #print("checking " + repr(args[i]) + ' ' + repr(types[i]))
             Types.checkType("ProxyObject", name, args[i], types[i])
     return f(*args)
Beispiel #20
0
 def fn(*args):
     #print(str(len(types)) + " " + str(len(args)))
     Errors.checkNumArgs(len(types), len(args), "ProxyObject", name)
     for arg in args:
         #(print("lift: " + str(arg)))
         if isinstance(arg, SFact):
             return LiftF(name,f,args,types = types, outType = outType)
     if len(types) is not 0:
         for i in range(len(args)):
             #print("checking " + repr(args[i]) + ' ' + repr(types[i]))
             Types.checkType("ProxyObject", name, args[i], types[i])
     return f(*args)
Beispiel #21
0
 def start(self, expectedType = Types.anyType, obj = "ProxyObject"):
     self.args = list(self.args)
     argsLen = len(self.args)
     Types.addCheck(self)
     Types.checkType(obj, self, self.outType, expectedType)
     Errors.checkNumArgs(len(self.types), argsLen, obj, self)
     #list() call for pyhton 3 mapping support
     #print("LiftF: " + str(self.args))
     ea = list(map(lambda x: maybeLift(x).start(), self.args))
     #print("LiftF 2: " + str(ea))
     #print("LiftF 3: " + str(ea[0][0].now()))
     for i in range(len(self.types)):
         Types.checkType(obj, self, ea[i][1], self.types[i])
     #Some where between here and the Lift const
     return Lift(self.name,self.f, list(map(lambda x: x[0], ea))), self.outType
Beispiel #22
0
 def start(self, expectedType=Types.anyType, obj="ProxyObject"):
     self.args = list(self.args)
     argsLen = len(self.args)
     Types.addCheck(self)
     Types.checkType(obj, self, self.outType, expectedType)
     Errors.checkNumArgs(len(self.types), argsLen, obj, self)
     #list() call for pyhton 3 mapping support
     #print("LiftF: " + str(self.args))
     ea = list(map(lambda x: maybeLift(x).start(), self.args))
     #print("LiftF 2: " + str(ea))
     #print("LiftF 3: " + str(ea[0][0].now()))
     for i in range(len(self.types)):
         Types.checkType(obj, self, ea[i][1], self.types[i])
     #Some where between here and the Lift const
     return Lift(self.name, self.f, list(map(lambda x: x[0],
                                             ea))), self.outType
Beispiel #23
0
    def _update(self):
        if self._alive:
            #            print("Object: " + str(self) + " signals: " + str(self._signals))
            for k, v in self._signals.items():
                #                print("Objects: " + str(self) + " is updating: " + k)
                v.now()
            thunks = []

            #Evaluate one time reactions:
            for c in self._1Reactions:
                #                print("Object: " + str(self) + " is updating: " + str(c[0]))
                temp = c[0].now()
                Errors.checkEvent(temp, "One time reaction in " + self._name)
                if temp.occurs():
                    #print("    " + str(temp) + " is being added to thunks")
                    thunks.append(Reaction(c[1], self, temp.value))
                    self._1Reactions.remove(c)
                    break

            if (len(thunks) >= 2):
                print("Multiple one time reactions in a heartbeat in object " +
                      self._name)

            #Evaluate recurring reactions
            # print("Number of reactions in " + self._name + " " + str(len(self._gReactions)))
            for d in self._gReactions:
                temp = d[0].now()
                Errors.checkEvent(temp, "recurring reaction in " + self._name)
                #                print("Object: " + str(self) + " is updating: " + str(d[0]))
                if temp.occurs():
                    #print("    " + repr(temp) + " is being added to thunks")
                    #print("Thunks" + str(thunks) + " " + str(d))
                    thunks.append(Reaction(d[1], self, temp.value))

            #push to the actuall object
            self._updater(self)
            return thunks
Beispiel #24
0
    def _update(self):
        if self._alive:
#            print("Object: " + str(self) + " signals: " + str(self._signals))
            for k, v in self._signals.items():
#                print("Objects: " + str(self) + " is updating: " + k)
                v.now()
            thunks = []

            #Evaluate one time reactions:
            for c in self._1Reactions:
#                print("Object: " + str(self) + " is updating: " + str(c[0]))
                temp = c[0].now()
                Errors.checkEvent(temp, "One time reaction in " + self._name)
                if temp.occurs():
                    #print("    " + str(temp) + " is being added to thunks")
                    thunks.append(Reaction(c[1], self, temp.value))
                    self._1Reactions.remove(c)
                    break

            if (len(thunks) >= 2):
                print("Multiple one time reactions in a heartbeat in object " + self._name)

            #Evaluate recurring reactions
            # print("Number of reactions in " + self._name + " " + str(len(self._gReactions)))
            for d in self._gReactions:
                temp = d[0].now()
                Errors.checkEvent(temp, "recurring reaction in " + self._name)
#                print("Object: " + str(self) + " is updating: " + str(d[0]))
                if temp.occurs():
                    #print("    " + repr(temp) + " is being added to thunks")
                    #print("Thunks" + str(thunks) + " " + str(d))
                    thunks.append(Reaction(d[1], self, temp.value))

            #push to the actuall object
            self._updater(self)
            return thunks
Beispiel #25
0
 def __radd__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP2):
         return addP2(self, y)
     Errors.errorOnStaticTypes("Add", "SP2", y)
Beispiel #26
0
 def __radd__(self, y):
     if y is zero:
         return self
     if isinstance(y, SHPR):
         return addHPR(self, y)
     Errors.errorOnStaticTypes("Add", "SHPR", y)
Beispiel #27
0
 def __rsub__(self, y):
     if y is zero:
         return self
     if isinstance(y, SHPR):
         return subHPR(self, y)
     Errors.errorOnStaticTypes("Sub", "SHPR", y)
Beispiel #28
0
 def __radd__(self, y):
     if y is zero:
         return self
     if isinstance(y, SP2):
         return addP2(self, y)
     Errors.errorOnStaticTypes("Add", "SP2", y)
Beispiel #29
0
 def __rsub__(self, y):
     if y is zero:
         return zero.sub(self, zero)
     if isinstance(y, SP3):
         return subP3(y, self)
     Errors.errorOnStaticTypes("Sub", "SP3", y)
Beispiel #30
0
 def __rsub__(self, y):
     if y is zero:
         return zero.sub(self, zero)
     if isinstance(y, SP2):
         return subP2(y, self)
     Errors.errorOnStaticTypes("Sub", "SP2", y)