From: Brendan Hansen Date: Mon, 31 Aug 2020 03:11:01 +0000 (-0500) Subject: code cleanup and bugfixes; added file location directives X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=d11ab5e13e5732d90daf0e9424a8ad671a65feeb;p=onyx.git code cleanup and bugfixes; added file location directives --- diff --git a/Makefile b/Makefile index 597d5dd3..2ddccb14 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -RELEASE=0 +RELEASE=1 OBJ_FILES=\ build/onyxlex.o \ @@ -20,6 +20,10 @@ INCLUDES=-I./include LIBS= TARGET=./onyx +# These aren't working yet +INSTALL_FOLDER=/usr/share/onyx/core +DEFINES=-DCORE_INSTALLATION=$(INSTALL_FOLDER) + ifeq ($(RELEASE), 1) FLAGS=-O3 else @@ -34,7 +38,7 @@ $(TARGET): $(OBJ_FILES) install: $(TARGET) core/* cp $(TARGET) /usr/bin/ - cp -r core/ /usr/share/onyx + cp -r core/* $(INSTALL_FOLDER) install_syntax: misc/onyx.vim misc/onyx.sublime-syntax cp ./misc/onyx_compiler.vim /usr/share/vim/vim82/compiler/onyx.vim diff --git a/core/builtin.onyx b/core/builtin.onyx index 7f1dc555..a3158dea 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -60,6 +60,10 @@ array_free :: proc (arr: ^[..] $T) { arr.data = null; } +array_clear :: proc (arr: ^[..] $T) { + arr.count = 0; +} + array_ensure_capacity :: proc (arr: ^[..] $T, cap: u32) { if arr.capacity >= cap do return; diff --git a/core/wasi.onyx b/core/wasi.onyx index 35122dbe..a871a853 100644 --- a/core/wasi.onyx +++ b/core/wasi.onyx @@ -356,42 +356,42 @@ IOVecArray :: struct { // FUNCTIONS -args_get :: proc (argv: ^^u8, argv_buf: ^u8) -> Errno #foreign "wasi_snapshot_preview1" "args_get"--- -args_sizes_get :: proc (argc: ^Size, argv_buf_size: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "args_sizes_get" --- - -environ_get :: proc (environ: ^^u8, environ_buf: ^u8) -> Errno #foreign "wasi_snapshot_preview1" "environ_get" --- -environ_sizes_get :: proc (environc: ^Size, environ_buf_size: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "environ_sizes_get" --- - -clock_res_get :: proc (id: ClockID, resolution: ^Timestamp) -> Errno #foreign "wasi_snapshot_preview1" "clock_res_get" --- -clock_time_get :: proc (id: ClockID, precision: Timestamp, time: ^Timestamp) -> Errno #foreign "wasi_snapshot_preview1" "clock_time_get" --- - -fd_advise :: proc (fd: FileDescriptor, offset: Filesize, len: Filesize, advice: Advice) -> Errno #foreign "wasi_snapshot_preview1" "fd_advise" --- -fd_allocate :: proc (fd: FileDescriptor, offset: Filesize, len: Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_allocate" --- -fd_close :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_close" --- -fd_datasync :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_datasync" --- -fd_fdstat_get :: proc (fd: FileDescriptor, stat: ^FDStat) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_get" --- -fd_fdstat_set_flags :: proc (fd: FileDescriptor, flags: FDFlags) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_set_flags" --- -fd_fdstat_set_rights :: proc (fd: FileDescriptor, rights_base: Rights, rights_inheriting: Rights) -> Errno #foreign "wasi_snapshot_preview1" "fd_fdstat_set_rights" --- -fd_filestat_get :: proc (fd: FileDescriptor, buf: ^FileStat) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_get" --- -fd_filestat_set_size :: proc (fd: FileDescriptor, size: Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_set_size" --- -fd_filestat_set_times :: proc (fd: FileDescriptor, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_snapshot_preview1" "fd_filestat_set_times" --- -fd_pread :: proc (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nread: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_pread" --- -fd_prestat_get :: proc (fd: FileDescriptor, buf: ^PrestatTagged) -> Errno #foreign "wasi_snapshot_preview1" "fd_prestat_get" --- -fd_prestat_dir_name :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_snapshot_preview1" "fd_prestat_dir_name" --- -fd_pwrite :: proc (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nwritten: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_pwrite" --- -fd_read :: proc (fd: FileDescriptor, iovs: IOVecArray, nread: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_read" --- -fd_readdir :: proc (fd: FileDescriptor, buf: ^u8, buf_len: Size, cookie: DirCookie, bufused: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_readdir" --- -fd_renumber :: proc (fd: FileDescriptor, to: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_renumber" --- -fd_seek :: proc (fd: FileDescriptor, offset: FileDelta, whence: Whence, newoffset: ^Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_seek" --- -fd_sync :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_snapshot_preview1" "fd_sync" --- -fd_tell :: proc (fd: FileDescriptor, offset: ^Filesize) -> Errno #foreign "wasi_snapshot_preview1" "fd_tell" --- -fd_write :: proc (fd: FileDescriptor, iovs: IOVecArray, nwritten: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "fd_write" --- - -path_create_directory :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_create_directory" --- -path_filestat_get :: proc (fd: FileDescriptor, flags: LookupFlags, path: string, buf: ^FileStat) -> Errno #foreign "wasi_snapshot_preview1" "path_filestat_get" --- -path_filestat_set_times :: proc (fd: FileDescriptor, flags: LookupFlags, path: string, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_snapshot_preview1" "path_filestat_set_times" --- - -path_link :: proc (fd: FileDescriptor, old_flags: LookupFlags, old_path: string, new_fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_link" --- +args_get :: proc (argv: ^^u8, argv_buf: ^u8) -> Errno #foreign "wasi_unstable" "args_get"--- +args_sizes_get :: proc (argc: ^Size, argv_buf_size: ^Size) -> Errno #foreign "wasi_unstable" "args_sizes_get" --- + +environ_get :: proc (environ: ^^u8, environ_buf: ^u8) -> Errno #foreign "wasi_unstable" "environ_get" --- +environ_sizes_get :: proc (environc: ^Size, environ_buf_size: ^Size) -> Errno #foreign "wasi_unstable" "environ_sizes_get" --- + +clock_res_get :: proc (id: ClockID, resolution: ^Timestamp) -> Errno #foreign "wasi_unstable" "clock_res_get" --- +clock_time_get :: proc (id: ClockID, precision: Timestamp, time: ^Timestamp) -> Errno #foreign "wasi_unstable" "clock_time_get" --- + +fd_advise :: proc (fd: FileDescriptor, offset: Filesize, len: Filesize, advice: Advice) -> Errno #foreign "wasi_unstable" "fd_advise" --- +fd_allocate :: proc (fd: FileDescriptor, offset: Filesize, len: Filesize) -> Errno #foreign "wasi_unstable" "fd_allocate" --- +fd_close :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_close" --- +fd_datasync :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_datasync" --- +fd_fdstat_get :: proc (fd: FileDescriptor, stat: ^FDStat) -> Errno #foreign "wasi_unstable" "fd_fdstat_get" --- +fd_fdstat_set_flags :: proc (fd: FileDescriptor, flags: FDFlags) -> Errno #foreign "wasi_unstable" "fd_fdstat_set_flags" --- +fd_fdstat_set_rights :: proc (fd: FileDescriptor, rights_base: Rights, rights_inheriting: Rights) -> Errno #foreign "wasi_unstable" "fd_fdstat_set_rights" --- +fd_filestat_get :: proc (fd: FileDescriptor, buf: ^FileStat) -> Errno #foreign "wasi_unstable" "fd_filestat_get" --- +fd_filestat_set_size :: proc (fd: FileDescriptor, size: Filesize) -> Errno #foreign "wasi_unstable" "fd_filestat_set_size" --- +fd_filestat_set_times :: proc (fd: FileDescriptor, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_unstable" "fd_filestat_set_times" --- +fd_pread :: proc (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nread: ^Size) -> Errno #foreign "wasi_unstable" "fd_pread" --- +fd_prestat_get :: proc (fd: FileDescriptor, buf: ^PrestatTagged) -> Errno #foreign "wasi_unstable" "fd_prestat_get" --- +fd_prestat_dir_name :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_unstable" "fd_prestat_dir_name" --- +fd_pwrite :: proc (fd: FileDescriptor, iovs: IOVecArray, offset: Filesize, nwritten: ^Size) -> Errno #foreign "wasi_unstable" "fd_pwrite" --- +fd_read :: proc (fd: FileDescriptor, iovs: IOVecArray, nread: ^Size) -> Errno #foreign "wasi_unstable" "fd_read" --- +fd_readdir :: proc (fd: FileDescriptor, buf: ^u8, buf_len: Size, cookie: DirCookie, bufused: ^Size) -> Errno #foreign "wasi_unstable" "fd_readdir" --- +fd_renumber :: proc (fd: FileDescriptor, to: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_renumber" --- +fd_seek :: proc (fd: FileDescriptor, offset: FileDelta, whence: Whence, newoffset: ^Filesize) -> Errno #foreign "wasi_unstable" "fd_seek" --- +fd_sync :: proc (fd: FileDescriptor) -> Errno #foreign "wasi_unstable" "fd_sync" --- +fd_tell :: proc (fd: FileDescriptor, offset: ^Filesize) -> Errno #foreign "wasi_unstable" "fd_tell" --- +fd_write :: proc (fd: FileDescriptor, iovs: IOVecArray, nwritten: ^Size) -> Errno #foreign "wasi_unstable" "fd_write" --- + +path_create_directory :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_unstable" "path_create_directory" --- +path_filestat_get :: proc (fd: FileDescriptor, flags: LookupFlags, path: string, buf: ^FileStat) -> Errno #foreign "wasi_unstable" "path_filestat_get" --- +path_filestat_set_times :: proc (fd: FileDescriptor, flags: LookupFlags, path: string, atim: Timestamp, mtim: Timestamp, fst_flags: FSTFlags) -> Errno #foreign "wasi_unstable" "path_filestat_set_times" --- + +path_link :: proc (fd: FileDescriptor, old_flags: LookupFlags, old_path: string, new_fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_unstable" "path_link" --- path_open :: proc ( fd: FileDescriptor , dirflags: LookupFlags @@ -402,26 +402,26 @@ path_open :: proc , fdflags: FDFlags , opened_fd: ^FileDescriptor ) -> Errno - #foreign "wasi_snapshot_preview1" "path_open" --- + #foreign "wasi_unstable" "path_open" --- -path_readlink :: proc (fd: FileDescriptor, path: string, buf: ^u8, buf_len: Size, bufused: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "path_readlink" --- -path_remove_directory :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_remove_directory" --- -path_rename :: proc (fd: FileDescriptor, old_path: string, new_fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_rename" --- -path_symlink :: proc (old_path: ^u8, old_path_len: Size, fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_symlink" --- -path_unlink_file :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_snapshot_preview1" "path_unlink_file" --- +path_readlink :: proc (fd: FileDescriptor, path: string, buf: ^u8, buf_len: Size, bufused: ^Size) -> Errno #foreign "wasi_unstable" "path_readlink" --- +path_remove_directory :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_unstable" "path_remove_directory" --- +path_rename :: proc (fd: FileDescriptor, old_path: string, new_fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_unstable" "path_rename" --- +path_symlink :: proc (old_path: ^u8, old_path_len: Size, fd: FileDescriptor, new_path: string) -> Errno #foreign "wasi_unstable" "path_symlink" --- +path_unlink_file :: proc (fd: FileDescriptor, path: string) -> Errno #foreign "wasi_unstable" "path_unlink_file" --- -poll_oneoff :: proc (in: ^Subscription, out: ^Event, nsubscriptions: Size, nevents: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "poll_oneoff" --- +poll_oneoff :: proc (in: ^Subscription, out: ^Event, nsubscriptions: Size, nevents: ^Size) -> Errno #foreign "wasi_unstable" "poll_oneoff" --- -proc_exit :: proc (rval: ExitCode) #foreign "wasi_snapshot_preview1" "proc_exit" --- -proc_raise :: proc (sig: Signal) -> Errno #foreign "wasi_snapshot_preview1" "proc_raise" --- +proc_exit :: proc (rval: ExitCode) #foreign "wasi_unstable" "proc_exit" --- +proc_raise :: proc (sig: Signal) -> Errno #foreign "wasi_unstable" "proc_raise" --- -sched_yield :: proc -> Errno #foreign "wasi_snapshot_preview1" "proc_raise" --- +sched_yield :: proc -> Errno #foreign "wasi_unstable" "sched_yield" --- -random_get :: proc (buf: ^u8, buf_len: Size) -> Errno #foreign "wasi_snapshot_preview1" "random_get" --- +random_get :: proc (buf: ^u8, buf_len: Size) -> Errno #foreign "wasi_unstable" "random_get" --- -sock_recv :: proc (fd: FileDescriptor, ri_data: IOVecArray, ri_flags: RIFlags, ro_datalen: ^Size, ro_flags: ^ROFlags) -> Errno #foreign "wasi_snapshot_preview1" "sock_recv" --- -sock_send :: proc (fd: FileDescriptor, si_data: IOVecArray, si_flags: SIFlags, so_datalen: ^Size) -> Errno #foreign "wasi_snapshot_preview1" "sock_send" --- -sock_shutdown :: proc (fd: FileDescriptor, how: SDFlags) -> Errno #foreign "wasi_snapshot_preview1" "sock_shutdown" --- +sock_recv :: proc (fd: FileDescriptor, ri_data: IOVecArray, ri_flags: RIFlags, ro_datalen: ^Size, ro_flags: ^ROFlags) -> Errno #foreign "wasi_unstable" "sock_recv" --- +sock_send :: proc (fd: FileDescriptor, si_data: IOVecArray, si_flags: SIFlags, so_datalen: ^Size) -> Errno #foreign "wasi_unstable" "sock_send" --- +sock_shutdown :: proc (fd: FileDescriptor, how: SDFlags) -> Errno #foreign "wasi_unstable" "sock_shutdown" --- diff --git a/onyx b/onyx index cb650b75..18f0a464 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/poly_test.onyx b/progs/poly_test.onyx index 0a6cbb77..50bb842e 100644 --- a/progs/poly_test.onyx +++ b/progs/poly_test.onyx @@ -1,8 +1,5 @@ package main -#include_folder "./core" - -#include_file "builtin" #include_file "wasi" #include_file "alloc" #include_file "intrinsics" @@ -25,7 +22,7 @@ print_arr_details :: proc (arr: ^[..] $T) { print("\n\tCapacity: "); print(arr.capacity); print("\n\tData ptr: "); - print(cast(u32) arr.data, 16); + print(arr.data); print("\n\tSize of elements: "); print(sizeof T); print("\n\tAlignment of elements: "); @@ -34,10 +31,10 @@ print_arr_details :: proc (arr: ^[..] $T) { } // This works on both slices and arrays -print_arr :: proc (arr: $T) { +print_arr :: proc (arr: $T, sep := " ") { for i: 0, arr.count { print(arr.data[i]); - print(" "); + if i != arr.count - 1 do print(sep); } print("\n"); @@ -57,6 +54,15 @@ print_vec :: proc (v: Vec3) #add_overload print { get_count :: proc (x: $T) -> u32 do return x.count; +// Because of the static duck typing, this will pass as an +// array/slice in most places. +Dummy :: struct { + count : u32 = 5; + data : ^u32; +} + + + SOA :: struct { a : [..] i32; b : [..] i64; @@ -166,7 +172,13 @@ main2 :: proc (args: [] cstring) { array_push(^varr, Vec3.{ 4, 2, 3 }); print_arr_details(^varr); - print_arr(varr); + print_arr(varr, "\n"); + + + dummy := Dummy.{ data = calloc(sizeof [5] i32) }; + for i: 0, dummy.count do dummy.data[i] = i * 5; + + print_arr(dummy); print(get_count(iarr)); print("\n"); @@ -174,6 +186,8 @@ main2 :: proc (args: [] cstring) { print("\n"); print(get_count(varr)); print("\n"); + print(get_count(dummy)); + print("\n"); } Vec3 :: struct { diff --git a/src/onyx.c b/src/onyx.c index 75527496..0cd33f76 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -12,6 +12,14 @@ #define VERSION "0.1" + +#ifndef CORE_INSTALLATION + #ifdef __unix__ + #define CORE_INSTALLATION "/usr/share/onyx/core" + #endif +#endif + + static const char* docstring = "Onyx compiler version " VERSION "\n" "\n" "The compiler for the Onyx programming language.\n" @@ -54,10 +62,11 @@ static OnyxCompileOptions compile_opts_parse(bh_allocator alloc, int argc, char .target_file = "out.wasm", }; - bh_arr_new(alloc, options.files, 1); - bh_arr_new(alloc, options.included_folders, 1); + bh_arr_new(alloc, options.files, 2); + bh_arr_new(alloc, options.included_folders, 2); // NOTE: Add the current folder + bh_arr_push(options.included_folders, CORE_INSTALLATION); bh_arr_push(options.included_folders, "."); fori(i, 1, argc) { @@ -119,6 +128,8 @@ typedef struct CompilerState { OnyxWasmModule wasm_mod; } CompilerState; +static char* lookup_included_file(CompilerState* cs, char* filename); + static void compiler_state_init(CompilerState* compiler_state, OnyxCompileOptions* opts) { compiler_state->options = opts; @@ -139,6 +150,8 @@ static void compiler_state_init(CompilerState* compiler_state, OnyxCompileOption bh_arr_new(opts->allocator, compiler_state->queued_files, 4); + bh_arr_push(compiler_state->queued_files, lookup_included_file(compiler_state, "builtin")); + // NOTE: Add all files passed by command line to the queue bh_arr_each(const char *, filename, opts->files) bh_arr_push(compiler_state->queued_files, (char *) *filename); @@ -153,19 +166,17 @@ static void compiler_state_free(CompilerState* cs) { -static char* lookup_included_file(CompilerState* cs, OnyxToken* filename) { +static char* lookup_included_file(CompilerState* cs, char* filename) { static char path[256]; fori (i, 0, 256) path[i] = 0; static char fn[128]; fori (i, 0, 128) fn[i] = 0; - token_toggle_end(filename); - if (!bh_str_ends_with(filename->text, ".onyx")) { - bh_snprintf(fn, 128, "%s.onyx", filename->text); + if (!bh_str_ends_with(filename, ".onyx")) { + bh_snprintf(fn, 128, "%s.onyx", filename); } else { - bh_snprintf(fn, 128, "%s", filename->text); + bh_snprintf(fn, 128, "%s", filename); } - token_toggle_end(filename); bh_arr_each(const char *, folder, cs->options->included_folders) { if ((*folder)[strlen(*folder) - 1] != '/') @@ -197,9 +208,11 @@ static ParseResults parse_source_file(CompilerState* compiler_state, bh_file_con static void merge_parse_results(CompilerState* compiler_state, ParseResults* results) { bh_arr_each(AstInclude *, include, results->includes) { if ((*include)->kind == Ast_Kind_Include_File) { - char* filename = lookup_included_file(compiler_state, (*include)->name); - char* formatted_name = bh_strdup(global_heap_allocator, filename); + token_toggle_end((*include)->name); + char* filename = lookup_included_file(compiler_state, (*include)->name->text); + token_toggle_end((*include)->name); + char* formatted_name = bh_strdup(global_heap_allocator, filename); bh_arr_push(compiler_state->queued_files, formatted_name); } else if ((*include)->kind == Ast_Kind_Include_Folder) { const char* folder = bh_aprintf(global_heap_allocator, "%b", (*include)->name->text, (*include)->name->length); diff --git a/src/onyxparser.c b/src/onyxparser.c index b025fd95..d3fe8209 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -116,6 +116,17 @@ static void add_node_to_process(OnyxParser* parser, AstNode* node) { } +static AstNumLit* make_int_literal(bh_allocator a, i64 i) { + AstNumLit* num = onyx_ast_node_new(a, sizeof(AstNumLit), Ast_Kind_NumLit); + if (bh_abs(i) >= ((u64) 1 << 32)) + num->type_node = (AstType *) &basic_type_i64; + else + num->type_node = (AstType *) &basic_type_i32; + + num->value.l = i; + return num; +} + static AstNumLit* parse_int_literal(OnyxParser* parser) { AstNumLit* int_node = make_node(AstNumLit, Ast_Kind_NumLit); @@ -420,6 +431,37 @@ static AstTyped* parse_factor(OnyxParser* parser) { retval = (AstTyped *) fc; break; } + else if (parse_possible_directive(parser, "file")) { + OnyxToken* dir_token = parser->curr - 2; + + OnyxToken* str_token = bh_alloc(parser->allocator, sizeof(OnyxToken)); + str_token->text = bh_strdup(global_heap_allocator, (char *) dir_token->pos.filename); + str_token->length = strlen(dir_token->pos.filename); + str_token->pos = dir_token->pos; + str_token->type = Token_Type_Literal_String; + + AstStrLit* filename = make_node(AstStrLit, Ast_Kind_StrLit); + filename->token = str_token; + filename->addr = 0; + + add_node_to_process(parser, (AstNode *) filename); + retval = (AstTyped *) filename; + break; + } + else if (parse_possible_directive(parser, "line")) { + OnyxToken* dir_token = parser->curr - 2; + + AstNumLit* line_num = make_int_literal(parser->allocator, dir_token->pos.line); + retval = (AstTyped *) line_num; + break; + } + else if (parse_possible_directive(parser, "column")) { + OnyxToken* dir_token = parser->curr - 2; + + AstNumLit* col_num = make_int_literal(parser->allocator, dir_token->pos.column); + retval = (AstTyped *) col_num; + break; + } else if (parse_possible_directive(parser, "char")) { AstNumLit* char_lit = make_node(AstNumLit, Ast_Kind_NumLit); char_lit->flags |= Ast_Flag_Comptime; diff --git a/src/onyxwasm.c b/src/onyxwasm.c index e0ddb40e..312c78c5 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -767,8 +767,10 @@ EMIT_FUNC(for, AstFor* for_node) { WID(WI_BLOCK_START, 0x40); WID(WI_LOOP_START, 0x40); + WID(WI_BLOCK_START, 0x40); bh_arr_push(mod->structured_jump_target, 1); + bh_arr_push(mod->structured_jump_target, 0); bh_arr_push(mod->structured_jump_target, 2); if (it_is_local) { @@ -780,10 +782,13 @@ EMIT_FUNC(for, AstFor* for_node) { } emit_expression(mod, &code, for_node->end); WI(ge_instr); - WID(WI_COND_JUMP, 0x01); + WID(WI_COND_JUMP, 0x02); emit_block(mod, &code, for_node->stmt, 0); + bh_arr_pop(mod->structured_jump_target); + WI(WI_BLOCK_END); + if (it_is_local) { WIL(WI_LOCAL_GET, tmp); emit_expression(mod, &code, for_node->step);