-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
Add primitive type tutorial blog #321
Conversation
@ViralBShah |
We need some reviews. |
Sure. |
author: 鄭景文(Peter Cheng), 杜岳華(Yueh-Hua Tu) | ||
--- | ||
|
||
Julia provide some APIs for you to declare your own primitive types in Julia. However, when you open [the official docs about primitive type](https://docs.julialang.org/en/v1/manual/types/#Primitive-Types-1), you still don't know how to make your new primitive types work in your code. Therefore, here is a simple tutorial that tell you how to do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Julia provides
No need to repeat "in Julia" at the end :)
primitive type «name» «bits» end | ||
primitive type «name» <: «supertype» «bits» end | ||
|
||
Currently, Julia only support sizes that are multiples of 8 bits. So like the `Bool` only take 1 bit, you still need to declare it as 8 bits. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Julia only supports
So even though Bool
only takes 1 bit, you need to declare it as 8 bits
In the URL: |
There is an English version included. We wrote in both Chinese and English |
|
||
1. `Core.Intrinsics.bitcase(type, value)` | ||
|
||
`bitcase` told the LLVM to make a new same sized value of a primitive type instance `value` and mark it as type `type`. The type of `value` must have the same bitsize as `type`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why these spaces between value
and "and". Same applies to next lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I guess it's due to some problems in my editor, let me remove it.
primitive type chinese standard author name primitive type chinese reference fix primitive type chinese typo Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type-zh_tw.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> Update blog/_posts/2019-03-02-custom-primitiv-type.md Co-Authored-By: chengchingwen <adgjl5645@hotmail.com> add s, remove space fix typo in filename
Co-Authored-By: chengchingwen <adgjl5645@hotmail.com>
Do we really want to document/blog about this as long as
aka JuliaLang/julia#29193 JuliaLang/julia#29053 JuliaLang/julia#26026 ? I'd feel much better if we deferred documentation / public blogging / advertisement of primitive types until they actually work reliably. |
FWIW, the same issue appears with your bitsize, just harder to spot. Example:
The issue is that everybody has different opinions on whether the size of A is 9 byte or 16 byte (8 byte + 1 byte + 7 bytes padding for alignment). Hence the allocated buffer is sometimes too small and we corrupt memory. Also, |
@chethega Thank you for telling us these issues. |
Ah, so that's the reason why there is no documentation yet. @yuehhua I'm fine with it, but after that we might need to change the content a little bit. |
Bump. Is this happening? |
@ViralBShah As @chethega mentioned, there are still some bugs of primitive type. Should we just ignore those bugs, or should we close this PR for now? |
We can close for now and always reopen in the future |
With English and Traditional Chinese version.