While working on FixedArr, I was thinking what else can be useful for Yaksha. I came up with two ideas.
New annotation ideas #
Packed ##
This will compile a struct into a packed struct. This will be useful for writing binary parsers. #pragma push(pack, N) will be used to pack the struct.
I’m also thinking to limit this to only structs and not classes.
1@packed("1")
2struct Foo:
3 a: u8
4 b: u16
Expose ##
This will expose a struct / class / function to C. This will be useful for exposing things to C (access from @native). Tuples cannot be exposed to C.
1@expose("foo") # foo will be the name of the function in `C`
2def foo(a: u8, b: u16) -> u32:
3 return a + b
FixedArr #
Auto casting ##
FixedArrandArraycan be casted toPtr,AnyPtrandAnyPtrToConst.
Returning FixedArr from functions ##
Since FixedArr is allocated on stack, it is not possible to return it from a function in C. However, if we wrap it in a struct or Tuple, it is possible to return it from a function.
If we can add few quality of life improvements to Tuple, it will be easy to use it as a wrapper for FixedArr.
1def foo() -> Tuple[FixedArr[u8, 2]]:
2 return tuple(fixedarr(1u8, 2u8))
Impossible assigns (Impossible in C should not mean impossible in Yaksha) ##
If we can make fixed arrays and tuples assignable, we can do some interesting things.
1def foo():
2 a: FixedArr[u8, 2] = fixedarr(1u8, 2u8)
3 b: FixedArr[u8, 2]
4 a = b # This is not possible nowS