Skip to content

Commit f8e6194

Browse files
committed
added: implementation of onyx_inject_code
1 parent 16037d4 commit f8e6194

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/src/library_main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,13 @@ void onyx_add_mapped_dir(onyx_context_t *ctx, char *mapped_name, int32_t mapped_
714714

715715
/// Directly injects Onyx code as a new compilation unit
716716
void onyx_inject_code(onyx_context_t *ctx, uint8_t *code, int32_t length) {
717-
assert(0 && "unimplemented");
717+
bh_file_contents file_contents;
718+
file_contents.allocator = ctx->context.ast_alloc;
719+
file_contents.data = code;
720+
file_contents.length = length;
721+
file_contents.filename = "(injected)";
722+
723+
parse_source_file(&ctx->context, &file_contents);
718724
}
719725

720726
//

core/onyx/toolchain/toolchain.onyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Builder.add_source :: (use self: &#Self, filename: str) {
4141
native.onyx_include_file(ctx, filename)
4242
}
4343

44+
Builder.inject_source :: (use self: &#Self, source: str) {
45+
native.onyx_inject_code(ctx, source)
46+
}
47+
4448
Builder.set_platform :: (use self: &#Self, platform: native.onyx_platform_t) {
4549
native.onyx_set_option_int(ctx, .PLATFORM, ~~platform)
4650
}

0 commit comments

Comments
 (0)