예제 #1
0
 def create_int_const(self, v):
     try:
         return self.int_cache[v]
     except KeyError:
         a = len(self.consts)
         self.consts.append(W_IntObject(v))
         self.int_cache[v] = a
         return a
예제 #2
0
 def test_from_object_dynamic(self):
     output = self.run('''
     class String
     {
         public $length = 5;
     }
     $obj = new String();
     $obj->x = 1;
     $prop = new ReflectionProperty($obj, 'x');
     echo $prop->getValue($obj);
     $obj2 = new String();
     echo $prop->getValue($obj2);
     ''')
     assert output == [W_IntObject(1), self.space.w_Null]
예제 #3
0
파일: convert.py 프로젝트: netyum/hippyvm
def _convert_octal(s, i):
    value_int = 0
    value_float = 0.0
    while True:
        c = nextchr(s, i)
        if '0' <= c <= '7':
            digit = ord(c) - ord('0')
        else:
            break
        value_int = intmask((value_int * 8) + digit)
        value_float = (value_float * 8.0) + digit
        i += 1
    fully_processed = i == len(s)
    if abs(float(value_int) - value_float) < _OVERFLOWED:
        return W_IntObject(value_int), fully_processed
    else:  # overflowed at some point
        return W_FloatObject(value_float), fully_processed
예제 #4
0
파일: convert.py 프로젝트: netyum/hippyvm
def _convert_hexadecimal(s, i):
    value_int = 0
    value_float = 0.0
    fully_processed = False
    while True:
        c = nextchr(s, i)
        if '0' <= c <= '9':
            digit = ord(c) - ord('0')
        elif 'A' <= c <= 'F':
            digit = ord(c) - ord('A') + 10
        elif 'a' <= c <= 'f':
            digit = ord(c) - ord('a') + 10
        else:
            break
        value_int = intmask((value_int * 16) + digit)
        value_float = (value_float * 16.0) + digit
        fully_processed = True
        i += 1
    fully_processed = fully_processed and i == len(s)
    if abs(float(value_int) - value_float) < _OVERFLOWED:
        return W_IntObject(value_int), fully_processed
    else:  # overflowed at some point
        return W_FloatObject(value_float), fully_processed
예제 #5
0
파일: property.py 프로젝트: youaani/hippyvm
def _get_name(interp, this):
    return interp.space.newstr(this.name)


def _set_name(interp, this, w_value):
    pass


k_ReflectionProperty = def_class('ReflectionProperty', [
    'export', '__construct', 'getName', 'getValue', 'setValue',
    'getDeclaringClass', "isPublic", "isPrivate", "isProtected", "isStatic",
    "isDefault", "getModifiers", "__toString"
], [
    GetterSetterWrapper(_get_name, _set_name, 'name', consts.ACC_PUBLIC),
    GetterSetterWrapper(_get_class, _set_class, 'class', consts.ACC_PUBLIC)
], [('IS_STATIC', W_IntObject(IS_STATIC)),
    ('IS_PUBLIC', W_IntObject(IS_PUBLIC)),
    ('IS_PROTECTED', W_IntObject(IS_PROTECTED)),
    ('IS_PRIVATE', W_IntObject(IS_PRIVATE))],
                                 instance_class=W_ReflectionProperty)


@k_ReflectionProperty.def_method(
    ['interp', W_Root, str, Optional(bool)], flags=consts.ACC_STATIC)
def export(interp, w_klass, name, return_string=False):
    refl = k_ReflectionProperty.call_args(
        interp, [w_klass, interp.space.wrap(name)])
    result = refl.get_str()
    if return_string:
        return interp.space.wrap(result)
    else:
예제 #6
0
파일: function.py 프로젝트: rlamy/hippyvm
    return this.ref_fun.get_name()


@wrap_method(['interp', ThisUnwrapper(W_ReflectionFunction)],
             name='ReflectionFunction::getParameters')
