Skip to content

Commit

Permalink
libuv
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Feb 19, 2024
1 parent 068bf92 commit b223aa4
Show file tree
Hide file tree
Showing 32 changed files with 3,418 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ bench
test/bench
.koka
scratch
.cache
4 changes: 4 additions & 0 deletions kklib/include/kklib.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ typedef struct kk_context_s {
kk_yield_t yield; // inlined yield structure (for efficiency)
int32_t marker_unique; // unique marker generation
kk_block_t* delayed_free; // list of blocks that still need to be freed
void* loop; // a reference to an event loop (e.g. uv_loop_t* or NULL)
kk_integer_t unique; // thread local unique number generation
size_t thread_id; // unique thread id
kk_box_any_t kk_box_any; // used when yielding as a value of any type
Expand All @@ -444,6 +445,9 @@ typedef struct kk_context_s {
kk_decl_export kk_context_t* kk_get_context(void);
kk_decl_export void kk_free_context(void);


kk_decl_export void kk_debugger_break(kk_context_t* ctx);

// The current context is passed as a _ctx parameter in the generated code
#define kk_context() _ctx

Expand Down
2 changes: 1 addition & 1 deletion kklib/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void kk_free_fun(void* p, kk_block_t* b, kk_context_t* ctx) {

kk_string_t kk_get_host(kk_context_t* ctx) {
kk_unused(ctx);
kk_define_string_literal(static, host, 5, "libc", ctx);
kk_define_string_literal(static, host, 4, "libc", ctx);
return kk_string_dup(host,ctx);
}

Expand Down
3 changes: 3 additions & 0 deletions kklib/src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,20 +865,23 @@ kk_string_t kk_string_trim_right(kk_string_t str, kk_context_t* ctx) {
kk_unit_t kk_println(kk_string_t s, kk_context_t* ctx) {
// TODO: set locale to utf-8?
puts(kk_string_cbuf_borrow(s, NULL, ctx)); // todo: allow printing embedded 0 characters?
fflush(stdout);
kk_string_drop(s, ctx);
return kk_Unit;
}

kk_unit_t kk_print(kk_string_t s, kk_context_t* ctx) {
// TODO: set locale to utf-8?
fputs(kk_string_cbuf_borrow(s, NULL, ctx), stdout); // todo: allow printing embedded 0 characters?
fflush(stdout);
kk_string_drop(s, ctx);
return kk_Unit;
}

kk_unit_t kk_trace(kk_string_t s, kk_context_t* ctx) {
fputs(kk_string_cbuf_borrow(s, NULL, ctx), stderr); // todo: allow printing embedded 0 characters?
fputs("\n", stderr);
fflush(stdout);
kk_string_drop(s, ctx);
return kk_Unit;
}
Expand Down
150 changes: 74 additions & 76 deletions lib/std/async.kk

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions lib/std/async/async-inline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "std_time_timer.h"


kk_box_t kk_set_timeout(kk_function_t cb, int64_t time, kk_context_t* _ctx) {
kk_std_time_timer__timer t = kk_std_time_timer_timer_init(_ctx);
kk_std_time_timer_timer_start(t, time, 0, cb, _ctx);
return kk_std_time_timer__timer_box(t, _ctx);
}


static kk_box_t kk_unit_closure(kk_function_t _fself, kk_context_t* _ctx);
static kk_function_t kk_new_unit_closure(kk_context_t* _ctx) {
kk_define_static_function(_fself, kk_unit_closure, _ctx)
return kk_function_dup(_fself,kk_context());
}

static kk_box_t kk_unit_closure(kk_function_t _fself, kk_context_t* _ctx) {
kk_unused(_fself);
return kk_unit_box(kk_Unit);
}


kk_unit_t kk_clear_timeout(kk_box_t t, kk_context_t* _ctx) {
kk_std_time_timer__timer timer = kk_std_time_timer__timer_unbox(t, KK_OWNED, _ctx);
kk_std_os_uv_close(kk_std_os_uv__new_UvHandle(timer.internal, _ctx), kk_new_unit_closure(_ctx), _ctx);
return kk_Unit;
}



6 changes: 6 additions & 0 deletions lib/std/core.kk
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub alias io-total = <ndet,console,net,fsys,ui,st<global>>
// The `:io-noexn` effect is used for functions that perform arbitrary I/O operations, but raise no exceptions
pub alias io-noexn = <div,io-total>

// The `:event-loop` effect signifies that a function requires an initialized event loop
pub type event-loop :: X

// The `:io-event` effect is used for functions that perform arbitrary I/O operations and raise no exceptions, but do require an initialized event loop
pub alias io-event = <div,io-total,event-loop>

// The `:io` effect is used for functions that perform arbitrary I/O operations.
pub alias io = <exn,io-noexn>

Expand Down
3 changes: 0 additions & 3 deletions lib/std/core/types.kk
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ pub type vector<a>
// A raw wrapper around a uint8 character array.
pub type bytes

// A raw wrapper around a uint8 character array.
pub type bytes

// An any type. Used for external calls.
pub type any

Expand Down
Loading

0 comments on commit b223aa4

Please sign in to comment.