コード例 #1
0
ファイル: stmt.py プロジェクト: ProGamerCode/vyper
    def parse_Call(self):
        is_self_function = ((isinstance(self.stmt.func, vy_ast.Attribute))
                            and isinstance(self.stmt.func.value, vy_ast.Name)
                            and self.stmt.func.value.id == "self")

        if isinstance(self.stmt.func, vy_ast.Name):
            funcname = self.stmt.func.id
            return STMT_DISPATCH_TABLE[funcname].build_IR(
                self.stmt, self.context)

        elif isinstance(self.stmt.func,
                        vy_ast.Attribute) and self.stmt.func.attr in (
                            "append",
                            "pop",
                        ):
            darray = Expr(self.stmt.func.value, self.context).ir_node
            args = [Expr(x, self.context).ir_node for x in self.stmt.args]
            if self.stmt.func.attr == "append":
                assert len(args) == 1
                arg = args[0]
                assert isinstance(darray.typ, DArrayType)
                assert arg.typ == darray.typ.subtype
                return append_dyn_array(darray, arg)
            else:
                assert len(args) == 0
                return pop_dyn_array(darray, return_popped_item=False)

        elif is_self_function:
            return self_call.ir_for_self_call(self.stmt, self.context)
        else:
            return external_call.ir_for_external_call(self.stmt, self.context)
コード例 #2
0
    def parse_Call(self):
        # TODO check out this inline import
        from vyper.builtin_functions import DISPATCH_TABLE

        if isinstance(self.expr.func, vy_ast.Name):
            function_name = self.expr.func.id

            if function_name in DISPATCH_TABLE:
                return DISPATCH_TABLE[function_name].build_IR(
                    self.expr, self.context)

            # Struct constructors do not need `self` prefix.
            elif function_name in self.context.structs:
                args = self.expr.args
                if len(args) == 1 and isinstance(args[0], vy_ast.Dict):
                    return Expr.struct_literals(args[0], function_name,
                                                self.context)

            # Interface assignment. Bar(<address>).
            elif function_name in self.context.sigs:
                ret, arg_ir = self._is_valid_interface_assign()
                if ret is True:
                    arg_ir.typ = InterfaceType(
                        function_name)  # Cast to Correct interface type.
                    return arg_ir

        elif isinstance(self.expr.func,
                        vy_ast.Attribute) and self.expr.func.attr == "pop":
            # TODO consider moving this to builtins
            darray = Expr(self.expr.func.value, self.context).ir_node
            assert len(self.expr.args) == 0
            assert isinstance(darray.typ, DArrayType)
            return pop_dyn_array(darray, return_popped_item=True)

        elif (
                # TODO use expr.func.type.is_internal once
                # type annotations are consistently available
                isinstance(self.expr.func, vy_ast.Attribute)
                and isinstance(self.expr.func.value, vy_ast.Name)
                and self.expr.func.value.id == "self"):
            return self_call.ir_for_self_call(self.expr, self.context)
        else:
            return external_call.ir_for_external_call(self.expr, self.context)
コード例 #3
0
ファイル: expr.py プロジェクト: subhrajyoti21/viper
    def parse_Call(self):
        # TODO check out this inline import
        from vyper.builtin_functions import DISPATCH_TABLE

        if isinstance(self.expr.func, vy_ast.Name):
            function_name = self.expr.func.id

            if function_name in DISPATCH_TABLE:
                return DISPATCH_TABLE[function_name].build_LLL(
                    self.expr, self.context)

            # Struct constructors do not need `self` prefix.
            elif function_name in self.context.structs:
                args = self.expr.args
                if len(args) == 1 and isinstance(args[0], vy_ast.Dict):
                    return Expr.struct_literals(args[0], function_name,
                                                self.context)

            # Interface assignment. Bar(<address>).
            elif function_name in self.context.sigs:
                ret, arg_lll = self._is_valid_interface_assign()
                if ret is True:
                    arg_lll.typ = InterfaceType(
                        function_name)  # Cast to Correct interface type.
                    return arg_lll

        elif isinstance(self.expr.func,
                        vy_ast.Attribute) and self.expr.func.attr == "pop":
            darray = Expr(self.expr.func.value, self.context).lll_node
            assert len(self.expr.args) == 0
            assert isinstance(darray.typ, DArrayType)
            return pop_dyn_array(darray,
                                 return_popped_item=True,
                                 pos=getpos(self.expr))

        elif (isinstance(self.expr.func, vy_ast.Attribute)
              and isinstance(self.expr.func.value, vy_ast.Name)
              and self.expr.func.value.id == "self"):  # noqa: E501
            return self_call.lll_for_self_call(self.expr, self.context)
        else:
            return external_call.lll_for_external_call(self.expr, self.context)
コード例 #4
0
ファイル: stmt.py プロジェクト: vyperlang/vyper
    def parse_Call(self):
        # TODO use expr.func.type.is_internal once type annotations
        # are consistently available.
        is_self_function = ((isinstance(self.stmt.func, vy_ast.Attribute))
                            and isinstance(self.stmt.func.value, vy_ast.Name)
                            and self.stmt.func.value.id == "self")

        if isinstance(self.stmt.func, vy_ast.Name):
            funcname = self.stmt.func.id
            return STMT_DISPATCH_TABLE[funcname].build_IR(
                self.stmt, self.context)

        elif isinstance(self.stmt.func,
                        vy_ast.Attribute) and self.stmt.func.attr in (
                            "append",
                            "pop",
                        ):
            # TODO: consider moving this to builtins
            darray = Expr(self.stmt.func.value, self.context).ir_node
            args = [Expr(x, self.context).ir_node for x in self.stmt.args]
            if self.stmt.func.attr == "append":
                # sanity checks
                assert len(args) == 1
                arg = args[0]
                assert isinstance(darray.typ, DArrayType)
                check_assign(dummy_node_for_type(darray.typ.subtype),
                             dummy_node_for_type(arg.typ))

                return append_dyn_array(darray, arg)
            else:
                assert len(args) == 0
                return pop_dyn_array(darray, return_popped_item=False)

        elif is_self_function:
            return self_call.ir_for_self_call(self.stmt, self.context)
        else:
            return external_call.ir_for_external_call(self.stmt, self.context)