jule icon indicating copy to clipboard operation
jule copied to clipboard

[PROPOSAL] `include` functions

Open koibtw opened this issue 1 year ago • 2 comments

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.

koibtw avatar Jan 14 '25 14:01 koibtw

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 avatar Jan 14 '25 14:01 mertcandav

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 :)

koibtw avatar Jan 14 '25 14:01 koibtw