From 9d1e0423481b1695d6de2e75705bd038513ab021 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 26 Apr 2022 22:11:06 -0500 Subject: [PATCH] bugfixes for ncurses library --- modules/ncurses/module.onyx | 72 ++++++++++++++++++++++--------------- src/onyx_runtime.c | 2 ++ src/polymorph.h | 6 ++++ 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/modules/ncurses/module.onyx b/modules/ncurses/module.onyx index 4b1ca1c1..3ca8d6b9 100644 --- a/modules/ncurses/module.onyx +++ b/modules/ncurses/module.onyx @@ -3,33 +3,6 @@ package ncurses use package core {cptr, conv, string} -WINDOW :: #distinct u64 -SCREEN :: #distinct u64 - -chtype :: u32 - -attr_t :: u32 -A_NORMAL :: 0 -A_ATTRIBUTES :: 0xffffff00 -A_CHARTEXT :: 0xff -A_COLOR :: 0xff00 -A_STANDOUT :: 0x00010000 -A_UNDERLINE :: 0x00020000 -A_REVERSE :: 0x00040000 -A_BLINK :: 0x00080000 -A_DIM :: 0x00100000 -A_BOLD :: 0x00200000 -A_ALTCHARSET :: 0x00400000 -A_INVIS :: 0x00800000 -A_PROTECT :: 0x01000000 -A_HORIZONTAL :: 0x02000000 -A_LEFT :: 0x04000000 -A_LOW :: 0x08000000 -A_RIGHT :: 0x10000000 -A_TOP :: 0x20000000 -A_VERTICAL :: 0x40000000 -A_ITALIC :: 0x80000000 - #library "onyx_ncurses" #foreign "onyx_ncurses" { @@ -308,12 +281,30 @@ getparyx :: __get_par_yx getbegyx :: __get_beg_yx getmaxyx :: __get_max_yx -ogetstr :: ($max_length: i32) -> str { +ogetstr :: ($max_length: i32 = 1024) => { buf: [max_length] u8; err := getnstr(buf); return string.alloc_copy(string.from_cstr(~~ buf)); } +mvogetstr :: (y, x: i32, $max_length: i32 = 1024) => { + buf: [max_length] u8; + err := mvgetnstr(y, x, buf); + return string.alloc_copy(string.from_cstr(~~ buf)); +} + +wogetstr :: (w: WINDOW, $max_length: i32 = 1024) => { + buf: [max_length] u8; + err := wgetnstr(w, buf); + return string.alloc_copy(string.from_cstr(~~ buf)); +} + +mvwogetstr :: (w: WINDOW, y, x: i32, $max_length: i32 = 1024) => { + buf: [max_length] u8; + err := mvwgetnstr(w, y, x, buf); + return string.alloc_copy(string.from_cstr(~~ buf)); +} + printw :: (fmt: str, args: ..any) { buf: [1024] u8; to_output := conv.format_va(buf, fmt, args); @@ -338,6 +329,31 @@ mvwprintw :: (w: WINDOW, y, x: i32, fmt: str, args: ..any) { mvwaddnstr(w, y, x, to_output); } +WINDOW :: #distinct u64 +SCREEN :: #distinct u64 +chtype :: u32 +attr_t :: u32 + +A_NORMAL :: 0 +A_ATTRIBUTES :: 0xffffff00 +A_CHARTEXT :: 0xff +A_COLOR :: 0xff00 +A_STANDOUT :: 0x00010000 +A_UNDERLINE :: 0x00020000 +A_REVERSE :: 0x00040000 +A_BLINK :: 0x00080000 +A_DIM :: 0x00100000 +A_BOLD :: 0x00200000 +A_ALTCHARSET :: 0x00400000 +A_INVIS :: 0x00800000 +A_PROTECT :: 0x01000000 +A_HORIZONTAL :: 0x02000000 +A_LEFT :: 0x04000000 +A_LOW :: 0x08000000 +A_RIGHT :: 0x10000000 +A_TOP :: 0x20000000 +A_VERTICAL :: 0x40000000 +A_ITALIC :: 0x80000000 COLOR_BLACK :: 0 COLOR_RED :: 1 diff --git a/src/onyx_runtime.c b/src/onyx_runtime.c index 7e871e2b..33410e02 100644 --- a/src/onyx_runtime.c +++ b/src/onyx_runtime.c @@ -402,6 +402,8 @@ ONYX_DEF(__kill_thread, (WASM_I32), (WASM_I32)) { bh_arr_each(OnyxThread, thread, threads) { if (thread->id == thread_id) { #ifdef _BH_LINUX + // This leads to some weirdness and bugs... + // pthread_kill(thread->thread, SIGKILL); #endif diff --git a/src/polymorph.h b/src/polymorph.h index 744cbfa4..34b4ced4 100644 --- a/src/polymorph.h +++ b/src/polymorph.h @@ -408,6 +408,12 @@ static AstTyped* lookup_param_in_arguments(AstFunction* func, AstPolyParam* para } } + if (param->idx <= (u64) bh_arr_length(func->params)) { + if (func->params[param->idx].default_value) { + return (AstTyped *) func->params[param->idx].default_value; + } + } + // CLEANUP if (err_msg) *err_msg = "Not enough arguments to polymorphic procedure. This error message may not be entirely right."; -- 2.25.1