[pypy-svn] r14735 - in pypy/dist/pypy: interpreter module/posix module/posix/test rpython rpython/module
ale at codespeak.net
ale at codespeak.net
Mon Jul 18 17:18:49 CEST 2005
Author: ale
Date: Mon Jul 18 17:18:47 2005
New Revision: 14735
Added:
pypy/dist/pypy/module/posix/
pypy/dist/pypy/module/posix/__init__.py
pypy/dist/pypy/module/posix/interp_posix.py
pypy/dist/pypy/module/posix/test/
pypy/dist/pypy/module/posix/test/test_posix.py
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/rpython/extfunctable.py
pypy/dist/pypy/rpython/module/ll_os.py
Log:
The start of the mixedmodule os. The module function used in _file and _sio are implemented. The lowlevel support for these functions are not complete (fstat for instance doent work). a few test is added as well
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Mon Jul 18 17:18:47 2005
@@ -153,7 +153,7 @@
self.setbuiltinmodule('parser', 'recparser')
elif self.options.useparsermodule == "parser":
self.setbuiltinmodule('parser')
-
+ self.setbuiltinmodule('posix')
# initialize with "bootstrap types" from objspace (e.g. w_None)
for name, value in self.__dict__.items():
if name.startswith('w_') and not name.endswith('Type'):
Added: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/posix/__init__.py Mon Jul 18 17:18:47 2005
@@ -0,0 +1,18 @@
+# Package initialisation
+from pypy.interpreter.mixedmodule import MixedModule
+
+class Module(MixedModule):
+ appleveldefs = {
+ }
+ interpleveldefs = {
+ 'open' : 'interp_posix.open',
+ 'lseek' : 'interp_posix.lseek',
+ 'write' : 'interp_posix.write',
+ 'isatty' : 'interp_posix.isatty',
+ 'read' : 'interp_posix.read',
+ 'close' : 'interp_posix.close',
+ 'ftruncate' : 'interp_posix.ftruncate',
+ 'fstat' : 'interp_posix.fstat',
+ 'dup' : 'interp_posix.dup'
+ '__doc__' : "space.wrap('Posix module')"
+ }
Added: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/posix/interp_posix.py Mon Jul 18 17:18:47 2005
@@ -0,0 +1,49 @@
+from pypy.interpreter.baseobjspace import ObjSpace,W_Root
+
+import os
+from os import *
+
+def open(space, w_fname, w_flag, w_mode=0777):
+ fname = space.str_w(w_fname)
+ flag = space.int_w(w_flag)
+ mode = space.int_w(w_mode)
+ # notice that an unwrap_spec attached to open could be used to the same effect
+ fd = os.open(fname, flag, mode)
+ return space.wrap(fd)
+
+
+def lseek(space, w_fd, pos, how):
+ os.lseek(fd,pos,how)
+lseek.unwrap_spec = [ObjSpace, W_Root, int, int]
+
+def isatty(space, w_fd):
+ return os.isatty(fd)
+lseek.unwrap_spec = [ObjSpace, W_Root, int, int]
+
+def read(space, w_fd, buffersize):
+ return os.read(w_fd,buffersize)
+read.unwrap_spec = [ObjSpace, W_Root, int]
+
+def write(space, w_fd, data):
+ return os.write( w_fd, data)
+write.unwrap_spec = [ObjSpace, W_Root, str]
+
+def close(space, w_fd):
+ os.close(w_fd)
+close.unwrap_spec = [ObjSpace, W_Root]
+
+def ftruncate(space, w_fd, length):
+ os.ftruncate(w_fd, length)
+ftruncate.unwrap_spec = [ObjSpace, W_Root, int]
+
+def fstat(space, w_fd):
+ return os.fstat(w_fd)
+fstat.unwrap_spec = [ObjSpace, W_Root]
+
+def getcwd(space):
+ return os.getcwd()
+getcwd.unwrap_spec = [ObjSpace]
+
+def dup(space, w_fd):
+ return os.dup(w_fd)
+dup.unwrap_spec = [ObjSpace, W_Root]
\ No newline at end of file
Added: pypy/dist/pypy/module/posix/test/test_posix.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/module/posix/test/test_posix.py Mon Jul 18 17:18:47 2005
@@ -0,0 +1,28 @@
+from pypy.rpython.test.test_llinterp import interpret
+
+def test_open():
+ def f():
+ import os
+ ff = os.open('test_posix.py',0,0755)
+ return ff
+ func = interpret(f,[])
+ assert func
+
+def test_dup():
+ def ff():
+ import os
+ fi = os.open('test_posix.py',0,0755)
+ g = os.dup(fi)
+ #fi.close()
+ return g
+ func = interpret(ff,[])
+ assert func
+
+def test_fstat():
+ def fo():
+ import os
+ fi = os.open('test_posix.py',0,0755)
+ g = os.fstat(fi)
+ return g
+ func = interpret(fo,[],True)
+ assert func
Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py (original)
+++ pypy/dist/pypy/rpython/extfunctable.py Mon Jul 18 17:18:47 2005
@@ -57,6 +57,7 @@
declare(os.close , nonefactory, 'll_os/close')
declare(os.getcwd , str , 'll_os/getcwd')
declare(os.dup , int , 'll_os/dup')
+declare(os.fstat , int , 'll_os/fstat')
declare(time.time , float , 'll_time/time')
declare(time.clock, float , 'll_time/clock')
declare(time.sleep, nonefactory, 'll_time/sleep')
Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os.py Mon Jul 18 17:18:47 2005
@@ -15,7 +15,7 @@
import os, errno
from pypy.rpython.rstr import STR
-from pypy.rpython.lltype import malloc
+from pypy.rpython.lltype import GcStruct, Signed, Array, Char, Ptr, malloc
# utility conversion functions
@@ -77,3 +77,14 @@
def ll_os_dup(fd):
return os.dup(fd)
ll_os_dup.suggested_primitive = True
+
+def ll_os_fstat(fd):
+ stat = os.fstat(fd)
+ n = len(stat)
+ fieldnames = ['item%d' % i for i in range(n)]
+ lltypes = [Signed]*n
+ fields = tuple(zip(fieldnames, lltypes))
+ tup = GcStruct('tuple%d' % n, fields)
+ #lowleveltype = Ptr(tup)
+ #p = malloc( tup )
+ return tup
\ No newline at end of file
More information about the Pypy-commit
mailing list