~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/objspace/fake/objspace.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, W_Root
 
2
from pypy.rlib.nonconst import NonConstant
 
3
from pypy.rlib.rarithmetic import r_uint
 
4
 
 
5
class W_Type(W_Root):
 
6
    pass
 
7
 
 
8
class W_Object(W_Root):
 
9
    pass
 
10
W_Object.typedef = W_Type()
 
11
 
 
12
def make_dummy(a=W_Object(), b=W_Object()):
 
13
    def fn(*args):
 
14
        if NonConstant(True):
 
15
            return a
 
16
        else:
 
17
            return b
 
18
    return fn
 
19
 
 
20
int_dummy   = make_dummy(42, 43)
 
21
float_dummy = make_dummy(42.0, 42.1)
 
22
uint_dummy  = make_dummy(r_uint(42), r_uint(43))
 
23
str_dummy   = make_dummy('foo', 'bar')
 
24
bool_dummy  = make_dummy(True, False)
 
25
 
 
26
class FakeObjSpace(ObjSpace):
 
27
    w_None           = W_Object()
 
28
    w_False          = W_Object()
 
29
    w_True           = W_Object()
 
30
    w_Ellipsis       = W_Object()
 
31
    w_NotImplemented = W_Object()
 
32
    w_int            = W_Object()
 
33
    w_dict           = W_Object()
 
34
    w_float          = W_Object()
 
35
    w_long           = W_Object()
 
36
    w_tuple          = W_Object()
 
37
    w_str            = W_Object()
 
38
    w_unicode        = W_Object()
 
39
    w_type           = W_Object()
 
40
    w_instance       = W_Object()
 
41
    w_slice          = W_Object()
 
42
    w_hex            = W_Object()
 
43
    w_oct            = W_Object()
 
44
    
 
45
    def initialize(self):
 
46
        self.config.objspace.geninterp = False
 
47
        self.wrap_cache = {}
 
48
        self.make_builtins()
 
49
 
 
50
    def _freeze_(self):
 
51
        return True
 
52
 
 
53
    def wrap(self, x):
 
54
        if isinstance(x, Wrappable):
 
55
            w_result = x.__spacebind__(self)
 
56
            return w_result
 
57
        return W_Object()
 
58
    wrap._annspecialcase_ = "specialize:argtype(1)"
 
59
 
 
60
    def unwrap(self, w_obj):
 
61
        assert isinstance(w_obj, W_Object)
 
62
        return None
 
63
 
 
64
    lookup            = make_dummy()
 
65
    allocate_instance = make_dummy()
 
66
    getattr           = make_dummy()
 
67
    setattr           = make_dummy()
 
68
    getitem           = make_dummy()
 
69
    setitem           = make_dummy()
 
70
    delitem           = make_dummy()
 
71
    int_w             = int_dummy
 
72
    uint_w            = uint_dummy
 
73
    float_w           = float_dummy
 
74
    iter              = make_dummy()
 
75
    type              = make_dummy()
 
76
    str               = make_dummy()
 
77
    repr              = make_dummy()
 
78
    id                = make_dummy()
 
79
    len               = make_dummy()
 
80
    str_w             = str_dummy
 
81
    call_args         = make_dummy()
 
82
    new_interned_str  = make_dummy()
 
83
    newstring         = make_dummy()
 
84
    newunicode        = make_dummy()
 
85
    newint            = make_dummy()
 
86
    newlong           = make_dummy()
 
87
    newfloat          = make_dummy()
 
88
    def newdict(self, track_builtin_shadowing=False):
 
89
        return self.newfloat()
 
90
    newlist           = make_dummy()
 
91
    emptylist         = make_dummy()
 
92
    newtuple          = make_dummy()
 
93
    newslice          = make_dummy()
 
94
    lt                = make_dummy()
 
95
    le                = make_dummy()
 
96
    eq                = make_dummy()
 
97
    ne                = make_dummy()
 
98
    gt                = make_dummy()
 
99
    ge                = make_dummy()
 
100
    lt_w              = bool_dummy
 
101
    le_w              = bool_dummy
 
102
    eq_w              = bool_dummy
 
103
    ne_w              = bool_dummy
 
104
    gt_w              = bool_dummy
 
105
    ge_w              = bool_dummy
 
106
    is_w              = bool_dummy
 
107
    is_               = make_dummy()
 
108
    next              = make_dummy()
 
109
    is_true           = bool_dummy
 
110
    nonzero           = make_dummy()
 
111
    issubtype         = make_dummy()
 
112
    ord               = make_dummy()
 
113
    hash              = make_dummy()
 
114
    delattr           = make_dummy() # should return None?
 
115
    contains          = make_dummy()
 
116
    hex               = make_dummy()
 
117
    oct               = make_dummy()
 
118
    pow               = make_dummy()
 
119
    inplace_pow       = make_dummy()
 
120
    cmp               = make_dummy()
 
121
 
 
122
    # XXsX missing operations
 
123
    def coerce(self, *args):   raise NotImplementedError("space.coerce()")
 
124
    def get(self, *args):      raise NotImplementedError("space.get()")
 
125
    def set(self, *args):      raise NotImplementedError("space.set()")
 
126
    def delete(self, *args):   raise NotImplementedError("space.delete()")
 
127
    def userdel(self, *args):  raise NotImplementedError("space.userdel()")
 
128
    def marshal_w(self, *args):raise NotImplementedError("space.marshal_w()")
 
129
    def log(self, *args):      raise NotImplementedError("space.log()")
 
130
 
 
131
    gettypefor     = make_dummy()
 
132
    gettypeobject  = make_dummy()
 
133
    unpackiterable = make_dummy([W_Object()], [W_Object()])
 
134
 
 
135
 
 
136
## Register all exceptions
 
137
import exceptions
 
138
for name in ObjSpace.ExceptionTable:
 
139
    exc = getattr(exceptions, name)
 
140
    setattr(FakeObjSpace, 'w_' + name, W_Object())