Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax authored and Supercip971 committed May 22, 2022
1 parent e638601 commit 299736a
Show file tree
Hide file tree
Showing 90 changed files with 1,562 additions and 1,571 deletions.
4 changes: 2 additions & 2 deletions sources/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ BrResult syscall_dispatch(BrSyscall syscall, BrArg args)
{
log$("Syscall: Task({}): {}({#p}) -> {}",
task_self()->id,
str$(br_syscall_to_string(syscall)),
str$(br_syscall_to_str(syscall)),
args,
str$(br_result_to_string(result)));
str$(br_result_to_str(result)));
}

task_end_syscall();
Expand Down
4 changes: 2 additions & 2 deletions sources/libs/bal/abi/helpers.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <bal/abi/helpers.h>
#include <brutal-debug/log.h>

char const *br_syscall_to_string(BrSyscall syscall)
char const *br_syscall_to_str(BrSyscall syscall)
{
static char const *SYSCALL_NAMES[] = {
#define ITER(SYSCALL) #SYSCALL,
Expand All @@ -17,7 +17,7 @@ char const *br_syscall_to_string(BrSyscall syscall)
return SYSCALL_NAMES[syscall];
}

char const *br_result_to_string(BrResult result)
char const *br_result_to_str(BrResult result)
{
static char const *RESULT_NAMES[] = {
#define ITER(RESULT) #RESULT,
Expand Down
4 changes: 2 additions & 2 deletions sources/libs/bal/abi/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <bal/abi/types.h>

char const *br_syscall_to_string(BrSyscall syscall);
char const *br_syscall_to_str(BrSyscall syscall);

char const *br_result_to_string(BrResult result);
char const *br_result_to_str(BrResult result);

Error br_result_to_error(BrResult result);

Expand Down
28 changes: 17 additions & 11 deletions sources/libs/brutal-base/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@

typedef struct
{
void const *buf;
size_t len;

size_t size;
void const *buf;
} SliceImpl;

#define slice_impl$(SLICE) \
(SliceImpl) { .len = (SLICE).len, .size = sizeof(*(SLICE).buf), .buf = (SLICE).buf, }

#define InlineBuf(T) \
struct \
{ \
size_t len; \
T buf[]; \
}

#define Slice(T) \
struct \
{ \
size_t len; \
T const *buf; \
size_t len; \
}

typedef Slice(void) VoidSlice;

#define slice$(type, buffer, size) \
(type) { .len = size, .buf = buffer }
(type) { .buf = buffer, .len = size }

#define slice_array$(type, buffer) \
(type) { .len = sizeof(buffer) / sizeof(*buffer), .buf = &(buffer) }
(type) { .buf = (buffer), .len = sizeof(buffer) / sizeof(*buffer), }

#define slice_begin$(SLICE) ((SLICE).buf)

#define slice_end$(SLICE) ((SLICE).buf + (SLICE).len)

#define slice_foreach$(VAR, SELF) \
if ((SELF).len) \
for (typeof((SELF).buf) VAR = slice_begin$(SELF); VAR != slice_end$(SELF); VAR++)

#define slice_foreach_rev$(VAR, SELF) \
if ((SELF).len) \
for (typeof((SELF).buf) VAR = slice_end$(SELF) - 1; VAR >= slice_begin$(SELF); VAR--)
16 changes: 8 additions & 8 deletions sources/libs/brutal-debug/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
} \
})