def get_parameters(interp, this):
    return this.ref_fun.get_parameters()


@wrap_method(['interp', ThisUnwrapper(W_ReflectionFunction)],
             name='ReflectionFunction::getDocComment')
def get_doc_comment(interp, this):
    return interp.space.wrap("")


def _get_name(interp, this):
    return this.ref_fun.get_name()


def _set_name(interp, this, w_value):
    pass


def_class(
    'ReflectionFunction',
    [construct, get_name, get_doc_comment, get_parameters],
    [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)],
    [('IS_DEPRECATED', W_IntObject(IS_DEPRECATED))],
    instance_class=W_ReflectionFunction,
    extends=ReflectionFunctionAbstract)
예제 #7
0
def _get_name(interp, this):
    return interp.space.wrap(this.ref_method.get_name())


def _set_name(interp, this, w_value):
    pass


k_ReflectionMethod = def_class('ReflectionMethod', [
    '__construct', 'isPublic', 'isstatic', 'getDocComment', 'getParameters',
    'getDeclaringClass'
], [
    GetterSetterWrapper(_get_class, _set_class, "class", consts.ACC_PUBLIC),
    GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)
], [('IS_STATIC', W_IntObject(IS_STATIC)),
    ('IS_PUBLIC', W_IntObject(IS_PUBLIC)),
    ('IS_PROTECTED', W_IntObject(IS_PROTECTED)),
    ('IS_PRIVATE', W_IntObject(IS_PRIVATE)),
    ('IS_ABSTRACT', W_IntObject(IS_ABSTRACT)),
    ('IS_FINAL', W_IntObject(IS_FINAL))],
                               instance_class=W_ReflectionMethodObject,
                               extends=k_ReflectionFunctionAbstract)


@k_ReflectionMethod.def_method(['interp', 'this', str, str])
def __construct(interp, this, class_name, method_name):
    klass = interp.lookup_class_or_intf(class_name)

    this.ref_klass = klass
    try:
예제 #8
0
파일: spl.py 프로젝트: netyum/hippyvm
def _get_enclosure(interp, this):
    return interp.space.wrap(this.enclosure)


def _set_enclosure(interp, this, w_value):
    raise NotImplementedError()


SplFileObjectClass = def_class(
    'SplFileObject',
    [sfo_construct, sfo_rewind, sfo_valid, sfo_key, sfo_current, sfo_next,
     sfo_seek, sfo_get_children, sfo_has_children, sfo_fwrite, sfo_eof,
     sfo_fgets, sfo_fgetc, sfo_tostring, sfo_get_max_line_len, sfo_fgetss,
     sfo_set_max_line_len, sfo_fflush, sfo_fgetcsv, sfo_flock, sfo_fputcsv,
     sfo_fscanf, sfo_fseek, sfo_fstat, sfo_ftell, sfo_ftruncate,
     sfo_get_csv_control, sfo_set_csv_control, sfo_get_flags, sfo_set_flags,
     sfo_get_current_line, sfo_fpassthru],
    properties=[GetterSetterWrapper(_get_openmode, _set_openmode,
                                    "openMode", consts.ACC_PRIVATE),
                GetterSetterWrapper(_get_delimiter, _set_delimiter,
                                    "delimiter", consts.ACC_PRIVATE),
                GetterSetterWrapper(_get_enclosure, _set_enclosure,
                                    "enclosure", consts.ACC_PRIVATE), ],
    constants=[(
        'DROP_NEW_LINE', W_IntObject(1)), ('READ_AHEAD', W_IntObject(2)),
        ('SKIP_EMPTY', W_IntObject(4)), ('READ_CSV', W_IntObject(8))],
    implements=["RecursiveIterator", "SeekableIterator"],
    instance_class=W_SplFileObject,
    extends='SplFileInfo',)
예제 #9
0
def _set_name(interp, this, w_value):
    pass


