Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Script] Add pointer arthematic #237

Merged
merged 5 commits into from May 23, 2023

Conversation

yaoyaoding
Copy link
Member

def test_const_pointer():
    from hidet.lang import attrs, void_p, printf, int32

    with hidet.script_module() as script_module:

        @hidet.script
        def func():
            attrs.func_kind = 'host_kernel'

            v = int32(0)  # int32 v = 0;
            p_int32 = ~v  # int32* p_int32 = &v;
            p_void = void_p(p_int32)  # void* p_void = (void*)p_int32;
            printf("%p\n", p_void)

            p_void_0 = void_p(0)  # void* p_void_0 = (void*)0;
            printf("%p\n", p_void_0)

            p_void_1 = p_void_0 + 1
            p_void_2 = p_void_1 - 1
            printf("%p\n", p_void_1)
            printf("%p\n", p_void_2)
            printf("%d\n", p_void_1 == p_void_2)
            printf("%d\n", p_void_1 == p_void_2 + 1)
            printf("%p\n", p_int32 + 1)

    func = script_module.build()
    func()
0x7ffdc4cbeb2c
(nil)
0x1
0x2
0
0
0x7ffdc4cbeb30

@yaoyaoding yaoyaoding merged commit 36e39d0 into hidet-org:main May 23, 2023
2 checks passed
@yaoyaoding yaoyaoding deleted the pointer-constant branch May 23, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant