diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | code/main.felan | 7 | ||||
-rw-r--r-- | src/compiler/ast-tree.c | 9 | ||||
-rw-r--r-- | src/runner/runner.c | 2 |
4 files changed, 15 insertions, 7 deletions
@@ -18,9 +18,9 @@ NC := \033[0m INC_DIRS := $(SRC_DIR) INC_FLAGS := $(addprefix -I,$(INC_DIRS)) -# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -O3 +CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -O3 # CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -Oz -CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -g +# CFLAGS := $(INC_FLAGS) -Wall -Wextra -std=gnu23 -g EXEC_FILE := $(BUILD_DIR)/$(PROJECT_NAME) diff --git a/code/main.felan b/code/main.felan index ce11587..e8e3254 100644 --- a/code/main.felan +++ b/code/main.felan @@ -7,10 +7,13 @@ double :: f64; main :: () -> void { a :u64= 2; - f :: (c:u64,b:u64)->void{ + f := (c:u64,b:u64)->void{ print_u64 c-b+a; }; - foo(f); + f = (c:u64,b:u64)->void{ + print_u64 c*b; + }; + foo(fun = f); }; foo :: (fun:(b:u64,u64)->void)->void{ 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; |