Skip to content

Commit 6bd633f

Browse files
authored
Merge pull request #158 from onyx-lang/rc-0.1.13
Release 0.1.13
2 parents 16142d7 + 19bf172 commit 6bd633f

File tree

154 files changed

+1802
-1272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1802
-1272
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Additions:
88
- "Field update" syntax. A shorthand to change a field of a structure.
99
- `.{ ..old_value, field = new_value }`
1010
- `onyx watch` now works on MacOS.
11+
- `onyx run-watch` to automatically re-run the program on changes.
1112
- `#wasm_section` directive to add custom sections to the WASM binary.
1213
- Custom commands per project
1314
- Installed in a `.onyx` directory
@@ -30,13 +31,18 @@ Additions:
3031
Removals:
3132

3233
Changes:
34+
- Capture/closure syntax is now `(params) use (captures) ...`.
35+
- `(x: i32) use (variable) -> str { ... }`
36+
- `(x) use (variable) => { ... }`
3337
- `&&` and `||` now short-circuit.
38+
- Fixed-sized arrays (`[N] T`) are now passed by value.
3439
- The size of tag field for unions is now dependent on the number of variants.
3540
- Parsing structs no longer sometimes needs `#type`.
3641
- Renamed `core.alloc.memdebug` to `core.alloc.memwatch`.
3742

3843
Bugfixes:
3944
- Bug when injecting into a `#distinct` type.
45+
- Many, many random bugs.
4046

4147