k_ReflectionClass = def_class(
    'ReflectionClass',
    ["__construct", "newInstance", "newInstanceArgs", "hasConstant",
     "getConstant", "getConstants", "getConstructor", "getDefaultProperties",
     "getDocComment", "getEndLine", "getInterfaces", "getInterfaceNames",
     "getMethod", "getMethods", "getModifiers", "getName", "getStartLine",
     "getFileName", "getExtension", "getExtensionName", "getNamespaceName",
     "getStaticProperties", "getProperties", "getProperty", "hasProperty",
     "isSubclassOf", "isInstantiable", "hasMethod", "isAbstract"],
    [GetterSetterWrapper(_get_name, _set_name, "name", consts.ACC_PUBLIC)],
    [('IS_IMPLICIT_ABSTRACT', W_IntObject(IS_IMPLICIT_ABSTRACT)),
     ('IS_EXPLICIT_ABSTRACT', W_IntObject(IS_EXPLICIT_ABSTRACT)),
     ('IS_FINAL', W_IntObject(IS_FINAL))],
    instance_class=W_ReflectionClass
)

@k_ReflectionClass.def_method(['interp', 'this', W_Root])
def __construct(interp, this, klass):
    space = interp.space

    if isinstance(klass, W_ConstStringObject):
        name = space.str_w(klass)
        this.refl_klass = interp.lookup_class_or_intf(name)

    if isinstance(klass, W_InstanceObject):
        this.refl_klass = klass.getclass()
예제 #10
0
파일: iterator.py 프로젝트: youaani/hippyvm
        return self.stack[-1].w_iter


LEAVES_ONLY = 0
SELF_FIRST = 1
CHILD_FIRST = 2

k_RecursiveIteratorIterator = def_class(
    'RecursiveIteratorIterator', [
        '__construct', 'rewind', 'valid', 'key', 'current', 'next',
        'getInnerIterator', 'beginIteration', 'endIteration',
        'callHasChildren', 'callGetChildren', 'beginChildren', 'endChildren',
        'nextElement'
    ],
    constants=[
        ('LEAVES_ONLY', W_IntObject(LEAVES_ONLY)),
        ('SELF_FIRST', W_IntObject(SELF_FIRST)),
        ('CHILD_FIRST', W_IntObject(CHILD_FIRST)),
    ],
    implements=[k_OuterIterator],
    instance_class=W_RecursiveIteratorIterator)


@k_RecursiveIteratorIterator.def_method(
    ['interp', 'this', 'object', Optional(int)])
def __construct(interp, this, w_iter, mode=LEAVES_ONLY):
    if w_iter.klass.is_iterable:
        w_iter = interp.call_method(w_iter, 'getIterator', [])
    if (not isinstance(w_iter, W_InstanceObject)
            or not w_iter.klass.is_subclass_of_class_or_intf_name(
                'RecursiveIterator')):
예제 #11
0
파일: reference.py 프로젝트: xhava/hippyvm
def from_stored_value(w_value):
    if isinstance(w_value, W_MutIntObject):
        w_value = W_IntObject(w_value.intval)
    return w_value
예제 #12
0
    'SplFileObject',
    [sfo_construct, sfo_rewind, sfo_valid, sfo_key, sfo_current, sfo_next,
     sfo_seek, sfo_get_children, sfo_has_children, sfo_fwrite, sfo_eof,
     sfo_fgets, sfo_fgetc, sfo_tostring, sfo_get_max_line_len, sfo_fgetss,
     sfo_set_max_line_len, sfo_fflush, sfo_fgetcsv, sfo_flock, sfo_fputcsv,
     sfo_fscanf, sfo_fseek, sfo_fstat, sfo_ftell, sfo_ftruncate,
     sfo_get_csv_control, sfo_set_csv_control, sfo_get_flags, sfo_set_flags,
     sfo_get_current_line, sfo_fpassthru],
    properties=[GetterSetterWrapper(_get_openmode, _set_openmode,
                                    "openMode", consts.ACC_PRIVATE),
                GetterSetterWrapper(_get_delimiter, _set_delimiter,
                                    "delimiter", consts.ACC_PRIVATE),
                GetterSetterWrapper(_get_enclosure, _set_enclosure,
                                    "enclosure", consts.ACC_PRIVATE),],
    constants=[
        ('DROP_NEW_LINE', W_IntObject(SFO_DROP_NEW_LINE)),
        ('READ_AHEAD', W_IntObject(SFO_READ_AHEAD)),
        ('SKIP_EMPTY', W_IntObject(SFO_SKIP_EMPTY)),
        ('READ_CSV', W_IntObject(SFO_READ_CSV))],
    implements=["RecursiveIterator", "SeekableIterator"],
    instance_class=W_SplFileObject,
    extends='SplFileInfo',)


class W_DirectoryIterator(W_SplFileInfo):
    w_dir_res = None

    def clone(self, interp, contextclass):
        w_res = W_InstanceObject.clone(self, interp, contextclass)
        assert isinstance(w_res, W_DirectoryIterator)
        w_res.path_name = self.path_name
예제 #13
0
 def rshift(self, w_left, w_right):
     left = self.force_int(w_left)
     right = self.force_int(w_right)
     z = intmask(left >> (right & MASK_31_63))
     return W_IntObject(z)
예제 #14
0
 def newint(self, v):
     return W_IntObject(v)
예제 #15
0
파일: convert.py 프로젝트: netyum/hippyvm
def convert_string_to_number(s, can_be_octal=False):
    """Returns (wrapped number, flag: number-fully-processed)."""
    i = _whitespaces_in_front(s)
    forced_float = False
    negative_sign = False
    at_least_one_digit = False

    if nextchr(s, i) == '-':
        negative_sign = True
        i += 1
    elif nextchr(s, i) == '+':
        i += 1
    elif nextchr(s, i) == '0':
        if nextchr(s, i + 1) in 'xX':
            return _convert_hexadecimal(s, i + 2)
        if can_be_octal:
            return _convert_octal(s, i + 1)

    value_int = 0
    value_float = 0.0
    while nextchr(s, i).isdigit():
        digit = ord(s[i]) - ord('0')
        value_int = intmask((value_int * 10) + digit)
        value_float = (value_float * 10.0) + digit
        if abs(value_int - value_float) < _OVERFLOWED:
            value_float = float(value_int)  # force equal
        at_least_one_digit = True
        i += 1

    if nextchr(s, i) == '.':
        i += 1
        fraction = 1.0
        while nextchr(s, i).isdigit():
            digit = ord(s[i]) - ord('0')
            fraction *= 0.1
            value_float += fraction * digit
            at_least_one_digit = True
            i += 1
        forced_float |= at_least_one_digit

    if nextchr(s, i) in 'Ee' and at_least_one_digit:
        at_least_one_digit = False
        negative_exponent = False
        i += 1
        if nextchr(s, i) == '-':
            negative_exponent = True
            i += 1
        elif nextchr(s, i) == '+':
            i += 1

        exponent = 0
        while nextchr(s, i).isdigit():
            digit = ord(s[i]) - ord('0')
            exponent = exponent * 10 + digit
            if exponent > 99999:
                exponent = 99999  # exponent is huge enough already
            at_least_one_digit = True
            i += 1

        if negative_exponent:
            exponent = -exponent
        try:
            value_float *= math.pow(10.0, exponent)
        except OverflowError:
            value_float = 0.0

        # value_float *= math.pow(10.0, exponent)
        forced_float |= at_least_one_digit

    if negative_sign:
        value_int = intmask(-value_int)
        value_float = -value_float

    fully_processed = at_least_one_digit and i == len(s)
    if forced_float or abs(float(value_int) - value_float) > _OVERFLOWED:
        return W_FloatObject(value_float), fully_processed
    else:
        return W_IntObject(value_int), fully_processed