コード例 #1
0
ファイル: slast.py プロジェクト: duanemoody/renpy
    def prepare(self):

        SLBlock.prepare(self)

        # Prepare the positional arguments.

        exprs = [ ]
        values = [ ]
        has_exprs = False
        has_values = False


        for a in self.positional:
            node = py_compile(a, 'eval', ast_node=True)

            if is_constant(node):
                values.append(py_eval_bytecode(compile_expr(node)))
                exprs.append(ast.Num(n=0))
                has_values = True
            else:
                values.append(use_expression)
                exprs.append(node)
                has_exprs = True

        if has_values:
            self.positional_values = values
        else:
            self.positional_values = None

        if has_exprs:
            t = ast.Tuple(elts=exprs, ctx=ast.Load())
            ast.copy_location(t, exprs[0])
            self.positional_exprs = compile_expr(t)
        else:
            self.positional_exprs = None
コード例 #2
0
ファイル: slast.py プロジェクト: duanemoody/renpy
    def prepare(self):

        for i in self.children:
            i.prepare()

        # Compile the keywords.

        keyword_values = { }
        keyword_keys = [ ]
        keyword_exprs = [ ]

        for k, expr in self.keyword:

            node = py_compile(expr, 'eval', ast_node=True)

            if is_constant(node):
                keyword_values[k] = py_eval_bytecode(compile_expr(node))
            else:
                keyword_keys.append(ast.Str(s=k))
                keyword_exprs.append(node)

        if keyword_values:
            self.keyword_values = keyword_values
        else:
            self.keyword_values = None

        if keyword_keys:
            node = ast.Dict(keys=keyword_keys, values=keyword_exprs)
            ast.copy_location(node, keyword_exprs[0])
            self.keyword_exprs = compile_expr(node)
        else:
            self.keyword_exprs = None
コード例 #3
0
ファイル: pyanalysis.py プロジェクト: SegreDSG/renpy
    def ast_eval_literal(self, expr):
        """
        Compiles an expression into an AST.
        """

        if isinstance(expr, renpy.ast.PyExpr):
            filename = expr.filename
            linenumber = expr.linenumber
        else:
            filename = None
            linenumber = None

        key = (expr, filename, linenumber)

        rv = self.ast_eval_cache.get(key, None)

        if rv is None:
            expr = py_compile(expr, 'eval', ast_node=True)

            try:
                ast.literal_eval(expr)
                literal = True
            except:
                literal = False

            rv = (expr, literal)

            self.ast_eval_cache[key] = rv
            self.updated = True

        return rv
コード例 #4
0
    def ast_eval_literal(self, expr):
        """
        Compiles an expression into an AST.
        """

        if isinstance(expr, renpy.ast.PyExpr):
            filename = expr.filename
            linenumber = expr.linenumber
        else:
            filename = None
            linenumber = None

        key = (expr, filename, linenumber)

        rv = self.ast_eval_cache.get(key, None)

        if rv is None:
            expr = py_compile(expr, 'eval', ast_node=True)

            try:
                ast.literal_eval(expr)
                literal = True
            except:
                literal = False

            rv = (expr, literal)

            self.ast_eval_cache[key] = rv
            self.updated = True

        return rv
コード例 #5
0
    def prepare(self):

        SLBlock.prepare(self)

        # Prepare the positional arguments.

        exprs = []
        values = []
        has_exprs = False
        has_values = False

        for a in self.positional:
            node = py_compile(a, 'eval', ast_node=True)

            if is_constant(node):
                values.append(py_eval_bytecode(compile_expr(node)))
                exprs.append(ast.Num(n=0))
                has_values = True
            else:
                values.append(use_expression)
                exprs.append(node)
                has_exprs = True

        if has_values:
            self.positional_values = values
        else:
            self.positional_values = None

        if has_exprs:
            t = ast.Tuple(elts=exprs, ctx=ast.Load())
            ast.copy_location(t, exprs[0])
            self.positional_exprs = compile_expr(t)
        else:
            self.positional_exprs = None
