summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVAN BOSSUYT Nicolas <nicolas.van.bossuyt@gmail.com>2022-03-18 07:09:17 +0100
committerVAN BOSSUYT Nicolas <nicolas.van.bossuyt@gmail.com>2022-03-18 07:09:17 +0100
commit06e10ee20303991eb01842157133c1b645149aea (patch)
treea162cf8e79f5b4eb5c097d8311fa7952d22fae8f
parentc83ed277f3638c8f6f963f7a4dade52450da6b17 (diff)
-rw-r--r--sources/apps/bench/main.c12
-rw-r--r--sources/kernel/sched.c12
-rw-r--r--sources/kernel/sched.h2
-rw-r--r--sources/kernel/tasking.c2
-rw-r--r--sources/libs/bal/abi/types.h3
-rw-r--r--sources/libs/brutal/debug/log.c6
-rw-r--r--sources/libs/brutal/fibers/fibers.c14
-rw-r--r--sources/libs/brutal/fibers/fibers.h7
-rw-r--r--sources/libs/brutal/io/emit.h3
-rw-r--r--sources/libs/brutal/io/print.h2
-rw-r--r--sources/libs/brutal/parse/scan.c13
-rw-r--r--sources/libs/brutal/time.h4
-rw-r--r--sources/libs/brutal/time/constants.h1
-rw-r--r--sources/libs/brutal/time/convert.c14
-rw-r--r--sources/libs/brutal/time/convert.h7
-rw-r--r--sources/libs/brutal/time/mod.c129
-rw-r--r--sources/libs/brutal/time/mod.h51
-rw-r--r--sources/libs/brutal/time/query.c12
-rw-r--r--sources/libs/brutal/time/query.h15
-rw-r--r--sources/libs/brutal/time/types.h54
-rw-r--r--sources/libs/brutal/ui.h1
-rw-r--r--sources/libs/brutal/ui/app.c70
-rw-r--r--sources/libs/brutal/ui/app.h13
-rw-r--r--sources/libs/brutal/ui/defer.c36
-rw-r--r--sources/libs/brutal/ui/defer.h28
-rw-r--r--sources/libs/cc/trans/decl.c26
-rw-r--r--sources/libs/cc/trans/expr.c36
-rw-r--r--sources/libs/cc/trans/stmt.c52
-rw-r--r--sources/libs/cc/trans/type.c54
-rw-r--r--sources/libs/cc/trans/unit.c38
-rw-r--r--sources/libs/cc/trans/val.c8
-rw-r--r--sources/libs/embed/app.h3
-rw-r--r--sources/libs/embed/brutal/app.c4
-rw-r--r--sources/libs/embed/brutal/debug.c2
-rw-r--r--sources/libs/embed/efi/debug.c2
-rw-r--r--sources/libs/embed/kernel/debug.c4
-rw-r--r--sources/libs/embed/sdl/app.c12
-rw-r--r--sources/libs/embed/time.h8
-rw-r--r--sources/libs/hw/fdt/fdt.c22
-rw-r--r--sources/libs/ipc/component.c2
-rw-r--r--sources/libs/json/emit.c38
-rw-r--r--sources/loader/main.c16
-rw-r--r--sources/srvs/wm/server.c2
-rw-r--r--sources/utils/cc/main.c26
-rw-r--r--sources/utils/fstools/main.c2
45 files changed, 524 insertions, 344 deletions
diff --git a/sources/apps/bench/main.c b/sources/apps/bench/main.c
index 954ba96b..1b3eb261 100644
--- a/sources/apps/bench/main.c
+++ b/sources/apps/bench/main.c
@@ -43,24 +43,24 @@ static double bench_run(UiApp *app, UiWin *win, Bench bench, int sec_per_bench)
gfx_push(&win->gfx);
// only used to know when we need to stop the benchmark, this hasn't any implication in the calculation of the framerate/dt
- TimeStamp time_begin = timestamp_now();
+ Time time_begin = time_now();
double avg_delta = 0;
long frame = 0;
- while (time_begin + sec_per_bench > timestamp_now() && app->alive)
+ while (time_begin + sec_per_bench > time_now() && app->alive)
{
gfx_clear(&win->gfx, GFX_BLACK);
// avoid T calculation during benchmark
- float t = time_ns_now() / 1000000000.;
+ float t = time_now_ns() / 1000000000.;
// here we calculate the time it tooks to render the benchmark
- NanoSeconds start = time_ns_now();
+ NanoSeconds start = time_now_ns();
- bench_run_tick(&win->gfx, bench,t);
+ bench_run_tick(&win->gfx, bench, t);
- NanoSeconds end = time_ns_now();
+ NanoSeconds end = time_now_ns();
double delta_s = (end - start) / 1000000000.;
diff --git a/sources/kernel/sched.c b/sources/kernel/sched.c
index 03f89b40..8a240595 100644
--- a/sources/kernel/sched.c
+++ b/sources/kernel/sched.c
@@ -84,16 +84,6 @@ BrResult sched_block(Blocker blocker)
return task_self()->blocker.result;
}
-Tick sched_deadline(BrTimeout timeout)
-{
- if (timeout == BR_TIMEOUT_INFINITY)
- {
- return -1;
- }
-
- return _tick + timeout;
-}
-
/* --- Attach/Detach -------------------------------------------------------- */
Cpu *sched_cpu(Task *task)
@@ -273,7 +263,7 @@ static void sched_updated_blocked(void)
blocker->function(blocker->context);
bool has_reached_deadline =
- blocker->deadline != (Tick)-1 &&
+ blocker->deadline != END_OF_TIME &&
blocker->deadline < _tick;
if (has_reached_function)
diff --git a/sources/kernel/sched.h b/sources/kernel/sched.h
index 880be9b2..304e9695 100644
--- a/sources/kernel/sched.h
+++ b/sources/kernel/sched.h
@@ -17,8 +17,6 @@ void sched_finalize(void);
BrResult sched_block(Blocker blocker);
-Tick sched_deadline(BrTimeout timeout);
-
void sched_yield(void);
void sched_next(Task *task, Cpu *cpu);
diff --git a/sources/kernel/tasking.c b/sources/kernel/tasking.c
index 8a4ec407..8d69536c 100644
--- a/sources/kernel/tasking.c
+++ b/sources/kernel/tasking.c
@@ -19,7 +19,7 @@ static void finalizer(void)
sched_finalize();
sched_block((Blocker){
- .deadline = sched_deadline(2500),
+ .deadline = sched_tick() + 2500,
});
}
}
diff --git a/sources/libs/bal/abi/types.h b/sources/libs/bal/abi/types.h
index 2c0d790a..fe703182 100644
--- a/sources/libs/bal/abi/types.h
+++ b/sources/libs/bal/abi/types.h
@@ -135,9 +135,6 @@ typedef uint32_t BrMsgFlags;
#define BR_DEADLINE_INFINITY ((BrDeadline)-1)
typedef uint64_t BrDeadline;
-#define BR_TIMEOUT_INFINITY ((BrTimeout)-1)
-typedef uint64_t BrTimeout;
-
typedef uint64_t BrTick;
typedef uint64_t BrTimeStamp;
diff --git a/sources/libs/brutal/debug/log.c b/sources/libs/brutal/debug/log.c
index d80e2174..0359d4be 100644
--- a/sources/libs/brutal/debug/log.c
+++ b/sources/libs/brutal/debug/log.c
@@ -9,12 +9,12 @@ void log_unlock_impl(LogLevel level, SourceLocation location, Str fmt, PrintArgs
if (level == LOG_PANIC)
{
- print(embed_log_writer(), "panic: ");
+ io_print$(embed_log_writer(), "panic: ");
}
- print(embed_log_writer(), "{}:{3d}: ", location.filename, location.line);
+ io_print$(embed_log_writer(), "{}:{3d}: ", location.filename, location.line);
print_impl(embed_log_writer(), fmt, args);
- print(embed_log_writer(), "\n");
+ io_print$(embed_log_writer(), "\n");
}
void log_impl(LogLevel level, SourceLocation location, Str fmt, PrintArgs args)
diff --git a/sources/libs/brutal/fibers/fibers.c b/sources/libs/brutal/fibers/fibers.c
index e1cb65ee..6deddc29 100644
--- a/sources/libs/brutal/fibers/fibers.c
+++ b/sources/libs/brutal/fibers/fibers.c
@@ -80,10 +80,10 @@ FiberBlockResult fiber_block(FiberBlocker blocker)
return current->blocker.result;
}
-void fiber_sleep(Timeout timeout)
+void fiber_sleep_until(Time time)
{
fiber_block((FiberBlocker){
- .deadline = timeout + tick_now(),
+ .deadline = time,
});
}
@@ -123,7 +123,7 @@ void *fiber_await(Fiber *fiber)
fiber_block((FiberBlocker){
.function = (FiberBlockerFn *)wait_fiber,
.context = &ctx,
- .deadline = TIME_TIMEOUT_INFINITY,
+ .deadline = END_OF_TIME,
});
return ctx.ret;
@@ -146,8 +146,8 @@ static bool fiber_try_unblock(Fiber *self)
return true;
}
- if (blocker->deadline != TIME_TIMEOUT_INFINITY &&
- blocker->deadline < tick_now())
+ if (blocker->deadline != END_OF_TIME &&
+ blocker->deadline < time_now_ms())
{
blocker->result = FIBER_TIMEOUT;
self->state = FIBER_RUNNING;
@@ -223,9 +223,9 @@ void fiber_yield(void)
}
}
-Tick fiber_deadline(void)
+Time fiber_deadline(void)
{
- Tick min = -1;
+ Time min = -1;
Fiber *f = current;
do
diff --git a/sources/libs/brutal/fibers/fibers.h b/sources/libs/brutal/fibers/fibers.h
index 3e912452..773cbbf7 100644
--- a/sources/libs/brutal/fibers/fibers.h
+++ b/sources/libs/brutal/fibers/fibers.h
@@ -13,7 +13,6 @@ typedef struct PACKED
{
uint64_t rip, rsp;
uint64_t rbx, rbp, r12, r13, r14, r15;
-
uint32_t fc_mxcsr;
uint32_t fc_x86_cw;
} FibersContext;
@@ -43,7 +42,7 @@ typedef struct
{
FiberBlockerFn *function;
void *context;
- Timeout deadline;
+ Time deadline;
FiberBlockResult result;
} FiberBlocker;
@@ -73,7 +72,7 @@ Fiber *fiber_start(FiberFn fn, void *args);
FiberBlockResult fiber_block(FiberBlocker blocker);
-void fiber_sleep(Timeout timeout);
+void fiber_sleep_until(Time timeout);
void fiber_ret(void *ret);
@@ -81,4 +80,4 @@ void *fiber_await(Fiber *fiber);
Fiber *fiber_self(void);
-Tick fiber_deadline(void);
+Time fiber_deadline(void);
diff --git a/sources/libs/brutal/io/emit.h b/sources/libs/brutal/io/emit.h
index c926edd0..bbccb4eb 100644
--- a/sources/libs/brutal/io/emit.h
+++ b/sources/libs/brutal/io/emit.h
@@ -1,6 +1,7 @@
#pragma once
#include <brutal/io/buf.h>
+#include <brutal/io/print.h>
typedef struct
{
@@ -22,4 +23,4 @@ void emit_deident(Emit *self);
IoWriter emit_writer(Emit *self);
-#define emit_fmt(SELF, FMT, ...) print_impl(emit_writer(SELF), str$(FMT), PRINT_ARGS(__VA_ARGS__));
+#define emit_fmt$(SELF, FMT, ...) print_impl(emit_writer(SELF), str$(FMT), PRINT_ARGS(__VA_ARGS__));
diff --git a/sources/libs/brutal/io/print.h b/sources/libs/brutal/io/print.h
index ce079a78..c9e0790c 100644
--- a/sources/libs/brutal/io/print.h
+++ b/sources/libs/brutal/io/print.h
@@ -129,7 +129,7 @@ PrintValue print_val_pointer(void *);
IoResult print_impl(IoWriter writer, Str format, PrintArgs args);
-#define print(writer, fmt, ...) \
+#define io_print$(writer, fmt, ...) \
print_impl(writer, str$(fmt), PRINT_ARGS(__VA_ARGS__))
Str str_fmt_impl(Alloc *alloc, Str format, PrintArgs args);
diff --git a/sources/libs/brutal/parse/scan.c b/sources/libs/brutal/parse/scan.c
index 4e53d13c..1ca18ccc 100644
--- a/sources/libs/brutal/parse/scan.c
+++ b/sources/libs/brutal/parse/scan.c
@@ -268,8 +268,8 @@ bool scan_dump_error(Scan *self, IoWriter writer)
ScanError err = self->error;
Str src = str_n$(self->size, (char *)self->buf);
- print(writer, "error: {}: {}\n", err.message, str$(&err.token));
- print(writer, " :\n");
+ io_print$(writer, "error: {}: {}\n", err.message, str$(&err.token));
+ io_print$(writer, " :\n");
int line_number = str_count_chr(str_sub(src, 0, err.position), '\n') + 1;
int line_start = str_last_chr(str_sub(src, 0, err.position), '\n') + 1;
@@ -285,16 +285,15 @@ bool scan_dump_error(Scan *self, IoWriter writer)
}
Str line = str_sub(src, line_start, line_end);
- print(writer, "{3d} | {}\n", line_number, line);
-
- print(writer, " : ");
+ io_print$(writer, "{3d} | {}\n", line_number, line);
+ io_print$(writer, " : ");
for (int i = 0; i < err.position - line_start; i++)
{
- print(writer, " ");
+ io_print$(writer, " ");
}
- print(writer, "^ here\n");
+ io_print$(writer, "^ here\n");
return true;
}
diff --git a/sources/libs/brutal/time.h b/sources/libs/brutal/time.h
index 0a236d17..f07a7583 100644
--- a/sources/libs/brutal/time.h
+++ b/sources/libs/brutal/time.h
@@ -2,6 +2,4 @@
#include <brutal/base.h>
/* --- */
-#include <brutal/time/convert.h>
-#include <brutal/time/query.h>
-#include <brutal/time/types.h>
+#include <brutal/time/mod.h>
diff --git a/sources/libs/brutal/time/constants.h b/sources/libs/brutal/time/constants.h
index f8c75cd1..ba32d4bb 100644
--- a/sources/libs/brutal/time/constants.h
+++ b/sources/libs/brutal/time/constants.h
@@ -1,6 +1,5 @@
#pragma once
-#define EPOCH_YEAR 1970
#define SECONDS_PER_MINUTE (60)
#define SECONDS_PER_HOURS (SECONDS_PER_MINUTE * 60)
diff --git a/sources/libs/brutal/time/convert.c b/sources/libs/brutal/time/convert.c
index 37643068..88d7648c 100644
--- a/sources/libs/brutal/time/convert.c
+++ b/sources/libs/brutal/time/convert.c
@@ -1,13 +1,15 @@
#include <brutal/time/constants.h>
#include <brutal/time/convert.h>
+
+
Date timestamp_to_date(TimeStamp timestamp)
{
Date date = {};
int days = timestamp / SECONDS_PER_DAY;
- date.year = EPOCH_YEAR;
+ date.year = TIME_EPOCH;
while (days - DAYS_PER_YEAR[is_leap_year(date.year)] > 0)
{
@@ -32,9 +34,9 @@ Date timestamp_to_date(TimeStamp timestamp)
Time timestamp_to_time(TimeStamp timestamp)
{
return (Time){
- .second = (int)(timestamp % 60),
- .minute = (int)((timestamp / SECONDS_PER_MINUTE) % 60),
- .hour = (int)((timestamp / SECONDS_PER_HOURS) % 24),
+ .second = timestamp % 60,
+ .minute = (timestamp / SECONDS_PER_MINUTE) % 60,
+ .hour = (timestamp / SECONDS_PER_HOURS) % 24,
};
}
@@ -50,12 +52,12 @@ TimeStamp datetime_to_timestamp(DateTime datetime)
{
TimeStamp timestamp = 0;
- for (Year year = EPOCH_YEAR; year < datetime.year; year++)
+ for (uint64_t year = TIME_EPOCH; year < datetime.year; year++)
{
timestamp += DAYS_PER_YEAR[is_leap_year(year)] * SECONDS_PER_DAY;
}
- for (Mounth month = 0; month < datetime.month - 1; month++)
+ for (uint64_t month = 0; month < datetime.month - 1; month++)
{
timestamp += DAYS_PER_MONTH[is_leap_year(datetime.year)][month] * SECONDS_PER_DAY;
}
diff --git a/sources/libs/brutal/time/convert.h b/sources/libs/brutal/time/convert.h
index db1b648a..e17c12f2 100644
--- a/sources/libs/brutal/time/convert.h
+++ b/sources/libs/brutal/time/convert.h
@@ -2,10 +2,3 @@
#include <brutal/time/types.h>
-Date timestamp_to_date(TimeStamp timestamp);
-
-Time timestamp_to_time(TimeStamp timestamp);
-
-DateTime timestamp_to_datetime(TimeStamp timestamp);
-
-TimeStamp datetime_to_timestamp(DateTime datetime);
diff --git a/sources/libs/brutal/time/mod.c b/sources/libs/brutal/time/mod.c
new file mode 100644
index 00000000..62500027
--- /dev/null
+++ b/sources/libs/brutal/time/mod.c
@@ -0,0 +1,129 @@
+#include <brutal/io/emit.h>
+#include <brutal/time/mod.h>
+#include <embed/time.h>
+
+static bool time_is_leap_year(int year)
+{
+ return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
+}
+
+static int time_days_per_year(int year)
+{
+ return time_is_leap_year(year) ? 366 : 365;
+}
+
+static int time_days_per_month(int year, int month)
+{
+ static int const DAYS_PER_MONTH[2][12] = {
+ {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+ {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+ };
+
+ return DAYS_PER_MONTH[time_is_leap_year(year)][month];
+}
+
+static Time time_per_year(int year)
+{
+ return time_days_per_year(year) * TIME_DAY;
+}
+
+static Time time_per_month(int year, int month)
+{
+ return time_days_per_month(year, month) * TIME_DAY;
+}
+
+Time time_now(void)
+{
+ return embed_time_now();
+}
+
+Date time_to_date(Time time)
+{
+ uint64_t secs = time / TIME_SEC;
+ int64_t days = secs / TIME_DAY;
+
+ Date date = {};
+
+ date.years = TIME_EPOCH;
+
+ while (days >= time_days_per_year(date.years))
+ {
+ days -= time_days_per_year(date.years);
+ date.years++;
+ }
+
+ date.months = 0;
+
+ while (days >= time_days_per_month(date.years, date.months))
+ {
+ days -= time_days_per_month(date.years, date.months);
+ date.months++;
+ }
+
+ date.days = days + 1;
+ date.months++;
+
+ return date;
+}
+
+static bool time_emit(Scan *scan, Emit *emit, Date date)
+{
+ if (scan_skip_word(scan, str$("YYYYY")))
+ {
+ emit_fmt$(emit, "{04d}", date.years);
+ return true;
+ }
+ else if (scan_skip_word(scan, str$("MM")))
+ {
+ emit_fmt$(emit, "{02d}", date.months);
+ return true;
+ }
+ else if (scan_skip_word(scan, str$("DD")))
+ {
+
+ }
+
+ return false;
+}
+
+IoResult time_fmt(IoWriter writer, Str fmt, Time time)
+{
+ size_t written = 0;
+
+ Scan scan;
+ scan_init(&scan, fmt);
+
+ return OK(IoResult, written);
+}
+
+IoResult time_iso(IoWriter writer, Time time)
+{
+ return time_fmt(writer, str$("YYYY-MM-DDTHH:mm:ss.sssZ"), time);
+}
+
+Date date_now(void)
+{
+ return time_to_date(time_now());
+}
+
+Time date_to_time(Date date)
+{
+ Time time = 0;
+
+ for (uint64_t year = TIME_EPOCH; year < date.years; year++)
+ {
+ time += time_secs_per_year(year);
+ }
+
+ for (uint64_t month = 0; month < date.months - 1; month++)
+ {
+ time += time_secs_per_month(date.years, month);
+ }
+
+ time += (date.days - 1) * TIME_DAY;
+ time += date.hours * TIME_HOUR;
+ time += date.minutes * TIME_MIN;
+ time += date.seconds * TIME_SEC;
+
+ return time;
+}
diff --git a/sources/libs/brutal/time/mod.h b/sources/libs/brutal/time/mod.h
new file mode 100644
index 00000000..04346863
--- /dev/null
+++ b/sources/libs/brutal/time/mod.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <brutal/base/attributes.h>
+#include <brutal/base/std.h>
+#include <brutal/io/fmt.h>
+#include <brutal/text/str.h>
+
+#define TIME_EPOCH (1970)
+#define END_OF_TIME ((Time)-1)
+
+typedef uint64_t Time;
+
+#define TIME_NS ((Time)1)
+#define TIME_US ((Time)1000 * TIME_NS)
+#define TIME_MS ((Time)1000 * TIME_US)
+#define TIME_SEC ((Time)1000 * TIME_MS)
+#define TIME_MIN ((Time)60 * TIME_SEC)
+#define TIME_HOUR ((Time)60 * TIME_MIN)
+#define TIME_DAY ((Time)24 * TIME_HOUR)
+
+#define time_us$(V) (Time)(V)
+#define time_ns$(V) ((Time)(V)*TIME_NS)
+#define time_ms$(V) ((Time)(V)*TIME_MS)
+#define time_sec$(V) ((Time)(V)*TIME_SEC)
+#define time_min$(V) ((Time)(V)*TIME_MIN)
+#define time_hour$(V) ((Time)(V)*TIME_HOUR)
+#define time_day$(V) ((Time)(V)*TIME_DAY)
+
+typedef union
+{
+ uint64_t seconds;
+ uint64_t minutes;
+ uint64_t hours;
+ uint64_t days;
+ uint64_t months;
+ uint64_t years;
+} Date;
+
+Time time_now(void);
+
+Date time_to_date(Time time);
+
+IoResult time_fmt(IoWriter writer, Str fmt, Time time);
+
+IoResult time_iso(IoWriter writer, Time time);
+
+#define time_fmt$(FMT, TIME) time_fmt(str$(FMT), TIME)
+
+Date date_now(void);
+
+Time date_to_time(Date date);
diff --git a/sources/libs/brutal/time/query.c b/sources/libs/brutal/time/query.c
index bb2d74b6..95e82362 100644
--- a/sources/libs/brutal/time/query.c
+++ b/sources/libs/brutal/time/query.c
@@ -2,11 +2,16 @@
#include <brutal/time/query.h>
#include <embed/time.h>
-Tick tick_now(void)
+Tick time_now_ms(void)
{
return embed_time_current_tick();
}
+NanoSeconds time_now_ns(void)
+{
+ return embed_time_current_nsec();
+}
+
TimeStamp timestamp_now(void)
{
return embed_time_current_timestamp();
@@ -26,8 +31,3 @@ DateTime datetime_now(void)
{
return timestamp_to_datetime(timestamp_now());
}
-
-NanoSeconds time_ns_now(void)
-{
- return embed_time_current_nsec();
-}
diff --git a/sources/libs/brutal/time/query.h b/sources/libs/brutal/time/query.h
deleted file mode 100644
index e19e920b..00000000
--- a/sources/libs/brutal/time/query.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include <brutal/time/types.h>
-
-Tick tick_now(void);
-
-TimeStamp timestamp_now(void);
-
-Date date_now(void);
-
-Time time_now(void);
-
-DateTime datetime_now(void);
-
-NanoSeconds time_ns_now(void);
diff --git a/sources/libs/brutal/time/types.h b/sources/libs/brutal/time/types.h
deleted file mode 100644
index b6bb437c..00000000
--- a/sources/libs/brutal/time/types.h
+++ /dev/null
@@ -1,54 +0,0 @@
-#pragma once
-
-#include <brutal/base/attributes.h>
-#include <brutal/base/std.h>
-
-typedef uint64_t Tick;
-typedef uint64_t TimeStamp;
-
-#define TIME_TIMEOUT_INFINITY ((Timeout)-1)
-typedef uint64_t Timeout;
-typedef uint64_t Deadline;
-
-typedef uint64_t NanoSeconds;
-typedef uint64_t Seconds;
-typedef uint64_t Minutes;
-typedef uint64_t Hours;
-
-typedef struct PACKED
-{
- Seconds second;
- Minutes minute;
- Hours hour;
-} Time;
-
-typedef uint64_t Day;
-typedef uint64_t Mounth;
-typedef uint64_t Year;
-
-typedef struct PACKED
-{
- Day day;
- Mounth month;
- Year year;
-} Date;
-
-typedef union PACKED
-{
- struct
- {
- Day day;
- Mounth month;
- Year year;
-
- Seconds second;
- Minutes minute;
- Hours hour;
- };
-
- struct
- {
- Date date;
- Time time;
- };
-} DateTime;
diff --git a/sources/libs/brutal/ui.h b/sources/libs/brutal/ui.h
index 7fc1db17..39a2e32e 100644
--- a/sources/libs/brutal/ui.h
+++ b/sources/libs/brutal/ui.h
@@ -4,6 +4,7 @@
/* --- */
#include <brutal/ui/app.h>
#include <brutal/ui/color.h>
+#include <brutal/ui/defer.h>
#include <brutal/ui/event.h>
#include <brutal/ui/font.h>
#include <brutal/ui/parser.h>
diff --git a/sources/libs/brutal/ui/app.c b/sources/libs/brutal/ui/app.c
index 34829282..4ab3a91a 100644
--- a/sources/libs/brutal/ui/app.c
+++ b/sources/libs/brutal/ui/app.c
@@ -1,10 +1,11 @@
#include <brutal/alloc/global.h>
#include <brutal/time/query.h>
#include <brutal/ui/app.h>
+#include <brutal/ui/defer.h>
#include <brutal/ui/win.h>
#include <embed/app.h>
-static UiApp *_instance;
+static UiApp *_instance = nullptr;
UiApp *ui_app_self(void)
{
@@ -15,7 +16,10 @@ UiApp *ui_app_self(void)
void ui_app_init(UiApp *self)
{
vec_init(&self->windows, alloc_global());
+ vec_init(&self->defers, alloc_global());
+
embed_app_init(self);
+
self->alive = true;
self->font = gfx_font_builtin();
ui_palette_init(&self->palette);
@@ -25,6 +29,8 @@ void ui_app_init(UiApp *self)
void ui_app_deinit(UiApp *self)
{
embed_app_deinit(self);
+
+ vec_deinit(&self->defers);
vec_deinit(&self->windows);
}
@@ -32,7 +38,8 @@ int ui_app_run(UiApp *self)
{
while (self->alive)
{
- embed_app_wait(self);
+ ui_app_update(self);
+ embed_app_wait(self, ui_app_deadline(self));
ui_app_pump(self);
}
@@ -54,6 +61,39 @@ void ui_app_detach_win(UiApp *self, UiWin *win)
vec_remove(&self->windows, win);
}
+void ui_app_attach_defer(UiApp *self, UiDefer *defer)
+{
+ vec_push(&self->defers, defer);
+}
+
+void ui_app_detach_defer(UiApp *self, UiDefer *defer)
+{
+ vec_remove(&self->defers, defer);
+}
+
+Tick ui_app_deadline(UiApp *self)
+{
+ Tick deadline = -1;
+ vec_foreach_v(defer, &self->defers)
+ {
+ deadline = m_min(deadline, defer->deadline);
+ }
+ return deadline;
+}
+
+void ui_app_update(UiApp *self)
+{
+ Tick tick = time_now_ms();
+
+ vec_foreach_v(defer, &self->defers)
+ {
+ if (defer->deadline <= tick)
+ {
+ ui_defer_invoke(defer);
+ }
+ }
+}
+
void ui_app_exit(UiApp *self, int result)
{
self->result = result;
@@ -76,29 +116,3 @@ void ui_app_overide_color(UiApp *self, UiRole role, GfxColor color)
{
ui_palette_overide(&self->palette, role, color);
}
-
-int ui_app_benchmark(UiApp *self)
-{
- int frames = 600;
- Tick start = tick_now();
-
- for (int f = 0; f < frames; f++)
- {
- vec_foreach_v(win, &self->windows)
- {
- ui_win_repaint(win);
- }
- }
-
- if (!self->alive)
- {
- return self->result;
- }
-
- Tick end = tick_now();
- float fps = frames / ((float)(end - start) / 1000.0);
-
- log$("Benchmark ui app took: {}ms for {}frames ({}fps)", (end - start), frames, fps);
-
- return self->result;
-}
diff --git a/sources/libs/brutal/ui/app.h b/sources/libs/brutal/ui/app.h
index 97d534f5..ac8fddd1 100644
--- a/sources/libs/brutal/ui/app.h
+++ b/sources/libs/brutal/ui/app.h
@@ -2,11 +2,13 @@
#include <brutal/ds/vec.h>
#include <brutal/gfx/font.h>
+#include <brutal/time/mod.h>
#include <brutal/ui/color.h>
#include <brutal/ui/event.h>
#include <embed/app-decl.h>
typedef struct _UiWin UiWin;
+typedef struct _UiDefer UiDefer;
typedef struct _UiApp
{
@@ -17,6 +19,7 @@ typedef struct _UiApp
UiPalette palette;
Vec(UiWin *) windows;
+ Vec(UiDefer *) defers;
} UiApp;
UiApp *ui_app_self(void);
@@ -33,6 +36,14 @@ void ui_app_attach_win(UiApp *self, UiWin *win);
void ui_app_detach_win(UiApp *self, UiWin *win);
+void ui_app_attach_defer(UiApp *self, UiDefer *defer);
+
+void ui_app_detach_defer(UiApp *self, UiDefer *defer);
+
+Time ui_app_deadline(UiApp *self);
+
+void ui_app_update(UiApp *self);
+
void ui_app_exit(UiApp *self, int result);
void ui_app_font(UiApp *self, GfxFont font);
@@ -40,5 +51,3 @@ void ui_app_font(UiApp *self, GfxFont font);
GfxColor ui_app_color(UiApp *self, UiRole role);
void ui_app_overide_color(UiApp *self, UiRole role, GfxColor color);
-
-int ui_app_benchmark(UiApp *self);
diff --git a/sources/libs/brutal/ui/defer.c b/sources/libs/brutal/ui/defer.c
new file mode 100644
index 00000000..733a8c39
--- /dev/null
+++ b/sources/libs/brutal/ui/defer.c
@@ -0,0 +1,36 @@
+#include <brutal/ui/defer.h>
+
+void ui_defer_init(UiDefer *self, UiDeferFn *fn, void *context)
+{
+ self->fn = fn;
+ self->context = context;
+ self->deadline = -1;
+
+ ui_app_attach_defer(ui_app_self(), self);
+}
+
+void ui_defer_deinit(UiDefer *self)
+{
+ ui_app_detach_defer(ui_app_self(), self);
+}
+
+void ui_defer_sched(UiDefer *self)
+{
+ self->deadline = 0;
+}
+
+void ui_defer_delay(UiDefer *self, Tick tick)
+{
+ self->deadline = time_now_ms() + tick;
+}
+
+void ui_defer_cancel(UiDefer *self)
+{
+ self->deadline = -1;
+}
+
+void ui_defer_invoke(UiDefer *self)
+{
+ self->fn(self->context, self);
+ self->deadline = -1;
+}
diff --git a/sources/libs/brutal/ui/defer.h b/sources/libs/brutal/ui/defer.h
new file mode 100644
index 00000000..f4fc58f5
--- /dev/null
+++ b/sources/libs/brutal/ui/defer.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <brutal/time.h>
+#include <brutal/ui/app.h>
+
+typedef struct _UiDefer UiDefer;
+
+typedef void UiDeferFn(void *context, struct _UiDefer *defer);
+
+struct _UiDefer
+{
+ bool removed;
+ Tick deadline;
+ UiDeferFn *fn;
+ void *context;
+};
+
+void ui_defer_init(UiDefer *self, UiDeferFn *fn, void *context);
+
+void ui_defer_deinit(UiDefer *self);
+
+void ui_defer_sched(UiDefer *self);
+
+void ui_defer_delay(UiDefer *self, Tick tick);
+
+void ui_defer_cancel(UiDefer *self);
+
+void ui_defer_invoke(UiDefer *self);
diff --git a/sources/libs/cc/trans/decl.c b/sources/libs/cc/trans/decl.c
index 7ce2c79b..bc023c9e 100644
--- a/sources/libs/cc/trans/decl.c
+++ b/sources/libs/cc/trans/decl.c
@@ -4,32 +4,32 @@ static void cc_trans_decl_attr(Emit *emit, CDeclAttr attr)
{
if (attr & CDECL_AUTO)
{
- emit_fmt(emit, "auto ");
+ emit_fmt$(emit, "auto ");
}
if (attr & CDECL_STATIC)
{
- emit_fmt(emit, "static ");
+ emit_fmt$(emit, "static ");
}
if (attr & CDECL_REGISTER)
{
- emit_fmt(emit, "register ");
+ emit_fmt$(emit, "register ");
}
if (attr & CDECL_INLINE)
{
- emit_fmt(emit, "inline ");
+ emit_fmt$(emit, "inline ");
}
if (attr & CDECL_EXTERN)
{
- emit_fmt(emit, "extern ");
+ emit_fmt$(emit, "extern ");
}
if (attr & CDECL_THREAD)
{
- emit_fmt(emit, "thread ");
+ emit_fmt$(emit, "thread ");
}
}
@@ -43,14 +43,14 @@ void cc_trans_decl(Emit *emit, CDecl decl)
if (is_typedef)
{
- emit_fmt(emit, "typedef ");
+ emit_fmt$(emit, "typedef ");
}
cc_trans_type_start(emit, decl.type_.type);
if (is_typedef)
{
- emit_fmt(emit, " {}", decl.name);
+ emit_fmt$(emit, " {}", decl.name);
}
cc_trans_type_end(emit, decl.type_.type);
@@ -58,13 +58,13 @@ void cc_trans_decl(Emit *emit, CDecl decl)
else if (decl.type == CDECL_VAR)
{
cc_trans_type_start(emit, decl.var_.type);
- emit_fmt(emit, " {} ", decl.name);
+ emit_fmt$(emit, " {} ", decl.name);
cc_trans_type_end(emit, decl.var_.type);
if (decl.var_.expr.type != CEXPR_INVALID &&
decl.var_.expr.type != CEXPR_EMPTY)
{
- emit_fmt(emit, "=");
+ emit_fmt$(emit, "=");
cc_trans_expr(emit, decl.var_.expr);
}
}
@@ -74,18 +74,18 @@ void cc_trans_decl(Emit *emit, CDecl decl)
// Declarator
cc_trans_type_start(emit, func_type);
- emit_fmt(emit, " {}", decl.name);
+ emit_fmt$(emit, " {}", decl.name);
cc_trans_type_end(emit, func_type);
// Body
if (decl.func_.body.type != CSTMT_EMPTY)
{
- emit_fmt(emit, "\n", decl.name);
+ emit_fmt$(emit, "\n", decl.name);
cc_trans_stmt(emit, decl.func_.body);
}
else
{
- emit_fmt(emit, ";", decl.name);
+ emit_fmt$(emit, ";", decl.name);
}
}
}
diff --git a/sources/libs/cc/trans/expr.c b/sources/libs/cc/trans/expr.c
index 3c0d3125..ed5f4542 100644
--- a/sources/libs/cc/trans/expr.c
+++ b/sources/libs/cc/trans/expr.c
@@ -3,7 +3,7 @@
static void cc_trans_op_fix(Emit *emit, COp op)
{
- emit_fmt(emit, "{}", cop_to_str(op));
+ emit_fmt$(emit, "{}", cop_to_str(op));
}
static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
@@ -12,7 +12,7 @@ static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
if (pre >= parent_pre)
{
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
}
switch (expr.type)
@@ -25,7 +25,7 @@ static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
break;
case CEXPR_IDENT:
- emit_fmt(emit, "{}", expr.ident_);
+ emit_fmt$(emit, "{}", expr.ident_);
break;
case CEXPR_SELF:
@@ -54,13 +54,13 @@ static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
cc_trans_expr_pre(emit, *expr.infix_.rhs, pre);
if (expr.infix_.op == COP_INDEX)
{
- emit_fmt(emit, "]");
+ emit_fmt$(emit, "]");
}
break;
case CEXPR_CALL:
cc_trans_expr_pre(emit, *expr.call_.expr, pre);
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
bool first = true;
vec_foreach_v(v, &expr.call_.args)
{
@@ -70,49 +70,49 @@ static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
}
else
{
- emit_fmt(emit, ", ");
+ emit_fmt$(emit, ", ");
}
cc_trans_expr_pre(emit, v, CEXPR_MAX_PRECEDENCE);
}
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
break;
case CEXPR_CAST:
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
cc_trans_type(emit, expr.cast_.type);
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
cc_trans_expr_pre(emit, *expr.cast_.expr, pre);
break;
case CEXPR_TERNARY:
cc_trans_expr_pre(emit, *expr.ternary_.expr_cond, pre);
- emit_fmt(emit, " ? ");
+ emit_fmt$(emit, " ? ");
cc_trans_expr_pre(emit, *expr.ternary_.expr_true, pre);
- emit_fmt(emit, " : ");
+ emit_fmt$(emit, " : ");
cc_trans_expr_pre(emit, *expr.ternary_.expr_false, pre);
break;
case CEXPR_INITIALIZER:
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
cc_trans_type(emit, expr.initializer_.type);
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
- emit_fmt(emit, "{{\n");
+ emit_fmt$(emit, "{{\n");
emit_ident(emit);
vec_foreach_v(v, &expr.initializer_.initializer)
{
cc_trans_expr_pre(emit, v, CEXPR_MAX_PRECEDENCE);
- emit_fmt(emit, ",\n");
+ emit_fmt$(emit, ",\n");
}
emit_deident(emit);
- emit_fmt(emit, "}}");
+ emit_fmt$(emit, "}}");
break;
case CEXPR_LAMBDA:
- emit_fmt(emit, "[]");
+ emit_fmt$(emit, "[]");
cc_trans_func_params(emit, expr.lambda_.type);
cc_trans_stmt(emit, *expr.lambda_.body);
break;
@@ -123,7 +123,7 @@ static void cc_trans_expr_pre(Emit *emit, CExpr expr, int parent_pre)
if (pre >= parent_pre)
{
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
}
}
diff --git a/sources/libs/cc/trans/stmt.c b/sources/libs/cc/trans/stmt.c
index d3a3649e..cc136152 100644
--- a/sources/libs/cc/trans/stmt.c
+++ b/sources/libs/cc/trans/stmt.c
@@ -29,7 +29,7 @@ void cc_trans_stmt(Emit *emit, CStmt stmt)
return;
case CSTMT_BLOCK:
- emit_fmt(emit, "{{\n");
+ emit_fmt$(emit, "{{\n");
emit_ident(emit);
vec_foreach_v(v, &stmt.block_.stmts)
@@ -37,20 +37,20 @@ void cc_trans_stmt(Emit *emit, CStmt stmt)
cc_trans_stmt(emit, v);
if (cc_trans_should_stmt_endline(v.type))
{
- emit_fmt(emit, ";");
+ emit_fmt$(emit, ";");
}
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
emit_deident(emit);
- emit_fmt(emit, "}}");
+ emit_fmt$(emit, "}}");
return;
case CSTMT_IF:
- emit_fmt(emit, "if (");
+ emit_fmt$(emit, "if (");
cc_trans_expr(emit, stmt.if_.expr);
- emit_fmt(emit, ")\n");
+ emit_fmt$(emit, ")\n");
if (stmt.if_.stmt_true->type != CSTMT_BLOCK)
{
@@ -65,7 +65,7 @@ void cc_trans_stmt(Emit *emit, CStmt stmt)
if (stmt.if_.stmt_false->type != CSTMT_EMPTY)
{
- emit_fmt(emit, "\nelse\n");
+ emit_fmt$(emit, "\nelse\n");
if (stmt.if_.stmt_true->type != CSTMT_BLOCK)
{
emit_ident(emit);
@@ -80,73 +80,73 @@ void cc_trans_stmt(Emit *emit, CStmt stmt)
return;
case CSTMT_FOR:
- emit_fmt(emit, "for (");
+ emit_fmt$(emit, "for (");
cc_trans_stmt(emit, *stmt.for_.init_stmt);
- emit_fmt(emit, "; ");
+ emit_fmt$(emit, "; ");
cc_trans_expr(emit, stmt.for_.cond_expr);
- emit_fmt(emit, "; ");
+ emit_fmt$(emit, "; ");
cc_trans_expr(emit, stmt.for_.iter_expr);
- emit_fmt(emit, ")\n");
+ emit_fmt$(emit, ")\n");
cc_trans_stmt(emit, *stmt.for_.stmt);
return;
case CSTMT_WHILE:
- emit_fmt(emit, "while (");
+ emit_fmt$(emit, "while (");
cc_trans_expr(emit, stmt.while_.expr);
- emit_fmt(emit, ") \n");
+ emit_fmt$(emit, ") \n");
cc_trans_stmt(emit, *stmt.while_.stmt);
return;
case CSTMT_DO:
- emit_fmt(emit, "do \n ");
+ emit_fmt$(emit, "do \n ");
cc_trans_stmt(emit, *stmt.do_.stmt);
- emit_fmt(emit, "while (");
+ emit_fmt$(emit, "while (");
cc_trans_expr(emit, stmt.do_.expr);
- emit_fmt(emit, ") \n");
+ emit_fmt$(emit, ") \n");
return;
case CSTMT_SWITCH:
- emit_fmt(emit, "switch (");
+ emit_fmt$(emit, "switch (");
cc_trans_expr(emit, stmt.while_.expr);
- emit_fmt(emit, ")\n");
+ emit_fmt$(emit, ")\n");
cc_trans_stmt(emit, *stmt.while_.stmt);
return;
case CSTMT_RETURN:
- emit_fmt(emit, "return ");
+ emit_fmt$(emit, "return ");
cc_trans_expr(emit, stmt.return_.expr);
return;
case CSTMT_GOTO:
- emit_fmt(emit, "goto {}", stmt.goto_.label);
+ emit_fmt$(emit, "goto {}", stmt.goto_.label);
return;
case CSTMT_BREAK:
- emit_fmt(emit, "break");
+ emit_fmt$(emit, "break");
return;
case CSTMT_CONTINUE:
- emit_fmt(emit, "continue");
+ emit_fmt$(emit, "continue");
return;
case CSTMT_LABEL:
- emit_fmt(emit, "{}:", stmt.label_.label);
+ emit_fmt$(emit, "{}:", stmt.label_.label);
return;
case CSTMT_CASE:
- emit_fmt(emit, "case ");
+ emit_fmt$(emit, "case ");
cc_trans_expr(emit, stmt.case_.expr);
- emit_fmt(emit, ":");
+ emit_fmt$(emit, ":");
return;
case CSTMT_DEFAULT:
- emit_fmt(emit, "default:");
+ emit_fmt$(emit, "default:");
return;
default:
diff --git a/sources/libs/cc/trans/type.c b/sources/libs/cc/trans/type.c
index 7d9aa2c5..b7b008c2 100644
--- a/sources/libs/cc/trans/type.c
+++ b/sources/libs/cc/trans/type.c
@@ -3,17 +3,17 @@
static void cc_trans_member(Emit *emit, CTypeMember type)
{
cc_trans_type_start(emit, type.type);
- emit_fmt(emit, " {}", type.name);
+ emit_fmt$(emit, " {}", type.name);
cc_trans_type_end(emit, type.type);
}
static void cc_trans_constant(Emit *emit, CTypeConst member)
{
- emit_fmt(emit, "{}", member.name);
+ emit_fmt$(emit, "{}", member.name);
if (member.value.type != CVAL_INVALID)
{
- emit_fmt(emit, " = ");
+ emit_fmt$(emit, " = ");
cc_trans_value(emit, member.value);
}
}
@@ -22,17 +22,17 @@ static void cc_trans_type_attr(Emit *emit, CTypeAttr attr)
{
if (attr & CTYPE_CONST)
{
- emit_fmt(emit, " const");
+ emit_fmt$(emit, " const");
}
if (attr & CTYPE_RESTRICT)
{
- emit_fmt(emit, " restrict");
+ emit_fmt$(emit, " restrict");
}
if (attr & CTYPE_VOLATILE)
{
- emit_fmt(emit, " volatile");
+ emit_fmt$(emit, " volatile");
}
}
@@ -46,19 +46,19 @@ void cc_trans_type_start(Emit *emit, CType type)
{
if (type.type == CTYPE_NAME)
{
- emit_fmt(emit, type.name);
+ emit_fmt$(emit, type.name);
cc_trans_type_attr(emit, type.attr);
}
else if (type.type == CTYPE_PTR)
{
cc_trans_type_start(emit, *type.ptr_.subtype);
- emit_fmt(emit, "*");
+ emit_fmt$(emit, "*");
cc_trans_type_attr(emit, type.attr);
}
else if (type.type == CTYPE_PARENT)
{
cc_trans_type_start(emit, *type.ptr_.subtype);
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
}
else if (type.type == CTYPE_FUNC)
{
@@ -69,51 +69,51 @@ void cc_trans_type_start(Emit *emit, CType type)
{
if (type.type == CTYPE_STRUCT)
{
- emit_fmt(emit, "struct");
+ emit_fmt$(emit, "struct");
}
else
{
- emit_fmt(emit, "union");
+ emit_fmt$(emit, "union");
}
if (str_any(type.name))
{
- emit_fmt(emit, " {}", type.name);
+ emit_fmt$(emit, " {}", type.name);
}
cc_trans_type_attr(emit, type.attr);
- emit_fmt(emit, "\n{{\n");
+ emit_fmt$(emit, "\n{{\n");
emit_ident(emit);
vec_foreach_v(v, &type.struct_.members)
{
cc_trans_member(emit, v);
- emit_fmt(emit, ";\n");
+ emit_fmt$(emit, ";\n");
}
emit_deident(emit);
- emit_fmt(emit, "}}");
+ emit_fmt$(emit, "}}");
}
else if (type.type == CTYPE_ENUM)
{
- emit_fmt(emit, "enum", type.name);
+ emit_fmt$(emit, "enum", type.name);
if (str_any(type.name))
{
- emit_fmt(emit, " {}", type.name);
+ emit_fmt$(emit, " {}", type.name);
}
- emit_fmt(emit, "\n{{\n");
+ emit_fmt$(emit, "\n{{\n");
emit_ident(emit);
vec_foreach_v(v, &type.enum_.constants)
{
cc_trans_constant(emit, v);
- emit_fmt(emit, ",\n");
+ emit_fmt$(emit, ",\n");
}
emit_deident(emit);
- emit_fmt(emit, "}}");
+ emit_fmt$(emit, "}}");
cc_trans_type_attr(emit, type.attr);
}
@@ -124,25 +124,25 @@ void cc_trans_type_start(Emit *emit, CType type)
}
else
{
- emit_fmt(emit, ctype_to_str(type.type));
+ emit_fmt$(emit, ctype_to_str(type.type));
}
}
void cc_trans_func_params(Emit *emit, CType type)
{
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
bool first = true;
vec_foreach_v(v, &type.func_.params)
{
if (!first)
{
- emit_fmt(emit, ", ");
+ emit_fmt$(emit, ", ");
}
first = false;
cc_trans_member(emit, v);
}
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
}
void cc_trans_type_end(Emit *emit, CType type)
@@ -153,7 +153,7 @@ void cc_trans_type_end(Emit *emit, CType type)
}
else if (type.type == CTYPE_PARENT)
{
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
cc_trans_type_end(emit, *type.ptr_.subtype);
}
else if (type.type == CTYPE_FUNC)
@@ -165,11 +165,11 @@ void cc_trans_type_end(Emit *emit, CType type)
{
if (type.array_.size == CTYPE_ARRAY_UNBOUNDED)
{
- emit_fmt(emit, "[]", type.array_.size);
+ emit_fmt$(emit, "[]", type.array_.size);
}
else
{
- emit_fmt(emit, "[{}]", type.array_.size);
+ emit_fmt$(emit, "[{}]", type.array_.size);
}
cc_trans_type_end(emit, *type.ptr_.subtype);
}
diff --git a/sources/libs/cc/trans/unit.c b/sources/libs/cc/trans/unit.c
index eb7ee39f..1efc6621 100644
--- a/sources/libs/cc/trans/unit.c
+++ b/sources/libs/cc/trans/unit.c
@@ -2,50 +2,50 @@
static void cc_trans_include(Emit *emit, CInclude path)
{
- emit_fmt(emit, "#include ");
+ emit_fmt$(emit, "#include ");
if (path.is_system)
{
- emit_fmt(emit, "<{}>\n", path.path);
+ emit_fmt$(emit, "<{}>\n", path.path);
}
else
{
- emit_fmt(emit, "\"{}\"\n", path.path);
+ emit_fmt$(emit, "\"{}\"\n", path.path);
}
}
static void cc_trans_pragma(Emit *emit, CPragma pragma)
{
- emit_fmt(emit, "#pragma ");
- emit_fmt(emit, pragma.text);
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "#pragma ");
+ emit_fmt$(emit, pragma.text);
+ emit_fmt$(emit, "\n");
}
static void cc_trans_define(Emit *emit, CDefine define)
{
- emit_fmt(emit, "#define ");
- emit_fmt(emit, define.name);
+ emit_fmt$(emit, "#define ");
+ emit_fmt$(emit, define.name);
if (define.args.len != 0)
{
- emit_fmt(emit, "(");
+ emit_fmt$(emit, "(");
for (int i = 0; i < define.args.len; i++)
{
if (i != 0)
{
- emit_fmt(emit, ", {}", define.args.data[i]);
+ emit_fmt$(emit, ", {}", define.args.data[i]);
}
else
{
- emit_fmt(emit, "{}", define.args.data[i]);
+ emit_fmt$(emit, "{}", define.args.data[i]);
}
}
- emit_fmt(emit, ")");
+ emit_fmt$(emit, ")");
}
- emit_fmt(emit, " ");
+ emit_fmt$(emit, " ");
cc_trans_expr(emit, define.expression);
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
void cc_trans_unit(Emit *emit, CUnit unit)
@@ -59,7 +59,7 @@ void cc_trans_unit(Emit *emit, CUnit unit)
case CUNIT_INCLUDE:
if (prev_type != entry.type)
{
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
cc_trans_include(emit, entry._include);
@@ -70,22 +70,22 @@ void cc_trans_unit(Emit *emit, CUnit unit)
break;
case CUNIT_DECLARATION:
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
cc_trans_decl(emit, entry._decl);
if (entry._decl.type != CDECL_FUNC)
{
- emit_fmt(emit, ";");
+ emit_fmt$(emit, ";");
}
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
break;
case CUNIT_DEFINE:
if (prev_type != entry.type)
{
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
cc_trans_define(emit, entry._define);
diff --git a/sources/libs/cc/trans/val.c b/sources/libs/cc/trans/val.c
index aac13133..0b5cd46b 100644
--- a/sources/libs/cc/trans/val.c
+++ b/sources/libs/cc/trans/val.c
@@ -6,19 +6,19 @@ void cc_trans_value(Emit *emit, CVal value)
switch (value.type)
{
case CVAL_SIGNED:
- emit_fmt(emit, "{}", value.signed_);
+ emit_fmt$(emit, "{}", value.signed_);
break;
case CVAL_UNSIGNED:
- emit_fmt(emit, "{}", value.unsigned_);
+ emit_fmt$(emit, "{}", value.unsigned_);
break;
case CVAL_FLOAT:
- emit_fmt(emit, "{}", value.float_);
+ emit_fmt$(emit, "{}", value.float_);
break;
case CVAL_STRING:
- emit_fmt(emit, "\"{}\"", value.string_);
+ emit_fmt$(emit, "\"{}\"", value.string_);
break;
default:
diff --git a/sources/libs/embed/app.h b/sources/libs/embed/app.h
index 303525ca..12f320f9 100644
--- a/sources/libs/embed/app.h
+++ b/sources/libs/embed/app.h
@@ -1,5 +1,6 @@
#pragma once
+#include <brutal/time/types.h>
#include <brutal/ui/app.h>
void embed_app_init(UiApp *self);
@@ -8,4 +9,4 @@ void embed_app_deinit(UiApp *self);
void embed_app_pump(UiApp *self);
-void embed_app_wait(UiApp *self);
+void embed_app_wait(UiApp *self, Tick deadline);
diff --git a/sources/libs/embed/brutal/app.c b/sources/libs/embed/brutal/app.c
index 78e9fcbf..7fcda6a1 100644
--- a/sources/libs/embed/brutal/app.c
+++ b/sources/libs/embed/brutal/app.c
@@ -1,6 +1,6 @@
-#include <ipc/ipc.h>
#include <embed/app.h>
#include <embed/win.h>
+#include <ipc/ipc.h>
void embed_app_init(UiApp *)
{
@@ -14,7 +14,7 @@ void embed_app_pump(UiApp *)
{
}
-void embed_app_wait(UiApp *)
+void embed_app_wait(UiApp *, Tick)
{
ipc_component_run(ipc_component_self());
}
diff --git a/sources/libs/embed/brutal/debug.c b/sources/libs/embed/brutal/debug.c
index 91a52089..1fdb2ec3 100644
--- a/sources/libs/embed/brutal/debug.c
+++ b/sources/libs/embed/brutal/debug.c
@@ -3,5 +3,5 @@
void embed_log_prefix(IoWriter writer)
{
- print(writer, "user: {}: ", embed_task_self());
+ io_print$(writer, "user: {}: ", embed_task_self());
}
diff --git a/sources/libs/embed/efi/debug.c b/sources/libs/embed/efi/debug.c
index 8433b271..7dd6df6c 100644
--- a/sources/libs/embed/efi/debug.c
+++ b/sources/libs/embed/efi/debug.c
@@ -2,5 +2,5 @@
void embed_log_prefix(IoWriter writer)
{
- print(writer, "efi: ");
+ io_print$(writer, "efi: ");
}
diff --git a/sources/libs/embed/kernel/debug.c b/sources/libs/embed/kernel/debug.c
index 9fc2f9e4..7b10a619 100644
--- a/sources/libs/embed/kernel/debug.c
+++ b/sources/libs/embed/kernel/debug.c
@@ -3,10 +3,10 @@
void embed_log_prefix(IoWriter writer)
{
- print(writer, "cpu{}: ", cpu_self_id());
+ io_print$(writer, "cpu{}: ", cpu_self_id());
if (task_self())
{
- print(writer, "{}: ", task_self()->id);
+ io_print$(writer, "{}: ", task_self()->id);
}
}
diff --git a/sources/libs/embed/sdl/app.c b/sources/libs/embed/sdl/app.c
index f90b6052..467953f9 100644
--- a/sources/libs/embed/sdl/app.c
+++ b/sources/libs/embed/sdl/app.c
@@ -145,7 +145,15 @@ void embed_app_pump(UiApp *self)
}
}
-void embed_app_wait(MAYBE_UNUSED UiApp *self)
+void embed_app_wait(MAYBE_UNUSED UiApp *self, Tick deadline)
{
- SDL_WaitEventTimeout(nullptr, 1000);
+ Tick now = time_now_ms();
+ int wait = 0;
+
+ if (now < deadline)
+ {
+ wait = deadline - now;
+ }
+
+ SDL_WaitEventTimeout(nullptr, wait);
}
diff --git a/sources/libs/embed/time.h b/sources/libs/embed/time.h
index 683b1e77..46c67e1c 100644
--- a/sources/libs/embed/time.h
+++ b/sources/libs/embed/time.h
@@ -1,9 +1,5 @@
#pragma once
-#include <brutal/time/types.h>
+#include <brutal/time/mod.h>
-Tick embed_time_current_tick(void);
-
-TimeStamp embed_time_current_timestamp(void);
-
-unsigned long embed_time_current_nsec(void);
+Time embed_time_now(void);
diff --git a/sources/libs/hw/fdt/fdt.c b/sources/libs/hw/fdt/fdt.c
index 149726ee..1369d889 100644
--- a/sources/libs/hw/fdt/fdt.c
+++ b/sources/libs/hw/fdt/fdt.c
@@ -257,7 +257,7 @@ static void fdt_dump_props_value(FdtProp *prop, Emit *out)
be_uint32_t *val = ((be_uint32_t *)prop->value.buf);
for (unsigned int i = 0; i < prop->value.len / sizeof(uint32_t); i++)
{
- emit_fmt(out, "- as uint32_t: {#x} \n", load_be(val[i]));
+ emit_fmt$(out, "- as uint32_t: {#x} \n", load_be(val[i]));
}
}
if (prop->value.len % sizeof(uint64_t) == 0)
@@ -265,21 +265,21 @@ static void fdt_dump_props_value(FdtProp *prop, Emit *out)
be_uint64_t *val = ((be_uint64_t *)prop->value.buf);
for (unsigned int i = 0; i < prop->value.len / sizeof(uint64_t); i++)
{
- emit_fmt(out, "- as uint64_t: {#x}\n", load_be(val[i]));
+ emit_fmt$(out, "- as uint64_t: {#x}\n", load_be(val[i]));
}
}
if (prop->value.len > 2)
{
Str as_string = str_n$(prop->value.len, (char *)prop->value.buf);
- emit_fmt(out, "- as string: {} \n", as_string);
+ emit_fmt$(out, "- as string: {} \n", as_string);
}
- emit_fmt(out, "- as data: ");
+ emit_fmt$(out, "- as data: ");
for (unsigned int i = 0; i < prop->value.len; i++)
{
- emit_fmt(out, "{#x} ", ((uint8_t *)prop->value.buf)[i]);
+ emit_fmt$(out, "{#x} ", ((uint8_t *)prop->value.buf)[i]);
}
- emit_fmt(out, "\n");
+ emit_fmt$(out, "\n");
}
typedef struct
@@ -290,7 +290,7 @@ typedef struct
static Iter fdt_dump_props_iter(FdtProp *prop, IterDumpCtx *ctx)
{
- emit_fmt(ctx->out, "- prop: {}\n", prop->name);
+ emit_fmt$(ctx->out, "- prop: {}\n", prop->name);
emit_ident(ctx->out);
if (ctx->dump_values)
{
@@ -302,7 +302,7 @@ static Iter fdt_dump_props_iter(FdtProp *prop, IterDumpCtx *ctx)
static Iter fdt_dump_node_iter(FdtNode *node, IterDumpCtx *ctx)
{
- emit_fmt(ctx->out, "node: {}\n", node->name);
+ emit_fmt$(ctx->out, "node: {}\n", node->name);
emit_ident(ctx->out);
fdt_node_props(*node, (IterFn *)fdt_dump_props_iter, ctx);
fdt_node_childs(*node, (IterFn *)fdt_dump_node_iter, ctx);
@@ -318,18 +318,18 @@ void fdt_dump(FdtHeader *fdt, Emit *out, bool dump_values)
.dump_values = dump_values,
};
- emit_fmt(out, "fdt-dump:\n");
+ emit_fmt$(out, "fdt-dump:\n");
emit_ident(out);
fdt_node_childs(root, (IterFn *)fdt_dump_node_iter, &ctx);
emit_deident(out);
- emit_fmt(out, "fdt reserved memory:\n");
+ emit_fmt$(out, "fdt reserved memory:\n");
FdtReservationEntry *entry = ((void *)fdt) + load_be(fdt->memory_reservation_offset);
emit_ident(out);
while (load_be(entry->size) != 0 || load_be(entry->address) != 0)
{
- emit_fmt(out, "- [{#x}] - [{#x}] \n", load_be(entry->address), load_be(entry->address) + load_be(entry->size));
+ emit_fmt$(out, "- [{#x}] - [{#x}] \n", load_be(entry->address), load_be(entry->address) + load_be(entry->size));
entry++;
}
emit_deident(out);
diff --git a/sources/libs/ipc/component.c b/sources/libs/ipc/component.c
index 4fba39b6..28ab2301 100644
--- a/sources/libs/ipc/component.c
+++ b/sources/libs/ipc/component.c
@@ -312,7 +312,7 @@ BrResult ipc_component_request(IpcComponent *self, IpcCap to, BrMsg *req, BrMsg
fiber_block((FiberBlocker){
.function = wait_pending,
.context = pending,
- .deadline = TIME_TIMEOUT_INFINITY,
+ .deadline = END_OF_TIME,
});
*resp = pending->resp;
diff --git a/sources/libs/json/emit.c b/sources/libs/json/emit.c
index 03326010..1c62c823 100644
--- a/sources/libs/json/emit.c
+++ b/sources/libs/json/emit.c
@@ -3,19 +3,19 @@
void json_emit_string(Str str, Emit *emit)
{
- emit_fmt(emit, "\"");
+ emit_fmt$(emit, "\"");
for (size_t i = 0; i < str.len; i++)
{
if (str.buf[i] == '"')
{
- emit_fmt(emit, "\\");
+ emit_fmt$(emit, "\\");
}
- emit_fmt(emit, "{c}", str.buf[i]);
+ emit_fmt$(emit, "{c}", str.buf[i]);
}
- emit_fmt(emit, "\"");
+ emit_fmt$(emit, "\"");
}
void json_emit(Json const json, Emit *emit)
@@ -26,27 +26,27 @@ void json_emit(Json const json, Emit *emit)
switch (json.type)
{
case JSON_NULL:
- emit_fmt(emit, "null");
+ emit_fmt$(emit, "null");
break;
case JSON_TRUE:
- emit_fmt(emit, "true");
+ emit_fmt$(emit, "true");
break;
case JSON_FALSE:
- emit_fmt(emit, "false");
+ emit_fmt$(emit, "false");
break;
case JSON_ARRAY:
- emit_fmt(emit, "[");
+ emit_fmt$(emit, "[");
emit_ident(emit);
vec_foreach_v(el, &json.array)
{
if (!first)
{
- emit_fmt(emit, ",");
+ emit_fmt$(emit, ",");
}
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
json_emit(el, emit);
@@ -56,27 +56,27 @@ void json_emit(Json const json, Emit *emit)
if (any)
{
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
emit_deident(emit);
- emit_fmt(emit, "]");
+ emit_fmt$(emit, "]");
break;
case JSON_OBJECT:
- emit_fmt(emit, "{{");
+ emit_fmt$(emit, "{{");
emit_ident(emit);
map_foreach(k, v, &json.object)
{
if (!first)
{
- emit_fmt(emit, ",");
+ emit_fmt$(emit, ",");
}
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
json_emit_string(k, emit);
- emit_fmt(emit, ": ");
+ emit_fmt$(emit, ": ");
json_emit(v, emit);
first = false;
@@ -85,11 +85,11 @@ void json_emit(Json const json, Emit *emit)
if (any)
{
- emit_fmt(emit, "\n");
+ emit_fmt$(emit, "\n");
}
emit_deident(emit);
- emit_fmt(emit, "}}");
+ emit_fmt$(emit, "}}");
break;
case JSON_STRING:
@@ -97,7 +97,7 @@ void json_emit(Json const json, Emit *emit)
break;
case JSON_NUMBER:
- emit_fmt(emit, "{}", json.number);
+ emit_fmt$(emit, "{}", json.number);
break;
default:
diff --git a/sources/loader/main.c b/sources/loader/main.c
index 413c40ac..cb753abf 100644
--- a/sources/loader/main.c
+++ b/sources/loader/main.c
@@ -15,7 +15,7 @@ void __chkstk() { return; }
void loader_splash(void)
{
- print(io_chan_out(), "Brutal boot\n");
+ io_print$(io_chan_out(), "Brutal boot\n");
}
void loader_load(Elf64Header const *elf_header, void *base, VmmSpace vmm)
@@ -33,9 +33,9 @@ void loader_load(Elf64Header const *elf_header, void *base, VmmSpace vmm)
mem_cpy(mem_phys_segment, file_segment, prog_header->file_size);
mem_set(mem_phys_segment + prog_header->file_size, 0, prog_header->memory_size - prog_header->file_size);
memory_map_range(vmm, (VmmRange){
- .base = prog_header->virtual_address,
- .size = align_up$(prog_header->memory_size, PAGE_SIZE),
- },
+ .base = prog_header->virtual_address,
+ .size = align_up$(prog_header->memory_size, PAGE_SIZE),
+ },
(PmmRange){
.base = (uintptr_t)mem_phys_segment,
.size = align_up$(prog_header->memory_size, PAGE_SIZE),
@@ -86,9 +86,9 @@ Handover *allocate_handover(VmmSpace vmm)
uintptr_t handover_copy_phys = kernel_module_phys_alloc_page((sizeof(Handover) / PAGE_SIZE) + 1);
memory_map_range(vmm, (VmmRange){
- .base = handover_copy_phys + MMAP_KERNEL_BASE,
- .size = align_up$(sizeof(Handover), PAGE_SIZE),
- },
+ .base = handover_copy_phys + MMAP_KERNEL_BASE,
+ .size = align_up$(sizeof(Handover), PAGE_SIZE),
+ },
(PmmRange){
.base = handover_copy_phys,
.size = align_up$(sizeof(Handover), PAGE_SIZE),
@@ -112,7 +112,7 @@ void loader_boot(LoaderEntry const *entry)
efi_deinit();
memory_switch(vmm);
- entry_point(((void*)handover) + MMAP_KERNEL_BASE , 0xC001B001);
+ entry_point(((void *)handover) + MMAP_KERNEL_BASE, 0xC001B001);
panic$("entry_point should no return!");
}
diff --git a/sources/srvs/wm/server.c b/sources/srvs/wm/server.c
index 8463da76..13ad7340 100644
--- a/sources/srvs/wm/server.c
+++ b/sources/srvs/wm/server.c
@@ -55,7 +55,7 @@ static void *wm_render_fiber(void *ctx)
wm_server_render(self);
}
- fiber_sleep(16);
+ fiber_sleep_until(16);
}
return nullptr;
diff --git a/sources/utils/cc/main.c b/sources/utils/cc/main.c
index 8a7884a6..6733e364 100644
--- a/sources/utils/cc/main.c
+++ b/sources/utils/cc/main.c
@@ -45,30 +45,30 @@ int main(int argc, char const *argv[])
Emit emit;
emit_init(&emit, io_chan_out());
- emit_fmt(&emit, "\n");
+ emit_fmt$(&emit, "\n");
- emit_fmt(&emit, "--- BEGIN OG CODE ---\n");
- emit_fmt(&emit, "{}\n", buf_str(&source_buf));
- emit_fmt(&emit, "--- END OG CODE ---\n");
+ emit_fmt$(&emit, "--- BEGIN OG CODE ---\n");
+ emit_fmt$(&emit, "{}\n", buf_str(&source_buf));
+ emit_fmt$(&emit, "--- END OG CODE ---\n");
- emit_fmt(&emit, "\n");
- emit_fmt(&emit, "\n");
+ emit_fmt$(&emit, "\n");
+ emit_fmt$(&emit, "\n");
emit_ident_size(&emit, 2);
- emit_fmt(&emit, "--- BEGIN AST ---\n");
+ emit_fmt$(&emit, "--- BEGIN AST ---\n");
Json json = cdump_unit(unit, base$(&heap));
json_emit(json, &emit);
- emit_fmt(&emit, "--- END AST ---\n");
+ emit_fmt$(&emit, "--- END AST ---\n");
- emit_fmt(&emit, "\n");
- emit_fmt(&emit, "\n");
+ emit_fmt$(&emit, "\n");
+ emit_fmt$(&emit, "\n");
emit_ident_size(&emit, 4);
- emit_fmt(&emit, "--- BEGIN CODE ---\n");
+ emit_fmt$(&emit, "--- BEGIN CODE ---\n");
cc_trans_unit(&emit, unit);
- emit_fmt(&emit, "--- END CODE ---\n");
- emit_fmt(&emit, "\n");
+ emit_fmt$(&emit, "--- END CODE ---\n");
+ emit_fmt$(&emit, "\n");
heap_alloc_deinit(&heap);
diff --git a/sources/utils/fstools/main.c b/sources/utils/fstools/main.c
index a55ee1f0..658bfe24 100644
--- a/sources/utils/fstools/main.c
+++ b/sources/utils/fstools/main.c
@@ -82,7 +82,7 @@ Emit emit;
Iter file_block_dump(Ext2FsFile *file, void *ctx)
{
emit_ident(&emit);
- emit_fmt(&emit, "- founded file: {}\n", file->name);
+ emit_fmt$(&emit, "- founded file: {}\n", file->name);
if (!str_eq(file->name, str$(".")) && !str_eq(file->name, str$("..")))
{
ext2_fs_iter(ctx, &file->inode, (Ext2IterFileFn *)file_block_dump, ctx);