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

[PROPOSAL] include functions #128

Open
adamperkowski opened this issue Jan 14, 2025 · 2 comments
Open

[PROPOSAL] include functions #128

adamperkowski opened this issue Jan 14, 2025 · 2 comments
Labels
proposal A proposal for new feature or changings

Comments

@adamperkowski
Copy link
Member

adamperkowski commented Jan 14, 2025

Detailed description

Hey. I think having a function that would "include" data from files at compiletime (i.e. "embed" the file) would be really useful.
We don't have to have "include as code" (see Rust's include!()). The ones I care about are Rust's include_bytes!() and include_str!(). See the context below.
Opinions?

Context

Rust std's implementation:
https://doc.rust-lang.org/std/macro.include.html
https://doc.rust-lang.org/std/macro.include_bytes.html
https://doc.rust-lang.org/std/macro.include_str.html

Additional information

The usage would look something like this:

use "std/comptime"

static TEST_FILE_BYTES: []byte = comptime::IncludeBytes("test.txt")
static TEST_FILE_STR: str = comptime::IncludeStr("test.txt")

fn main() {
	println(TEST_FILE_STR)
}

// Doing this should work too:
use "std/comptime"

fn main() {
	testFileStr := comptime::IncludeStr("test.txt")
	println(testFileStr)
}

Outputs the contents of test.txt converted to str, read on compiletime.

If there are no objections, I'd be happy to work on this.

@adamperkowski adamperkowski added the proposal A proposal for new feature or changings label Jan 14, 2025
@adamperkowski adamperkowski changed the title [PROPOSAL] include functions feat(os): include functions Jan 14, 2025
@adamperkowski adamperkowski changed the title feat(os): include functions feat(std/os): include functions Jan 14, 2025
@mertcandav
Copy link
Member

Hey.
Jule does not have macros and, based on current design decisions, it will not support them. Therefore, it is not possible to support the include! macro. However, the suggested include_bytes!() and include_str!() macros appear feasible.

These align well with Jule's compile-time capabilities and would likely be provided under std/comptime as comptime::IncludeBytes() and comptime::IncludeStr() functions.

I'm marking this proposal as "Active". If you wish, you can start working on this. I'm currently working on a few major bug fixes for the compiler. After completing it, I can devote time to implement this proposal.

Note

The comptime::IncludeBytes function might be enough. Because compiler can optimize str(comptime::IncludeBytes()) expressions if possible. However, it is not always possible. So I have no objection to comptime::IncludeStr function.

@mertcandav mertcandav moved this to Active in proposals Jan 14, 2025
@adamperkowski adamperkowski changed the title feat(std/os): include functions [PROPOSAL] include functions Jan 14, 2025
@adamperkowski
Copy link
Member Author

Hey. Jule does not have macros and, based on current design decisions, it will not support them. Therefore, it is not possible to support the include! macro.

Yes, I know. That's why I said that my proposal is not about include!()

These align well with Jule's compile-time capabilities and would likely be provided under std/comptime as comptime::IncludeBytes() and comptime::IncludeStr() functions.
I'm marking this proposal as "Active". If you wish, you can start working on this. I'm currently working on a few major bug fixes for the compiler. After completing it, I can devote time to implement this proposal.

The comptime::IncludeBytes function might be enough. Because compiler can optimize str(comptime::IncludeBytes()) expressions if possible. However, it is not always possible. So I have no objection to comptime::IncludeStr function.

Thanks. I'll start working on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal A proposal for new feature or changings
Projects
Status: Active
Development

No branches or pull requests

2 participants