4248

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ use core {*}
3737
Person :: struct { age: i32; name: str }
3838
3939
main :: () {
40-
// Generate a list of random people
41-
people := iter.comp(0 .. 30, [](Person.{
42-
random.between(1, 10)
43-
random.string(10, alpha_numeric=true)
44-
}))
40+
// Generate a list of 30 random people
41+
people := Iterator.from(0 .. 30)
42+
|> Iterator.map(_ => Person.{
43+
random.between(1, 10)
44+
random.string(10, alpha_numeric=true)
45+
})
46+
|> Iterator.collect()
4547
4648
// Sort them by age
47-
people->sort((a, b) => a.age - b.age)
49+
Slice.sort(people, (a, b) => a.age - b.age)
4850
4951
// Group them by age
50-
group_iter := iter.as_iter(people)
51-
|> iter.group_by((a, b) => a.age == b.age)
52+
group_iter := Iterator.from(people)
53+
|> Iterator.group_by((a, b) => a.age == b.age)
5254
5355
// Print the groups of people
5456
for group in group_iter {

compiler/include/astnodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define VERSION_MAJOR 0
55
#define VERSION_MINOR 1
6-
#define VERSION_PATCH 12
6+
#define VERSION_PATCH 13
77

88
#include "stb_ds.h"
99
#include "lex.h"
@@ -2000,7 +2000,7 @@ struct CompileOptions {
20002000

20012001
Runtime runtime;
20022002

2003-
bh_arr(const char *) included_folders;
2003+
bh_arr(bh_mapped_folder) mapped_folders;
20042004
bh_arr(const char *) files;
20052005
const char* target_file;
20062006
const char* documentation_file;

compiler/include/wasm_emit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,11 @@ typedef struct OnyxWasmModule {
791791
CallingConvention curr_cc;
792792
i32 null_proc_func_idx;
793793

794+
i32 global_type_table_data_id;
795+
i32 type_info_size;
796+
i32 *type_info_entry_count;
797+
bh_arr(i32) types_enqueued_for_info;
798+
794799
b32 has_stack_locals : 1;
795800
b32 doing_linking : 1;
796801

compiler/src/checker.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,50 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) {
17831783
return Check_Success;
17841784
}
17851785

1786+
if (sl->type->kind == Type_Kind_Array) {
1787+
if (bh_arr_length(sl->args.named_values) > 0) {
1788+
ERROR_(sl->token->pos, "Cannot specify named values when creating a '%s'.", type_get_name(sl->type));
1789+
}
1790+
1791+
i32 value_count = bh_arr_length(sl->args.values);
1792+
if (value_count == 0) {
1793+
AstZeroValue *zv = make_zero_value(context.ast_alloc, sl->token, sl->type);
1794+
bh_arr_push(sl->values_to_initialize, ((ValueWithOffset) { (AstTyped *) zv, 0 }));
1795+
1796+
sl->flags |= Ast_Flag_Has_Been_Checked;
1797+
return Check_Success;
1798+
}
1799+
1800+
if (value_count != sl->type->Array.count) {
1801+
ERROR_(sl->token->pos,
1802+
"Expected exactly '%d' values when constructing a '%s', but got '%d' value%s.",
1803+
sl->type->Array.count,
1804+
type_get_name(sl->type),
1805+
value_count,
1806+
bh_num_plural(value_count));
1807+
}
1808+
1809+
Type* type_to_match = sl->type->Array.elem;
1810+
i32 offset = 0;
1811+
bh_arr_each(AstTyped *, pval, sl->args.values) {
1812+
CHECK(expression, pval);
1813+
1814+
TYPE_CHECK(pval, type_to_match) {
1815+
ERROR_(sl->token->pos,
1816+
"Mismatched type. Expected something of type '%s', got '%s'.",
1817+
type_get_name(type_to_match),
1818+
type_get_name((*pval)->type));
1819+
}
1820+
1821+
bh_arr_push(sl->values_to_initialize, ((ValueWithOffset) { *pval, offset }));
1822+
offset += type_size_of(type_to_match);
1823+
bh_align(offset, type_alignment_of(type_to_match));
1824+
}
1825+
1826+
return Check_Success;
1827+
}
1828+
1829+
17861830
if (!type_is_structlike_strict(sl->type)) {
17871831
if ((sl->flags & Ast_Flag_Has_Been_Checked) != 0) return Check_Success;
17881832

@@ -3545,6 +3589,13 @@ CheckStatus check_function_header(AstFunction* func) {
35453589
if (local->type->kind != Type_Kind_Array && type_size_of(local->type) == 0) {
35463590
ERROR(local->token->pos, "Function parameters cannot have 'void' as their type.");
35473591
}
3592+
3593+
if (local->type->kind == Type_Kind_Array && type_size_of(local->type) >= 128) {
3594+
onyx_report_warning(local->token->pos, "Since arrays are passed by value, this array parameter would copy %d bytes per function call. Unless this is what you want, you should make this parameter a slice instead ('[] %s').",
3595+
type_size_of(local->type),
3596+
type_get_name(local->type->Array.elem)
3597+
);
3598+
}
35483599
}
35493600

35503601
if (func->return_type != NULL) CHECK(type, &func->return_type);
@@ -3913,7 +3964,7 @@ CheckStatus check_process_directive(AstNode* directive) {
39133964

39143965
char *path = bh_strdup(
39153966
global_scratch_allocator,
3916-
bh_lookup_file(temp_str, parent_folder, "", 0, NULL, 0)
3967+
bh_lookup_file(temp_str, parent_folder, NULL, NULL, NULL)
39173968
);
39183969

39193970
if (!bh_file_exists(path)) {

compiler/src/cli.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static const char *build_docstring = DOCSTRING_HEADER
7171
C_BOLD "Flags:\n" C_NORM
7272
C_LBLUE " -o, --output " C_GREY "target_file " C_NORM "Specify the target file " C_GREY "(default: out.wasm)\n"
7373
C_LBLUE " -r, --runtime " C_GREY "runtime " C_NORM "Specifies the runtime " C_GREY "(onyx, wasi, js, custom)\n"
74-
C_LBLUE " -I, --include " C_GREY "dir " C_NORM "Include a directory in the search path\n"
74+
C_LBLUE " --map-dir " C_GREY "name:folder " C_NORM "Adds a mapped directory\n"
7575
"\n"
7676
C_LBLUE " --debug " C_NORM "Output a debugable build\n"
7777
C_LBLUE " --feature " C_GREY "feature " C_NORM "Enable an experimental language feature\n"
@@ -331,7 +331,24 @@ static void cli_parse_compilation_options(CompileOptions *options, int arg_parse
331331
}
332332
}
333333
else if (!strcmp(argv[i], "-I") || !strcmp(argv[i], "--include")) {
334-
bh_arr_push(options->included_folders, argv[++i]);
334+
OnyxFilePos fp = {0};
335+
onyx_report_warning(fp, "%s has been removed in favor of --map-dir", argv[i++]);
336+
}
337+
else if (!strcmp(argv[i], "--map-dir")) {
338+
char *arg = argv[++i];
339+
int len = strnlen(arg, 256);
340+
341+
char *name = arg;
342+
char *folder = NULL;
343+
fori (i, 0, len) if (arg[i] == ':') {
344+
arg[i] = '\0';
345+
folder = &arg[i + 1];
346+
}
347+
348+
bh_mapped_folder mf;
349+
mf.name = name;
350+
mf.folder = folder;
351+
bh_arr_push(options->mapped_folders, mf);
335352
}
336353
else if (!strncmp(argv[i], "-D", 2)) {
337354
i32 len = strlen(argv[i]);
@@ -488,7 +505,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
488505
};
489506

490507
bh_arr_new(alloc, options.files, 2);
491-
bh_arr_new(alloc, options.included_folders, 2);
508+
bh_arr_new(alloc, options.mapped_folders, 2);
492509
bh_arr_new(alloc, options.defined_variables, 2);
493510

494511
#if defined(_BH_LINUX) || defined(_BH_DARWIN)
@@ -516,9 +533,10 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
516533
exit(1);
517534
}
518535

519-
// NOTE: Add the current folder
520-
bh_arr_push(options.included_folders, options.core_installation);
521-
bh_arr_push(options.included_folders, ".");
536+
bh_arr_push(options.mapped_folders, ((bh_mapped_folder) {
537+
.name = "core",
538+
.folder = bh_aprintf(alloc, "%s/core", options.core_installation)
539+
}));
522540

523541
if (argc == 1) return options;
524542

@@ -577,7 +595,7 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg
577595

578596
static void compile_opts_free(CompileOptions* opts) {
579597
bh_arr_free(opts->files);
580-
bh_arr_free(opts->included_folders);
598+
bh_arr_free(opts->mapped_folders);
581599
}
582600

583601
static void print_subcommand_help(const char *subcommand) {

compiler/src/extensions.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static b32 extension_spawn(CompilerExtension *ext, const char *path) {
8888
dup2(comp_to_ext[0], 0);
8989
dup2(ext_to_comp[1], 1);
9090

91-
execlp("onyx", "onyx", "run", path, NULL);
91+
execlp("onyx", "onyx", "run", "--no-compiler-extensions", "--no-file-contents", path, NULL);
9292
exit(1);
9393
break;
9494

@@ -191,10 +191,9 @@ TypeMatch compiler_extension_start(const char *name, const char *containing_file
191191
if (*out_extension_id == 0) {
192192
char* parent_folder = bh_path_get_parent(containing_filename, global_scratch_allocator);
193193

194-
// CLEANUP: Should the include folders be different than the other include files list?
195194
char *path = bh_strdup(
196195
global_scratch_allocator,
197-
bh_lookup_file((char *) name, parent_folder, ".wasm", 0, context.options->included_folders, 0)
196+
bh_lookup_file((char *) name, parent_folder, NULL, NULL, NULL)
198197
);
199198

200199
if (!bh_file_exists(path)) {

0 commit comments

Comments
 (0)