aboutsummaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-16 01:20:33 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-05-16 01:20:33 +0330
commit42eb5e5d3f10c3a9187dcf8edd7c023a3ea10dcd (patch)
tree78862ab27c3b1faf2d9ed5722bceb0264602bd1a /src/compiler
parent0b8d272292ca3f7fdb44efac65f012b484d962a2 (diff)
fix access operator and some stuff to make break work
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/ast-tree.c7
-rw-r--r--src/compiler/lexer.c6
-rw-r--r--src/compiler/lexer.h2
-rw-r--r--src/compiler/parser.c2
-rw-r--r--src/compiler/parser.h1
5 files changed, 12 insertions, 6 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 57f0568..1d0613b 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -4765,9 +4765,7 @@ bool setTypesReturn(AstTree *tree, AstTreeSetTypesHelper _helper,
astTreeDelete(helper.lookingType);
return false;
}
- if (helper.lookingType != function->returnType) {
- astTreeDelete(helper.lookingType);
- }
+ astTreeDelete(helper.lookingType);
if (!typeIsEqual(metadata->value->type, function->returnType)) {
printError(tree->str_begin, tree->str_end, "Type mismatch");
return false;
@@ -5530,7 +5528,7 @@ bool setTypesOperatorAccess(AstTree *tree, AstTreeSetTypesHelper helper) {
"Member not found");
return false;
} else if (typeIsEqual(metadata->object->type, &AST_TREE_NAMESPACE_TYPE)) {
- AstTree *value = getValue(metadata->object, false);
+ AstTree *value = getValue(metadata->object, true);
AstTreeNamespace *namespace = value->metadata;
AstTreeSetTypesHelper newHelper = {
.root = helper.root->imports[namespace->importedIndex].root,
@@ -5539,6 +5537,7 @@ bool setTypesOperatorAccess(AstTree *tree, AstTreeSetTypesHelper helper) {
.dependencies = helper.dependencies,
.lookingType = helper.lookingType,
};
+ astTreeDelete(value);
AstTreeVariable *var =
setTypesFindVariable(metadata->member.name.begin,
diff --git a/src/compiler/lexer.c b/src/compiler/lexer.c
index c540395..517e650 100644
--- a/src/compiler/lexer.c
+++ b/src/compiler/lexer.c
@@ -99,6 +99,7 @@ const char *LEXER_TOKEN_STRINGS[] = {
"LEXER_TOKEN_KEYWORD_RETURN",
"LEXER_TOKEN_KEYWORD_PUTC",
+ "LEXER_TOKEN_KEYWORD_BREAK",
"LEXER_TOKEN_KEYWORD_COMPTIME",
"LEXER_TOKEN_SYMBOL_EOL",
@@ -170,7 +171,7 @@ static const char *LEXER_KEYWORD_STRINGS[] = {
"f32", "f64", "f128", "bool", "putc", "return",
"true", "false", "if", "else", "while", "comptime",
"null", "struct", "undefined", "code", "lazy", "namespace",
- "shape_shifter",
+ "shape_shifter", "break",
};
static const LexerToken LEXER_KEYWORD_TOKENS[] = {
LEXER_TOKEN_KEYWORD_TYPE,
@@ -205,6 +206,7 @@ static const LexerToken LEXER_KEYWORD_TOKENS[] = {
LEXER_TOKEN_KEYWORD_LAZY,
LEXER_TOKEN_KEYWORD_NAMESPACE,
LEXER_TOKEN_KEYWORD_SHAPE_SHIFTER,
+ LEXER_TOKEN_KEYWORD_BREAK,
};
static const size_t LEXER_KEYWORD_SIZE =
sizeof(LEXER_KEYWORD_TOKENS) / sizeof(*LEXER_KEYWORD_TOKENS);
@@ -518,6 +520,8 @@ lexerPushClear(LexerNodeArray *array, size_t *array_size, char const *iter,
case LEXER_TOKEN_BUILTIN_SMALLER_OR_EQUAL:
case LEXER_TOKEN_SYMBOL_CLOSE_BRACKET:
case LEXER_TOKEN_SYMBOL_OPEN_BRACKET:
+ case LEXER_TOKEN_KEYWORD_SHAPE_SHIFTER:
+ case LEXER_TOKEN_KEYWORD_BREAK:
if (*array_size == array->size) {
*array_size += 1 + *array_size / 2;
array->data =
diff --git a/src/compiler/lexer.h b/src/compiler/lexer.h
index 4286f20..641e7c8 100644
--- a/src/compiler/lexer.h
+++ b/src/compiler/lexer.h
@@ -6,7 +6,6 @@
typedef enum LexerToken {
LEXER_TOKEN_SYMBOL_CLOSE_CURLY_BRACKET,
-
LEXER_TOKEN_ORDER0 = LEXER_TOKEN_SYMBOL_CLOSE_CURLY_BRACKET,
LEXER_TOKEN_SYMBOL_CLOSE_PARENTHESIS,
@@ -112,6 +111,7 @@ typedef enum LexerToken {
LEXER_TOKEN_KEYWORD_RETURN,
LEXER_TOKEN_ORDER11 = LEXER_TOKEN_KEYWORD_RETURN,
LEXER_TOKEN_KEYWORD_PUTC,
+ LEXER_TOKEN_KEYWORD_BREAK,
LEXER_TOKEN_KEYWORD_COMPTIME,
LEXER_TOKEN_SYMBOL_EOL,
diff --git a/src/compiler/parser.c b/src/compiler/parser.c
index 1fd2e06..ebfd66f 100644
--- a/src/compiler/parser.c
+++ b/src/compiler/parser.c
@@ -60,6 +60,7 @@ const char *PARSER_TOKEN_STRINGS[] = {
"PARSER_TOKEN_TYPE_SHAPE_SHIFTER",
"PARSER_TOKEN_KEYWORD_PUTC",
+ "PARSER_TOKEN_KEYWORD_BREAK",
"PARSER_TOKEN_KEYWORD_RETURN",
"PARSER_TOKEN_KEYWORD_IF",
"PARSER_TOKEN_KEYWORD_WHILE",
@@ -1443,6 +1444,7 @@ ParserNode *parserFunctionCall(LexerNode *closing, LexerNode *begin,
if (beforeNode < begin || beforeNode->parserNode == NULL ||
(before = getUntilCommonParent(beforeNode->parserNode, parent)) == NULL ||
!isExpression(before)) {
+ printError(closing->str_begin, closing->str_end, "Bad function call");
UNREACHABLE;
}
diff --git a/src/compiler/parser.h b/src/compiler/parser.h
index a6af8bb..4a1b5ac 100644
--- a/src/compiler/parser.h
+++ b/src/compiler/parser.h
@@ -57,6 +57,7 @@ typedef enum ParserToken {
PARSER_TOKEN_TYPE_SHAPE_SHIFTER,
PARSER_TOKEN_KEYWORD_PUTC,
+ PARSER_TOKEN_KEYWORD_BREAK,
PARSER_TOKEN_KEYWORD_RETURN,
PARSER_TOKEN_KEYWORD_IF,
PARSER_TOKEN_KEYWORD_WHILE,