Exemple #1
0
def repl():
    stdin = fdopen_as_stream(0, 'r')
    stdout = fdopen_as_stream(1, 'a')
    vm = VM()
    open_lib(vm)

    while True:
        if we_are_translated():
            # RPython -- cannot use readline
            stdout.write('> ')
            stdout.flush()
            raw_line_of_code = stdin.readline()
        else:
            # CPython -- use readline
            try:
                raw_line_of_code = raw_input('> ')
            except (EOFError, KeyboardInterrupt):
                raw_line_of_code = ''

        if not raw_line_of_code:
            break # handle EOF

        raw_line_of_code = raw_line_of_code.strip('\n') # RPy
        if not raw_line_of_code:
            continue # handle plain ENTER

        expr_list = parse_string(raw_line_of_code)
        if not expr_list:
            continue # handle whitespace in RPy

        w_skel = compile_list_of_expr(expr_list)
        # some hack so as to not return the vm?

        # to view code
        if DEBUG:
            print w_skel

        # to view code
        if DEBUG:
            continue

        vm.bootstrap(w_skel)
        vm.run()
        w_result = vm.exit_value
        if w_result is not w_unspecified:
            print w_result.to_string()
Exemple #2
0
def open_exclusive(space, cpathname, mode):
    try:
        os.unlink(cpathname)
    except OSError:
        pass

    flags = os.O_EXCL | os.O_CREAT | os.O_WRONLY | os.O_TRUNC | streamio.O_BINARY
    fd = os.open(cpathname, flags, mode)
    return streamio.fdopen_as_stream(fd, "wb")
Exemple #3
0
def open_exclusive(space, cpathname, mode):
    try:
        os.unlink(cpathname)
    except OSError:
        pass

    flags = (os.O_EXCL | os.O_CREAT | os.O_WRONLY | os.O_TRUNC
             | streamio.O_BINARY)
    fd = os.open(cpathname, flags, mode)
    return streamio.fdopen_as_stream(fd, "wb")
def main(argv):
    stdin = fdopen_as_stream(0, 'r')
    source = stdin.readall()
    try:
        ast = read_program(source)
        code = compile(ast)
        result = code.eval()
    except InterpError as e:
        print e.what
        return 1

    print result.to_s()
    return 0
def main(argv):
    stdin = fdopen_as_stream(0, 'r')
    source = stdin.readall()
    try:
        ast = read_program(source)
        code = compile(ast)
        result = code.eval()
    except InterpError as e:
        print e.what
        return 1

    print result.to_s()
    return 0
