aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2025-05-02 15:41:38 +0200
committerHimbeer <himbeer@disroot.org>2025-05-02 15:41:38 +0200
commitc640c9856b499af2ed5faedbf03e9945d74aafa9 (patch)
tree1d8bef9308091af429013d80a3a9b1a9aa6cd9c2
parent45bd094ceefe590be759993946fb3c9e84eab910 (diff)
Remove mut, import, export, enum
-rw-r--r--include/lex.h6
-rw-r--r--src/check.c27
-rw-r--r--src/lex.c6
-rw-r--r--src/parse.c119
4 files changed, 5 insertions, 153 deletions
diff --git a/include/lex.h b/include/lex.h
index c42dc4b..a339878 100644
--- a/include/lex.h
+++ b/include/lex.h
@@ -13,20 +13,18 @@ enum lexical_token {
T_CONTINUE,
T_DEFER,
T_ELSE,
- T_ENUM,
- T_EXPORT,
T_EXTERN,
T_FALSE,
T_FOR,
T_FUNC,
T_IF,
- T_IMPORT,
+ T_INCLUDE,
T_LET,
- T_MUT,
T_RETURN,
T_STRUCT,
T_TRUE,
T_UNION,
+ T_VAR,
T_LAST_KEYWORD,
// Builtin types
diff --git a/src/check.c b/src/check.c
index 10ba2bf..e1a7187 100644
--- a/src/check.c
+++ b/src/check.c
@@ -24,32 +24,6 @@ error(struct location loc, const char *fmt, ...)
}
static void
-check_import(struct ast_import *imports, int i)
-{
- for (int j = 0; j < i; ++j) {
- if (j == i) {
- continue;
- }
-
- if (!strcmp(imports[j].name, imports[i].name)) {
- error(imports[i].loc,
- "import collision (previous import at %s:%d:%d)",
- imports[j].loc.file,
- imports[j].loc.line,
- imports[j].loc.column);
- }
- }
-}
-
-static void
-check_imports(struct ast_import *imports, int n)
-{
- for (int i = 0; i < n; ++i) {
- check_import(imports, i);
- }
-}
-
-static void
check_toplevels(struct ast_toplevel *tops, int n)
{
/* TODO */
@@ -58,6 +32,5 @@ check_toplevels(struct ast_toplevel *tops, int n)
void
check(struct ast_unit *ast)
{
- check_imports(ast->imports, ast->implen);
check_toplevels(ast->tops, ast->toplen);
}
diff --git a/src/lex.c b/src/lex.c
index 169a1c0..974327b 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -15,20 +15,18 @@ const char *tokens[] = {
[T_CONTINUE] = "continue",
[T_DEFER] = "defer",
[T_ELSE] = "else",
- [T_ENUM] = "enum",
- [T_EXPORT] = "export",
[T_EXTERN] = "extern",
[T_FALSE] = "false",
[T_FOR] = "for",
[T_FUNC] = "func",
[T_IF] = "if",
- [T_IMPORT] = "import",
+ [T_INCLUDE] = "include",
[T_LET] = "let",
- [T_MUT] = "mut",
[T_RETURN] = "return",
[T_STRUCT] = "struct",
[T_TRUE] = "true",
[T_UNION] = "union",
+ [T_VAR] = "var",
[T_BOOL] = "bool",
[T_FLOAT32] = "float32",
diff --git a/src/parse.c b/src/parse.c
index c5ced09..86035cb 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -692,32 +692,6 @@ parse_expr(struct lexer *lexer, struct ast_expr *out)
}
static bool
-parse_import(struct lexer *lexer, struct ast_import *out)
-{
- if (!match(lexer, T_IMPORT)) {
- return false;
- }
-
- if (!parse_path(lexer, &out->path)) {
- error(lex_loc(lexer), "syntax error: expected import path");
- }
-
- struct token token;
- if (lex(lexer, &token) == T_NAME) {
- out->name = token.info.str;
- } else {
- unlex(lexer, &token);
- out->name = out->path.segments[out->path.seglen - 1];
- }
-
- if (!match(lexer, T_SEMICOLON)) {
- error(lex_loc(lexer), "syntax error: expected semicolon");
- }
-
- return true;
-}
-
-static bool
parse_integer(struct lexer *lexer, struct type *out)
{
struct token token;
@@ -852,78 +826,6 @@ parse_struct(struct lexer *lexer, struct type *out)
return true;
}
-static bool
-parse_enum(struct lexer *lexer, struct type *out)
-{
- if (!match(lexer, T_ENUM)) {
- return false;
- }
-
- out->kind = TYP_ENUM;
- // Default tag type is uint
- out->desc.en.tag_type = malloc(sizeof(struct type));
- out->desc.en.tag_type->kind = TYP_INT;
- out->desc.en.tag_type->desc.i.sign = false;
- out->desc.en.tag_type->desc.i.bits = PLATBITS;
-
- if (match(lexer, T_LPAREN)) {
- if (!parse_type(lexer, out->desc.en.tag_type)) {
- error(lex_loc(lexer),
- "syntax error: expected tag type");
- }
-
- if (!match(lexer, T_RPAREN)) {
- error(lex_loc(lexer), "syntax error: expected ')'");
- }
- }
-
- struct disjunction_e init;
- if (match(lexer, T_ASSIGN)) {
- if (!parse_disjunction_e(lexer, &init)) {
- error(lex_loc(lexer),
- "syntax error: expected expression");
- }
- }
-
- if (!match(lexer, T_LBRACE)) {
- error(lex_loc(lexer), "syntax error: expected '{'");
- }
-
- out->desc.en.variants = must_calloc(1, sizeof(struct variant));
- out->desc.en.variantsz = 1;
- out->desc.en.variantlen = 0;
-
- struct token name;
- uint64_t tag = 0;
- bool commabreak = false;
- while (lex(lexer, &name) == T_NAME) {
- if (out->desc.en.variantlen >= out->desc.en.variantsz) {
- out->desc.en.variantsz *= 2;
- size_t sz = sizeof(struct variant) *
- out->desc.en.variantsz;
- out->desc.en.variants = must_realloc(
- out->desc.en.variants, sz);
- }
- out->desc.en.variants[out->desc.en.variantlen].name =
- name.info.str;
- out->desc.en.variants[out->desc.en.variantlen++].tag = tag++;
-
- if (!match(lexer, T_COMMA)) {
- commabreak = true;
- break;
- }
- }
- if (!commabreak) {
- unlex(lexer, &name);
- }
-
- if (!match(lexer, T_RBRACE)) {
- error(lex_loc(lexer), "syntax error: expected '}'");
- }
-
- return true;
-}
-
static bool parse_union(struct lexer *lexer, struct type *out)
{
if (!match(lexer, T_UNION)) {
@@ -1043,9 +945,6 @@ parse_type(struct lexer *lexer, struct type *out)
if (parse_struct(lexer, out)) {
return true;
}
- if (parse_enum(lexer, out)) {
- return true;
- }
if (parse_union(lexer, out)) {
return true;
}
@@ -1186,11 +1085,7 @@ parse_declaration(struct lexer *lexer, struct ast_declaration *out)
return false;
}
- if (match(lexer, T_MUT)) {
- out->mut = true;
- } else {
- out->mut = false;
- }
+ out->mut = false;
struct token name;
if (lex(lexer, &name) != T_NAME) {
@@ -1448,8 +1343,6 @@ parse_function(struct lexer *lexer, struct ast_func *out)
out->paramsz = 1;
out->paramlen = 0;
- out->exported = match(lexer, T_EXPORT);
-
if (!match(lexer, T_FUNC)) {
if (out->exported) {
error(lex_loc(lexer),
@@ -1636,16 +1529,6 @@ parse(struct lexer *lexer, struct ast_unit *ast)
ast->topsz = 1;
ast->toplen = 0;
- struct ast_import import;
- while (parse_import(lexer, &import)) {
- if (ast->implen >= ast->impsz) {
- ast->impsz *= 2;
- size_t sz = sizeof(struct ast_import) * ast->impsz;
- ast->imports = must_realloc(ast->imports, sz);
- }
- ast->imports[ast->implen++] = import;
- }
-
struct ast_toplevel top;
while (parse_toplevel(lexer, &top)) {
if (ast->toplen >= ast->topsz) {