package core.alloc
-#include_file "core/alloc/arena"
-#include_file "core/alloc/fixed"
-#include_file "core/alloc/heap"
-#include_file "core/alloc/ring"
+#load "core/alloc/arena"
+#load "core/alloc/fixed"
+#load "core/alloc/heap"
+#load "core/alloc/ring"
TEMPORARY_ALLOCATOR_SIZE :: 1 << 12; // 4Kb
// of the language. You will not make your own instance of the heap
// allocator, since it controls WASM intrinsics such as memory_grow.
-#include_file "core/memory"
-#include_file "core/intrinsics/wasm"
+#load "core/memory"
+#load "core/intrinsics/wasm"
use package core.intrinsics.wasm { memory_size, memory_grow }
use package core.memory as memory
-#include_file "core/alloc"
-#include_file "core/array"
-#include_file "core/conv"
-#include_file "core/intrinsics/wasm"
-#include_file "core/map"
-#include_file "core/math"
-#include_file "core/memory"
-#include_file "core/random"
-#include_file "core/stdio"
-#include_file "core/string"
-#include_file "core/string/builder"
-#include_file "core/string/reader"
+#load "core/alloc"
+#load "core/array"
+#load "core/conv"
+#load "core/intrinsics/wasm"
+#load "core/map"
+#load "core/math"
+#load "core/memory"
+#load "core/random"
+#load "core/stdio"
+#load "core/string"
+#load "core/string/builder"
+#load "core/string/reader"
-#include_file "core/sys/js"
+#load "core/sys/js"
-#include_file "core/alloc"
-#include_file "core/array"
-#include_file "core/conv"
-#include_file "core/file"
-#include_file "core/intrinsics/wasm"
-#include_file "core/map"
-#include_file "core/math"
-#include_file "core/memory"
-#include_file "core/random"
-#include_file "core/stdio"
-#include_file "core/string"
-#include_file "core/string/builder"
-#include_file "core/string/reader"
-#include_file "core/wasi"
+#load "core/alloc"
+#load "core/array"
+#load "core/conv"
+#load "core/file"
+#load "core/intrinsics/wasm"
+#load "core/map"
+#load "core/math"
+#load "core/memory"
+#load "core/random"
+#load "core/stdio"
+#load "core/string"
+#load "core/string/builder"
+#load "core/string/reader"
+#load "core/wasi"
-#include_file "core/sys/wasi"
+#load "core/sys/wasi"
package system
-#include_file "core/wasi"
+#load "core/wasi"
use package wasi
use package core
// added to the queue of files to load. When all files in the queue have been parsed,
// the compiler can continue with the compilation process. You can also include the
// same file as many times as you want. The redudant copies will be discarded.
-#include_file "core/std/wasi"
+#load "core/std/wasi"
// All of the functionality we need is in the 'core' package. Unlike other package systems,
// there is no way to reference symbols in a package without specifically 'using' it. This
// This time, we are not adding, 'package main' to the top of the file, since
// every file is automatically part of the main package unless specified otherwise.
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
// Now, lets go over the basic types and control flow mechanisms in Onyx.
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
// This file will give examples of all of these things, as well as some of the gotchas
// you need to be aware of.
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core { println }
Ast_Kind_Error,
Ast_Kind_Program,
Ast_Kind_Package,
- Ast_Kind_Include_File,
- Ast_Kind_Include_Folder,
+ Ast_Kind_Load_File,
+ Ast_Kind_Load_Path,
Ast_Kind_Use_Package,
Ast_Kind_Alias,
Ast_Kind_Memres,
typedef enum EntityType {
Entity_Type_Unknown,
- Entity_Type_Include_Folder,
- Entity_Type_Include_File,
+ Entity_Type_Load_Path,
+ Entity_Type_Load_File,
Entity_Type_Use_Package,
Entity_Type_String_Literal,
Entity_Type_File_Contents,
- match: '#[a-zA-Z_]+'
scope: keyword.other.onyx
- - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*proc'
+ - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*(proc)'
captures:
1: entity.name.function
+ 2: keyword.control.onyx
- - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*struct'
+ - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*(struct)'
captures:
1: entity.name.struct
+ 2: keyword.control.onyx
- - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*enum'
+ - match: '([a-zA-Z_][a-zA-Z0-9_]*)\s*::\s*(enum)'
captures:
1: entity.name.enum
+ 2: keyword.control.onyx
- match: '([a-zA-Z_][a-zA-Z0-9_\.]+)\s*\('
captures:
-#include_file "core/std/wasi"
-#include_file "progs/foo_test"
+#load "core/std/wasi"
+#load "progs/foo_test"
use package core
package main
-#include_file "core/std/wasi"
-#include_file "core/simd_intrinsics"
+#load "core/std/wasi"
+#load "core/simd_intrinsics"
use package core
use package simd
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core
package main
-#include_file "core/std/wasi"
-#include_file "core/intrinsics/simd"
+#load "core/std/wasi"
+#load "core/intrinsics/simd"
use package core
use package core.intrinsics.simd
package main
-#include_file "core/std/wasi"
+#load "core/std/wasi"
use package core;
package main
-#include_file "core/std/wasi"
+#load "core/std/wasi"
// NOTE: Didn't realize this would work so easily
use package core { string_builder_append as sba }
static char* lookup_included_file(CompilerState* cs, char* filename);
-static AstInclude* create_include_file(bh_allocator alloc, char* filename) {
- AstInclude* include_node = onyx_ast_node_new(alloc, sizeof(AstInclude), Ast_Kind_Include_File);
+static AstInclude* create_load(bh_allocator alloc, char* filename) {
+ AstInclude* include_node = onyx_ast_node_new(alloc, sizeof(AstInclude), Ast_Kind_Load_File);
include_node->name = filename;
return include_node;
// NOTE: Add builtin entities to pipeline.
entity_heap_insert(&compiler_state->prog_info.entities, ((Entity) {
.state = Entity_State_Parse_Builtin,
- .type = Entity_Type_Include_File,
+ .type = Entity_Type_Load_File,
.package = NULL,
- .include = create_include_file(compiler_state->sp_alloc, "core/builtin"),
+ .include = create_load(compiler_state->sp_alloc, "core/builtin"),
}));
entity_heap_insert(&compiler_state->prog_info.entities, ((Entity) {
bh_arr_each(const char *, filename, opts->files) {
entity_heap_insert(&compiler_state->prog_info.entities, ((Entity) {
.state = Entity_State_Parse,
- .type = Entity_Type_Include_File,
+ .type = Entity_Type_Load_File,
.package = NULL,
- .include = create_include_file(compiler_state->sp_alloc, (char *) *filename),
+ .include = create_load(compiler_state->sp_alloc, (char *) *filename),
}));
}
}
ent.scope = n->scope;
switch (nkind) {
- case Ast_Kind_Include_File: {
+ case Ast_Kind_Load_File: {
ent.state = Entity_State_Parse;
- ent.type = Entity_Type_Include_File;
+ ent.type = Entity_Type_Load_File;
ent.include = (AstInclude *) node;
entity_heap_insert(&compiler_state->prog_info.entities, ent);
break;
}
- case Ast_Kind_Include_Folder: {
+ case Ast_Kind_Load_Path: {
ent.state = Entity_State_Parse;
- ent.type = Entity_Type_Include_Folder;
+ ent.type = Entity_Type_Load_Path;
ent.include = (AstInclude *) node;
entity_heap_insert(&compiler_state->prog_info.entities, ent);
break;
}
}
-static b32 process_include_entity(CompilerState* compiler_state, Entity* ent) {
- assert(ent->type == Entity_Type_Include_File || ent->type == Entity_Type_Include_Folder);
+static b32 process_load_entity(CompilerState* compiler_state, Entity* ent) {
+ assert(ent->type == Entity_Type_Load_File || ent->type == Entity_Type_Load_Path);
AstInclude* include = ent->include;
- if (include->kind == Ast_Kind_Include_File) {
+ if (include->kind == Ast_Kind_Load_File) {
char* filename = lookup_included_file(compiler_state, include->name);
char* formatted_name = bh_strdup(global_heap_allocator, filename);
process_source_file(compiler_state, formatted_name);
- } else if (include->kind == Ast_Kind_Include_Folder) {
+ } else if (include->kind == Ast_Kind_Load_Path) {
bh_arr_push(compiler_state->options->included_folders, include->name);
}
switch (ent->state) {
case Entity_State_Parse_Builtin:
- process_include_entity(compiler_state, ent);
+ process_load_entity(compiler_state, ent);
ent->state = Entity_State_Finalized;
if (onyx_has_errors()) return 0;
break;
case Entity_State_Parse:
- process_include_entity(compiler_state, ent);
+ process_load_entity(compiler_state, ent);
ent->state = Entity_State_Finalized;
break;
case Ast_Kind_Error: return sizeof(AstNode);
case Ast_Kind_Program: return sizeof(AstNode);
case Ast_Kind_Package: return sizeof(AstPackage);
- case Ast_Kind_Include_File: return sizeof(AstInclude);
- case Ast_Kind_Include_Folder: return sizeof(AstInclude);
+ case Ast_Kind_Load_File: return sizeof(AstInclude);
+ case Ast_Kind_Load_Path: return sizeof(AstInclude);
case Ast_Kind_Use_Package: return sizeof(AstUsePackage);
case Ast_Kind_Alias: return sizeof(AstAlias);
case Ast_Kind_Memres: return sizeof(AstMemRes);
while (parser->curr->type == '#') {
OnyxToken* dir_token = parser->curr;
- if (parse_possible_directive(parser, "include_file")) {
- AstInclude* include = make_node(AstInclude, Ast_Kind_Include_File);
+ if (parse_possible_directive(parser, "load")) {
+ AstInclude* include = make_node(AstInclude, Ast_Kind_Load_File);
include->token = dir_token;
OnyxToken* str_token = expect_token(parser, Token_Type_Literal_String);
return (AstNode *) include;
}
- else if (parse_possible_directive(parser, "include_folder")) {
- AstInclude* include = make_node(AstInclude, Ast_Kind_Include_Folder);
+ else if (parse_possible_directive(parser, "load_path")) {
+ AstInclude* include = make_node(AstInclude, Ast_Kind_Load_Path);
include->token = dir_token;
OnyxToken* str_token = expect_token(parser, Token_Type_Literal_String);
if (parser->hit_unexpected_token) return parser->results;
switch (curr_stmt->kind) {
- case Ast_Kind_Include_File:
- case Ast_Kind_Include_Folder:
+ case Ast_Kind_Load_File:
+ case Ast_Kind_Load_Path:
add_node_to_process(parser, curr_stmt);
break;
const char* entity_type_strings[Entity_Type_Count] = {
"Unknown",
- "Include Folder",
- "Include File",
+ "Add to Load Path",
+ "Load File",
"Use Package",
"String Literal",
"File Contents",
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
package main
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
use package core.string.reader as reader
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
package main
-#include_file "core/std/js"
+#load "core/std/js"
use package core
package main
-#include_file "core/std/js"
+#load "core/std/js"
use package core
package main
-#include_file "core/std/js"
+#load "core/std/js"
use package core
-#include_file "core/std/js"
+#load "core/std/js"
use package core
}
}
-#include_file "core/std/js"
\ No newline at end of file
+#load "core/std/js"
\ No newline at end of file
package main
-#include_file "core/std/js"
+#load "core/std/js"
use package core;