aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/codegen.c14
-rw-r--r--src/codegen.h2
-rw-r--r--src/lexer.c34
-rw-r--r--src/lexer.h6
-rw-r--r--src/main.c4
-rw-r--r--src/parser.c52
-rw-r--r--src/parser.h4
7 files changed, 57 insertions, 59 deletions
diff --git a/src/codegen.c b/src/codegen.c
index d0f90bb..abdf311 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -10,14 +10,14 @@
#include "errors.h"
#include "parser.h"
-static size_t codegenstmt(LLVMBuilderRef, struct ast_soa, struct lexemes_soa,
+static size_t codegenstmt(LLVMBuilderRef, struct ast, struct lexemes,
size_t);
-static size_t codegenexpr(LLVMBuilderRef, struct ast_soa, struct lexemes_soa,
+static size_t codegenexpr(LLVMBuilderRef, struct ast, struct lexemes,
size_t, LLVMValueRef *)
__attribute__((nonnull));
void
-codegen(struct ast_soa ast, struct lexemes_soa toks)
+codegen(struct ast ast, struct lexemes toks)
{
LLVMModuleRef mod = LLVMModuleCreateWithName("oryx");
@@ -29,8 +29,7 @@ codegen(struct ast_soa ast, struct lexemes_soa toks)
if (ast.kinds[expr] != ASTFN)
assert(!"not implemented");
- size_t proto = ast.kids[expr].lhs,
- body = ast.kids[expr].rhs;
+ size_t proto = ast.kids[expr].lhs, body = ast.kids[expr].rhs;
LLVMTypeRef ret;
LLVMTypeRef params[] = {0};
@@ -46,7 +45,6 @@ codegen(struct ast_soa ast, struct lexemes_soa toks)
ret = LLVMInt64Type();
else
err("codegen: Unknown type: %.*s", (int)sv.len, sv.p);
-
}
LLVMTypeRef fnproto = LLVMFunctionType(ret, params, 0, false);
@@ -76,7 +74,7 @@ codegen(struct ast_soa ast, struct lexemes_soa toks)
}
size_t
-codegenstmt(LLVMBuilderRef builder, struct ast_soa ast, struct lexemes_soa toks,
+codegenstmt(LLVMBuilderRef builder, struct ast ast, struct lexemes toks,
size_t i)
{
switch (ast.kinds[i]) {
@@ -95,7 +93,7 @@ codegenstmt(LLVMBuilderRef builder, struct ast_soa ast, struct lexemes_soa toks,
}
size_t
-codegenexpr(LLVMBuilderRef builder, struct ast_soa ast, struct lexemes_soa toks,
+codegenexpr(LLVMBuilderRef builder, struct ast ast, struct lexemes toks,
size_t i, LLVMValueRef *v)
{
(void)builder;
diff --git a/src/codegen.h b/src/codegen.h
index 79f3ad7..517b94d 100644
--- a/src/codegen.h
+++ b/src/codegen.h
@@ -4,6 +4,6 @@
#include "lexer.h"
#include "parser.h"
-void codegen(struct ast_soa ast, struct lexemes_soa toks);
+void codegen(struct ast ast, struct lexemes toks);
#endif /* !ORYX_CODEGEN_H */
diff --git a/src/lexer.c b/src/lexer.c
index 67ec212..400d1e4 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -18,8 +18,8 @@
static bool skip_comment(const uchar **, const uchar *);
-static struct lexemes_soa mk_lexemes_soa(void);
-static void lexemes_soa_resz(struct lexemes_soa *);
+static struct lexemes mklexemes(void);
+static void lexemesresz(struct lexemes *);
static const bool is_numeric_lookup[UCHAR_MAX + 1] = {
['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true,
@@ -27,7 +27,7 @@ static const bool is_numeric_lookup[UCHAR_MAX + 1] = {
['8'] = true, ['9'] = true, ['\''] = true,
};
-struct lexemes_soa
+struct lexemes
lexstring(const uchar *code, size_t codesz)
{
#if ORYX_SIMD
@@ -42,7 +42,7 @@ lexstring(const uchar *code, size_t codesz)
}
#endif
- struct lexemes_soa data = mk_lexemes_soa();
+ struct lexemes data = mklexemes();
const uchar *start = code, *end = start + codesz;
while (likely(code < end)) {
@@ -118,11 +118,11 @@ lexstring(const uchar *code, size_t codesz)
}
if (unlikely(data.len == data.cap))
- lexemes_soa_resz(&data);
+ lexemesresz(&data);
}
if (unlikely(data.len == data.cap))
- lexemes_soa_resz(&data);
+ lexemesresz(&data);
data.kinds[data.len++] = LEXEOF;
return data;
}
@@ -153,13 +153,13 @@ out:
return true;
}
-struct lexemes_soa
-mk_lexemes_soa(void)
+struct lexemes
+mklexemes(void)
{
- struct lexemes_soa soa;
+ struct lexemes soa;
- static_assert(offsetof(struct lexemes_soa, kinds)
- < offsetof(struct lexemes_soa, strs),
+ static_assert(offsetof(struct lexemes, kinds)
+ < offsetof(struct lexemes, strs),
"KINDS is not the first field before STRS");
static_assert(LEXEMES_DFLT_CAP * sizeof(*soa.kinds) % alignof(*soa.strs)
== 0,
@@ -167,17 +167,17 @@ mk_lexemes_soa(void)
soa.len = 0;
soa.cap = LEXEMES_DFLT_CAP;
- soa.kinds = bufalloc(NULL, soa.cap, LEXEMES_SOA_BLKSZ);
+ soa.kinds = bufalloc(NULL, soa.cap, LEXEMES_BLKSZ);
soa.strs = (void *)((char *)soa.kinds + soa.cap * sizeof(*soa.kinds));
return soa;
}
void
-lexemes_soa_resz(struct lexemes_soa *soa)
+lexemesresz(struct lexemes *soa)
{
- static_assert(offsetof(struct lexemes_soa, kinds)
- < offsetof(struct lexemes_soa, strs),
+ static_assert(offsetof(struct lexemes, kinds)
+ < offsetof(struct lexemes, strs),
"KINDS is not the first field before STRS");
size_t ncap, pad, newsz;
@@ -187,7 +187,7 @@ lexemes_soa_resz(struct lexemes_soa *soa)
becomes pretty trivial */
if ((soa->cap >> (SIZE_WDTH - 1)) != 0) {
errno = EOVERFLOW;
- err("lexemes_soa_resz:");
+ err("%s:", __func__);
}
ncap = soa->cap << 1;
@@ -197,7 +197,7 @@ lexemes_soa_resz(struct lexemes_soa *soa)
if (pad == alignof(*soa->strs))
pad = 0;
- newsz = ncap * LEXEMES_SOA_BLKSZ + pad;
+ newsz = ncap * LEXEMES_BLKSZ + pad;
soa->kinds = bufalloc(soa->kinds, newsz, 1);
soa->strs = (void *)((char *)soa->kinds + ncap * sizeof(*soa->kinds) + pad);
diff --git a/src/lexer.h b/src/lexer.h
index edd9225..636237f 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -39,9 +39,9 @@ enum {
typedef uint8_t lexeme_kind_t_;
-#define LEXEMES_SOA_BLKSZ (sizeof(lexeme_kind_t_) + sizeof(struct strview))
+#define LEXEMES_BLKSZ (sizeof(lexeme_kind_t_) + sizeof(struct strview))
-struct lexemes_soa {
+struct lexemes {
lexeme_kind_t_ *kinds;
struct strview *strs;
size_t len, cap;
@@ -49,6 +49,6 @@ struct lexemes_soa {
#define lexemes_free(x) free((x).kinds)
-struct lexemes_soa lexstring(const uchar *, size_t);
+struct lexemes lexstring(const uchar *, size_t);
#endif /* !ORYX_LEXER_H */
diff --git a/src/main.c b/src/main.c
index f3f354c..ca1d2f3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,8 +24,8 @@ main(int argc, char **argv)
size_t srclen;
char *src = readfile(argv[1], &srclen);
- struct lexemes_soa toks = lexstring(src, srclen);
- struct ast_soa ast = parsetoks(toks);
+ struct lexemes toks = lexstring(src, srclen);
+ struct ast ast = parsetoks(toks);
codegen(ast, toks);
#if DEBUG
diff --git a/src/parser.c b/src/parser.c
index 39f38a6..d194bac 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -14,7 +14,7 @@
#define AST_DFLT_CAP (8)
#define SIZE_WDTH (sizeof(size_t) * CHAR_BIT)
-typedef idx_t_ parsefn(struct ast_soa *, struct lexemes_soa);
+typedef idx_t_ parsefn(struct ast *, struct lexemes);
static parsefn parseblk,
parsedecl,
parseexpr,
@@ -22,16 +22,16 @@ static parsefn parseblk,
parsestmt,
parsetype;
-static idx_t_ ast_alloc(struct ast_soa *);
-static struct ast_soa mk_ast_soa(void);
-static void ast_soa_resz(struct ast_soa *);
+static idx_t_ astalloc(struct ast *);
+static struct ast mkast(void);
+static void astresz(struct ast *);
static size_t toksidx;
-struct ast_soa
-parsetoks(struct lexemes_soa toks)
+struct ast
+parsetoks(struct lexemes toks)
{
- struct ast_soa ast = mk_ast_soa();
+ struct ast ast = mkast();
for (;;) {
parsedecl(&ast, toks);
@@ -43,9 +43,9 @@ parsetoks(struct lexemes_soa toks)
}
idx_t_
-parseblk(struct ast_soa *ast, struct lexemes_soa toks)
+parseblk(struct ast *ast, struct lexemes toks)
{
- idx_t_ i = ast_alloc(ast);
+ idx_t_ i = astalloc(ast);
ast->lexemes[i] = toksidx;
ast->kinds[i] = ASTBLK;
ast->kids[i].lhs = ast->kids[i].rhs = AST_EMPTY;
@@ -64,9 +64,9 @@ parseblk(struct ast_soa *ast, struct lexemes_soa toks)
}
idx_t_
-parsedecl(struct ast_soa *ast, struct lexemes_soa toks)
+parsedecl(struct ast *ast, struct lexemes toks)
{
- idx_t_ i = ast_alloc(ast);
+ idx_t_ i = astalloc(ast);
ast->lexemes[i] = toksidx;
if (toks.kinds[toksidx++] != LEXIDENT)
@@ -103,9 +103,9 @@ parsedecl(struct ast_soa *ast, struct lexemes_soa toks)
}
idx_t_
-parseexpr(struct ast_soa *ast, struct lexemes_soa toks)
+parseexpr(struct ast *ast, struct lexemes toks)
{
- idx_t_ i = ast_alloc(ast);
+ idx_t_ i = astalloc(ast);
ast->lexemes[i] = toksidx;
switch (toks.kinds[toksidx]) {
@@ -126,9 +126,9 @@ parseexpr(struct ast_soa *ast, struct lexemes_soa toks)
}
idx_t_
-parseproto(struct ast_soa *ast, struct lexemes_soa toks)
+parseproto(struct ast *ast, struct lexemes toks)
{
- idx_t_ i = ast_alloc(ast);
+ idx_t_ i = astalloc(ast);
ast->lexemes[i] = toksidx;
ast->kinds[i] = ASTFNPROTO;
ast->kids[i].lhs = AST_EMPTY;
@@ -145,7 +145,7 @@ parseproto(struct ast_soa *ast, struct lexemes_soa toks)
}
idx_t_
-parsestmt(struct ast_soa *ast, struct lexemes_soa toks)
+parsestmt(struct ast *ast, struct lexemes toks)
{
idx_t_ i;
@@ -154,7 +154,7 @@ parsestmt(struct ast_soa *ast, struct lexemes_soa toks)
struct strview sv = toks.strs[toksidx];
if (strncmp("return", sv.p, sv.len) == 0) {
- i = ast_alloc(ast);
+ i = astalloc(ast);
ast->lexemes[i] = toksidx++;
ast->kinds[i] = ASTRET;
if (toks.kinds[toksidx] != LEXSEMI)
@@ -172,9 +172,9 @@ parsestmt(struct ast_soa *ast, struct lexemes_soa toks)
}
idx_t_
-parsetype(struct ast_soa *ast, struct lexemes_soa toks)
+parsetype(struct ast *ast, struct lexemes toks)
{
- idx_t_ i = ast_alloc(ast);
+ idx_t_ i = astalloc(ast);
ast->kinds[i] = ASTTYPE;
ast->lexemes[i] = toksidx;
@@ -184,10 +184,10 @@ parsetype(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-struct ast_soa
-mk_ast_soa(void)
+struct ast
+mkast(void)
{
- struct ast_soa soa;
+ struct ast soa;
static_assert(AST_DFLT_CAP * sizeof(*soa.kinds) % alignof(*soa.lexemes)
== 0,
@@ -208,7 +208,7 @@ mk_ast_soa(void)
}
void
-ast_soa_resz(struct ast_soa *soa)
+astresz(struct ast *soa)
{
size_t ncap, pad1, pad2, newsz;
ptrdiff_t lexemes_off, kids_off;
@@ -220,7 +220,7 @@ ast_soa_resz(struct ast_soa *soa)
becomes pretty trivial */
if ((soa->cap >> (SIZE_WDTH - 1)) != 0) {
errno = EOVERFLOW;
- err("ast_soa_resz:");
+ err("%s:", __func__);
}
ncap = soa->cap << 1;
@@ -253,9 +253,9 @@ ast_soa_resz(struct ast_soa *soa)
}
idx_t_
-ast_alloc(struct ast_soa *soa)
+astalloc(struct ast *soa)
{
if (soa->len == soa->cap)
- ast_soa_resz(soa);
+ astresz(soa);
return soa->len++;
}
diff --git a/src/parser.h b/src/parser.h
index c2bbac0..4fcdacd 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -51,7 +51,7 @@ typedef uint8_t ast_kind_t_;
#define AST_EMPTY ((idx_t_)-1)
#define AST_SOA_BLKSZ (sizeof(ast_kind_t_) + sizeof(idx_t_) * 3)
-struct ast_soa {
+struct ast {
ast_kind_t_ *kinds;
idx_t_ *lexemes;
struct {
@@ -63,6 +63,6 @@ struct ast_soa {
#define ast_free(x) free((x).kinds)
/* Parse the tokens in TOKS into an abstract syntax tree */
-struct ast_soa parsetoks(struct lexemes_soa toks);
+struct ast parsetoks(struct lexemes toks);
#endif /* !ORYX_PARSER_H */