Exemple #6
0
    def __init__(self):
        start = float(time.time())
        self._neurons = []
        self._columns = []
        self._layers = [[]] * LAYERS
        self._pulse_layers = [0] * LAYERS
        self._pulse_layers[0] = 1

        self._pulse_columns = [0] * COLUMNS
        self._pulse_columns[0] = 1
        self._pulse_columns[1] = 1
        self._pulse_columns[2] = 1
        self._pulse_columns[3] = 1

        inc = 360.0 / COLUMNS
        scale = float(LAYERS)
        expansion = 1.333
        linc = scale / LAYERS
        for column in range(COLUMNS):
            colNeurons = []
            self._columns.append(colNeurons)
            X = math.sin(radians(column * inc))
            Y = math.cos(radians(column * inc))
            expanding = STEM
            width = 1.0 / scale
            for layer in range(LAYERS):
                Z = layer * linc
                r = random() * random()
                g = 0.2
                b = 0.2
                for i in range(int(expanding)):
                    x = uniform(-width, width)
                    rr = random() * random()  # DJ's trick
                    y = uniform(-width * rr, width * rr) + X
                    z = Z + Y
                    # create 50/50 exitatory/inhibitory
                    n = RecurrentSpikingModel(x=x,
                                              y=y,
                                              z=z,
                                              column=column,
                                              layer=layer,
                                              red=r,
                                              green=g,
                                              blue=b)
                    self._neurons.append(n)
                    colNeurons.append(n)
                    self._layers[layer].append(n)

                expanding *= expansion
                width *= expansion

        dendrites = 0
        interlayer = 0
        for lay in self._layers:
            for a in lay:
                for b in lay:
                    if a is not b and a._column == b._column:
                        a.attach_dendrite(b)
                        dendrites += 1
                        interlayer += 1

        intercol = 0
        for col in self._columns:
            for a in col:
                for b in col:
                    if a is not b and random() * random() > 0.75:
                        a.attach_dendrite(b)
                        intercol += 1
                        dendrites += 1

        intercore = 0
        core = self._layers[-1]
        for a in core:
            for b in core:
                if a is not b and random() * random() > 0.85:
                    a.attach_dendrite(b)
                    intercore += 1
                    dendrites += 1

        print 'brain creation time (seconds)', float(time.time()) - start
        print 'neurons per column', len(self._columns[0])
        print 'inter-layer dendrites', interlayer
        print 'inter-column dendrites', intercol
        print 'inter-neocoretex dendrites', intercore
        print 'total dendrites', dendrites
        print 'total neurons', len(self._neurons)
        for i, lay in enumerate(self._layers):
            print 'layer: %s	neurons: %s' % (i, len(lay))
        for i, col in enumerate(self._columns):
            print 'column: %s	neurons: %s' % (i, len(col))

        self._stdin = streamio.fdopen_as_stream(0, 'r', 1)
        #self._stdout = streamio.fdopen_as_stream(1, 'w', 1)
        #self._stderr = streamio.fdopen_as_stream(2, 'w', 1)

        self._width = 640
        self._height = 480
        assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
        self.screen = RSDL.SetVideoMode(self._width, self._height, 32, 0)
        assert self.screen
        fmt = self.screen.c_format
        self.ColorWhite = white = RSDL.MapRGB(fmt, 255, 255, 255)
        self.ColorGrey = grey = RSDL.MapRGB(fmt, 128, 128, 128)
        self.ColorBlack = black = RSDL.MapRGB(fmt, 0, 0, 0)
        self.ColorBlue = blue = RSDL.MapRGB(fmt, 0, 0, 200)

        colors = {'white': white, 'grey': grey, 'black': black, 'blue': blue}

        x = 1
        y = 1
        for i, n in enumerate(self._neurons):
            braneRect = RSDL_helper.mallocrect(x, y, 12, 12)
            groupRect = RSDL_helper.mallocrect(x, y, 12, 2)
            spikeRect = RSDL_helper.mallocrect(x + 4, y + 4, 4, 4)
            n.setup_draw(self.screen.c_format, braneRect, groupRect, spikeRect,
                         colors)
            x += 13
            if x >= self._width - 14:
                x = 1
                y += 13
Exemple #7
0
 def direct_fdopen(self, fd, mode='r', buffering=-1):
     self.direct_close()
     self.check_mode_ok(mode)
     stream = streamio.fdopen_as_stream(fd, mode, buffering)
     self.fdopenstream(stream, fd, mode, '<fdopen>')
Exemple #8
0
 def direct_fdopen(self, fd, mode='r', buffering=-1):
     self.direct_close()
     self.w_name = self.space.wrap('<fdopen>')
     self.check_mode_ok(mode)
     stream = streamio.fdopen_as_stream(fd, mode, buffering)
     self.fdopenstream(stream, fd, mode)
