def __init__(self, from_, to_, target, exc_type, var_name): self.from_ = from_ self.to_ = to_ self.target = target self.exc_type = IMultiname(exc_type) self._exc_type_index = None self.var_name = IMultiname(var_name) self._var_name_index = None
def __init__(self, name, params, rettype, trait_type=traits.MethodTrait, static=False, override=False, prologue=True): self.name = IMultiname(name) self.param_types, self.param_names = zip(*params) or ([], []) self.rettype = rettype self.static, self.override = static, override self.exceptions = [] self.asm = assembler.CodeAssembler(['this'] + list(self.param_names)) if prologue: self.asm.emit('getlocal0') self.asm.emit('pushscope') self.method_info = abc.MethodInfo(str(name), self.param_types, rettype, param_names=self.param_names) self.method_body = abc.MethodBodyInfo(self.method_info, self.asm, exceptions=self.exceptions) self.trait = traits.MethodTrait(self.name, self.method_info, override=self.override)
def isinstance(self, TYPE): """ Checks if an object is an instance of TYPE. Pops an object from the top of the stack, checks if it inherits or implements TYPE, and pushes that boolean onto the stack. """ self.emit('istype', IMultiname(TYPE))
def __new__(cls, name, bases, dct): # We need __new__ because we modify the dct. straits = dct['__straits__'] = [] itraits = dct['__itraits__'] = [] functs = dct['__functs__'] = [] slots = dct['__tslots__'] = [] # exported name - name can be a multinamable # when using the ClassNodeMeta() constructor. if not IMultiname.providedBy(name): package = dct.pop('package', '') name = packagedQName(package, name) # set our name if it doesn't exist in the class. dct.setdefault('__multiname__', name) name = str(dct['__multiname__']) # XXX: should we allow __init__? if dct.get('__init__'): raise ValueError("ClassNodes aren't allowed to have __init__ " "methods. Please use __iinit__ or __cinit__.") basetype = dct.get('__basetype__') or bases[0] if len(bases) > 1: raise ValueError("Tamarin cannot do multiple inheritance.") elif not bases or basetype == object: bases = (object, ) basetype = QName("Object") slot_ids = set() for name in ('iinit', 'cinit'): key = '__%s__' % (name, ) if key in dct: meth = dct[key] = export_method(dct[key]) meth.special = name functs.append(meth) # Go through and set our attributes. for attr, val in dct.iteritems(): if isinstance(val, Slot): if val.slot_id: slot_ids.add(val.slot_id) val.name = attr slots.append(val) [itraits, straits][val.static].append(val) elif isinstance(val, FunctionType): if getattr(val, "exported", None): argtypes, rettype = val.exported val = FunctionNode(val, argtypes, rettype) dct[attr] = val functs.append(val) dct['__basetype__'] = basetype return super(ClassNodeMeta, cls).__new__(cls, name, bases, dct)
def __new__(cls, name, bases, dct): # We need __new__ because we modify the dct. straits = dct['__straits__'] = [] itraits = dct['__itraits__'] = [] functs = dct['__functs__'] = [] slots = dct['__tslots__'] = [] # exported name - name can be a multinamable # when using the ClassNodeMeta() constructor. if not IMultiname.providedBy(name): package = dct.pop('package', '') name = packagedQName(package, name) # set our name if it doesn't exist in the class. dct.setdefault('__multiname__', name) name = str(dct['__multiname__']) # XXX: should we allow __init__? if dct.get('__init__'): raise ValueError("ClassNodes aren't allowed to have __init__ " "methods. Please use __iinit__ or __cinit__.") basetype = dct.get('__basetype__') or bases[0] if len(bases) > 1: raise ValueError("Tamarin cannot do multiple inheritance.") elif not bases or basetype == object: bases = (object,) basetype = QName("Object") slot_ids = set() # Go through and set our attributes. for attr, val in dct.iteritems(): if isinstance(val, Slot): if val.slot_id: slot_ids.add(val.slot_id) val.name = attr slots.append(val) [itraits, straits][val.static].append(val) elif isinstance(val, FunctionType): if getattr(val, "exported", None): argtypes, rettype = val.exported val = FunctionNode(val, argtypes, rettype) dct[attr] = val functs.append(val) dct['__basetype__'] = basetype dct.setdefault('__iinit__', None) dct.setdefault('__cinit__', None) if dct['__iinit__']: iinit = dct['__iinit__'] = export_method(dct['__iinit__']) if dct['__cinit__']: cinit = dct['__cinit__'] = export_method(dct['__cinit__']) return super(ClassNodeMeta, cls).__new__(cls, name, bases, dct)
def __init__(self, name, type_name, default=None, slot_id=0): super(SlotTrait, self).__init__(name, False, False) self.slot_id = slot_id self.type_name = IMultiname(type_name) self._type_name_index = None self.default = default self._default_index = None self._default_kind = None
def _get_vector_type(self, TYPE): """ Returns a TypeName of Vector with the given TYPE. """ from fusion.avm2 import playerglobal TYPE = IMultiname(TYPE) Vector = playerglobal.__AS3__.vec.Vector if TYPE in Vector.SpecializedFast: return Vector.SpecializedFast[TYPE] return constants.TypeName(Vector, (TYPE, ))
def __init__(self, namestr, param_types, return_type, flags=0, options=None, param_names=None, varargs=None): self.namestr = namestr self._namestr_index = None self.param_types = [IMultiname(t) for t in param_types] if param_types else [] self._param_types_indices = None self.param_names = param_names or [] self._param_names_indices = None self.return_type = IMultiname(return_type) self._return_type_index = None self.flags = flags self.varargs = varargs self.body = None self.options = options or [] self._options_indices = None
def __init__(self, name, final=False, override=False): if name is not None: self.name = IMultiname(name) else: self.name = None self._name_index = None self.is_final = final self.is_override = override self.metadata = [] self._metadata_indices = None
def downcast(self, TYPE): """ Attempts to downcast an object to "TYPE". Pops an object "obj" from the top of the stack, checks if it inherits or implements TYPE. If it does, it pushes "obj" back on the top of the stack. Otherwise, it pushes the constant null on the top of the stack. """ TYPE = IMultiname(TYPE) if TYPE in self.fast_cast: self.emit(self.fast_cast[TYPE]) else: self.emit('coerce', TYPE)
def __init__(self, name, iinit, interfaces=None, is_interface=False, final=False, sealed=True, super_name=None, traits=None, protectedNs=None): super(InstanceInfo, self).__init__(traits) self.name = IMultiname(name) self._name_index = None self.super_name = IMultiname(super_name) self._super_name_index = None self.is_interface = is_interface self.is_sealed = sealed self.is_final = final self.interfaces = interfaces or [] self._interface_indices = None self.iinit = iinit self._iinit_index = 0 self.protectedNs = protectedNs self._protectedNs_index = None
def begin_catch(self, TYPE): """ Begin a catch block, attempting to catch TYPE. """ name = IMultiname(TYPE) rib = CatchRib(self.current_rib) idx = self.current_rib.add_exception(name) self.current_rib.restore_scopes() self.enter_rib(rib) self.emit('begincatch') self.emit('newcatch', idx) self.dup() self.store_var(rib.local) self.dup() self.emit('pushscope') self.swap() self.emit('setslot', 1)
def __init__(self, fn, argtypes, rettype): self.fn = fn fn.node = self argspec = inspect.getargspec(fn) if argspec.keywords: raise ValueError("Functions with keyword arguments" "cannot translate (maybe yet).") self.is_method = getattr(fn, "method", False) self.name = fn.func_name self.trait_type = getattr(fn, "trait_type", "method") self.static = getattr(fn, "static", None) if self.is_method: args = argspec.args[2:] # self, gen else: args = argspec.args[1:] # gen self.argspec = zip(argtypes, args) self.rettype = IMultiname(rettype)
def new_class(self, name, supercls=None): rib = ClassRib(name, supercls) self.tracker.track(name, rib, [IMultiname(supercls)]) # XXX return rib
def bases(self): bases, context = [], self while context and IMultiname(context) != IMultiname("Object"): bases.append(context) context = INode(get_type(IMultiname(context.__basetype__))) return bases
def __init__(self, type, slot_id=None, static=False): self.type = IMultiname(type) self.slot_id, self.static = slot_id or 0, static self.owner, self.name = None, None
def __repr__(self): return "<ClassDesc for %s>" % (IMultiname(self), )
def __init__(self, name, types): self.name = IMultiname(name) self.types = tuple(IMultiname(T) for T in types) self._name_index = None self._types_indices = None
def __init__(self, multiname): self.multiname = IMultiname(multiname) self._multiname_index = None
def __init__(self, multiname, num_args): self.multiname = IMultiname(multiname) self._multiname_index = None self.num_args = num_args
def __init__(self, name): self.name = IMultiname(name) self._name_index = None