コード例 #6
0
    def prepare(self):

        for i in self.children:
            i.prepare()

        # Compile the keywords.

        keyword_values = {}
        keyword_keys = []
        keyword_exprs = []

        for k, expr in self.keyword:

            node = py_compile(expr, 'eval', ast_node=True)

            if is_constant(node):
                keyword_values[k] = py_eval_bytecode(compile_expr(node))
            else:
                keyword_keys.append(ast.Str(s=k))
                keyword_exprs.append(node)

        if keyword_values:
            self.keyword_values = keyword_values
        else:
            self.keyword_values = None

        if keyword_keys:
            node = ast.Dict(keys=keyword_keys, values=keyword_exprs)
            ast.copy_location(node, keyword_exprs[0])
            self.keyword_exprs = compile_expr(node)
        else:
            self.keyword_exprs = None
コード例 #7
0
ファイル: pyutil.py プロジェクト: HikkeKun/renpy
    def is_constant_expr(self, expr):
        """
        Compiles `expr` into an AST node, then returns the result of
        self.is_constant called on that node.
        """

        node = py_compile(expr, 'eval', ast_node=True)
        return self.is_constant(node)
コード例 #8
0
ファイル: pyanalysis.py プロジェクト: Allowed/renpy
    def is_constant_expr(self, expr):
        """
        Compiles `expr` into an AST node, then returns the result of
        self.is_constant called on that node.
        """

        node = py_compile(expr, 'eval', ast_node=True)
        return self.is_constant(node)
コード例 #9
0
    def prepare(self):
        node = py_compile(self.expression, 'eval', ast_node=True)

        if is_constant(node):
            self.expression_value = py_eval_bytecode(compile_expr(node))
            self.expression_expr = None
        else:
            self.expression_value = None
            self.expression_expr = compile_expr(node)

        SLBlock.prepare(self)
コード例 #10
0
ファイル: pyanalysis.py プロジェクト: Allowed/renpy
    def python(self, code):
        """
        Performs analysis on a block of python code.
        """

        nodes = py_compile(code, 'exec', ast_node=True)

        a = PyAnalysis(self)

        for i in nodes:
            a.visit(i)
コード例 #11
0
ファイル: pyutil.py プロジェクト: HikkeKun/renpy
    def python(self, code):
        """
        Performs analysis on a block of python code.
        """

        nodes = py_compile(code, 'exec', ast_node=True)

        a = PyAnalysis(self)

        for i in nodes:
            a.visit(i)
コード例 #12
0
ファイル: slast.py プロジェクト: duanemoody/renpy
    def prepare(self):
        node = py_compile(self.expression, 'eval', ast_node=True)

        if is_constant(node):
            self.expression_value = py_eval_bytecode(compile_expr(node))
            self.expression_expr = None
        else:
            self.expression_value = None
            self.expression_expr = compile_expr(node)

        SLBlock.prepare(self)
コード例 #13
0
ファイル: slast.py プロジェクト: abergeron/renpy
    def prepare(self, analysis):
        node = py_compile(self.expression, 'eval', ast_node=True)

        if analysis.is_constant(node):
            self.expression_value = py_eval_bytecode(compile_expr(node))
            self.expression_expr = None
        else:
            self.expression_value = None
            self.expression_expr = compile_expr(node)
            self.constant = False

        SLBlock.prepare(self, analysis)
コード例 #14
0
ファイル: slast.py プロジェクト: abergeron/renpy
    def prepare(self, analysis):

        keywords = dict(self.keyword)

        event_node = py_compile(self.event, 'eval', ast_node=True)
        action_node = py_compile(keywords.get('action', None), 'eval', ast_node=True)

        self.event_expr = compile_expr(event_node)
        self.action_expr = compile_expr(action_node)

        if analysis.is_constant(event_node):
            self.event_value = py_eval_bytecode(self.event_expr)
        else:
            self.event_value = None

        if analysis.is_constant(action_node):
            self.action_value = py_eval_bytecode(self.action_expr)
        else:
            self.action_value = None

        self.constant = False
コード例 #15
0
    def prepare(self):

        # A list of prepared entries, with each consisting of expression
        # bytecode and a SLBlock.
        self.prepared_entries = []

        for cond, block in self.entries:
            if cond is not None:
                cond = py_compile(cond, 'eval')

            block.prepare()

            self.prepared_entries.append((cond, block))
