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 __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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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()
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)
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)
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)
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
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
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
def __radd__(self, y): if y is zero: return self if isinstance(y, SP2): return addP2(self, y) Errors.errorOnStaticTypes("Add", "SP2", y)
def __radd__(self, y): if y is zero: return self if isinstance(y, SHPR): return addHPR(self, y) Errors.errorOnStaticTypes("Add", "SHPR", y)
def __rsub__(self, y): if y is zero: return self if isinstance(y, SHPR): return subHPR(self, y) Errors.errorOnStaticTypes("Sub", "SHPR", y)
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)
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)