diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-10 15:37:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-10 15:37:19 -0700 |
| commit | a083a37ee58dc48d92cf2b844466a295eb3e643e (patch) | |
| tree | 69028f3d9f92fa7e2085c76bc234e1949ef645c5 /source/slang/core.meta.slang | |
| parent | 88f04c29244af23c1cdd472d8d1ae3e5a650494e (diff) | |
Add `none` literal that is convertible to `Optional`. (#2356)
* Add `none` literal that is convertible to `Optional`.
* Fix cpu code gen.
* Include vk and cpu test for is-as operator test.
* Inline comparison operators.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/core.meta.slang')
| -rw-r--r-- | source/slang/core.meta.slang | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 616511b01..d912fe8ce 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -349,6 +349,12 @@ struct NullPtr { }; +__magic_type(NoneType) +__intrinsic_type($(kIROp_VoidType)) +struct __none_t +{ +}; + __generic<T> __magic_type(PtrType) __intrinsic_type($(kIROp_PtrType)) @@ -472,8 +478,36 @@ struct Optional __intrinsic_op($(kIROp_GetOptionalValue)) get; } + + __implicit_conversion($(kConversionCost_ValToOptional)) + __intrinsic_op($(kIROp_MakeOptionalValue)) + __init(T val); }; +__generic<T> +[__unsafeForceInlineEarly] +bool operator==(Optional<T> val, __none_t noneVal) +{ + return !val.hasValue; +} +__generic<T> +[__unsafeForceInlineEarly] +bool operator!=(Optional<T> val, __none_t noneVal) +{ + return val.hasValue; +} +__generic<T> +[__unsafeForceInlineEarly] +bool operator==(__none_t noneVal, Optional<T> val) +{ + return !val.hasValue; +} +__generic<T> +[__unsafeForceInlineEarly] +bool operator!=(__none_t noneVal, Optional<T> val) +{ + return val.hasValue; +} __magic_type(StringType) __intrinsic_type($(kIROp_StringType)) |
