Exemple #1
0
 def contains(self, obj):
     custom_interface = jit.promote(self.custom_interface)
     method = custom_interface.lookup_method(u"+contains")
     if method is None:
         return Object.contains(self, obj)
     else:
         return space.is_true(method.call([self, obj]))
Exemple #2
0
 def contains(self, obj):
     try:
         method = self.custom_interface.methods[u"+contains"]
     except KeyError as error:
         return Object.contains(self, obj)
     else:
         return space.is_true(method.call([self, obj]))
Exemple #3
0
 def contains(self, obj):
     try:
         method = self.custom_interface.methods[u"+contains"]
     except KeyError as error:
         return Object.contains(self, obj)
     else:
         return space.is_true(method.call([self, obj]))
Exemple #4
0
def configured_stringify(obj, config):
    if config is None:
        ub = UnicodeBuilder()
        quick_stringify(ub, obj)
        return ub.build()
    scan = Scanner()
    scan.indent = space.to_int(get_config(config, u"indent", space.Integer(2)))
    scan.sort_keys = space.is_true(get_config(config, u"sort_keys", space.false))
    stringify(scan, obj)
    scan.finish()
    return scan.printer.result.build()
Exemple #5
0
def configured_stringify(obj, config):
    if config is None:
        ub = UnicodeBuilder()
        quick_stringify(ub, obj)
        return ub.build()
    scan = Scanner()
    scan.indent = space.to_int(get_config(config, u"indent", space.Integer(2)))
    scan.sort_keys = space.is_true(
        get_config(config, u"sort_keys", space.false))
    stringify(scan, obj)
    scan.finish()
    return scan.printer.result.build()
Exemple #6
0
def cmp_gt(a, b):
    t = setobject.Set_is_superset(a, b)
    if space.is_true(t) and len(a._set) != len(b._set):
        return space.true
    return space.false
Exemple #7
0
def eval(ctx, env, code):
    ip = 0
    stack = empty_stack
    sp = 0
    r1 = space.w_nil
    while ip < const_len(code):
        jitdriver.jit_merge_point(
                ip=ip,
                sp=sp,
                stack=stack,
                ctx=ctx,
                env=env,
                code=code,
                r1=r1,
                )
        assert r1 is not None
        assert sp >= 0
        op = get_op(code, ip)
        if op == ops.IF:
            ip += 1
            if not space.is_true(r1):
                ip += get_op(code, ip)
        elif op == ops.SYM:
            ip += 1
            r1 = lookup(env, ctx, get_op(code, ip))
        elif op == ops.KEYWORD:
            ip += 1
            r1 = space.W_Keyword(ctx.st().get_sym(get_op(code, ip)))
        elif op == ops.STRING:
            ip += 1
            r1 = space.W_String(ctx.st().get_sym(get_op(code, ip)))
        elif op == ops.INT:
            ip += 1
            r1 = space.W_Int(get_op(code, ip))
        elif op == ops.PUSH_ENV:
            ip += 1
            env = Env([(get_op(code, ip), r1)], env)
        elif op == ops.POP_ENV:
            env = env.parent
        elif op == ops.QUOTE:
            ip += 1
            r1 = space.W_Sym(ctx.st().get_sym(get_op(code, ip)))
        elif op == ops.RELJMP:
            ip += get_op(code, ip + 1) + 1
        elif op == ops.FN:
            ip += 1
            r1 = ctx.st().get_fn(get_op(code, ip)).with_env(env)
        elif op == ops.PUSH:
            if stack is empty_stack:
                stack = [None for _ in range(stack_size)]
            stack[jit.promote(sp)] = r1
            sp += 1
        elif op == ops.DEF:
            ip += 1
            ctx.bindings().set(get_op(code, ip), r1)
        elif op == ops.RECUR:
            ip += 1
            argc = jit.promote(get_op(code, ip))
            sp -= argc
            idx = argc - 1
            while idx >= 0:
                ip += 1
                env.set(get_op(code, ip), stack[jit.promote(idx + sp)])
                idx -= 1
            ip = -1
        elif op == ops.INVOKE:
            r1 = invoke(ip, env, code, r1, stack, sp, ctx)
            ip += 1
            sp -= get_op(code, ip)
        elif op == ops.APPLY:
            r1 = apply(ip, env, code, r1, stack, sp, ctx)
            ip += 1
            sp -= 2
        elif op == ops.TRY:
            try:
                assert isinstance(r1, space.W_Fun)
                r1 = eval(ctx, env, r1.code)
                ip += code[ip + 1]
            except space.SpaceException as ex:
                if stack is empty_stack:
                    stack = [None for _ in range(stack_size)]
                stack[jit.promote(sp)] = space.wrap(ex.reason())
                sp += 1
                ip += 1
        elif op == ops.CHAR:
            ip += 1
            r1 = space.W_Char(get_op(code, ip))
        else:
            raise Exception("Unknown code: %s, ip %s, code %s" %
                    (str(op), ip, str(code)))
        ip += 1
    assert sp == 0
    return r1
Exemple #8
0
 def lt(self, a, b):
     return space.is_true(self.w_lt.call([a, b]))
Exemple #9
0
 def eq(self, other):  # TODO: improve this.
     return space.is_true(operators.eq.call([self, other]))
Exemple #10
0
 def lt(self, a, b):
     return space.is_true(self.w_lt.call([a, b]))
Exemple #11
0
 def eq(self, other): # TODO: improve this.
     return space.is_true(operators.eq.call([self, other]))
Exemple #12
0
def cmp_gt(a, b):
    t = setobject.Set_is_superset(a, b)
    if space.is_true(t) and len(a._set) != len(b._set):
        return space.true
    return space.false