def write_str(s):
    from pypy.rlib.streamio import fdopen_as_stream
    f = fdopen_as_stream(1, 'w')
    f.write(s)
    f.flush()
	def __init__(self):
		start = float(time.time())
		self._neurons = []
		self._columns = []
		self._layers = [ [] ] * LAYERS
		self._pulse_layers = [0] * LAYERS
		self._pulse_layers[ 0 ] = 1

		self._pulse_columns = [0] * COLUMNS
		self._pulse_columns[ 0 ] = 1
		self._pulse_columns[ 1 ] = 1
		self._pulse_columns[ 2 ] = 1
		self._pulse_columns[ 3 ] = 1


		inc = 360.0 / COLUMNS
		scale = float( LAYERS )
		expansion = 1.333
		linc = scale / LAYERS
		for column in range(COLUMNS):
			colNeurons = []
			self._columns.append( colNeurons )
			X = math.sin( radians(column*inc) )
			Y = math.cos( radians(column*inc) )
			expanding = STEM
			width = 1.0 / scale
			for layer in range(LAYERS):
				Z = layer * linc
				r = random() * random()
				g = 0.2
				b = 0.2
				for i in range(int(expanding)):
					x = uniform( -width, width )
					rr = random()*random()		# DJ's trick
					y = uniform( -width*rr, width*rr ) + X
					z = Z + Y
					# create 50/50 exitatory/inhibitory
					n = RecurrentSpikingModel(x=x, y=y, z=z, column=column, layer=layer, red=r, green=g, blue=b )
					self._neurons.append( n )
					colNeurons.append( n )
					self._layers[ layer ].append( n )

				expanding *= expansion
				width *= expansion

		dendrites = 0
		interlayer = 0
		for lay in self._layers:
			for a in lay:
				for b in lay:
					if a is not b and a._column == b._column:
						a.attach_dendrite( b )
						dendrites += 1
						interlayer += 1

		intercol = 0
		for col in self._columns:
			for a in col:
				for b in col:
					if a is not b and random()*random() > 0.75:
						a.attach_dendrite( b )
						intercol += 1
						dendrites += 1

		intercore = 0
		core = self._layers[-1]
		for a in core:
			for b in core:
				if a is not b and random()*random() > 0.85:
					a.attach_dendrite( b )
					intercore += 1
					dendrites += 1

		print 'brain creation time (seconds)', float(time.time())-start
		print 'neurons per column', len(self._columns[0])
		print 'inter-layer dendrites', interlayer
		print 'inter-column dendrites', intercol
		print 'inter-neocoretex dendrites', intercore
		print 'total dendrites', dendrites
		print 'total neurons', len(self._neurons)
		for i,lay in enumerate(self._layers):
			print 'layer: %s	neurons: %s' %(i,len(lay))
		for i,col in enumerate(self._columns):
			print 'column: %s	neurons: %s' %(i,len(col))



		self._stdin = streamio.fdopen_as_stream(0, 'r', 1)
		#self._stdout = streamio.fdopen_as_stream(1, 'w', 1)
		#self._stderr = streamio.fdopen_as_stream(2, 'w', 1)

		self._width = 640; self._height = 480
		assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
		self.screen = RSDL.SetVideoMode(self._width, self._height, 32, 0)
		assert self.screen
		fmt = self.screen.c_format
		self.ColorWhite = white = RSDL.MapRGB(fmt, 255, 255, 255)
		self.ColorGrey = grey = RSDL.MapRGB(fmt, 128, 128, 128)
		self.ColorBlack = black = RSDL.MapRGB(fmt, 0, 0, 0)
		self.ColorBlue = blue = RSDL.MapRGB(fmt, 0, 0, 200)

		colors = {'white':white, 'grey':grey, 'black':black, 'blue':blue}

		x = 1; y = 1
		for i,n in enumerate(self._neurons):
			braneRect = RSDL_helper.mallocrect(x, y, 12, 12)
			groupRect = RSDL_helper.mallocrect(x, y, 12, 2)
			spikeRect = RSDL_helper.mallocrect(x+4, y+4, 4, 4)
			n.setup_draw( self.screen.c_format, braneRect, groupRect, spikeRect, colors )
			x += 13
			if x >= self._width-14:
				x = 1
				y += 13
def write_str(s):
    from pypy.rlib.streamio import fdopen_as_stream
    f = fdopen_as_stream(1, 'w')
    f.write(s)
    f.flush()
def ppr(ast, out=None):
    from pypy.rlib.streamio import fdopen_as_stream
    if not out:
        out = fdopen_as_stream(1, 'w')
    PrettyPrinter(out).write(ast)
    out.flush()
Exemple #13
0
 def open_file_handle(self):
     self.stdin = fdopen_as_stream(0, 'r')
     self.stdout = fdopen_as_stream(1, 'a+')
     self.stderr = fdopen_as_stream(2, 'a+')