#!/usr/bin/python import os, sys, time sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython('test2') @rpy.object class MyRpyObject(object): def __init__(self, x=.0, y=.0, z=.0): self.x = x self.y = y self.z = z def add(self, x=.0, y=.0, z=.0): print('add( %s, %s, %s )' % (x, y, z)) self.x += x self.y += y self.z += z def sum(self): return self.x + self.y + self.z def show(self): print('<%s %s %s>' % (self.x, self.y, self.z)) rpy.cache(refresh=1) o = MyRpyObject(.99, 0.33, 0.45)
#!/usr/bin/python import os, sys, array, time, ctypes if __name__ == '__main__': # standalone from python2 sys.path.append('../../rpythonic') import rpythonic rpythonic.set_pypy_root( '../../pypy' ) import pypy.rpython.lltypesystem.rffi as rffi from pypy.rlib import streamio else: # from inside blender import rpythonic ################################ rpy = rpythonic.RPython( 'blender2ogre' ) class Mesh(object): def __init__(self, data): self.numVerts = N = len( data.vertices ) self.numFaces = Nfaces = len(data.faces) self.vertex_positions = (ctypes.c_float * (N * 3))() data.vertices.foreach_get( 'co', self.vertex_positions ) v = self.vertex_positions self.vertex_normals = (ctypes.c_float * (N * 3))() data.vertices.foreach_get( 'normal', self.vertex_normals ) self.faces = (ctypes.c_uint * (Nfaces * 4))()
#!/usr/bin/python import os, sys, time if '..' not in sys.path: sys.path.append('..') import rpythonic rpythonic.set_pypy_root('../../pypy') rpythonic.set_android_sdk_root('../../android-sdk-linux_x86/') rpythonic.set_android_ndk_root('../../android-ndk-r5/') rpy = rpythonic.RPython('android') gl = rpy.rimport('GLES', namespace=globals()) e = rpy.rimport('EGL') glue = rpy.rimport('android_native_app_glue') ## API ## get_app_state = rffi.llexternal('rpythonic_get_app_state', [], lltype.Ptr(glue.android_app)) setup_glue = rffi.llexternal('rpythonic_setup_glue', [lltype.Ptr(glue.android_app)], rffi.VOIDP) swap_buffers = rffi.llexternal('rpythonic_swap_buffers', [rffi.VOIDP], rffi.INT) mainloop = rffi.llexternal('rpythonic_mainloop', [rffi.VOIDP], lltype.Void) #/* # * Send a simple string to the log. # */ #int __android_log_write(int prio, const char *tag, const char *text); log = rffi.llexternal('__android_log_write', [rffi.INT, rffi.CCHARP, rffi.CCHARP], rffi.INT)
#!/usr/bin/python import os, sys sys.path.append('..') import rpythonic rpythonic.set_pypy_root('../../pypy') ################################ rpy = rpythonic.RPython('jstest', platform='javascript') rprint = rpy.get_rprint() # normal print won't work def add(a=1, b=1000): # keyword defaults are given return a + b def sub(a, b): return a - b @rpy.standalone def main(): rprint('hello javascript world') x = add(1, 2) y = 0 for i in range(10): y = sub(x + y, 100) rprint(y) rprint('done') js = rpy.compile() print(js)
#!/usr/bin/python import os, sys sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython('test3') class R(object): def __init__(self): self.values = [] def append(self, value): self.values.append(value) def __getitem__(self, index): return self.values[index] def __setitem__(self, index, value): self.values[index] = value @rpy.bind() def test_neo_rpy(arg=1): r = R() r.append(arg) r.append(100) r[0] = r[0] + r[1] return r[0]
#!/usr/bin/python import os, sys, time sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython( 'test10', backend='llvm' ) @rpy.vector( type='float32', length=4 ) class Vector(object): def __init__(self, x=.0, y=.0, z=.0): self.x = x self.y = y self.z = z def __getitem__(self, index): r = .0 if index == 0: r = self.x elif index == 1: r = self.y elif index == 2: r = self.z return r def __setitem__(self, index, value): if index == 0: self.x = value if index == 1: self.y = value if index == 2: self.z = value def __add__( self, other ): x = self.x + other.x y = self.y + other.y z = self.z + other.z return Vector( x,y,z )
#!/usr/bin/python import os, sys, thread, time, math sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython('test_threadsafe') @rpy.object class MyRpyObject(object): def __init__(self): self._thread1 = [] self._thread2 = [] def append1(self, value=.0): self._thread1.append(math.sqrt(value)) def append2(self, value=.0): self._thread2.append(math.sqrt(value)) rpy.cache(refresh=1) o = MyRpyObject() lock = thread.allocate_lock() FINISHED = 0 def thread1(values):
#!/usr/bin/python import os, sys sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython('test1') @rpy.bind() # declare arg types is optional if, def add(a=1, b=1000): # keyword defaults are given print('rpy.add %s %s' % (a, b)) return a + b @rpy.bind(a=float, b=float) def sub(a, b): print('rpy.sub %s %s' % (a, b)) return a - b #rpythonic.set_cache( '/tmp' ) # defaults to /home/user/.rpythonic rpy.cache(refresh=1) # only compiles if cache is dirty ############### testing ############## print(add(100, 9)) print(add(1, 99)) print(sub(1.0, .8))
#!/usr/bin/python import os, sys, time if '..' not in sys.path: sys.path.append('..') import rpythonic rpythonic.set_pypy_root('../../pypy') rpy = rpythonic.RPython('rpyGLtest', platform='linux') gl = rpy.rimport('openGL', namespace=globals()) glu = rpy.rimport('openGLU', namespace=globals()) sdl = rpy.rimport('SDL') def reset_viewport(width, height): ratio = float(width) / float(height) glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() #/* Set our perspective */ gluPerspective(45.0, ratio, 0.1, 100.0) #/* Make sure we're chaning the model view and not the projection */ glMatrixMode(GL_MODELVIEW) #/* Reset The View */ glLoadIdentity() @rpy.standalone
#!/usr/bin/python import os, sys, array, time, ctypes sys.path.append('..') import rpythonic ################################ rpy = rpythonic.RPython('test_rpyarray') import pypy.rpython.lltypesystem.rffi as rffi @rpy.bind( addr=int, length=int ) def test_float( addr, length ): a = rffi.cast( rffi.FLOATP, addr ) for i in range( length ): f = rffi.cast( rffi.DOUBLE, a[i] ) print f @rpy.bind( addr=int, length=int ) def test( addr, length ): a = rffi.cast( rffi.DOUBLEP, addr ) x = ['<somexml'] for i in range( length ): print a[i] x.append( 'attribute="%s"' %a[i] ) x.append( '>' ) print( ' '.join(x) ) rpy.cache(refresh=1) ############### testing ##############
#!/usr/bin/python # The Computer Language Benchmarks Game # http://shootout.alioth.debian.org/ # # originally by Kevin Carson # modified by Tupteq, Fredrik Johansson, and Daniel Nanz # modified by Maciej Fijalkowski # modified by HartsAntler for RPythonic # 2to3 import datetime import sys, math, time if '..' not in sys.path: sys.path.append('..') import rpythonic rpy = rpythonic.RPython('testnbody', platform='linux') def combinations(l): result = [] for x in range(len(l) - 1): ls = l[x + 1:] for y in ls: result.append((l[x], y)) return result PI = 3.14159265358979323 SOLAR_MASS = 4 * PI * PI DAYS_PER_YEAR = 365.24 MASS = {