From 8f0baa7d6835efb13f15ae794e0252a12f1f487f Mon Sep 17 00:00:00 2001 From: siwon Date: Sun, 4 Feb 2024 18:06:14 +0900 Subject: [PATCH] delete child codes_size in ast_func --- src/Parser/Ast/ast.c | 2 +- src/Parser/Ast/ast.h | 10 ++++++++-- src/Parser/parser.c | 1 + src/Parser/parser.h | 1 + src/Parser/parser_id.c | 30 ++++++++++++++---------------- src/Visitor/visitor.c | 3 +-- src/develop_mode.c | 6 +++--- src/env.c | 1 - src/env.h | 3 +-- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/Parser/Ast/ast.c b/src/Parser/Ast/ast.c index cced5c0..cc5fb00 100644 --- a/src/Parser/Ast/ast.c +++ b/src/Parser/Ast/ast.c @@ -98,8 +98,8 @@ AST_function* init_ast_function(char* name, size_t length) ast_function->name = name; ast_function->name_length = length; ast_function->args_size = 0; - ast_function->codes_size = 0; ast_function->args = malloc(sizeof(AST)); + ast_function->codes = malloc(sizeof(AST)); ast_function->type = AST_FUNCTION_TYPE_NULL; ast_function->ast_type = AST_FUNCTION_NULL; diff --git a/src/Parser/Ast/ast.h b/src/Parser/Ast/ast.h index 26fc28d..a967ed5 100644 --- a/src/Parser/Ast/ast.h +++ b/src/Parser/Ast/ast.h @@ -53,10 +53,14 @@ typedef struct ast_function_t AST_FUNCTION_TYPE_NULL = 99 } type; - struct ast_t** codes; // I wonder + struct ast_t* codes; // I wonder // I should use a Lexer struct // or AST struct... or Token... - size_t codes_size; + // + // When type is AST_FUNCTION_TYPE_SINGLE... + // -> codes->type is value... + // When type is AST_FUNCTION_TYPE_DEFAULT... + // -> codes->type is compound... } AST_function; typedef struct ast_string_t @@ -69,6 +73,8 @@ typedef struct ast_string_t typedef struct ast_int_t { int value; // I should not use a pointer...?? + // ToDo... + // Create a new type that unlimited length } AST_int; typedef struct ast_float_t diff --git a/src/Parser/parser.c b/src/Parser/parser.c index bfd2748..fd41287 100644 --- a/src/Parser/parser.c +++ b/src/Parser/parser.c @@ -11,6 +11,7 @@ GET_COMPOUND_ENV* init_get_compound_env() GET_COMPOUND_ENV* new_env = malloc(sizeof(GET_COMPOUND_ENV)); new_env->is_in_parentheses = false; new_env->is_usefull_comma = false; + new_env->is_usefull_end = (void*) 0; return new_env; } diff --git a/src/Parser/parser.h b/src/Parser/parser.h index b5bf771..9c702ce 100644 --- a/src/Parser/parser.h +++ b/src/Parser/parser.h @@ -10,6 +10,7 @@ typedef struct get_compound_env_t { bool is_in_parentheses; bool is_usefull_comma; + char* is_usefull_end; } GET_COMPOUND_ENV; Parser* init_parser(Lexer* lexer); diff --git a/src/Parser/parser_id.c b/src/Parser/parser_id.c index 7a6e512..ab9a361 100644 --- a/src/Parser/parser_id.c +++ b/src/Parser/parser_id.c @@ -109,11 +109,12 @@ AST* parser_parse_function(Parser* parser, AST* ast, Token* last_token, if (value_node) { - new_ast_node->value.function_v->type = AST_FUNCTION_TYPE_SINGLE; + AST_function* new_ast_function = new_ast_node->value.function_v; + new_ast_function->type = AST_FUNCTION_TYPE_SINGLE; - new_ast_node->value.function_v->codes_size = 1; - new_ast_node->value.function_v->codes = malloc(sizeof(struct AST*)); - new_ast_node->value.function_v->codes[0] = value_node; + new_ast_function->codes = malloc(sizeof(AST)); + + new_ast_function->codes = value_node; } else { @@ -125,19 +126,16 @@ AST* parser_parse_function(Parser* parser, AST* ast, Token* last_token, AST_function* new_ast_function = new_ast_node->value.function_v; printf("!@#$@#!@$@#$#@$#@1223 %s\n", code); // For test.... - new_ast_function->codes_size += 3; new_ast_function->codes = - realloc(new_ast_function->codes, - new_ast_function->codes_size * sizeof(AST*)); - for (int i = 0; i < 3; i ++) - { - printf("@@@\n"); - GET_COMPOUND_ENV* get_function_code_env - = init_get_compound_env(); - printf("222 %s\n", parser->token->value); - new_ast_function->codes[i] = - parser_get_compound(parser, get_function_code_env); - } + realloc(new_ast_function->codes, sizeof(AST)); + + printf("@@@\n"); + GET_COMPOUND_ENV* get_function_code_env + = init_get_compound_env(); + printf("222 %s\n", parser->token->value); + new_ast_function->codes = + parser_get_compound(parser, get_function_code_env); + exit(1); // ToDo } diff --git a/src/Visitor/visitor.c b/src/Visitor/visitor.c index b195faa..e452985 100644 --- a/src/Visitor/visitor.c +++ b/src/Visitor/visitor.c @@ -404,7 +404,7 @@ AST_value_stack* visitor_get_value_from_function switch (env_function->type) { case ENV_FUNCTION_TYPE_SINGLE: - return visitor_get_value(new_envs, env_function->codes[0]->value.value_v); + return visitor_get_value(new_envs, env_function->codes->value.value_v); break; } @@ -910,7 +910,6 @@ Env_function* get_deep_copy_env_funtion new_env_funtion->args = env_function->args; new_env_funtion->args_size = env_function->args_size; new_env_funtion->codes = env_function->codes; - new_env_funtion->codes_size = env_function->codes_size; new_env_funtion->type = env_function->type; new_env_funtion->next = env_function->next; diff --git a/src/develop_mode.c b/src/develop_mode.c index 84af3e0..aa5e5b0 100644 --- a/src/develop_mode.c +++ b/src/develop_mode.c @@ -22,11 +22,11 @@ void print_function(AST_function* checked_function) break; } } - if (checked_function->codes_size) + if (checked_function->codes) { printf(" ->code:\n"); - if (checked_function->codes_size == 1) - print_value(checked_function->codes[0]); + if (checked_function->type == AST_FUNCTION_TYPE_SINGLE) + print_value(checked_function->codes); } } diff --git a/src/env.c b/src/env.c index a6926da..3150bac 100644 --- a/src/env.c +++ b/src/env.c @@ -12,7 +12,6 @@ Env_function* get_env_function_from_ast_function env_function->args_size = ast_function->args_size; env_function->codes = ast_function->codes; - env_function->codes_size = ast_function->codes_size; env_function->type = ast_function->type; diff --git a/src/env.h b/src/env.h index 0481d29..5424302 100644 --- a/src/env.h +++ b/src/env.h @@ -12,8 +12,7 @@ typedef struct env_function_t struct ast_t** args; int args_size; - struct ast_t** codes; - size_t codes_size; + struct ast_t* codes; enum {