コード例 #16
0
    def prepare(self, analysis):

        keywords = dict(self.keyword)

        event_node = py_compile(self.event, 'eval', ast_node=True)
        action_node = py_compile(keywords.get('action', None), 'eval', ast_node=True)

        self.event_expr = compile_expr(event_node)
        self.action_expr = compile_expr(action_node)

        if analysis.is_constant(event_node):
            self.event_value = py_eval_bytecode(self.event_expr)
        else:
            self.event_value = None

        if analysis.is_constant(action_node):
            self.action_value = py_eval_bytecode(self.action_expr)
        else:
            self.action_value = None

        self.constant = NOT_CONST
        self.last_keyword = True
コード例 #17
0
ファイル: slast.py プロジェクト: duanemoody/renpy
    def prepare(self):

        # A list of prepared entries, with each consisting of expression
        # bytecode and a SLBlock.
        self.prepared_entries = [ ]

        for cond, block in self.entries:
            if cond is not None:
                cond = py_compile(cond, 'eval')

            block.prepare()

            self.prepared_entries.append((cond, block))
コード例 #18
0
ファイル: slast.py プロジェクト: paulmorio/renpy
    def prepare(self, analysis):

        SLBlock.prepare(self, analysis)

        # Prepare the positional arguments.

        exprs = [ ]
        values = [ ]
        has_exprs = False
        has_values = False

        for a in self.positional:
            node = py_compile(a, 'eval', ast_node=True)

            const = analysis.is_constant(node)

            if const == GLOBAL_CONST:
                values.append(py_eval_bytecode(compile_expr(node)))
                exprs.append(ast.Num(n=0))
                has_values = True
            else:
                values.append(use_expression)
                exprs.append(node) # Will be compiled as part of the tuple.
                has_exprs = True

            self.constant = min(self.constant, const)

        if has_values:
            self.positional_values = values
        else:
            self.positional_values = None

        if has_exprs:
            t = ast.Tuple(elts=exprs, ctx=ast.Load())
            ast.copy_location(t, exprs[0])
            self.positional_exprs = compile_expr(t)
        else:
            self.positional_exprs = None

        # We do not pass keywords to our parents.
        self.has_keyword = False

        # We want to preserve last_keyword, however, in case we run a
        # python block.

        # If we have the id property, we're not constant - since we may get
        # additional keywords via id. (It's unlikely, but id should be pretty
        # rare.)
        for k, _expr in self.keyword:
            if k == "id":
                self.constant = NOT_CONST
コード例 #19
0
    def prepare(self, analysis):

        SLBlock.prepare(self, analysis)

        # Prepare the positional arguments.

        exprs = []
        values = []
        has_exprs = False
        has_values = False

        for a in self.positional:
            node = py_compile(a, 'eval', ast_node=True)

            const = analysis.is_constant(node)

            if const == GLOBAL_CONST:
                values.append(py_eval_bytecode(compile_expr(node)))
                exprs.append(ast.Num(n=0))
                has_values = True
            else:
                values.append(use_expression)
                exprs.append(node)  # Will be compiled as part of the tuple.
                has_exprs = True

            self.constant = min(self.constant, const)

        if has_values:
            self.positional_values = values
        else:
            self.positional_values = None

        if has_exprs:
            t = ast.Tuple(elts=exprs, ctx=ast.Load())
            ast.copy_location(t, exprs[0])
            self.positional_exprs = compile_expr(t)
        else:
            self.positional_exprs = None

        # We do not pass keywords to our parents.
        self.has_keyword = False

        # We want to preserve last_keyword, however, in case we run a
        # python block.

        # If we have the id property, we're not constant - since we may get
        # additional keywords via id. (It's unlikely, but id should be pretty
        # rare.)
        for k, _expr in self.keyword:
            if k == "id":
                self.constant = NOT_CONST
