Example #1
0
    def _init_instance(self, instance):
        if self._superclass is not None:
            self._superclass._init_instance(instance)
        
        for name, (ootype, default) in self._fields.iteritems():
            instance.__dict__[name] = enforce(ootype, default)

        for name, (ootype, default) in self._overridden_defaults.iteritems():
            instance.__dict__[name] = enforce(ootype, default)
Example #2
0
 def setvar(self, var, val):
     if var.concretetype is not lltype.Void:
         try:
             val = lltype.enforce(var.concretetype, val)
         except TypeError:
             assert False, "type error: input value of type:\n\n\t%r\n\n===> variable of type:\n\n\t%r\n" % (lltype.typeOf(val), var.concretetype)
     assert isinstance(var, Variable)
     self.bindings[var] = val
Example #3
0
 def setvar(self, var, val):
     if var.concretetype is not lltype.Void:
         try:
             val = lltype.enforce(var.concretetype, val)
         except TypeError:
             assert False, "type error: input value of type:\n\n\t%r\n\n===> variable of type:\n\n\t%r\n" % (
                 lltype.typeOf(val), var.concretetype)
     assert isinstance(var, Variable)
     self.bindings[var] = val
Example #4
0
    def __setattr__(self, name, value):
        self.__getattr__(name)

        FLDTYPE = self._TYPE._field_type(name)
        try:
            val = enforce(FLDTYPE, value)
        except TypeError:
            raise TypeError("Expected type %r" % FLDTYPE)

        self.__dict__[name] = value
Example #5
0
 def getval(self, varorconst):
     try:
         val = varorconst.value
     except AttributeError:
         val = self.bindings[varorconst]
     if isinstance(val, ComputedIntSymbolic):
         val = val.compute_fn()
     if varorconst.concretetype is not lltype.Void:
         try:
             val = lltype.enforce(varorconst.concretetype, val)
         except TypeError:
             assert False, "type error: %r val from %r var/const" % (lltype.typeOf(val), varorconst.concretetype)
     return val
Example #6
0
 def getval(self, varorconst):
     try:
         val = varorconst.value
     except AttributeError:
         val = self.bindings[varorconst]
     if isinstance(val, ComputedIntSymbolic):
         val = val.compute_fn()
     if varorconst.concretetype is not lltype.Void:
         try:
             val = lltype.enforce(varorconst.concretetype, val)
         except TypeError:
             assert False, "type error: %r val from %r var/const" % (
                 lltype.typeOf(val), varorconst.concretetype)
     return val
Example #7
0
   def _checkargs(self, args, check_callable=True):
       if len(args) != len(self._TYPE.ARGS):
           raise TypeError,"calling %r with wrong argument number: %r" % (self._TYPE, args)

       checked_args = []
       for a, ARG in zip(args, self._TYPE.ARGS):
           try:
               if ARG is not Void:
                   a = enforce(ARG, a)
           except TypeError:
               raise TypeError,"calling %r with wrong argument types: %r" % (self._TYPE, args)
           checked_args.append(a)
       if not check_callable:
           return checked_args
       callb = self._callable
       if callb is None:
           raise RuntimeError,"calling undefined or null function"
       return callb, checked_args