// the code base. This is used when a static if clears and new symbols are introduced.
// 'use package' statements have to be reevaluated to pull in the new symbols.
bh_arr(Entity *) use_package_entities;
+
+ // NOTE: These are entities that are stored in packages marked with `#allow_stale_code`.
+ // These entities are flushed to the entity heap when the package has been explicit used
+ // somewhere.
+ bh_arr(Entity *) buffered_entities;
+ b32 is_included_somewhere : 1;
};
typedef enum CompileAction CompileAction;
b32 use_multi_threading : 1;
b32 generate_foreign_info : 1;
b32 no_std : 1;
+ b32 no_stale_code : 1;
b32 generate_tag_file : 1;
b32 generate_symbol_info_file : 1;
Package* package_lookup_or_create(char* package_name, Scope* parent_scope, bh_allocator alloc, OnyxFilePos pos);
void package_track_use_package(Package* package, Entity* entity);
void package_reinsert_use_packages(Package* package);
+void package_mark_as_used(Package* package);
Scope* scope_create(bh_allocator a, Scope* parent, OnyxFilePos created_at);
void scope_include(Scope* target, Scope* source, OnyxFilePos pos);
"\t--doc <doc_file> Generates an O-DOC file, a.k.a an Onyx documentation file. Used by onyx-doc-gen.\n"
"\t--tag Generates a C-Tag file.\n"
"\t--syminfo <target_file> Generates a symbol resolution information file. Used by onyx-lsp.\n"
+ "\t--no-stale-code Disables use of `#allow_stale_code` directive\n"
"\t--generate-foreign-info\n"
"\n"
"Developer options:\n"
.use_post_mvp_features = 1,
.use_multi_threading = 0,
.no_std = 0,
+ .no_stale_code = 0,
.runtime = Runtime_Onyx,
else if (!strcmp(argv[i], "--no-std")) {
options.no_std = 1;
}
+ else if (!strcmp(argv[i], "--no-stale-code")) {
+ options.no_stale_code = 1;
+ }
else if (!strcmp(argv[i], "-I")) {
bh_arr_push(options.included_folders, argv[++i]);
}
}
void onyx_parser_free(OnyxParser* parser) {
+ bh_arr_free(parser->alternate_entity_placement_stack);
+ bh_arr_free(parser->current_symbol_stack);
+ bh_arr_free(parser->scope_flags);
+ bh_arr_free(parser->stored_tags);
}
void onyx_parse(OnyxParser *parser) {
parser->file_scope = scope_create(parser->allocator, parser->package->private_scope, parser->tokenizer->tokens[0].pos);
parser->current_scope = parser->file_scope;
+ if (parse_possible_directive(parser, "allow_stale_code")
+ && !parser->package->is_included_somewhere
+ && !context.options->no_stale_code) {
+ bh_arr_new(global_heap_allocator, parser->package->buffered_entities, 32);
+ bh_arr_push(parser->alternate_entity_placement_stack, &parser->package->buffered_entities);
+ }
+
parse_top_level_statements_until(parser, Token_Type_End_Stream);
parser->current_scope = parser->current_scope->parent;
}
if (package->package) {
+ package_mark_as_used(package->package);
return Symres_Success;
} else {
if (report_unresolved_symbols) {
bh_arr_set_length(package->use_package_entities, 0);
}
+void package_mark_as_used(Package* package) {
+ if (!package) return;
+ if (package->is_included_somewhere) return;
+ package->is_included_somewhere = 1;
+
+ bh_arr_each(Entity *, pent, package->buffered_entities) {
+ entity_heap_insert_existing(&context.entities, *pent);
+ }
+
+ bh_arr_clear(package->buffered_entities);
+}
+
+
//
// Scoping
package core.avl_tree
+#allow_stale_code
use core
use core.math
A.height = math.max(get_height(A.left), get_height(A.right)) + 1;
B.height = math.max(get_height(B.left), get_height(B.right)) + 1;
-}
\ No newline at end of file
+}
// @Incomplete // This implementation is not functional at all but is something I want to get around to adding.
package core.bucket_array
+#allow_stale_code
use core
use core.array
package core.list
+#allow_stale_code
use core
package core.doc
+#allow_stale_code
Doc :: struct {
header: Doc_Header;
package core.encoding.base64
+#allow_stale_code
use core.array
package core.encoding.csv
+#allow_stale_code
//
// A simple CSV parsing and encoding library.
package core.encoding.ini
+#allow_stale_code
//
// This library allows for parsing and formatting a simple 'ini' like
package core.encoding.osad
+#allow_stale_code
use core.io
use core.string
package core.encoding.utf8
+#allow_stale_code
use core.string
use core.array
package core.hash.md5
+#allow_stale_code
use core {io, memory, conv}
use core.intrinsics.wasm {rotl_i32}
package core.hash.sha256
+#allow_stale_code
use core {memory}
use core.intrinsics.wasm {wasm :: package}
0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,
0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,
0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
-];
\ No newline at end of file
+];
package core.io.binary
+#allow_stale_code
// NOTE: This is a very experimental and not well put together package.
// The primary reason it exists is because I was working on reading TTF
package core.test
+#allow_stale_code
use core
use core.array