当前位置: 首页>>代码示例>>Python>>正文


Python couscous.ref函数代码示例

本文整理汇总了Python中nope.couscous.ref函数的典型用法代码示例。如果您正苦于以下问题:Python ref函数的具体用法?Python ref怎么用?Python ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ref函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init_method_is_called_if_present

    def init_method_is_called_if_present(self):
        node = cc.class_("A", methods=[
            cc.func("__init__", [cc.arg("self"), cc.arg("value")], [
                cc.expression_statement(cc.call(cc.ref("print"), [cc.ref("value")]))
            ])
        ], body=[])
        expected_aux = """internal class __A {
    internal dynamic __init__;
}
"""

        expected = """A = new
{
    __call__ = ((System.Func<dynamic, dynamic>)((dynamic __value) =>
    {
        dynamic __self = null;
        __self = new __A {
            __init__ = ((System.Func<dynamic, dynamic>)((dynamic value) =>
            {
                dynamic self = __self;
                print(value);
            })),
        };
        __self.__init__(__value);
        return __self;
    })),
};
"""
        transformer = _create_transformer()
        assert_equal(expected, cs.dumps(transformer.transform(node)))
        assert_equal(expected_aux, cs.dumps(transformer.aux()))
开发者ID:mwilliamson,项目名称:nope,代码行数:31,代码来源:code_generation_tests.py

示例2: test_transform_try_except_with_multiple_exception_handlers

def test_transform_try_except_with_multiple_exception_handlers():
    _assert_transform(
        cc.try_(
            [cc.ret(cc.ref("x"))],
            handlers=[
                cc.except_(cc.ref("AssertionError"), None, [cc.ret(cc.ref("y"))]),
                cc.except_(cc.ref("Exception"), None, [cc.ret(cc.ref("z"))]),
            ],
        ),
        """
            try {
                return x;
            } catch ($exception0) {
                if ($exception0.$nopeException === $nope.undefined) {
                    throw $exception0;
                } else {
                    if ($nope.builtins.isinstance($exception0.$nopeException, AssertionError)) {
                        return y;
                    } else {
                        if ($nope.builtins.isinstance($exception0.$nopeException, Exception)) {
                            return z;
                        } else {
                            throw $exception0;
                        }
                    }
                }
            }
        """,
    )
开发者ID:mwilliamson,项目名称:nope,代码行数:29,代码来源:codegeneration_tests.py

示例3: test_transform_raise_without_exception_value

def test_transform_raise_without_exception_value():
    _assert_transform(
        cc.try_(
            [cc.ret(cc.ref("x"))],
            handlers=[
                cc.except_(cc.ref("AssertionError"), cc.ref("error"), [cc.raise_()]),
            ],
        ),
        """
            try {
                return x;
            } catch ($exception0) {
                if ($exception0.$nopeException === $nope.undefined) {
                    throw $exception0;
                } else {
                    if ($nope.builtins.isinstance($exception0.$nopeException, AssertionError)) {
                        var error = $exception0.$nopeException;
                        throw $exception0;
                    } else {
                        throw $exception0;
                    }
                }
            }
        """,
    )
开发者ID:mwilliamson,项目名称:nope,代码行数:25,代码来源:codegeneration_tests.py