コード例 #20
0
    def prepare(self, analysis):

        for i in self.children:
            i.prepare(analysis)
            self.constant = min(self.constant, i.constant)

        # Compile the keywords.

        keyword_values = {}
        keyword_keys = []
        keyword_exprs = []

        for k, expr in self.keyword:

            node = py_compile(expr, 'eval', ast_node=True)

            const = analysis.is_constant(node)

            if const == GLOBAL_CONST:
                keyword_values[k] = py_eval_bytecode(compile_expr(node))
            else:
                keyword_keys.append(ast.Str(s=k))
                keyword_exprs.append(
                    node)  # Will be compiled as part of ast.Dict below.

            self.constant = min(self.constant, const)

        if keyword_values:
            self.keyword_values = keyword_values
        else:
            self.keyword_values = None

        if keyword_keys:
            node = ast.Dict(keys=keyword_keys, values=keyword_exprs)
            ast.copy_location(node, keyword_exprs[0])
            self.keyword_exprs = compile_expr(node)
        else:
            self.keyword_exprs = None

        self.has_keyword = bool(self.keyword)
        self.keyword_children = []

        for i in self.children:
            if i.has_keyword:
                self.keyword_children.append(i)
                self.has_keyword = True

            if i.last_keyword:
                self.last_keyword = True
                break
コード例 #21
0
ファイル: slast.py プロジェクト: Ayutac/renpy
    def prepare(self, analysis):

        for i in self.children:
            i.prepare(analysis)
            self.constant = min(self.constant, i.constant)

        # Compile the keywords.

        keyword_values = { }
        keyword_keys = [ ]
        keyword_exprs = [ ]

        for k, expr in self.keyword:

            node = py_compile(expr, 'eval', ast_node=True)

            const = analysis.is_constant(node)

            if const == GLOBAL_CONST:
                keyword_values[k] = py_eval_bytecode(compile_expr(node))
            else:
                keyword_keys.append(ast.Str(s=k))
                keyword_exprs.append(node) # Will be compiled as part of ast.Dict below.

            self.constant = min(self.constant, const)

        if keyword_values:
            self.keyword_values = keyword_values
        else:
            self.keyword_values = None

        if keyword_keys:
            node = ast.Dict(keys=keyword_keys, values=keyword_exprs)
            ast.copy_location(node, keyword_exprs[0])
            self.keyword_exprs = compile_expr(node)
        else:
            self.keyword_exprs = None

        self.has_keyword = bool(self.keyword)
        self.keyword_children = [ ]

        for i in self.children:
            if i.has_keyword:
                self.keyword_children.append(i)
                self.has_keyword = True

            if i.last_keyword:
                self.last_keyword = True
                break
コード例 #22
0
    def prepare(self, analysis):
        node = py_compile(self.expression, 'eval', ast_node=True)

        const = analysis.is_constant(node)

        if const == GLOBAL_CONST:
            self.expression_value = py_eval_bytecode(compile_expr(node))
            self.expression_expr = None
        else:
            self.expression_value = None
            self.expression_expr = compile_expr(node)

        self.constant = min(self.constant, const)

        SLBlock.prepare(self, analysis)

        self.last_keyword = True
コード例 #23
0
    def ast_exec(self, code):
        """
        Compiles a block into an AST.
        """

        if isinstance(code, renpy.ast.PyExpr):
            key = (code, code.filename, code.linenumber)
        else:
            key = (code, None, None)

        rv = self.ast_exec_cache.get(key, None)

        if rv is None:
            rv = py_compile(code, 'exec', ast_node=True)
            self.ast_exec_cache[key] = rv
            self.updated = True

        return rv
コード例 #24
0
ファイル: pyanalysis.py プロジェクト: SegreDSG/renpy
    def ast_exec(self, code):
        """
        Compiles a block into an AST.
        """

        if isinstance(code, renpy.ast.PyExpr):
            key = (code, code.filename, code.linenumber)
        else:
            key = (code, None, None)

        rv = self.ast_exec_cache.get(key, None)

        if rv is None:
            rv = py_compile(code, 'exec', ast_node=True)
            self.ast_exec_cache[key] = rv
            self.updated = True

        return rv