#define assert_br_success(EXPR) ( \
{ \
BrResult __value = (EXPR); \
\
if (UNLIKELY(__value != BR_SUCCESS)) \
{ \
panic$("{} is not equal to BR_SUCCESS (but is equal to: '{}') ", #EXPR, br_result_to_string(__value)); \
} \
#define assert_br_success(EXPR) ( \
{ \
BrResult __value = (EXPR); \
\
if (UNLIKELY(__value != BR_SUCCESS)) \
{ \
panic$("{} is not equal to BR_SUCCESS (but is equal to: '{}') ", #EXPR, br_result_to_str(__value)); \
} \
})

#define assert_falsity(EXPR) ( \
Expand Down
4 changes: 4 additions & 0 deletions sources/libs/brutal-ds/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ void vec_swap_impl(VecImpl *impl, int idx1, int idx2);
if ((SELF)->len) \
for (typeof((SELF)->data) VAR = vec_begin(SELF); VAR != vec_end(SELF); VAR++)

#define vec_foreach_rev(VAR, SELF) \
if ((SELF)->len) \
for (typeof((SELF)->data) VAR = vec_end(SELF) - 1; VAR >= vec_begin(SELF); VAR--)

#define vec_foreach_idx(IDX, VAR, SELF) \
if ((SELF)->len) \
for (int IDX = 0; IDX < (SELF)->len; IDX++) \
Expand Down
14 changes: 14 additions & 0 deletions sources/libs/brutal-parse/lex.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,17 @@ bool lex_ok(Lex *self)
{
return !self->has_error;
}

SrcRef clex_src_ref(Lex *lex, int begin, int end)
{
Lexeme first = lex->lexemes.data[begin];
Lexeme last = lex->lexemes.data[end];

SrcRef cref = {
.begin = first.pos.begin,
.end = last.pos.end,
.translation_unit = first.pos.translation_unit,
};

return cref;
}
2 changes: 2 additions & 0 deletions sources/libs/brutal-parse/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ void lex_throw(Lex *self, Str message);
bool lex_expect(Lex *self, LexemeType type);

bool lex_ok(Lex *self);

SrcRef lex_src_ref(Lex *lex, int begin, int end);
12 changes: 6 additions & 6 deletions sources/libs/brutal-parse/nums.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,26 @@ bool scan_next_double(Scan *self, double *value)

#endif

bool str_to_uint(Str string, unsigned long *value)
bool str_to_uint(Str str, unsigned long *value)
{
Scan scan = {0};
scan_init(&scan, string);
scan_init(&scan, str);
return scan_next_uint(&scan, value);
}

bool str_to_int(Str string, long *value)
bool str_to_int(Str str, long *value)
{
Scan scan = {0};
scan_init(&scan, string);
scan_init(&scan, str);
return scan_next_int(&scan, value);
}

#ifndef __freestanding__

bool str_to_float(Str string, double *value)
bool str_to_float(Str str, double *value)
{
Scan scan = {0};
scan_init(&scan, string);
scan_init(&scan, str);
return scan_next_double(&scan, value);
}

Expand Down
6 changes: 3 additions & 3 deletions sources/libs/brutal-parse/nums.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ bool scan_next_double(Scan *self, double *value);

#endif

bool str_to_uint(Str string, unsigned long *value);
bool str_to_uint(Str str, unsigned long *value);

bool str_to_int(Str string, long *value);
bool str_to_int(Str str, long *value);

#ifndef __freestanding__

bool str_to_float(Str string, double *value);
bool str_to_float(Str str, double *value);

#endif
28 changes: 28 additions & 0 deletions sources/libs/brutal-parse/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ bool scan_skip_word(Scan *self, Str word)
return true;
}

bool scan_skip_word_nc(Scan *self, Str word)
{
for (size_t i = 0; i < word.len; i++)
{
if (tolower(scan_peek(self, i)) != tolower(word.buf[i]))
{
return false;
}
}

scan_next_n(self, word.len);
return true;
}

bool scan_skip_any(Scan *self, Str chars)
{
for (size_t i = 0; i < chars.len; i++)
Expand All @@ -162,6 +176,20 @@ bool scan_skip_match(Scan *self, ScanMatch *match)
return true;
}

bool scan_skip_any_nc(Scan *self, Str chars)
{
for (size_t i = 0; i < chars.len; i++)
{
if (tolower(scan_curr(self)) == tolower(chars.buf[i]))
{
scan_next(self);
return true;
}
}

return false;
}

bool scan_eat(Scan *self, ScanMatch *match)
{
bool result = false;
Expand Down
6 changes: 6 additions & 0 deletions sources/libs/brutal-parse/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ bool scan_skip(Scan *self, char c);

bool scan_skip_word(Scan *self, Str word);

bool scan_skip_word_nc(Scan *self, Str word);

bool scan_skip_any(Scan *self, Str chars);

bool scan_skip_match(Scan *self, ScanMatch *match);

bool scan_skip_any_nc(Scan *self, Str chars);

Str scan_skip_until(Scan *self, ScanMatch *match);

bool scan_skip_space(Scan *self);

bool scan_eat(Scan *self, ScanMatch *match);
Expand Down
7 changes: 3 additions & 4 deletions sources/libs/cc/ast/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

typedef enum
{
CDECL_NIL,

CDECL_EMPTY,

CDECL_TYPE,
CDECL_VAR,
CDECL_FUNC,
Expand All @@ -34,12 +33,12 @@ typedef struct

typedef struct _CDecl
{
CRef ref;
SrcRef ref;
CDeclType type;
CDeclAttr attr;
Str name;
CType sema_type;
bool global;

union
{
struct
Expand Down
Loading

0 comments on commit 299736a

Please sign in to comment.