summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-04 05:17:22 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-04-04 05:17:22 +0330
commitf570c63542bc644d829aff8c470db2385a3c5180 (patch)
tree2ed885895510eab9bc8845d3e14b5e76c064f845 /src
parent5c0542111e67d60490c7e218b985d6c6b9eaf9f2 (diff)
add reassignable functions in function scopes (reassignable lambdas)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/ast-tree.c9
-rw-r--r--src/runner/runner.c2
2 files changed, 8 insertions, 3 deletions
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 331c7e7..77b93d6 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -886,7 +886,7 @@ AstTree *copyAstTreeBack(AstTree *tree, AstTreeVariables oldVariables[],
new_metadata->expressions = a404m_malloc(
new_metadata->expressions_size * sizeof(*new_metadata->expressions));
- size_t new_variables_size = variables_size + 1;
+ const size_t new_variables_size = variables_size + 1;
AstTreeVariables new_oldVariables[new_variables_size];
AstTreeVariables new_newVariables[new_variables_size];
for (size_t i = 0; i < variables_size; ++i) {
@@ -1554,12 +1554,17 @@ AstTree *astTreeParseTypeFunction(ParserNode *parserNode,
if (variable_metadata->name->token != PARSER_TOKEN_IDENTIFIER) {
printError(node_argument->str_begin, node_argument->str_end,
"Name must be identifier");
- UNREACHABLE;
+ return NULL;
}
argument.name_begin = variable_metadata->name->str_begin;
argument.name_end = variable_metadata->name->str_end;
argument.type = astTreeParse(variable_metadata->type, helper);
+ if (variable_metadata->value != NULL) {
+ printError(node_argument->str_begin, node_argument->str_end,
+ "Cannot have value in function type");
+ return NULL;
+ }
if (argument.type == NULL) {
return NULL;
}
diff --git a/src/runner/runner.c b/src/runner/runner.c
index f228846..12000ea 100644
--- a/src/runner/runner.c
+++ b/src/runner/runner.c
@@ -787,6 +787,7 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet) {
case AST_TREE_TOKEN_VALUE_BOOL:
case AST_TREE_TOKEN_VALUE_FLOAT:
case AST_TREE_TOKEN_OPERATOR_POINTER:
+ case AST_TREE_TOKEN_FUNCTION:
return copyAstTree(expr);
case AST_TREE_TOKEN_OPERATOR_ADDRESS: {
AstTreeSingleChild *metadata = expr->metadata;
@@ -811,7 +812,6 @@ AstTree *runExpression(AstTree *expr, bool *shouldRet) {
AstTreeVariable *variable = expr->metadata;
return copyAstTree(variable->value);
}
- case AST_TREE_TOKEN_FUNCTION:
case AST_TREE_TOKEN_NONE:
}
UNREACHABLE;