示例4: test_transform_compound_assignments

 def test_transform_compound_assignments(self):
     _assert_transform(
         nodes.assign(["x", "y"], nodes.ref("z")),
         cc.statements([
             cc.declare("__nope_u_tmp0", cc.ref("z")),
             cc.assign(cc.ref("x"), cc.ref("__nope_u_tmp0")),
             cc.assign(cc.ref("y"), cc.ref("__nope_u_tmp0")),
         ]),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:desugar_tests.py

示例5: test_transform_boolean_or

 def test_transform_boolean_or(self):
     _assert_transform(
         nodes.bool_or(nodes.ref("x"), nodes.ref("y")),
         cc.ternary_conditional(
             cc.call(cc.builtin("bool"), [cc.ref("x")]),
             cc.ref("x"),
             cc.ref("y")
         ),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:9,代码来源:desugar_tests.py

示例6: test_transform_call_with_positional_arguments

 def test_transform_call_with_positional_arguments(self):
     func_node = nodes.ref("f")
     type_lookup = [
         (func_node, types.func([types.str_type], types.none_type))
     ]
     _assert_transform(
         nodes.call(func_node, [nodes.ref("x")]),
         cc.call(cc.ref("f"), [cc.ref("x")]),
         type_lookup=type_lookup,
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:10,代码来源:desugar_tests.py

示例7: test_import_of_module_in_package_assigns_values_for_both_package_and_module

 def test_import_of_module_in_package_assigns_values_for_both_package_and_module(self):
     _assert_transform(
         nodes.import_([
             nodes.import_alias("os.path", None),
         ]),
         cc.statements([
             cc.assign(cc.ref("os"), cc.module_ref(["os"])),
             cc.assign(cc.attr(cc.ref("os"), "path"), cc.module_ref(["os", "path"])),
         ])
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:10,代码来源:desugar_tests.py

示例8: test_transform_while_loop

 def test_transform_while_loop(self):
     _assert_transform(
         nodes.while_(
             nodes.ref("x"),
             [nodes.ret(nodes.ref("y"))],
         ),
         cc.while_(
             cc.call(cc.builtin("bool"), [cc.ref("x")]),
             [cc.ret(cc.ref("y"))],
         )
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:desugar_tests.py

示例9: test_multiple_imported_names_in_one_statement_generates_multiple_assignments

 def test_multiple_imported_names_in_one_statement_generates_multiple_assignments(self):
     _assert_transform(
         nodes.import_from(["."], [
             nodes.import_alias("x", None),
             nodes.import_alias("y", None),
         ]),
         cc.statements([
             cc.assign(cc.ref("x"), cc.attr(cc.module_ref(["."]), "x")),
             cc.assign(cc.ref("y"), cc.attr(cc.module_ref(["."]), "y")),
         ]),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:desugar_tests.py

示例10: test_import_multiple_values_in_single_import_statement

 def test_import_multiple_values_in_single_import_statement(self):
     _assert_transform(
         nodes.import_([
             nodes.import_alias("os", None),
             nodes.import_alias("sys", None)
         ]),
         cc.statements([
             cc.assign(cc.ref("os"), cc.module_ref(["os"])),
             cc.assign(cc.ref("sys"), cc.module_ref(["sys"])),
         ])
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:desugar_tests.py

示例11: test_transform_while_loop

def test_transform_while_loop():
    _assert_transform(
        cc.while_(
            cc.ref("x"),
            [cc.ret(cc.ref("y"))],
        ),
        js.while_(
            js.ref("x"),
            [js.ret(js.ref("y"))],
        )
    )
开发者ID:mwilliamson,项目名称:nope,代码行数:11,代码来源:codegeneration_tests.py

示例12: test_variables_are_declared

 def test_variables_are_declared(self):
     _assert_transform(
         nodes.func("f", nodes.args([]), [
             nodes.assign([nodes.ref("x")], nodes.ref("y")),
             nodes.ret(nodes.ref("value")),
         ], type=None),
         cc.func("f", [], [
             cc.declare("x"),
             cc.assign(cc.ref("x"), cc.ref("y")),
             cc.ret(cc.ref("value")),
         ]),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:12,代码来源:desugar_tests.py

示例13: test_transform_if_else

def test_transform_if_else():
    _assert_transform(
        cc.if_(
            cc.ref("x"),
            [cc.ret(cc.ref("y"))],
            [cc.ret(cc.ref("z"))],
        ),
        js.if_(
            js.ref("x"),
            [js.ret(js.ref("y"))],
            [js.ret(js.ref("z"))],
        )
    )
开发者ID:mwilliamson,项目名称:nope,代码行数:13,代码来源:codegeneration_tests.py

示例14: try_with_finally_is_converted_to_try_with_finally

    def try_with_finally_is_converted_to_try_with_finally(self):
        node = cc.try_(
            [cc.ret(cc.ref("x"))],
            finally_body=[cc.expression_statement(cc.ref("y"))]
        )
        
        expected = """try {
    return x;
} finally {
    y;
}
"""
        assert_equal(expected, cs.dumps(transform(node)))
开发者ID:mwilliamson,项目名称:nope,代码行数:13,代码来源:code_generation_tests.py

示例15: test_statements_in_bodies_are_transformed

 def test_statements_in_bodies_are_transformed(self):
     _assert_transform(
         nodes.try_(
             [nodes.ret(nodes.ref("x"))],
             handlers=[nodes.except_(nodes.ref("Exception"), nodes.ref("error"), [nodes.ref("y")])],
             finally_body=[nodes.ret(nodes.ref("z"))],
         ),
         cc.try_(
             [cc.ret(cc.ref("x"))],
             handlers=[cc.except_(cc.ref("Exception"), cc.ref("error"), [cc.ref("y")])],
             finally_body=[cc.ret(cc.ref("z"))],
         ),
     )
开发者ID:mwilliamson,项目名称:nope,代码行数:13,代码来源:desugar_tests.py


注:本文中的nope.couscous.ref函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。