def emit_call(block, x): #if len(x) == 0: # raise TypeError("Cannot sum sequences of length 0") tmp = pygpu.compiler.variable.TemporaryVariable(typeOf(x[0])) block.add(GPUMov(tmp, x[0])) for v in x[1:]: tmp2 = pygpu.compiler.variable.TemporaryVariable(typeOf(v)) block.add(GPUAdd(tmp2, tmp, v)) tmp = tmp2 return tmp
def call(x): t = typeOf(x) if t == Float: return Constant(__builtin__['floor'](x), t) elif t in [Float2, Float3, Float4]: return Constant(map(__builtin__['floor'], x), t) else: raise TypeError("Cannot floor variables of type %s" % t)
def STORE_FAST(self, stack, block, oparg): v = self.lookup(stack.pop()) t = self.locals[oparg] if t.type == None: try: t.type = typeOf(v) except TypeError: pass else: assert t.type == typeOf(v) if t.type is not None: block.add(GPUMov(t, v)) # if isConstant(v) : if not isinstance(v, TemporaryVariable): self.currentLocals[t] = v
def BINARY_SUBTRACT(self, stack, block, oparg): l, r = stack.popN(2) if isConstant(l) and isConstant(r): stack.push(l - r) elif l in self.currentLocals and isConstant(r): stack.push(self.currentLocals[l] - r) else: tmp = TemporaryVariable(typeOf(l)) block.add(GPUSub(tmp, self.lookup(l), self.lookup(r))) stack.push(tmp)
def STORE_FAST(self, stack, block, oparg): v = self.lookup(stack.pop()) t = self.locals[oparg] if t.type == None: try: t.type = typeOf(v) except TypeError: pass else: assert t.type == typeOf(v) if t.type is not None: block.add(GPUMov(t,v)) #if isConstant(v) : if not isinstance(v, TemporaryVariable): self.currentLocals[t] = v
def BINARY_SUBTRACT(self, stack, block, oparg): l,r = stack.popN(2) if isConstant(l) and isConstant(r): stack.push(l-r) elif l in self.currentLocals and isConstant(r): stack.push(self.currentLocals[l]-r) else: tmp = TemporaryVariable(typeOf(l)) block.add(GPUSub(tmp,self.lookup(l),self.lookup(r))) stack.push(tmp)
def BINARY_ADD(self, stack, block, oparg): l,r = stack.popN(2) if isConstant(l) and isConstant(r): stack.push(l+r) elif l in self.currentLocals and isConstant(r): #print repr(l),repr(r) #print self.currentLo stack.push(self.currentLocals[l]+r) else: tmp = TemporaryVariable(typeOf(l)) block.add(GPUAdd(tmp,self.lookup(l),self.lookup(r))) stack.push(tmp)
def BINARY_ADD(self, stack, block, oparg): l, r = stack.popN(2) if isConstant(l) and isConstant(r): stack.push(l + r) elif l in self.currentLocals and isConstant(r): # print repr(l),repr(r) # print self.currentLo stack.push(self.currentLocals[l] + r) else: tmp = TemporaryVariable(typeOf(l)) block.add(GPUAdd(tmp, self.lookup(l), self.lookup(r))) stack.push(tmp)
def emit_call(block, l, r): try: t = unify(typeOf(l), typeOf(r)) except TypeError, e: raise TypeError("Cannot multiply %s and %s since '%s'" % (l, r, e))
def __init__(self, value, type=None): self.value = value if type is None: type = typeOf(value) self.type = type
def __iter__(self): return DummyIterator(typeOf(self.start), self.start, self.stop, self.step)
def emit_call(block, a, b, x): ## !!FIXME!! implement type checking! tmp = TemporaryVariable(typeOf(a)) block.add(GPUCall(tmp, "lerp", [a, b, x])) return tmp
def emit_call(block, x): tmp = TemporaryVariable(typeOf(x)) block.add(GPUCall(tmp, "abs", [x])) return tmp
def emit_call(block, l, r): assert typeOf(r) == Int tmp = TemporaryVariable(typeOf(l)) block.add(GPUPow(tmp, l, r)) return tmp
def __init__(self, value, type = None): self.value = value if type is None: type = typeOf(value) self.type = type
def emit_call(block, l, r): try: t = unify(typeOf(l), typeOf(r)) except TypeError, e: raise TypeError("Cannot multiply %s and %s since '%s'" % (l,r,e))
def emit_call(block, a, b, x): ## !!FIXME!! implement type checking! tmp = TemporaryVariable(typeOf(a)) block.add(GPUCall(tmp, "lerp", [a,b,x])) return tmp