コード例 #25
0
    def prepare(self, analysis):

        # A list of prepared entries, with each consisting of expression
        # bytecode and a SLBlock.
        self.prepared_entries = []

        for cond, block in self.entries:
            if cond is not None:
                node = py_compile(cond, 'eval', ast_node=True)

                self.constant = min(self.constant, analysis.is_constant(node))

                cond = compile_expr(node)

            block.prepare(analysis)
            self.constant = min(self.constant, block.constant)
            self.prepared_entries.append((cond, block))

        self.last_keyword = True
コード例 #26
0
ファイル: slast.py プロジェクト: paulmorio/renpy
    def prepare(self, analysis):

        # A list of prepared entries, with each consisting of expression
        # bytecode and a SLBlock.
        self.prepared_entries = [ ]

        for cond, block in self.entries:
            if cond is not None:
                node = py_compile(cond, 'eval', ast_node=True)

                self.constant = min(self.constant, analysis.is_constant(node))

                cond = compile_expr(node)

            block.prepare(analysis)
            self.constant = min(self.constant, block.constant)
            self.prepared_entries.append((cond, block))

        self.last_keyword = True
コード例 #27
0
    def prepare(self, analysis):

        SLBlock.prepare(self, analysis)

        # Prepare the positional arguments.

        exprs = [ ]
        values = [ ]
        has_exprs = False
        has_values = False

        for a in self.positional:
            node = py_compile(a, 'eval', ast_node=True)

            const = analysis.is_constant(node)

            if const == GLOBAL_CONST:
                values.append(py_eval_bytecode(compile_expr(node)))
                exprs.append(ast.Num(n=0))
                has_values = True
            else:
                values.append(use_expression)
                exprs.append(node) # Will be compiled as part of the tuple.
                has_exprs = True

            self.constant = min(self.constant, const)

        if has_values:
            self.positional_values = values
        else:
            self.positional_values = None

        if has_exprs:
            t = ast.Tuple(elts=exprs, ctx=ast.Load())
            ast.copy_location(t, exprs[0])
            self.positional_exprs = compile_expr(t)
        else:
            self.positional_exprs = None

        # We do not pass keywords to our parents.
        self.has_keyword = False
コード例 #28
0
ファイル: slast.py プロジェクト: valeatory/renpy
    def prepare(self):

        # A list of prepared entries, with each consisting of expression
        # bytecode and a SLBlock.
        self.prepared_entries = [ ]

        for cond, block in self.entries:
            if cond is not None:
                node = py_compile(cond, 'eval', ast_node=True)

                if not is_constant(node):
                    self.constant = False

                cond = compile_expr(node)

            block.prepare()

            if not block.constant:
                self.constant = False

            self.prepared_entries.append((cond, block))
コード例 #29
0
ファイル: slast.py プロジェクト: abergeron/renpy
    def prepare(self, analysis):

        for i in self.children:
            i.prepare(analysis)

            if not i.constant:
                self.constant = False

        # Compile the keywords.

        keyword_values = { }
        keyword_keys = [ ]
        keyword_exprs = [ ]

        for k, expr in self.keyword:

            node = py_compile(expr, 'eval', ast_node=True)

            if analysis.is_constant(node):
                keyword_values[k] = py_eval_bytecode(compile_expr(node))
            else:
                keyword_keys.append(ast.Str(s=k))
                keyword_exprs.append(node) # Will be compiled as part of ast.Dict below.

        if keyword_values:
            self.keyword_values = keyword_values
        else:
            self.keyword_values = None

        if keyword_keys:
            node = ast.Dict(keys=keyword_keys, values=keyword_exprs)
            ast.copy_location(node, keyword_exprs[0])
            self.keyword_exprs = compile_expr(node)

            self.constant = False
        else:
            self.keyword_exprs = None
コード例 #30
0
ファイル: slast.py プロジェクト: duanemoody/renpy
 def prepare(self):
     self.expr = py_compile(self.expression, 'eval')
コード例 #31
0
 def prepare(self, analysis):
     self.expr = py_compile(self.expression, 'eval')
     self.constant = NOT_CONST
     self.last_keyword = True
コード例 #32
0
 def prepare(self):
     self.expr = py_compile(self.expression, 'eval')
コード例 #33
0
ファイル: slast.py プロジェクト: abergeron/renpy
 def prepare(self, analysis):
     self.expr = py_compile(self.expression, 'eval')
     self.constant = False