Skip to content

Commit c7258ce

Browse files
committed
libuv
1 parent 20d88b4 commit c7258ce

32 files changed

+3418
-96
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ bench
3333
test/bench
3434
.koka
3535
scratch
36+
.cache

kklib/include/kklib.h

+4
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ typedef struct kk_context_s {
422422
kk_yield_t yield; // inlined yield structure (for efficiency)
423423
int32_t marker_unique; // unique marker generation
424424
kk_block_t* delayed_free; // list of blocks that still need to be freed
425+
void* loop; // a reference to an event loop (e.g. uv_loop_t* or NULL)
425426
kk_integer_t unique; // thread local unique number generation
426427
size_t thread_id; // unique thread id
427428
kk_box_any_t kk_box_any; // used when yielding as a value of any type
@@ -444,6 +445,9 @@ typedef struct kk_context_s {
444445
kk_decl_export kk_context_t* kk_get_context(void);
445446
kk_decl_export void kk_free_context(void);
446447

448+
449+
kk_decl_export void kk_debugger_break(kk_context_t* ctx);
450+
447451
// The current context is passed as a _ctx parameter in the generated code
448452
#define kk_context() _ctx
449453

kklib/src/init.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void kk_free_fun(void* p, kk_block_t* b, kk_context_t* ctx) {
6262

6363
kk_string_t kk_get_host(kk_context_t* ctx) {
6464
kk_unused(ctx);
65-
kk_define_string_literal(static, host, 5, "libc", ctx);
65+
kk_define_string_literal(static, host, 4, "libc", ctx);
6666
return kk_string_dup(host,ctx);
6767
}
6868

kklib/src/string.c

+3
Original file line numberDiff line numberDiff line change
@@ -865,20 +865,23 @@ kk_string_t kk_string_trim_right(kk_string_t str, kk_context_t* ctx) {
865865
kk_unit_t kk_println(kk_string_t s, kk_context_t* ctx) {
866866
// TODO: set locale to utf-8?
867867
puts(kk_string_cbuf_borrow(s, NULL, ctx)); // todo: allow printing embedded 0 characters?
868+
fflush(stdout);
868869
kk_string_drop(s, ctx);
869870
return kk_Unit;
870871
}
871872

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

879881
kk_unit_t kk_trace(kk_string_t s, kk_context_t* ctx) {
880882
fputs(kk_string_cbuf_borrow(s, NULL, ctx), stderr); // todo: allow printing embedded 0 characters?
881883
fputs("\n", stderr);
884+
fflush(stdout);
882885
kk_string_drop(s, ctx);
883886
return kk_Unit;
884887
}

lib/std/async.kk

+74-76
Large diffs are not rendered by default.

lib/std/async/async-inline.h

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "std_time_timer.h"
2+
3+
4+
kk_box_t kk_set_timeout(kk_function_t cb, int64_t time, kk_context_t* _ctx) {
5+
kk_std_time_timer__timer t = kk_std_time_timer_timer_init(_ctx);
6+
kk_std_time_timer_timer_start(t, time, 0, cb, _ctx);
7+
return kk_std_time_timer__timer_box(t, _ctx);
8+
}
9+
10+
11+
static kk_box_t kk_unit_closure(kk_function_t _fself, kk_context_t* _ctx);
12+
static kk_function_t kk_new_unit_closure(kk_context_t* _ctx) {
13+
kk_define_static_function(_fself, kk_unit_closure, _ctx)
14+
return kk_function_dup(_fself,kk_context());
15+
}
16+
17+
static kk_box_t kk_unit_closure(kk_function_t _fself, kk_context_t* _ctx) {
18+
kk_unused(_fself);
19+
return kk_unit_box(kk_Unit);
20+
}
21+
22+
23+
kk_unit_t kk_clear_timeout(kk_box_t t, kk_context_t* _ctx) {
24+
kk_std_time_timer__timer timer = kk_std_time_timer__timer_unbox(t, KK_OWNED, _ctx);
25+
kk_std_os_uv_close(kk_std_os_uv__new_UvHandle(timer.internal, _ctx), kk_new_unit_closure(_ctx), _ctx);
26+
return kk_Unit;
27+
}
28+
29+
30+

lib/std/core.kk

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ pub alias io-total = <ndet,console,net,fsys,ui,st<global>>
7272
// The `:io-noexn` effect is used for functions that perform arbitrary I/O operations, but raise no exceptions
7373
pub alias io-noexn = <div,io-total>
7474

75+
// The `:event-loop` effect signifies that a function requires an initialized event loop
76+
pub type event-loop :: X
77+
78+
// 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
79+
pub alias io-event = <div,io-total,event-loop>
80+
7581
// The `:io` effect is used for functions that perform arbitrary I/O operations.
7682
pub alias io = <exn,io-noexn>
7783

lib/std/core/types.kk

-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ pub type vector<a>
104104
// A raw wrapper around a uint8 character array.
105105
pub type bytes
106106

107-
// A raw wrapper around a uint8 character array.
108-
pub type bytes
109-
110107
// An any type. Used for external calls.
111108
pub type any
112109

0 commit comments

Comments
 (0)