aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/codegen.c3
-rw-r--r--src/parser.c46
-rw-r--r--src/parser.h8
-rw-r--r--src/types.h2
4 files changed, 23 insertions, 36 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 4f10e61..d0f90bb 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -8,8 +8,7 @@
#include "alloc.h"
#include "codegen.h"
#include "errors.h"
-
-#define AST_EMPTY ((size_t)-1)
+#include "parser.h"
static size_t codegenstmt(LLVMBuilderRef, struct ast_soa, struct lexemes_soa,
size_t);
diff --git a/src/parser.c b/src/parser.c
index 3ba9c79..39f38a6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -12,10 +12,9 @@
/* #define AST_DFLT_CAP (2048) */
#define AST_DFLT_CAP (8)
-#define AST_EMPTY ((size_t)-1)
#define SIZE_WDTH (sizeof(size_t) * CHAR_BIT)
-typedef size_t parsefn(struct ast_soa *, struct lexemes_soa);
+typedef idx_t_ parsefn(struct ast_soa *, struct lexemes_soa);
static parsefn parseblk,
parsedecl,
parseexpr,
@@ -23,11 +22,10 @@ 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 size_t ast_alloc(struct ast_soa *);
-
static size_t toksidx;
struct ast_soa
@@ -44,10 +42,10 @@ parsetoks(struct lexemes_soa toks)
return ast;
}
-size_t
+idx_t_
parseblk(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i = ast_alloc(ast);
+ idx_t_ i = ast_alloc(ast);
ast->lexemes[i] = toksidx;
ast->kinds[i] = ASTBLK;
ast->kids[i].lhs = ast->kids[i].rhs = AST_EMPTY;
@@ -65,10 +63,10 @@ parseblk(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-size_t
+idx_t_
parsedecl(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i = ast_alloc(ast);
+ idx_t_ i = ast_alloc(ast);
ast->lexemes[i] = toksidx;
if (toks.kinds[toksidx++] != LEXIDENT)
@@ -104,10 +102,10 @@ parsedecl(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-size_t
+idx_t_
parseexpr(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i = ast_alloc(ast);
+ idx_t_ i = ast_alloc(ast);
ast->lexemes[i] = toksidx;
switch (toks.kinds[toksidx]) {
@@ -127,10 +125,10 @@ parseexpr(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-size_t
+idx_t_
parseproto(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i = ast_alloc(ast);
+ idx_t_ i = ast_alloc(ast);
ast->lexemes[i] = toksidx;
ast->kinds[i] = ASTFNPROTO;
ast->kids[i].lhs = AST_EMPTY;
@@ -146,10 +144,10 @@ parseproto(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-size_t
+idx_t_
parsestmt(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i;
+ idx_t_ i;
if (toks.kinds[toksidx] != LEXIDENT)
err("parser: Expected identifier");
@@ -173,10 +171,10 @@ parsestmt(struct ast_soa *ast, struct lexemes_soa toks)
return i;
}
-size_t
+idx_t_
parsetype(struct ast_soa *ast, struct lexemes_soa toks)
{
- size_t i = ast_alloc(ast);
+ idx_t_ i = ast_alloc(ast);
ast->kinds[i] = ASTTYPE;
ast->lexemes[i] = toksidx;
@@ -254,24 +252,10 @@ ast_soa_resz(struct ast_soa *soa)
soa->cap = ncap;
}
-size_t
+idx_t_
ast_alloc(struct ast_soa *soa)
{
if (soa->len == soa->cap)
ast_soa_resz(soa);
return soa->len++;
}
-
-/* size_t */
-/* ast_soa_push(struct ast_soa *soa, ast_kind kind, size_t lexeme, size_t lhs, */
-/* size_t rhs) */
-/* { */
-/* if (soa->len == soa->cap) */
-/* ast_soa_resz(soa); */
-/**/
-/* soa->kinds[soa->len] = kind; */
-/* soa->lexemes[soa->len] = lexeme; */
-/* soa->kids[soa->len].lhs = lhs; */
-/* soa->kids[soa->len].rhs = rhs; */
-/* return soa->len++; */
-/* } */
diff --git a/src/parser.h b/src/parser.h
index 62f557b..5398162 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -6,6 +6,7 @@
#include <stdint.h>
#include "lexer.h"
+#include "types.h"
enum {
/* Variable declaration, lhs and rhs may be unused
@@ -47,13 +48,14 @@ enum {
typedef uint8_t ast_kind;
-#define AST_SOA_BLKSZ (sizeof(ast_kind) + sizeof(size_t) * 4)
+#define AST_EMPTY ((idx_t_)-1)
+#define AST_SOA_BLKSZ (sizeof(ast_kind) + sizeof(idx_t_) * 3)
struct ast_soa {
ast_kind *kinds;
- size_t *lexemes;
+ idx_t_ *lexemes;
struct {
- size_t lhs, rhs;
+ idx_t_ lhs, rhs;
} *kids;
size_t len, cap;
};
diff --git a/src/types.h b/src/types.h
index c784b26..34441b5 100644
--- a/src/types.h
+++ b/src/types.h
@@ -2,8 +2,10 @@
#define ORYX_TYPES_H
#include <stddef.h>
+#include <stdint.h>
typedef unsigned char uchar;
+typedef uint32_t idx_t_;
struct strview {
const uchar *p;