Skip to content

Commit

Permalink
delete child codes_size in ast_func
Browse files Browse the repository at this point in the history
  • Loading branch information
ysw421 committed Feb 4, 2024
1 parent bebed6a commit 8f0baa7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Parser/Ast/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 8 additions & 2 deletions src/Parser/Ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 14 additions & 16 deletions src/Parser/parser_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/Visitor/visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/develop_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 8f0baa7

Please sign in to comment.